Opened 8 years ago

Closed 7 years ago

#6622 closed (invalid)

Model with edit_inline on parent Model doesn't get saved on parent Model save

Reported by: panni@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: edit_inline, admin, not saved
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Assuming we're having the following constellation:

class model_a(models.Model):
  cf = models.CharField("x", null=True, blank=True)
  def save(self):
    """do_something"""

  class Admin:
    pass

class model_b(models.Model):
  cf = models.CharField("y", null=True, blank=True)
  reftox = models.ForeignKey(another_model, ...)
  reftoa = models.ForeignKey(model_a, verbose_name="A", related_name="BtoA", edit_inline=models.TABULAR, num_in_admin=3, num_extra_on_change=3, core=True)

  def __unicode__(self):
    if self.reftox:
      return u"%s, %s" % (self.reftox, self.reftoa.somefield)
    else:
      return u"%s, %s" % (self.cf, self.reftoa.somefield)

  class Admin:
    pass

  class Meta:
    pass

When saving model_a in Django Admin any filled model_b won't be saved on save.
Model_b.save() doesn't even get called.

This seems to be some issue with the resolving of unicode's reference to model_a.

Change History (2)

comment:1 Changed 8 years ago by panni@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This can be fixed by removing "core=True" on model_b reference to model_a, and adding it to model_b.cf.
Also unicode seems to be needed to be rewritten like:

  def __unicode__(self):
    if self.reftoa:
      if self.reftox:
        return u"%s, %s" % (self.reftox, self.reftoa.somefield)
      else:
        return u"%s, %s" % (self.cf, self.reftoa.somefield)
    return "Blah"

comment:2 Changed 7 years ago by Honza_Kral

  • Resolution set to invalid
  • Status changed from new to closed

Closing this ticket since its deprecated with newforms-admin. Handling of edit_inline is rewrtitten from scratch there...

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