Changes between Initial Version and Version 2 of Ticket #19774
- Timestamp:
- Mar 28, 2013, 9:16:53 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #19774
- Property Keywords dependency generic contenttypes added
- Property Triage Stage Unreviewed → Accepted
- Property Type Bug → Cleanup/optimization
- Property Owner changed from to
- Property Status new → assigned
-
Ticket #19774 – Description
initial v2 1 (Copied from https://code.djangoproject.com/ticket/16368#comment:16)1 (Copied and adapted from https://code.djangoproject.com/ticket/16368#comment:16) 2 2 3 The django/contrib/contenttypes/generic.py modules contains both the definitions of the model-related generic stuff (!GenericForeignKey, etc.) AND the admin app-related specialized inlines (!GenericInlineModelAdmin, !GenericStackedInline, !GenericTabularInline.) 3 Consider a project with a `foo` and a `bar` apps listed on `INSTALLED_APPS`: 4 * `foo` uses generic foreign keys, with the following `models.py`: 5 {{{ 6 from django.db import models 7 from django.contrib.contenttypes.models import ContentType 8 from django.contrib.contenttypes import generic 4 9 5 So, for example, if you import `django.contrib.contenttypes.generic` from your models.py because you need !GenericForeignKey then the !GenericXInlineY sutff imports django.contrib.admin and it in its own turn imports contrib.sites causing the reported failure (see below). Again, the Sites framework isn't listed in INSTALLED_APPS and what is worse: The admin app isn't either (!). 10 class TaggedItem(models.Model): 11 tag = models.SlugField() 12 content_type = models.ForeignKey(ContentType) 13 object_id = models.PositiveIntegerField() 14 content_object = generic.GenericForeignKey() 15 }}} 6 16 7 Maybe it's time we move !GenericInlineModelAdmin, !GenericStackedInline, !GenericTabularInline from django.contrib.contenttypes.generic to, say, django.contrib.contenttypes.generic_admin? (of course this would need a deprecation process) 17 * `bar` has a `Site` model: 18 {{{ 19 from django.db import models 8 20 9 {{{ 10 from django.contrib.contenttypes import generic 11 File "django/contrib/contenttypes/generic.py", line 14, in <module> 12 from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets 13 File "django/contrib/admin/__init__.py", line 6, in <module> 14 from django.contrib.admin.sites import AdminSite, site 15 File "django/contrib/admin/sites.py", line 4, in <module> 16 from django.contrib.admin.forms import AdminAuthenticationForm 17 File "django/contrib/admin/forms.py", line 4, in <module> 18 from django.contrib.auth.forms import AuthenticationForm 19 File "django/contrib/auth/forms.py", line 10, in <module> 20 from django.contrib.sites.models import get_current_site 21 File "/django/contrib/sites/models.py", line 5, in <module> 22 raise Exception 21 class Site(models.Model): 22 name = models.CharField(... 23 # ... 23 24 }}} 25 * Neither the admin nor sites Django apps are being used. 26 27 This causes the user's Site model to be overridden and masked by Django sites framework's one. 28 29 This is because the `django/contrib/contenttypes/generic.py` module contain both the definitions of the model-related generic stuff (!GenericForeignKey, etc.) AND the admin app-related specialized inlines (!GenericInlineModelAdmin, !GenericStackedInline, !GenericTabularInline.) 30 31 Maybe it's time we move the latter ones from `django.contrib.contenttypes.generic` to, say, a new `generic_admin` (or `admin_tools`?) on `django.contrib.contenttypes`?. Of course this would need a deprecation process.