Hi everyone,
I have two dropdowns on the create/ edit pages of an object in the admin site. I need to filter the second dropdown's contents based on the selection in the first (as a user-friendliness measure). I have tried the recommended use of formfield_or_foreignkey with no progress. The difference is that the following example uses the request object's user, whereas I need a way to obtain and use the first dropdown's selected item.
I also noticed that the form does not post when a selection is made.
class MyModelAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "car":
kwargs["queryset"] = Car.objects.filter(owner=request.user)
return db_field.formfield(**kwargs)
return super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
Any ideas?
--
Regards,
Sithembewena Lloyd Dube