I want django to only show related fields in the filters when an item is filtered.
For example, if I choose the brand "XYZ", it will only show options in the filter that contain "XYZ" brand.
My code below is taken from another question here- but it doesn't work. I keep getting a "NotRelationField" error (http://dpaste.com/23Y8ZE3).
Admin.py---
from django.contrib.admin.filters import RelatedOnlyFieldListFilter
# Some SimpleListFilter filters
class ProductAdmin(admin.ModelAdmin):
actions = ['tag_Active_Wear', 'tag_Trending',]
list_filter = (
('brand', RelatedOnlyFieldListFilter),
)
admin_order_field = ('price',)
# Some querysets for the actions
admin.site.register(Product, ProductAdmin)
Models.py----
class Product(models.Model):
name = models.CharField ("Name", max_length=400)
store = models.ForeignKey(Store)
brand = models.CharField("Brand", max_length=200, blank=True)
category = models.ManyToManyField(Category, blank=True)
def __unicode__(self):
return self.name
it should be store
instead of brand
, because brand
is not a RelatedField
list_filter = (
('store', RelatedOnlyFieldListFilter),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With