Filter for admin site, How does FilterSpec, RelatedFilterSpec, ChoicesFilterSpec ie work?

Yesterday I ran into a problem when I was trying to create a special filter for my admin site in Django.

I have 3 models:



class ShopInfo(models.Model):
    name = models.CharField(max_length=200)


class Keyword(models.Model):
    keyword1 = models.CharField(max_length=4096,  blank=True)
    product = models.ManyToManyField(Products)


class Products(models.Model):
    shop = models.ForeignKey(ShopInfo)

code>

In the "Admin" section of the keyword editing page, I want to create a filter for keywords by shopping. In other words, I want to see the full list of stores in the filter list to the right of the page, when you click on it, we will select the keywords belonging to this store.

+3
source share
1 answer

FilterSpec. django list_filter ModelAdmin. :

class KeywordAdmin(admin.ModelAdmin):
    list_filter = ['product__shop']
+1

All Articles