Answer the question
In order to leave comments, you need to log in
How to filter list for ForeignKey in admin panel?
Hello, I really need your help please, I'm new to Django. How do I filter the list in the admin for ForeignKey. Based on this example
class NewsAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "category":
kwargs["queryset"] = Category.objects.filter(some_parameter='не знаю что вставлять')
return super(NewsAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
Answer the question
In order to leave comments, you need to log in
Figured it out myself, great library django-autocomplete-light
Documentation, on my question
https://django-autocomplete-light.readthedocs.io/e...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question