Changes between Initial Version and Version 1 of Ticket #33950


Ignore:
Timestamp:
Aug 23, 2022, 5:08:22 AM (2 years ago)
Author:
Vincent Lefoulon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33950 – Description

    initial v1  
    33I have these three models:
    44
    5 ```
     5{{{
    66class Place(models.Model):
    77    name = models.CharField(max_length=255)
     
    1414    visit = models.ForeignKey(Visit, on_delete=models.CASCADE, related_name="documents")
    1515    file = models.FileField()
    16 ```
     16}}}
    1717
    1818A form to edit a visit:
    1919
    20 ```
     20{{{
    2121class VisitForm(forms.ModelForm):
    2222    class Meta:
     
    3131            required=False,
    3232        )
    33 ```
     33}}}
    3434
    3535And a generic view for the places:
    3636
    37 ```
     37{{{
    3838class PlaceView(DetailView):
    3939    queryset = Place.objects.prefetch_related("visits__documents")
     
    4949    def post(self, request, *args, **kwargs):
    5050        // Handle the form
    51 ```
     51}}}
    5252
    53 Despite the `prefetch_related("visits__documents")` call in my view, `ModelMultipleChoiceField()` doesn't detect that the documents of the visit (i.e. the form instance) are already fetched because `visit.documents.all()._prefetch_related_lookups` is null: https://github.com/django/django/blob/stable/3.2.x/django/forms/models.py#L1167
     53Despite the {{{prefetch_related("visits__documents")}}} call in my view, {{{ModelMultipleChoiceField()}}} doesn't detect that the documents of the visit (i.e. the form instance) are already fetched because {{{visit.documents.all()._prefetch_related_lookups}}} is null: https://github.com/django/django/blob/stable/3.2.x/django/forms/models.py#L1167
    5454
    55 So is in the view: `self.object.visits.all()._prefetch_related_lookups` is null as well.
     55So is in the view: {{{self.object.visits.all()._prefetch_related_lookups}}} is null as well.
    5656
    5757Many thanks!
Back to Top