mirror of https://github.com/django/django.git
Moved generic relations into django.contrib.contenttypes, since it depends on
that to work. Backwards incompatible change. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5172 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0839a0046a
commit
1c53661bd1
|
@ -241,14 +241,14 @@ def _get_sql_for_pending_references(model, pending_references):
|
|||
|
||||
def _get_many_to_many_sql_for_model(model):
|
||||
from django.db import backend, get_creation_module
|
||||
from django.db.models import GenericRel
|
||||
from django.contrib.contenttypes import generic
|
||||
|
||||
data_types = get_creation_module().DATA_TYPES
|
||||
|
||||
opts = model._meta
|
||||
final_output = []
|
||||
for f in opts.many_to_many:
|
||||
if not isinstance(f.rel, GenericRel):
|
||||
if not isinstance(f.rel, generic.GenericRel):
|
||||
table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
|
||||
style.SQL_TABLE(backend.quote_name(f.m2m_db_table())) + ' (']
|
||||
table_output.append(' %s %s %s,' % \
|
||||
|
|
|
@ -8,7 +8,6 @@ from django.db.models.manager import Manager
|
|||
from django.db.models.base import Model, AdminOptions
|
||||
from django.db.models.fields import *
|
||||
from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel, TABULAR, STACKED
|
||||
from django.db.models.fields.generic import GenericRelation, GenericRel, GenericForeignKey
|
||||
from django.db.models import signals
|
||||
from django.utils.functional import curry
|
||||
from django.utils.text import capfirst
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from django.db import backend, connection, transaction
|
||||
from django.db.models.fields import DateField, FieldDoesNotExist
|
||||
from django.db.models.fields.generic import GenericRelation
|
||||
from django.db.models import signals
|
||||
from django.db.models import signals, loading
|
||||
from django.dispatch import dispatcher
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.contrib.contenttypes import generic
|
||||
import operator
|
||||
import re
|
||||
|
||||
|
@ -1041,7 +1041,7 @@ def delete_objects(seen_objs):
|
|||
|
||||
pk_list = [pk for pk,instance in seen_objs[cls]]
|
||||
for related in cls._meta.get_all_related_many_to_many_objects():
|
||||
if not isinstance(related.field, GenericRelation):
|
||||
if not isinstance(related.field, generic.GenericRelation):
|
||||
for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
|
||||
cursor.execute("DELETE FROM %s WHERE %s IN (%s)" % \
|
||||
(qn(related.field.m2m_db_table()),
|
||||
|
@ -1049,7 +1049,7 @@ def delete_objects(seen_objs):
|
|||
','.join(['%s' for pk in pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE]])),
|
||||
pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE])
|
||||
for f in cls._meta.many_to_many:
|
||||
if isinstance(f, GenericRelation):
|
||||
if isinstance(f, generic.GenericRelation):
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
query_extra = 'AND %s=%%s' % f.rel.to._meta.get_field(f.content_type_field_name).column
|
||||
args_extra = [ContentType.objects.get_for_model(cls).id]
|
||||
|
|
|
@ -11,6 +11,7 @@ from complete).
|
|||
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
|
||||
class TaggedItem(models.Model):
|
||||
"""A tag on an item."""
|
||||
|
@ -18,7 +19,7 @@ class TaggedItem(models.Model):
|
|||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
|
||||
content_object = models.GenericForeignKey()
|
||||
content_object = generic.GenericForeignKey()
|
||||
|
||||
class Meta:
|
||||
ordering = ["tag"]
|
||||
|
@ -30,7 +31,7 @@ class Animal(models.Model):
|
|||
common_name = models.CharField(maxlength=150)
|
||||
latin_name = models.CharField(maxlength=150)
|
||||
|
||||
tags = models.GenericRelation(TaggedItem)
|
||||
tags = generic.GenericRelation(TaggedItem)
|
||||
|
||||
def __str__(self):
|
||||
return self.common_name
|
||||
|
@ -39,7 +40,7 @@ class Vegetable(models.Model):
|
|||
name = models.CharField(maxlength=150)
|
||||
is_yucky = models.BooleanField(default=True)
|
||||
|
||||
tags = models.GenericRelation(TaggedItem)
|
||||
tags = generic.GenericRelation(TaggedItem)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -6,6 +6,7 @@ This class sets up a model for each model field type
|
|||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
# The following classes are for testing basic data
|
||||
|
@ -80,7 +81,7 @@ class Tag(models.Model):
|
|||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
|
||||
content_object = models.GenericForeignKey()
|
||||
content_object = generic.GenericForeignKey()
|
||||
|
||||
class Meta:
|
||||
ordering = ["data"]
|
||||
|
@ -88,7 +89,7 @@ class Tag(models.Model):
|
|||
class GenericData(models.Model):
|
||||
data = models.CharField(maxlength=30)
|
||||
|
||||
tags = models.GenericRelation(Tag)
|
||||
tags = generic.GenericRelation(Tag)
|
||||
|
||||
# The following test classes are all for validation
|
||||
# of related objects; in particular, forward, backward,
|
||||
|
|
Loading…
Reference in New Issue