Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved generic relations into django.contrib.contenttypes, since it de…

…pends on

that to work. Backwards incompatible change.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5172 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1c53661bd14cbb19138bd7f9dbc03074c58d63c2 1 parent 0839a00
Malcolm Tredinnick authored
0  django/db/models/fields/generic.py → django/contrib/contenttypes/generic.py
File renamed without changes
4  django/core/management.py
@@ -241,14 +241,14 @@ def _get_sql_for_pending_references(model, pending_references):
241 241
 
242 242
 def _get_many_to_many_sql_for_model(model):
243 243
     from django.db import backend, get_creation_module
244  
-    from django.db.models import GenericRel
  244
+    from django.contrib.contenttypes import generic
245 245
 
246 246
     data_types = get_creation_module().DATA_TYPES
247 247
 
248 248
     opts = model._meta
249 249
     final_output = []
250 250
     for f in opts.many_to_many:
251  
-        if not isinstance(f.rel, GenericRel):
  251
+        if not isinstance(f.rel, generic.GenericRel):
252 252
             table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
253 253
                 style.SQL_TABLE(backend.quote_name(f.m2m_db_table())) + ' (']
254 254
             table_output.append('    %s %s %s,' % \
1  django/db/models/__init__.py
@@ -8,7 +8,6 @@
8 8
 from django.db.models.base import Model, AdminOptions
9 9
 from django.db.models.fields import *
10 10
 from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel, TABULAR, STACKED
11  
-from django.db.models.fields.generic import GenericRelation, GenericRel, GenericForeignKey
12 11
 from django.db.models import signals
13 12
 from django.utils.functional import curry
14 13
 from django.utils.text import capfirst
8  django/db/models/query.py
... ...
@@ -1,9 +1,9 @@
1 1
 from django.db import backend, connection, transaction
2 2
 from django.db.models.fields import DateField, FieldDoesNotExist
3  
-from django.db.models.fields.generic import GenericRelation
4  
-from django.db.models import signals
  3
+from django.db.models import signals, loading
5 4
 from django.dispatch import dispatcher
6 5
 from django.utils.datastructures import SortedDict
  6
+from django.contrib.contenttypes import generic
7 7
 import operator
8 8
 import re
9 9
 
@@ -1041,7 +1041,7 @@ def delete_objects(seen_objs):
1041 1041
 
1042 1042
         pk_list = [pk for pk,instance in seen_objs[cls]]
1043 1043
         for related in cls._meta.get_all_related_many_to_many_objects():
1044  
-            if not isinstance(related.field, GenericRelation):
  1044
+            if not isinstance(related.field, generic.GenericRelation):
1045 1045
                 for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
1046 1046
                     cursor.execute("DELETE FROM %s WHERE %s IN (%s)" % \
1047 1047
                         (qn(related.field.m2m_db_table()),
@@ -1049,7 +1049,7 @@ def delete_objects(seen_objs):
1049 1049
                             ','.join(['%s' for pk in pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE]])),
1050 1050
                         pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE])
1051 1051
         for f in cls._meta.many_to_many:
1052  
-            if isinstance(f, GenericRelation):
  1052
+            if isinstance(f, generic.GenericRelation):
1053 1053
                 from django.contrib.contenttypes.models import ContentType
1054 1054
                 query_extra = 'AND %s=%%s' % f.rel.to._meta.get_field(f.content_type_field_name).column
1055 1055
                 args_extra = [ContentType.objects.get_for_model(cls).id]
7  tests/modeltests/generic_relations/models.py
@@ -11,6 +11,7 @@
11 11
 
12 12
 from django.db import models
13 13
 from django.contrib.contenttypes.models import ContentType
  14
+from django.contrib.contenttypes import generic
14 15
 
15 16
 class TaggedItem(models.Model):
16 17
     """A tag on an item."""
@@ -18,7 +19,7 @@ class TaggedItem(models.Model):
18 19
     content_type = models.ForeignKey(ContentType)
19 20
     object_id = models.PositiveIntegerField()
20 21
     
21  
-    content_object = models.GenericForeignKey()
  22
+    content_object = generic.GenericForeignKey()
22 23
     
23 24
     class Meta:
24 25
         ordering = ["tag"]
@@ -30,7 +31,7 @@ class Animal(models.Model):
30 31
     common_name = models.CharField(maxlength=150)
31 32
     latin_name = models.CharField(maxlength=150)
32 33
     
33  
-    tags = models.GenericRelation(TaggedItem)
  34
+    tags = generic.GenericRelation(TaggedItem)
34 35
 
35 36
     def __str__(self):
36 37
         return self.common_name
@@ -39,7 +40,7 @@ class Vegetable(models.Model):
39 40
     name = models.CharField(maxlength=150)
40 41
     is_yucky = models.BooleanField(default=True)
41 42
     
42  
-    tags = models.GenericRelation(TaggedItem)
  43
+    tags = generic.GenericRelation(TaggedItem)
43 44
     
44 45
     def __str__(self):
45 46
         return self.name
5  tests/regressiontests/serializers_regress/models.py
@@ -6,6 +6,7 @@
6 6
 """
7 7
 
8 8
 from django.db import models
  9
+from django.contrib.contenttypes import generic
9 10
 from django.contrib.contenttypes.models import ContentType
10 11
 
11 12
 # The following classes are for testing basic data 
@@ -80,7 +81,7 @@ class Tag(models.Model):
80 81
     content_type = models.ForeignKey(ContentType)
81 82
     object_id = models.PositiveIntegerField()
82 83
 
83  
-    content_object = models.GenericForeignKey()
  84
+    content_object = generic.GenericForeignKey()
84 85
 
85 86
     class Meta:
86 87
         ordering = ["data"]
@@ -88,7 +89,7 @@ class Meta:
88 89
 class GenericData(models.Model):
89 90
     data = models.CharField(maxlength=30)
90 91
 
91  
-    tags = models.GenericRelation(Tag)
  92
+    tags = generic.GenericRelation(Tag)
92 93
     
93 94
 # The following test classes are all for validation
94 95
 # of related objects; in particular, forward, backward,

0 notes on commit 1c53661

Please sign in to comment.
Something went wrong with that request. Please try again.