#9461: raw id fields for inherited models in inline intermediate models show
base
class __unicode__ rather than id
--------------------------------------------------+-------------------------
Reporter: Jacob Smullyan <[EMAIL PROTECTED]> | Owner: nobody
Status: new | Milestone:
Component: django.contrib.admin | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
--------------------------------------------------+-------------------------
A raw id field targetting a model that inherits concretely from another,
when appearing in an intermediate model's inline in a m2m field, will be
populated upon selection, not with an id, but with a string representation
of the target model's base class (which breaks). That's accurate but a
bit opaque. Here is an example:
{{{
from django.contrib import admin
from django.contrib.contenttypes import generic
from django.db import models
class Base(models.Model):
title=models.CharField(max_length=80)
class X(Base):
number=models.IntegerField()
class Y(models.Model):
some_as=models.ManyToManyField(X, through='X2YRelation')
class X2YRelation(models.Model):
sort_number=models.IntegerField()
x=models.ForeignKey(X)
y=models.ForeignKey(Y)
admin.site.register(X)
class X2YInline(admin.TabularInline):
model=X2YRelation
raw_id_fields=('x',)
class YAdmin(admin.ModelAdmin):
inlines=[X2YInline]
admin.site.register(Y, YAdmin)
}}}
If you run this and go in the admin to create a Y object, you can
successfully create an X inline, but you cannot choose an existing X,
because instead of an id showing up in the raw id field, you get the
string "Base object", which of course makes the form blow up on submit.
The ramifications of this bug in a real life application, from which the
above example is abstracted, are pretty severe, since dropdowns aren't
really usable when the number of choices is unlimited -- and inline's
extras cause the dropdown to be repeated, making things even worse. A
workaround is to set the {{{ __unicode__ }}} of the base class to return
{{{ u"%d" % self.id }}}, but that makes {{{ __unicode__ }}} useless for
other purposes.
(Note: I'm running the 1.0.X branch, but I've also tested the above
example on trunk.)
--
Ticket URL: <http://code.djangoproject.com/ticket/9461>
Django <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
-~----------~----~----~----~------~----~------~--~---