Opened 11 years ago

Closed 11 years ago

#19467 closed Bug (needsinfo)

Admin inlines doesn't properly call model.clean() — at Version 1

Reported by: Marc Aymerich Owned by: nobody
Component: Uncategorized Version: dev
Severity: Normal Keywords: admin inline clean
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Karen Tracey)

Seems that model forms or admin dones't clean correctly inline forms.

class Child(models.Model):
   parent = models.ForeignKey(Parent)
   something = models.CharField(blank=True, null=True, unique=True)

   def clean(self):
       if self.something == '':
           self.something = None
       super(Child, self).clean()

Postgres raises a: duplicate key value violates unique constraint "child_something_key"

I've made a little hack on django's code and call child.clean() just before child.save(), and then it works. Also I've tried a similar scenario with an admin.ModelAdmin instead of admin.TabularInline and it works to. So it must be a bug somewhere on the inlines.

Node: I'm using master, not tested with 1.4

thanks.

Change History (1)

comment:1 by Karen Tracey, 11 years ago

Description: modified (diff)
Resolution: needsinfo
Status: newclosed

Fixed formatting, please use WikiFormatting and preview before posting.

Could you provide a complete example of parent/child models plus the admin classes you are using? It's going to require a bit of guesswork to try to replicate the error you describe with just a single model definition and no guidance on how you have set up the admin defs.

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