#1711 closed defect (worksforme)
[patch] inline editing uses invalid parent_id field when saving
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | magic-removal |
Severity: | normal | Keywords: | |
Cc: | gary.wilson@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the following example (taken from the OneToOneField example) when adding a new Restaurant or changing a Restaurant in the Admin
interface with some values in the inline edited Pizza fields, an exception is thrown because rather than using the correct "id"
of Restaurant (taken from Place) the string representation of Place is used:
from django.db import models class Place(models.Model): name = models.CharField(maxlength=50) address = models.CharField(maxlength=80) def __repr__(self): return "%s the place" % self.name class Admin: list_display=['name', 'address'] class Restaurant(models.Model): place = models.OneToOneField(Place) serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() def __repr__(self): return "%s the restaurant" % self.place.name class Admin: list_display=['place'] class Pizza(models.Model): name = models.CharField(maxlength=50, core=True) price = models.IntegerField() restaurant = models.ForeignKey( Restaurant, edit_inline=models.TABULAR, num_in_admin=3, num_extra_on_change=3, )
That's the exception:
ProgrammingError at /admin/bug1/restaurant/add/ ERROR: syntax error at or near "Pizza" at character 86 INSERT INTO "bug1_pizza" ("name","price","restaurant_id") VALUES ('Pepperoni',12,Fat Pizza the place) Request Method: POST Request URL: http://192.168.1.111:8000/admin/bug1/restaurant/add/ Exception Type: ProgrammingError Exception Value: ERROR: syntax error at or near "Pizza" at character 86 INSERT INTO "bug1_pizza" ("name","price","restaurant_id") VALUES ('Pepperoni',12,Fat Pizza the place) Exception Location: .....\django\django\db\backends\util.py in execute, line 11
A simple workaround is to replace the repr method in Place with:
def __repr__(self): return "%s" % self.id
Attachments (1)
Change History (4)
by , 18 years ago
Attachment: | manipulators.diff added |
---|
comment:1 by , 18 years ago
Summary: | inline editing uses invalid parent_id field when saving → [patch] inline editing uses invalid parent_id field when saving |
---|
comment:2 by , 18 years ago
Cc: | added |
---|
comment:3 by , 18 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I can't repeat this problem at all, using the example given. However, Gary's patch does fix another bug, so I will apply that shortly. But this ticket seems unrepeatable with or without Gary's patch, so I think we've fixed it somehow in the interim.
That being said, please do reopen if it is repeatable (with as many details as you can).
ForeignKey's to models with OneToOneField use the wrong attribute name. Does the patch also need to check if the db_column has been specified or has that already been handled with attname containing the correct column name?