mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #19774 -- Deprecated the contenttypes.generic module.
It contained models, forms and admin objects causing undesirable import side effects. Refs #16368. Thanks to Ramiro, Carl and Loïc for the review.
This commit is contained in:
parent
c3881944e8
commit
10e3faf191
33 changed files with 1011 additions and 906 deletions
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||
|
||||
from .models import (Media, PhoneNumber, Episode, EpisodeExtra, Contact,
|
||||
Category, EpisodePermanent, EpisodeMaxNum)
|
||||
|
@ -8,7 +8,7 @@ from .models import (Media, PhoneNumber, Episode, EpisodeExtra, Contact,
|
|||
site = admin.AdminSite(name="admin")
|
||||
|
||||
|
||||
class MediaInline(generic.GenericTabularInline):
|
||||
class MediaInline(GenericTabularInline):
|
||||
model = Media
|
||||
|
||||
|
||||
|
@ -18,22 +18,22 @@ class EpisodeAdmin(admin.ModelAdmin):
|
|||
]
|
||||
|
||||
|
||||
class MediaExtraInline(generic.GenericTabularInline):
|
||||
class MediaExtraInline(GenericTabularInline):
|
||||
model = Media
|
||||
extra = 0
|
||||
|
||||
|
||||
class MediaMaxNumInline(generic.GenericTabularInline):
|
||||
class MediaMaxNumInline(GenericTabularInline):
|
||||
model = Media
|
||||
extra = 5
|
||||
max_num = 2
|
||||
|
||||
|
||||
class PhoneNumberInline(generic.GenericTabularInline):
|
||||
class PhoneNumberInline(GenericTabularInline):
|
||||
model = PhoneNumber
|
||||
|
||||
|
||||
class MediaPermanentInline(generic.GenericTabularInline):
|
||||
class MediaPermanentInline(GenericTabularInline):
|
||||
model = Media
|
||||
can_delete = False
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.fields import (
|
||||
GenericForeignKey, GenericRelation
|
||||
)
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
@ -17,7 +19,7 @@ class Media(models.Model):
|
|||
"""
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = generic.GenericForeignKey()
|
||||
content_object = GenericForeignKey()
|
||||
url = models.URLField()
|
||||
description = models.CharField(max_length=100, blank=True)
|
||||
keywords = models.CharField(max_length=100, blank=True)
|
||||
|
@ -56,7 +58,7 @@ class Category(models.Model):
|
|||
class PhoneNumber(models.Model):
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||
content_object = GenericForeignKey('content_type', 'object_id')
|
||||
phone_number = models.CharField(max_length=30)
|
||||
category = models.ForeignKey(Category, null=True, blank=True)
|
||||
|
||||
|
@ -66,7 +68,7 @@ class PhoneNumber(models.Model):
|
|||
|
||||
class Contact(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
phone_numbers = generic.GenericRelation(PhoneNumber)
|
||||
phone_numbers = GenericRelation(PhoneNumber)
|
||||
|
||||
|
||||
#
|
||||
|
|
|
@ -4,8 +4,8 @@ import warnings
|
|||
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.contrib.contenttypes.generic import (
|
||||
generic_inlineformset_factory, GenericTabularInline)
|
||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||
from django.contrib.contenttypes.forms import generic_inlineformset_factory
|
||||
from django.forms.formsets import DEFAULT_MAX_NUM
|
||||
from django.forms.models import ModelForm
|
||||
from django.test import TestCase, override_settings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue