#17214: incorrect rendering of inline fk when parent has custom pk field
-------------------------------------------+--------------------
Reporter: Aryeh Leib Taurog <vim@…> | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------------+--------------------
pkfk/models.py
{{{#!python
from django.db import models
class TZDateField(models.DateField):
description = "Date field stored in PostgreSQL as TIMESTAMP WITH TIME
ZONE"
__metaclass__ = models.SubfieldBase
def db_type(self, connection): return "TIMESTAMP WITH TIME ZONE"
class FooDate(models.Model):
foo_date = TZDateField(primary_key=True)
class Bar(models.Model):
baz = models.CharField(max_length=10)
foo_date = models.ForeignKey("FooDate")
class Meta:
unique_together = ("baz", "foo_date")
}}}
pkfk/admin.py
{{{#!python
from django.contrib import admin
from pkfk.models import FooDate, Bar
class BarInline(admin.TabularInline):
model = Bar
class FooDateAdmin(admin.ModelAdmin):
inlines = [BarInline]
admin.site.register(FooDate, FooDateAdmin)
}}}
When trying to re-save inline objects in the admin, I get a mysterious
"Please correct the errors below." message, but no further error messages
are displayed. If I supply my own inline formset and catch the `clean()`
call, I can see the following `formset.errors`:
{{{#!python
[{'foo_date': [u'The inline foreign key did not match the parent instance
primary key.']},
{'foo_date': [u'The inline foreign key did not match the parent instance
primary key.']},
{},
{},
{}]
}}}
This is because html for the hidden foreign key field on the inline is
rendered as follows:
{{{#!xml
<input type="hidden" name="bar_set-0-foo_date" value="2011-11-12 00:00:00"
id="id_bar_set-0-foo_date">
}}}
In order for this to work it needs to be rendered without the time:
{{{#!xml
<input type="hidden" name="bar_set-0-foo_date" value="2011-11-12"
id="id_bar_set-0-foo_date">
}}}
If the inline form would only call the pk field's `to_python` or
`get_prep_value` before rendering the fk, it would be correct, but it
seems to be pulling it straight from the db and rendering that datum on
its own. Perhaps [ticket:17122 this ticket] is related? Am I missing
something?
I tried this and got the same results under 1.2.4, 1.2.7, and 1.3.1.
--
Ticket URL: <https://code.djangoproject.com/ticket/17214>
Django <https://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.