So in order to actually modify the related object and then save it, you
must do something like this:
{{{
#!python
class CustomRelatedField(ForeignKey):
def pre_save(self, model_instance, add):
related_object = getattr(model_instance, self.name)
# Do stuff with object, custom saving
id = getattr(related_object, 'id', None)
setattr(model_instance, self.attname, id)
setattr(model_instance, self.name, redirect)
return id
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19427>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:1>
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:2>
* owner: nobody => vijay_shanker
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:3>
* owner: vijay_shanker => anonymous
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:4>
* owner: anonymous =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:5>
* needs_docs: 1 => 0
* easy: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:6>
* status: new => closed
* resolution: => wontfix
Comment:
Not sure what to do here as `attname` isn't referenced in the linked doc
(maybe it's since been removed). This seems in the realm of private API
anyway.
--
Ticket URL: <https://code.djangoproject.com/ticket/19427#comment:7>