Registering models with the Django Admin


Django tip:

Instead of using admin.site.register for registering models with the Django admin, you can use a decorator.

https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#the-register-decorator

👇

## option 1 ##

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title')

admin.site.register(Author, AuthorAdmin)


## option 2 ##

# you can use a decorator instead
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title')