-
Notifications
You must be signed in to change notification settings - Fork 468
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
'list' object has no attribute 'queryset' #1320
Comments
I'm sure this isn't a priority and/or everyone is very busy, but is it possible to get some help on this? I am trying to use this module for a project with a tight deadline. I appreciate any help you all can provide! |
I ended up working around this by switching to ListSelect2 instead of the ModelSelect2. Would be nice to know why this didn't work, though. |
I assume you're running into this exception? (please, always include a stack trace if you have one) [...] in filter_choices_to_render
self.choices.queryset = self.choices.queryset.filter(
AttributeError: 'list' object has no attribute 'queryset' The formfield sets the choices on the widget when the formfield is instantiated: def _set_queryset(self, queryset):
self._queryset = None if queryset is None else queryset.all()
self.widget.choices = self.choices But you override the widget after and never set the choices - so this widget has the default value for So either explicitly set the choices on the widget after it has been created in your |
Thanks, so much @Actionb - not sure how I missed that difference. I blame being a newbie and also seeing another issue with it in the view that I lost context when copying/pasting. Checking now, I am actually forwarding 2 values so that I can create objects, including a kwarg. How would I do this in the model meta without access to self?
One final thing - I am actually wondering what do i gain/lose by using the ModelSelect vs ListSelect if I have it working now? |
I don't quite follow what you are trying to do with the limited information you have given - and I don't think the issue tracker is the right place to ask for implementation advice like that (try asking on stackoverflow).
I think (I'm not a dal developer) the choice of widget only matters for the initial rendering of the form. After that, the choices are served by your autocomplete view. That's why the choice of what widget class to use doesn't seem to matter once the form is up and rendered. It comes down to what type of object In the dal workflow, |
I encounter the same issue, is that because of some logic conflicts with django-filter? |
What do you mean by conflict? This issue comes from overriding the widget of a ModelChoiceField formfield after the field has already been instantiated. The ModelChoiceField sets the widget's choices only once. If you override the widget after that, you have to set the choices yourself. Or use the form's meta options to override the widget for a given formfield, as described by the Django docs. |
Tried with pypi latest version and latest dev git install. I have seen this error a few times from previous searches (such as #790 , so maybe it came back?
Simple model called FundraisingTeam with a team name, that I reference as a ForeignKey field here:
urls.py
note: I am able to call the url and retrieve the JSON data
Then, in my view the query (removed the filter to just double check):
And finally, I override the get_form() in my createview to set the widget:
My example seems pretty vanilla so far from the tutorial, so not sure what's happening. Latest released Django 4.1.
Appreciate any help!
The text was updated successfully, but these errors were encountered: