-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Docs are incorrect about filtering by a Model[Multiple]ChoiceFilter #1661
Comments
Thank you for your issue, I just bumped in the same issue, this also solved it for me. |
Created a simple pull request fixing the example. |
That is strange. I stumbled across this issue by chance, but I have to add the suffix to the This works in my case: modalities = django_filters.ModelMultipleChoiceFilter(
queryset=Modality.objects.order_by("code"),
field_name="modalities__code",
to_field_name="code",
) But this doesn't: modalities = django_filters.ModelMultipleChoiceFilter(
queryset=Modality.objects.order_by("code"),
field_name="modalities",
to_field_name="code",
) (Error: |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
In the current documentation we have this following example:
However, it's not necessary to set the filter
field_name
to point to theuuid
field. The only needed step is to add theto_field_name
and point to the correct relationship.In my case I've tried doing what is described above, but this fails here:
location: django_filters.filters.ChoiceFilter#158
The reason it fails is that
value
in this particular code location is already the related model. If you userelated_model__uuid
as the field name, the lookup becomes:related_model__uuid
and value is the model itself. Django fails when it tries to convert the related model instance to an UUID.The only necessary change seems to be changing the
field_name
to remove the extra__uuid
.The text was updated successfully, but these errors were encountered: