Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 878
UtkarshPramodGupta Avatar asked Oct 16 '25 03:10

UtkarshPramodGupta


1 Answers

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.

like image 161
Alasdair Avatar answered Oct 18 '25 19:10

Alasdair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!