MorganFreeFarm
MorganFreeFarm

Reputation: 3733

Django Admin how to add filter menu like basic UserModel:

This is how looks template of Django Admin Model:

strong text

This is model which I created:

class ProfileUser(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    profile_image = models.URLField()
    is_qualified = models.BooleanField(default=False)

How can I create same filter menu ? for is_qualified ?

Upvotes: 2

Views: 33

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476594

You can specify this in the list_filter attribute [Django-doc] of the ModelAdmin you make for your model:

from django.contrib import admin
from app.models import ProfileUser

class ProfileUserAdmin(admin.ModelAdmin):
    list_filter = ('is_qualified',)

admin.site.register(ProfileUser, ProfileUserAdmin)

It is however advisable only to use this for fields with a limited number of options (a BooleanField of course is a good candidate for this).

Upvotes: 1

Related Questions