UtkarshPramodGupta
UtkarshPramodGupta

Reputation: 8152

Use of "class Meta" in Django's admin.py

Can someone please explain why we use nested meta class here? I understood why we use Meta class in model.py from "https://docs.djangoproject.com/en/1.9/topics/db/models/#meta-options" but I can't understand why we use it in admin.py and forms.py classes as shown below:

from django.contrib import admin

# Register your models here.
from .models import SignUp

class SignUpAdmin(admin.ModelAdmin):
    list_display = ["__unicode__", "timestamp", "updated"]
    class Meta:
        model = SignUp

admin.site.register(SignUp, SignUpAdmin)

Upvotes: 4

Views: 2585

Answers (1)

Alasdair
Alasdair

Reputation: 308799

Your SignUpAdmin.Meta class will have no effect. The ModelAdmin does not use a Meta class.

You don't have to specify the model for a ModelAdmin class, because you specify the model when registering it. In fact, you can register the same admin class multiple times with different models.

admin.site.register(SignUp, SignUpAdmin)
admin.site.register(MyOtherModel, SignUpAdmin)

The Meta class for model forms has many possible options. See the docs for more info.

Upvotes: 4

Related Questions