Opened 16 years ago

Closed 15 years ago

Last modified 13 years ago

#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


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]: is the core of it
18:25 <Spads> [530]: and it's generating
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)

10638.diff (1.8 KB ) - added by David Gouldin 15 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 by Spads, 16 years ago

SeanL- tried testing if the pk field was editable, but that didn't fix the problem for me:

However, it feels like that's very close to the cause of this problem.

comment:2 by Sean Legassick, 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 gkelly, 16 years ago

Component: django-admin.pyAdmin interface
Keywords: admin TabularInline added

comment:4 by Ivan Giuliani, 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='')
    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], EquipmentOptions)


<tr class="row1 ">
   <td class="original">
     <input type="text" name="networkinterface_set-0-ip" value="" id="id_networkinterface_set-0-ip" />
   <td class="ip">
      <input type="text" name="networkinterface_set-0-ip" value="" id="id_networkinterface_set-0-ip" />
   <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 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 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 class="delete"></td>

comment:5 by Idan Gazit, 16 years ago

Confirming this problem, django 1.0.

comment:6 by Idan Gazit, 16 years ago

Cc: Idan Gazit added

comment:7 by Spads, 16 years ago

Owner: changed from nobody to Spads
Status: newassigned

I've noticed that this problem still exists in django 1.0.2. Are there any plans to address it?

comment:8 by Spads, 16 years ago

Oh criminy, I really didn't mean to take this ticket...

comment:9 by Spads, 16 years ago

As a workaround, I have been copying the
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 }}/{{ }}/">{% 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 %}

in reply to:  9 comment:10 by Spads, 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 Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:12 by Malcolm Tredinnick, 15 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.

comment:13 by Karen Tracey, 15 years ago

#10638 reports this again and has a patch.

by David Gouldin, 15 years ago

Attachment: 10638.diff added

comment:14 by David Gouldin, 15 years ago

Cc: dgouldin@… added
Has patch: set

Transferred my patch over from 10638.

comment:15 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [10670]) [1.0.X] Fixed #8903 -- Corrected rendering of admin inline formsets (tabular and stacked) when the inline model has a custom non-autofield primary key. Thanks to dgouldin for the patch.

Merge of r10666 from trunk.

comment:16 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top