#8483: Admin interface does not check for incompatible generic relations
-----------------------------+----------------------------------------------
Reporter: smoluf | Owner: nobody
Status: new | Milestone:
Component: Admin interface | Version: 1.0-beta-1
Keywords: | Stage: Unreviewed
Has_patch: 0 |
-----------------------------+----------------------------------------------
{{{
# myapp.models.py
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class User (models.Model):
username = models.CharField(max_length=50, primary_key=True)
birthdate = models.DateField()
class PhoneNumber:
phone_number = PhoneNumberField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
}}}
{{{
# myapp.admin.py
from django.contrib import admin
from myapp.models import *
from django.contrib.contenttypes import generic
class PhoneNumberInline (admin.TabularInline):
model = PhoneNumber
class UserAdmin (admin.ModelAdmin):
inlines = [
PhoneNumberInline,
]
admin.site.register(User, UserAdmin)
}}}
In the above example, a PhoneNumber cannot be associated with a User
because the PhoneNumber stores object_id as a PositiveIntegerField,
whereas the primary key of User is a CharField. However, the admin
interface does not check for this and throws a ValueError exception when
it attempts to give PhoneNumber.object_id (an integer) the value of
User.username (a string).
It seems to me this should be a ConfigurationError.
--
Ticket URL: <http://code.djangoproject.com/ticket/8483>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---