﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17214	incorrect rendering of inline fk when parent has custom pk field	Aryeh Leib Taurog <vim@…>	nobody	"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."	Bug	closed	Forms	1.3	Normal	fixed		vim@…	Accepted	0	0	0	0	0	0
