summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-03-10 12:08:17 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-03-10 12:08:17 +0000
commitee0320f63400de67cb5a3363d95899bc21354172 (patch)
tree1a6cb4139066a32090bbb910e0d1609f599d6146 /django/forms/models.py
parentea350187a5dc52861d85d513c846bd1f062513be (diff)
[1.0.X] Fixed #10271, #10281 -- Fixed the handling multiple inline models that share a common base class and have the link to the inline parent on the base class. Includes modifications that allow the equivalent handling for GenericFields. Thanks to Idan Gazit, Antti Kaihola (akaihola), and Alex Gaynor for their work on this patch.
Backport of r10017 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10019 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index e6bbb98718..bfc0b35803 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -249,8 +249,8 @@ class BaseModelForm(BaseForm):
# This is an extra field that's not on the ModelForm, ignore it
continue
if not isinstance(f, ModelField):
- # This is an extra field that happens to have a name that matches,
- # for example, a related object accessor for this model. So
+ # This is an extra field that happens to have a name that matches,
+ # for example, a related object accessor for this model. So
# get_field_by_name found it, but it is not a Field so do not proceed
# to use it as if it were.
continue
@@ -472,7 +472,7 @@ class BaseInlineFormSet(BaseModelFormSet):
# 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()
qs = self.model._default_manager.filter(**{self.fk.name: self.instance})
- super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix or self.rel_name,
+ super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
queryset=qs)
def _construct_forms(self):
@@ -489,6 +489,12 @@ class BaseInlineFormSet(BaseModelFormSet):
form.data[form.add_prefix(self._pk_field.name)] = None
return form
+ #@classmethod
+ def get_default_prefix(cls):
+ from django.db.models.fields.related import RelatedObject
+ return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name()
+ get_default_prefix = classmethod(get_default_prefix)
+
def save_new(self, form, commit=True):
fk_attname = self.fk.get_attname()
kwargs = {fk_attname: self.instance.pk}