[Django]-Django: show useful database data in admin interface?

4👍

✅

Just as it says in the documentation, your model’s ModelAdmin describes how the admin section will represent your model. It does need to be somewhat in sync with the actual model, it doesn’t make sense for you to display fields that aren’t present on your model, etc. You seem interested in the changelist view, which has numerous customization options (all described in the documentation, and in the tutorial). A simple start might be:

from django.contrib import admin

class CommentAdmin(admin.ModelAdmin):
    # define which columns displayed in changelist
    list_display = ('text', 'name', 'date', 'article')
    # add filtering by date
    list_filter = ('date',)
    # add search field 
    search_fields = ['text', 'article']

admin.site.register(Comment, CommentAdmin)

There are a lot of options for customization, as always refer to the docs! Finally, you could certainly use it in lieu of PHPMyAdmin, it’s very easy to setup admin for browsing, modifying object, etc, how much use you get out of it is up to you.

5👍

The admin turns your object into a string so just put a def __str__ or def __unicode__

(As @Mandax has reminded me the docs recommend to define __unicode__ only.)

def __unicode__(self);
    return u"%s (%s): %s" % (self.article, self.date, self.name)

Leave a comment