Ticket #10262: delete_cascade_option_r9832.diff
File delete_cascade_option_r9832.diff, 3.1 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
11 11 import django.db.models.manager # Imported to register signal handler. 12 12 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError 13 13 from django.db.models.fields import AutoField, FieldDoesNotExist 14 from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField 14 from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField, RelatedObject 15 15 from django.db.models.query import delete_objects, Q, CollectedObjects 16 16 from django.db.models.options import Options 17 17 from django.db import connection, transaction, DatabaseError … … 456 456 def delete(self): 457 457 assert self._get_pk_val() is not None, "%s object can't be deleted because its %s attribute is set to None." % (self._meta.object_name, self._meta.pk.attname) 458 458 459 # Clear all related object with delete_cascade=False 460 for field in self._meta.get_all_fields(): 461 if isinstance(field, RelatedObject) and not field.field.delete_cascade: 462 related_manager = getattr(self, field.get_accessor_name()) 463 related_manager.clear() 464 459 465 # Find all the objects than need to be deleted. 460 466 seen_objs = CollectedObjects() 461 467 self._collect_sub_objects(seen_objs) -
django/db/models/options.py
283 283 raise FieldDoesNotExist('%s has no field named %r' 284 284 % (self.object_name, name)) 285 285 286 def get_all_fields(self): 287 """ 288 Returns a list of all fields that are possible for this model 289 (including reverse relation names). 290 """ 291 try: 292 cache = self._name_map 293 except AttributeError: 294 cache = self.init_name_map() 295 fields = [ r[0] for r in cache.values() ] 296 return fields 297 286 298 def get_all_field_names(self): 287 299 """ 288 300 Returns a list of all field names that are possible for this model -
django/db/models/fields/related.py
646 646 limit_choices_to=kwargs.pop('limit_choices_to', None), 647 647 lookup_overrides=kwargs.pop('lookup_overrides', None), 648 648 parent_link=kwargs.pop('parent_link', False)) 649 650 self.delete_cascade = kwargs.pop('delete_cascade', True) 651 649 652 Field.__init__(self, **kwargs) 650 653 651 654 self.db_index = True 655 assert self.null or self.delete_cascade, "%s cannot define a not null relation (null=False) without deleting cascade (delete_cascade=False)" % self.__class__.__name__ 652 656 653 657 def get_attname(self): 654 658 return '%s_id' % self.name