Introduction
The admin interface helps you manage your website data easily without writing extra code. It saves time and makes updating content simple.
The admin interface helps you manage your website data easily without writing extra code. It saves time and makes updating content simple.
from django.contrib import admin from .models import YourModel @admin.register(YourModel) class YourModelAdmin(admin.ModelAdmin): list_display = ('field1', 'field2')
from django.contrib import admin from .models import Book @admin.register(Book) class BookAdmin(admin.ModelAdmin): list_display = ('title', 'author', 'published_date')
from django.contrib import admin from .models import Author admin.site.register(Author)
This code creates a Product model and registers it with the admin interface. The admin will show product name and price in the list view.
from django.contrib import admin from django.db import models class Product(models.Model): name = models.CharField(max_length=100) price = models.DecimalField(max_digits=6, decimal_places=2) @admin.register(Product) class ProductAdmin(admin.ModelAdmin): list_display = ('name', 'price')
The admin interface is only for trusted users; do not expose it publicly without protection.
You can customize the admin interface a lot to fit your needs without extra frontend work.
The admin interface lets you manage website data easily.
It saves time by avoiding custom management pages.
It is customizable and secure for trusted users.
Book with the Django admin?admin.site.register(ModelName).admin.py:
from django.contrib import admin from .models import Product admin.site.register(Product)What will happen when you run the Django development server and visit
/admin/?admin.py:
from django.contrib import admin from .models import Author admin.register(Author)But the Author model does not appear in the admin site. What is the problem?
admin.register(Author), which is incorrect syntax.admin.site.register(Author) to register models.admin.register instead of admin.site.register. -> Option ACustomer model. Which approach best uses the admin interface's power?admin.ModelAdmin with desired options.admin.site.register(Model, CustomAdmin) to apply customizations.Pass the test and this pattern moves unknown