magic-removal: Small manipulator simplification. Deletion fix for edit inline.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1752 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3ee086f80d
commit
d316f6a8cd
|
@ -220,7 +220,7 @@ class Model(object):
|
||||||
|
|
||||||
def delete(self, ignore_objects=None):
|
def delete(self, ignore_objects=None):
|
||||||
assert getattr(self, self._meta.pk.attname) is not None, "%r can't be deleted because it doesn't have an ID."
|
assert getattr(self, self._meta.pk.attname) is not None, "%r can't be deleted because it doesn't have an ID."
|
||||||
ignore_objects = ignore_objects and dict([(o.__class,o.__get_pk_val) for o in ignore_objects]) or {}
|
ignore_objects = ignore_objects and dict([(o.__class__,o.__get_pk_val()) for o in ignore_objects]) or {}
|
||||||
|
|
||||||
seen_objs = {}
|
seen_objs = {}
|
||||||
self.__collect_sub_objects(seen_objs, ignore_objects)
|
self.__collect_sub_objects(seen_objs, ignore_objects)
|
||||||
|
|
|
@ -213,7 +213,7 @@ class Field(object):
|
||||||
field_objs = self.get_manipulator_field_objs()
|
field_objs = self.get_manipulator_field_objs()
|
||||||
return (field_objs,params)
|
return (field_objs,params)
|
||||||
|
|
||||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False):
|
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
||||||
"""
|
"""
|
||||||
Returns a list of formfields.FormField instances for this field. It
|
Returns a list of formfields.FormField instances for this field. It
|
||||||
calculates the choices at runtime, not at compile time.
|
calculates the choices at runtime, not at compile time.
|
||||||
|
@ -326,10 +326,10 @@ class AutoField(Field):
|
||||||
assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__
|
assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__
|
||||||
Field.__init__(self, *args, **kwargs)
|
Field.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False):
|
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
||||||
if not rel:
|
if not rel:
|
||||||
return [] # Don't add a FormField unless it's in a related context.
|
return [] # Don't add a FormField unless it's in a related context.
|
||||||
return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel)
|
return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel, follow)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [formfields.HiddenField]
|
return [formfields.HiddenField]
|
||||||
|
@ -462,8 +462,8 @@ class FileField(Field):
|
||||||
self.upload_to = upload_to
|
self.upload_to = upload_to
|
||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False):
|
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
||||||
field_list = Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel)
|
field_list = Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel, follow)
|
||||||
|
|
||||||
if not self.blank:
|
if not self.blank:
|
||||||
if rel:
|
if rel:
|
||||||
|
|
|
@ -19,7 +19,6 @@ def add_lookup(rel_cls, field):
|
||||||
key = (module, name)
|
key = (module, name)
|
||||||
pending_lookups.setdefault(key, []).append((rel_cls, field))
|
pending_lookups.setdefault(key, []).append((rel_cls, field))
|
||||||
|
|
||||||
|
|
||||||
def do_pending_lookups(sender):
|
def do_pending_lookups(sender):
|
||||||
other_cls = sender
|
other_cls = sender
|
||||||
key = (other_cls.__module__, other_cls.__name__)
|
key = (other_cls.__module__, other_cls.__name__)
|
||||||
|
|
|
@ -72,15 +72,9 @@ class AutomaticManipulator(Manipulator):
|
||||||
self.follow = self.model._meta.get_follow(follow)
|
self.follow = self.model._meta.get_follow(follow)
|
||||||
self.fields = []
|
self.fields = []
|
||||||
self.original_object = original_object
|
self.original_object = original_object
|
||||||
for f in self.opts.fields + self.opts.many_to_many:
|
for f in self.opts.get_data_holders(self.follow):
|
||||||
if self.follow.get(f.name, False):
|
|
||||||
self.fields.extend(f.get_manipulator_fields(self.opts, self, self.change))
|
|
||||||
|
|
||||||
# Add fields for related objects.
|
|
||||||
for f in self.opts.get_all_related_objects():
|
|
||||||
if self.follow.get(f.name, False):
|
|
||||||
fol = self.follow[f.name]
|
fol = self.follow[f.name]
|
||||||
fields = f.get_manipulator_fields(self.opts, self, self.change, fol)
|
fields = f.get_manipulator_fields(self.opts, self, self.change, follow=fol)
|
||||||
self.fields.extend(fields)
|
self.fields.extend(fields)
|
||||||
|
|
||||||
def save(self, new_data):
|
def save(self, new_data):
|
||||||
|
|
Loading…
Reference in New Issue