I am testing the new @admin.register
decorator that is a new feature from Django 1.7.
I am currently using Django 1.8.2 and Python 3 and happened me the following situation in relation to @admin.register
decorator:
In my admin.py
file I have:
from django.contrib import admin
from .models import Track
# Register your models here.
@admin.register(Track)
class TrackAdmin(admin.ModelAdmin):
list_display = ('title','artist')
And when I try http://localhost:8000/admin/
I get the following output in my browser:
Now, When I use the admin.site.register(Track,TrackAdmin)
that is the traditional way of register models and classes in the django admin, happened me the same
from django.contrib import admin
from .models import Track
# Register your models here.
class TrackAdmin(admin.ModelAdmin):
list_display = ('title','artist')
admin.site.register(Track,TrackAdmin)
How to can I use the @admin.register decorator for record together classes? (Track and TrackAdmin)
Thanks a lot. :)
fieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a “section” of the form.)
Django's Admin is amazing. A built-in and fully functional interface that quickly gets in and allows data entry is priceless. Developers can focus on building additional functionality instead of creating dummy interfaces to interact with the database.
Please see following reference: https://docs.djangoproject.com/en/1.8/ref/contrib/admin/
Place your decorator @admin.register(Track) before your class as "sugar" or wrapper for it.
from django.contrib import admin
from .models import Track
# Register your models here
@admin.register(Track)
class TrackAdmin(admin.ModelAdmin):
list_display = ('title','artist')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With