Regression in ability to override queryset on BaseModelAdmin.formfield_for_foreignkey
|Reported by:||guido@…||Owned by:||claudep|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
After upgrading to Django 1.6, i have a problem with formfield_for_foreignkey.
This is my code:
class MatchScoreIntInline(admin.TabularInline): model = MatchScoreInt def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "partial": kwargs["queryset"] = Partial.objects.filter(...my filters...) if db_field.name == "subscriber": kwargs["queryset"] = Subscriber.objects.filter(...my filters...) return super(MatchScoreIntInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
The super method override my kwargsqueryset?, only for "subscriber" db_field because of this code:
queryset = self.get_field_queryset(db, db_field, request) if queryset is not None: kwargs['queryset'] = queryset
get_field_queryset method return a new ordered queryset if the related admin has "ordering" parameter.
So I removed the ordering parameter from my ModelAdmin and everything works fine.
Why I cannot override the queryset with formfield_for_foreignkey method when the related_admin has "ordering" parameter set?
Change History (4)
comment:1 Changed 16 months ago by timo
- Component changed from Uncategorized to contrib.admin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Severity changed from Normal to Release blocker
- Summary changed from formfield_for_foreignkey to Regression in ability to override queryset on BaseModelAdmin.formfield_for_foreignkey
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Uncategorized to Bug
comment:2 Changed 16 months ago by claudep
- Owner changed from nobody to claudep
- Status changed from new to assigned
comment:3 Changed 16 months ago by Claude Paroz <claude@…>
- Resolution set to fixed
- Status changed from assigned to closed