#8903 closed (fixed)
admin.TabularInline creates duplicate pk input boxes
Reported by: | Spads | Owned by: | Spads |
---|---|---|---|
Component: | contrib.admin | Version: | 1.0 |
Severity: | Keywords: | admin TabularInline | |
Cc: | Idan Gazit, dgouldin@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Just filing this bug based on a conversation in #django:
18:09 <Spads> I'm converting my models and admin to django 1.0, and I'm using an admin.TabularInline. It seems to have a <td class="original"> that *repeats* the primary key input box (defaults and all). This seems to be logic for links to the "View on site" stuff, but it's an input box.
18:18 <[530]> Spads: show the code
18:24 <Spads> [530]: http://dpaste.com/76156/ is the core of it
18:25 <Spads> [530]: and it's generating http://dpaste.com/76158/
18:26 <SeanL-> Spads: I think that's a bug because you have a custom pk
18:27 <SeanL-> Spads: don't know if it's been reported, just noticing myself. For me it works fine, but then I don't have a custom pk
18:27 <SeanL-> Spads: for me that first render of the pk input is the only one
18:28 <SeanL-> Spads; and it's hidden
18:28 <SeanL-> Spads: I'd file a ticket about it
Attachments (1)
Change History (17)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
I realised after some thought that even if my proposed fix had worked, there's more to the problem than that. What happens if the PK field is modified and delete is checked? Or if the PK is modified how to prevent creating a new row in the inline model's table instead of updating the existing row?
comment:3 by , 16 years ago
Component: | django-admin.py → Admin interface |
---|---|
Keywords: | admin TabularInline added |
comment:4 by , 16 years ago
Since dpaste is going to delete the code in the near future, here's the test case:
class NetworkInterface(models.Model): location = models.ForeignKey(Equipment, verbose_name="system") ip = models.IPAddressField("IP address", primary_key=True, default='127.0.0.1') mac = models.CharField("MAC address", max_length=17, unique=True, default='02:00:00:00:00:01') interface_name = models.CharField(max_length=15, default="eth0") media_settings = models.CharField(max_length=10, blank=True, default='HURG') def __unicode__(self): return unicode(u'%s %s: %s', location, self.interface_name, self.ip)
class NetworkInterface_Inline(admin.TabularInline): model = models.NetworkInterface fk_name = 'location' class EquipmentOptions(admin.ModelAdmin): inlines = [NetworkInterface_Inline, PowerSupply_Inline, Memory_Inline, Processor_Inline] admin.site.register(models.Equipment, EquipmentOptions)
Producing:
<tr class="row1 "> <td class="original"> <input type="text" name="networkinterface_set-0-ip" value="127.0.0.1" id="id_networkinterface_set-0-ip" /> </td> <td class="ip"> <input type="text" name="networkinterface_set-0-ip" value="127.0.0.1" id="id_networkinterface_set-0-ip" /> </td> <td class="mac"> <input name="networkinterface_set-0-mac" value="02:00:00:00:00:01" class="vTextField" maxlength="17" type="text" id="id_networkinterface_set-0-mac" /> </td> <td class="interface_name"> <input name="networkinterface_set-0-interface_name" value="eth0" class="vTextField" maxlength="15" type="text" id="id_networkinterface_set-0-interface_name" /> </td> <td class="media_settings"> <input name="networkinterface_set-0-media_settings" value="HURG" class="vTextField" maxlength="10" type="text" id="id_networkinterface_set-0-media_settings" /> </td> <td class="delete"></td> </tr>
comment:6 by , 16 years ago
Cc: | added |
---|
comment:7 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I've noticed that this problem still exists in django 1.0.2. Are there any plans to address it?
follow-up: 10 comment:9 by , 16 years ago
As a workaround, I have been copying the
/var/lib/python-support/python2.5/django/contrib/admin/templates/admin/edit_inline/tabular.html
into my templates dir and applying the following ham-fisted patch. I then set
it as the template for tabular inlines in my admin where the pk is custom, but
leave the others alone.
--- /var/lib/python-support/python2.5/django/contrib/admin/templates/admin/edit_inline/tabular.html 2008-11-19 05:44:27.000000000 +0000 +++ custompktabular.html 2008-11-26 11:02:25.000000000 +0000 @@ -26,7 +26,6 @@ {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %} {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %} </p>{% endif %} - {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }} {% spaceless %} {% for fieldset in inline_admin_form %} {% for line in fieldset %}
comment:10 by , 16 years ago
Replying to Spads:
--- /var/lib/python-support/python2.5/django/contrib/admin/templates/admin/edit_inline/tabular.html 2008-11-19 05:44:27.000000000 +0000
+++ custompktabular.html 2008-11-26 11:02:25.000000000 +0000
@@ -26,7 +26,6 @@
- {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }}
This appears not to work. StackedInline has a similar problem here. I'm going to have to just bail and not use Inlines for this I guess.
comment:11 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:12 by , 16 years ago
The example in question hasn't been reduced to the simplest possible case to demonstrate the problem. Untangling the example in #10243 I came across this again. The only requirement is a manually specified, non-AutoField primary key column.
by , 16 years ago
Attachment: | 10638.diff added |
---|
comment:15 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
SeanL- tried testing if the pk field was editable, but that didn't fix the problem for me: http://dpaste.com/76161/
However, it feels like that's very close to the cause of this problem.