#9730: When using model inheritance, raw_id_fields returns a model's name in the
input field.
----------------------------------+-----------------------------------------
Reporter: grantmoney | Owner: nobody
Status: new | Milestone:
Component: django.contrib.admin | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
----------------------------------+-----------------------------------------
# Parent Model
{{{
from django.db import models
class Place(models.Model):
name = models.CharField(max_length=99)
description = models.CharField(max_length=400, blank=True)
}}}
# Child Models
{{{
class Country(Place):
place = models.OneToOneField(Place, primary_key=True,
parent_link=True, related_name='place_country')
class City(Place):
place = models.OneToOneField(Place, primary_key=True,
parent_link=True, related_name='place_city')
country = models.ForeignKey(Country, related_name='city_country')
}}}
# Admin
{{{
from django.contrib import admin
class CityOptions(admin.ModelAdmin):
raw_id_fields = ('country',)
admin.site.register(Place)
admin.site.register(Country)
admin.site.register(City, CityOptions)
}}}
# Description
First we start with a base model named Place, and then set up 2 Child
models (Country and City in this case).
If we then use raw_id_fields for a ForeignKey to a model that inherits
from the base model, instead of returning the model's pk/id, it instead
returns the name of the object.
{{{
# First we create a Country
country, x = Country.objects.get_or_create(name="America")
}}}
If we now try to add a City using Django's admin, when selecting the
country (which when using raw_id_fields is done via a pop up browser
window), the input field will be given a value of "America" instead of the
object's pk which in this case would be 1.
Going through where this might have started to occur, it seems to have
started with the changes to ForeignKeyRawIdWidget in [8823].
--
Ticket URL: <http://code.djangoproject.com/ticket/9730>
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
-~----------~----~----~----~------~----~------~--~---