-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoOneToOneField breaks Django admin lookups #86
Comments
Thank you for your bug report. Unfortunately, I inherited this code and am not very familiar with this field. The code above seems to be a check for filtering on values on the "remote" model that also exist on the "local" model. As the comment says, you can filter on |
Which makes sense for PKs, but doesn't for more complicated lookups, right? So if this code is to blame, and not the field itself, I wonder how the condition should look like then? |
I would think so. Unfortunately I'm not sure how you could work around this... Is it excluded because is_relation is not set? Then mayber we need to set that to True? |
No, is_relation == True. The problem is with the last section: |
Oh, hmm. In that case, I'm not sure, I'd have to trace more of the code to figure it out... |
Imagine a lookup
model_a__model_b__field_c
added to aModelAdmin.list_filters
, which employsAutoOneToOneField
as a relationship field betweenmodel_a
andmodel_b
.Method
lookup_allowed
would return false once you try to use it. This is where it goes wrong: https://github.com/django/django/blame/4420761ea9457d386b2000cf9df5b2f6f88f8f91/django/contrib/admin/options.py#L382While debugging I can see that contents of
.target_fields
is(<annoying.fields.AutoOneToOneField: model_b>,)
at the moment of second iteration, that's what results inFalse
for this whole condition here.Thus the field is being erroneously excluded from
relation_parts
list within the method which later leads toclean_lookup
becomingmodel_a__field_c
instead of its correct form.Even with these comments I don't fully understand the purpose of this code and what's expected from the field in this case. List of
.target_fields
should be empty? Is that universally correct or just within this code?Could it be that the bug is within
Django
and notAnnoying
code? Any ideas how to solve it?P.S. This might be very confusing. Let me know if any clarification is needed.
The text was updated successfully, but these errors were encountered: