Ticket #9076: inline_queryset.diff
File inline_queryset.diff, 1.7 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
447 447 class BaseInlineFormSet(BaseModelFormSet): 448 448 """A formset for child objects related to a parent.""" 449 449 def __init__(self, data=None, files=None, instance=None, 450 save_as_new=False, prefix=None ):450 save_as_new=False, prefix=None, queryset=None): 451 451 from django.db.models.fields.related import RelatedObject 452 452 self.instance = instance 453 453 self.save_as_new = save_as_new 454 454 # is there a better way to get the object descriptor? 455 455 self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name() 456 super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name) 456 if queryset is None: 457 kwargs = {self.fk.name: self.instance} 458 queryset = self.model._default_manager.filter(**kwargs) 459 super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name, 460 queryset=queryset) 457 461 458 462 def _construct_forms(self): 459 463 if self.save_as_new: … … 469 473 form.data[form.add_prefix(self._pk_field.name)] = None 470 474 return form 471 475 472 def get_queryset(self):473 """474 Returns this FormSet's queryset, but restricted to children of475 self.instance476 """477 kwargs = {self.fk.name: self.instance}478 return self.model._default_manager.filter(**kwargs)479 480 476 def save_new(self, form, commit=True): 481 477 kwargs = {self.fk.get_attname(): self.instance.pk} 482 478 new_obj = self.model(**kwargs)