Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9076 -- Changed BaseInlineFormSet to not override Base…

…ModelFormSet's get_queryset method. BaseInlineFormSet's method did not include a couple of fixes/enhancements that were made to the parent's method, resulting in excessive queries (some of which can return bad data due to #9006) for admin pages with inlines. Thanks bthomas for the initial patch.

r9440 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 385f2fe2b5b5589c443d5db928fda51482d59fce 1 parent dbe18ce
Karen Tracey authored November 14, 2008

Showing 1 changed file with 3 additions and 9 deletions. Show diff stats Hide diff stats

  1. 12  django/forms/models.py
12  django/forms/models.py
@@ -463,7 +463,9 @@ def __init__(self, data=None, files=None, instance=None,
463 463
         self.save_as_new = save_as_new
464 464
         # is there a better way to get the object descriptor?
465 465
         self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()
466  
-        super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name)
  466
+        qs = self.model._default_manager.filter(**{self.fk.name: self.instance})
  467
+        super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name,
  468
+                                                queryset=qs)
467 469
 
468 470
     def _construct_forms(self):
469 471
         if self.save_as_new:
@@ -479,14 +481,6 @@ def _construct_form(self, i, **kwargs):
479 481
             form.data[form.add_prefix(self._pk_field.name)] = None
480 482
         return form
481 483
     
482  
-    def get_queryset(self):
483  
-        """
484  
-        Returns this FormSet's queryset, but restricted to children of
485  
-        self.instance
486  
-        """
487  
-        kwargs = {self.fk.name: self.instance}
488  
-        return self.model._default_manager.filter(**kwargs)
489  
-
490 484
     def save_new(self, form, commit=True):
491 485
         kwargs = {self.fk.get_attname(): self.instance.pk}
492 486
         new_obj = self.model(**kwargs)

0 notes on commit 385f2fe

Please sign in to comment.
Something went wrong with that request. Please try again.