[Django]-Django Group Permissions-like Field

4👍

The given image is a ManyToMany field registered on the admin as filter_horizontal

for an Author model described below,

class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)

class Book(models.Model):
    title = models.CharField(max_length=255)
    author = models.ManyToManyField(Author)

You can make the author like what shown in the image by registering it as

class BookAdmin(admin.ModelAdmin):
    filter_horizontal = ('authors',)

admin.site.register(Book, BookAdmin)

filter_horizontal = ('authors',) on the BookAdmin will create the author as shown below.

enter image description here

Leave a comment