When you created your own Models in a app, they still need to be registered in order to become available in the admin pages.
This is done in the admin
submodule. If your app was created using manage.py startapp
, an admin.py
file should already lay in you app module. Otherwise create it.
#myapp/admin.py
from django.contrib import admin
from myproject.myapp.models import MyModel
admin.site.register(MyModel)
All options are defined on the ModelAdmin subclass. some options:
class MyCustomAdmin(admin.ModelAdmin):
list_display = ('name','age','email') # fields to display in the listing
empty_value_display = '-empty-' # display value when empty
list_filter = ('name', 'company') # enable results filtering
list_per_page = 25 # number of items per page
ordering = ['-pub_date', 'name'] # Default results ordering
# and register it
admin.site.register(MyModel, MyCustomAdmin)
A more concise way to register a model is to use the admin.register
decorator:
@admin.register(MyModel)
class MyCustomAdmin(admin.ModelAdmin)
...