[Fixed]-Django Save method needs to update model instance twice

1👍

def save(self, *args, **kwargs):
    # save the instance, do this first so that we have an id
    super(MyModelClass, self).save(*args, **kwargs)
    # if it was a new instance fid is not set yet
    if self.id and not self.fid:
        self.fid = encode(self.id)
        # save the instance again now that we've set fid
        super(MyModelClass, self).save(*args, **kwargs)

Leave a comment