Skip to main content

Command Palette

Search for a command to run...

How to register a model twice in the Django admin?

Register a model twice in the Django admin

Published
1 min read
How to register a model twice in the Django admin?

Note: If you want to read the blog series on Django Admin customization, then click here.

Suppose you have a Book model as given below.

# app_name/models.py

class Book(models.Model):
    ...
    title = models.CharField(max_length=150)
    is_active = models.BooleanField(default=True)

You might have tried registering a model twice by writing the same code twice, but it gave an error, there is a workaround to register a model twice, you just have to create a proxy model of the same model that you want to register, in this example we are going to create a proxy model of Book and then re-registered it.

# app_name/admin.py

from django.contrib import admin
from django.db import models
from app_name.models import Book

class BookProxy(Book):
    class Meta:
        proxy = True

@admin.register(Book) # First registration of a Book model in Django admin
class BookAdmin(admin.ModelAdmin):
    verbose_name = "Books"

@admin.register(BookProxy) # Second registration of a Book model in Django admin
class BookProxyAdmin(admin.ModelAdmin):
    verbose_name = "New Books"

Any thoughts? Write it down in the comments.

For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.

Django admin tips and tricks

Part 2 of 14

Django provides a great Admin panel rich in features and highly customizable, in this series of blogs we will be introduced to all such possible customizations and more.

Up next

How to change the number of objects (rows) to show in the Django admin change list view?

Change the number of objects (rows) to show in the Django admin change list view