mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Now possible to save in a changeform
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1691 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -813,6 +813,7 @@ class AutomaticManipulator(formfields.Manipulator):
|
||||
|
||||
def save(self, new_data):
|
||||
add, change, opts, klass = self.add, self.change, self.opts, self.model
|
||||
print add, change, opts, klass
|
||||
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
||||
from django.utils.datastructures import DotExpandedDict
|
||||
params = {}
|
||||
@@ -918,7 +919,7 @@ class AutomaticManipulator(formfields.Manipulator):
|
||||
params[f.attname] = param
|
||||
|
||||
# Create the related item.
|
||||
new_rel_obj = related.opts.get_model_module().Klass(**params)
|
||||
new_rel_obj = related.model(**params)
|
||||
|
||||
# If all the core fields were provided (non-empty), save the item.
|
||||
if all_cores_given:
|
||||
@@ -976,8 +977,8 @@ class ModelAddManipulator(AutomaticManipulator):
|
||||
super(ModelAddManipulator, self).__init__(follow=follow)
|
||||
|
||||
class ModelChangeManipulator(AutomaticManipulator):
|
||||
change = False
|
||||
add = True
|
||||
change = True
|
||||
add = False
|
||||
|
||||
def __init__(self, obj_key=None, follow=None):
|
||||
assert obj_key is not None, "ChangeManipulator.__init__() must be passed obj_key parameter."
|
||||
|
||||
@@ -758,7 +758,8 @@ class ForeignKey(Field):
|
||||
# but only for related objects that are in the same app.
|
||||
# EXAMPLE: Poll.add_choice()
|
||||
if related.opts.app_label == cls._meta.app_label:
|
||||
setattr(cls, 'add_%s' % rel_obj_name, curry(cls._add_related, rel_class=related.model, rel_field=related.field))
|
||||
func = lambda self, *args, **kwargs: self._add_related(related.model, related.field, *args, **kwargs)
|
||||
setattr(cls, 'add_%s' % rel_obj_name, func)
|
||||
|
||||
|
||||
class ManyToManyField(Field):
|
||||
|
||||
Reference in New Issue
Block a user