diff --git a/django/db/models/base.py b/django/db/models/base.py index 63d1c490fc..1b26afa7f3 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -220,7 +220,7 @@ class Model(object): 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." - 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 = {} self.__collect_sub_objects(seen_objs, ignore_objects) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index a5ecb73e9b..1698f97362 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -213,7 +213,7 @@ class Field(object): field_objs = self.get_manipulator_field_objs() 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 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__ 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: 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): return [formfields.HiddenField] @@ -462,8 +462,8 @@ class FileField(Field): self.upload_to = upload_to Field.__init__(self, verbose_name, name, **kwargs) - def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False): - field_list = Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel) + 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, follow) if not self.blank: if rel: diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 7543fc6de5..99daccba5b 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -19,7 +19,6 @@ def add_lookup(rel_cls, field): key = (module, name) pending_lookups.setdefault(key, []).append((rel_cls, field)) - def do_pending_lookups(sender): other_cls = sender key = (other_cls.__module__, other_cls.__name__) diff --git a/django/db/models/manipulators.py b/django/db/models/manipulators.py index be0be631b1..04f7143c48 100644 --- a/django/db/models/manipulators.py +++ b/django/db/models/manipulators.py @@ -72,16 +72,10 @@ class AutomaticManipulator(Manipulator): self.follow = self.model._meta.get_follow(follow) self.fields = [] self.original_object = original_object - for f in self.opts.fields + self.opts.many_to_many: - 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] - fields = f.get_manipulator_fields(self.opts, self, self.change, fol) - self.fields.extend(fields) + for f in self.opts.get_data_holders(self.follow): + fol = self.follow[f.name] + fields = f.get_manipulator_fields(self.opts, self, self.change, follow=fol) + self.fields.extend(fields) def save(self, new_data): add, change, opts, klass = self.add, self.change, self.opts, self.model