mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
newforms-admin: Fixed a bug where each inline would get the prefix 'form'. This had the potential to cause clashes if there were multiple inline models with identical field names.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5ffaf83ced
commit
c58ff68881
@ -279,16 +279,16 @@ def formset_for_model(model, form=BaseForm, formfield_callback=lambda f: f.formf
|
|||||||
class InlineFormset(BaseModelFormSet):
|
class InlineFormset(BaseModelFormSet):
|
||||||
"""A formset for child objects related to a parent."""
|
"""A formset for child objects related to a parent."""
|
||||||
def __init__(self, instance=None, data=None):
|
def __init__(self, instance=None, data=None):
|
||||||
|
from django.db.models.fields.related import RelatedObject
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
super(InlineFormset, self).__init__(data, instances=self.get_inline_objects())
|
# is there a better way to get the object descriptor?
|
||||||
|
self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()
|
||||||
|
super(InlineFormset, self).__init__(data, instances=self.get_inline_objects(), prefix=self.rel_name)
|
||||||
|
|
||||||
def get_inline_objects(self):
|
def get_inline_objects(self):
|
||||||
if self.instance is None:
|
if self.instance is None:
|
||||||
return []
|
return []
|
||||||
from django.db.models.fields.related import RelatedObject
|
return getattr(self.instance, self.rel_name).all()
|
||||||
# is there a better way to get the object descriptor?
|
|
||||||
rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()
|
|
||||||
return getattr(self.instance, rel_name).all()
|
|
||||||
|
|
||||||
def save_new(self, form, commit=True):
|
def save_new(self, form, commit=True):
|
||||||
kwargs = {self.fk.get_attname(): self.instance._get_pk_val()}
|
kwargs = {self.fk.get_attname(): self.instance._get_pk_val()}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user