Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#9693 closed (worksforme)

Custom Model.save() don't change relational data when editing via admin (probably any other forms too)

Reported by: anonymous Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords:
Cc: dgouldin@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider following models:

class A(models.Model):
    name = models.CharField(max_length = 100)

class B(models.Model):
    name = models.CharField(max_length = 100)
    related = models.ForeignKey(to = A, null = True, blank = True)

    def save(self):
        if not self.name.startswith('@'):
            self.name = '@' + self.name # this will work always
        if self.related and self.related.name.startswith('@'):
            self.related = None # won't work when editing via admin form
        super(B, self).save()

This illustrates that submitting the data via admin interface will always override relational changes in the custom Model.save() method. Other fields, however, are changed as expected.

Calling save() under some other circumstances will always change relational data as expected.

Any glue how to fix it? Thanks.

Change History (5)

comment:1 by anonymous, 16 years ago

Component: UncategorizedForms

comment:2 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 by David Gouldin, 16 years ago

Cc: dgouldin@… added

I could not reproduce this behavior. Can anybody else?

comment:4 by jkocherhans, 16 years ago

Resolution: worksforme
Status: newclosed

I'm not able to duplicate this either. Please reopen with more details if this is still happening.

comment:5 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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