mirror of
https://github.com/django/django.git
synced 2025-07-18 16:49:13 +00:00
[1.0.X] Fixed #11302 -- Avoid unnesscary (and possibly unintentional) queries/results from generic inline formsets.
When an instance with no primary key value is passed in to a generic inline formset we ensure no queries/results occur. Thanks Alex Gaynor. Backport of [10981] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10982 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ea5e5a20a9
commit
bbe034a74f
@ -317,7 +317,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
|
||||
def get_queryset(self):
|
||||
# Avoid a circular import.
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
if self.instance is None:
|
||||
if self.instance is None or self.instance.pk is None:
|
||||
return self.model._default_manager.none()
|
||||
return self.model._default_manager.filter(**{
|
||||
self.ct_field.name: ContentType.objects.get_for_model(self.instance),
|
||||
|
Loading…
x
Reference in New Issue
Block a user