~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/db/models/deletion.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from collections import OrderedDict
1
2
from operator import attrgetter
2
3
 
3
4
from django.db import connections, transaction, IntegrityError
4
5
from django.db.models import signals, sql
5
 
from django.utils.datastructures import SortedDict
6
6
from django.utils import six
7
7
 
8
8
 
35
35
    else:
36
36
        def set_on_delete(collector, field, sub_objs, using):
37
37
            collector.add_field_update(field, value, sub_objs)
 
38
    set_on_delete.deconstruct = lambda: ('django.db.models.SET', (value,), {})
38
39
    return set_on_delete
39
40
 
40
41
 
41
 
SET_NULL = SET(None)
 
42
def SET_NULL(collector, field, sub_objs, using):
 
43
    collector.add_field_update(field, None, sub_objs)
42
44
 
43
45
 
44
46
def SET_DEFAULT(collector, field, sub_objs, using):
95
97
 
96
98
    def add_field_update(self, field, value, objs):
97
99
        """
98
 
        Schedules a field update. 'objs' must be a homogenous iterable
 
100
        Schedules a field update. 'objs' must be a homogeneous iterable
99
101
        collection of model instances (e.g. a QuerySet).
100
102
        """
101
103
        if not objs:
133
135
        # Foreign keys pointing to this model, both from m2m and other
134
136
        # models.
135
137
        for related in opts.get_all_related_objects(
136
 
            include_hidden=True, include_proxy_eq=True):
 
138
                include_hidden=True, include_proxy_eq=True):
137
139
            if related.field.rel.on_delete is not DO_NOTHING:
138
140
                return False
139
141
        for field in model._meta.virtual_fields:
143
145
        return True
144
146
 
145
147
    def collect(self, objs, source=None, nullable=False, collect_related=True,
146
 
        source_attr=None, reverse_dependency=False):
 
148
            source_attr=None, reverse_dependency=False):
147
149
        """
148
150
        Adds 'objs' to the collection of objects to be deleted as well as all
149
 
        parent instances.  'objs' must be a homogenous iterable collection of
 
151
        parent instances.  'objs' must be a homogeneous iterable collection of
150
152
        model instances (e.g. a QuerySet).  If 'collect_related' is True,
151
153
        related objects will be handled by their respective on_delete handler.
152
154
 
234
236
                    found = True
235
237
            if not found:
236
238
                return
237
 
        self.data = SortedDict([(model, self.data[model])
238
 
                                for model in sorted_models])
 
239
        self.data = OrderedDict((model, self.data[model])
 
240
                                for model in sorted_models)
239
241
 
240
242
    def delete(self):
241
243
        # sort instance collections