Opened 4 years ago
Last modified 2 years ago
#32619 closed Bug
'ManyToOneRel' object has no attribute 'get_limit_choices_to' — at Initial Version
Reported by: | Seb G | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Summary
The newly introduced feature in Django 3.2
ModelAdmin.autocomplete_fields now respects ForeignKey.to_field and ForeignKey.limit_choices_to when searching a related model)
Triggers a bug when used on ManyToOneRel
:
Traceback (most recent call last): File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 250, in wrapper return self.admin_view(view, cacheable)(*args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 232, in inner return view(request, *args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 417, in autocomplete_view return AutocompleteJsonView.as_view(admin_site=self)(request) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/contrib/admin/views/autocomplete.py", line 25, in get self.object_list = self.get_queryset() File "/home/me/.virtualenvs/myproject/lib/python3.7/site-packages/django/contrib/admin/views/autocomplete.py", line 42, in get_queryset qs = qs.complex_filter(self.source_field.get_limit_choices_to()) AttributeError: 'ManyToOneRel' object has no attribute 'get_limit_choices_to'
Steps to reproduce
Use the following model:
class Ticket(models.Model) user = models.ForeignKey("users.User, on_delete=models.PROTECT, verbose_name=_("user"))
And the following admin:
@admin.register(Ticket) class TicketAdmin(admin.ModelAdmin): autocomplete_fields = ("user",)
Note:
See TracTickets
for help on using tickets.