You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My guess at a solution at this moment in time is to just add _prefetch_related_lookups = () to FakeQuerySet.__init__(), but I'm not 100% sure that's the right answer.
Context
I'm creating a QuestionPage that has multiple choice questions on it. QuestionPages have many Questions which in turn have many Answers. I generate a Form to use on the page and that works fine, but it breaks when I'm previewing the page with the following error:
'FakeQuerySet' object has no attribute '_prefetch_related_lookups'
Here's a sketch:
classQuestionPage(Page):
...
content_panels= [
...,
InlinePanel('questions'),
]
classQuestion(ClusterableModel):
question_page=ParentalKey(QuestionPage, related_name='questions')
...
panels= [
InlinePanel('answers'),
...
]
classAnswer(models.Model):
question=ParentalKey(Question, related_name="answers")
...
classQuestionPageForm(forms.Form):
def__init__(self, *args, question_page: QuestionPage, **kwargs):
super().__init__(*args, **kwargs)
forquestioninquestion_page.questions.all():
self.fields[f"question-{question.pk}"] =forms.ModelChoiceField(
queryset=question.answers.all(), # This seems to be what causes the AttributeError during previews
)
The text was updated successfully, but these errors were encountered:
While working around this in my project, I found that we're missing FakeQuerySet.iterator() too. Here's my hack du jour that seems to be working nicely for the time being:
Hi, I just wanted to say that I got the same error, and the proposal by bcdickinson seems to be a good one!
I am using the latest version of Wagtail 2.16.2, Django 3.2.13 and getting this error when previewing certain wagtailpages which contain ClusterableModels and ParentalManyToManyFields:
'FakeQuerySet' object has no attribute '_prefetch_related_lookups'
Bug
FakeQuerySet
doesn't have a_prefetch_related_lookups
member, so Django throws an attribute error when using it as thequeryset
kwarg to aModelChoiceField
, here: https://github.com/django/django/blob/3.2.12/django/forms/models.py#L1167My guess at a solution at this moment in time is to just add
_prefetch_related_lookups = ()
toFakeQuerySet.__init__()
, but I'm not 100% sure that's the right answer.Context
I'm creating a
QuestionPage
that has multiple choice questions on it.QuestionPage
s have manyQuestion
s which in turn have manyAnswers
. I generate aForm
to use on the page and that works fine, but it breaks when I'm previewing the page with the following error:Here's a sketch:
The text was updated successfully, but these errors were encountered: