0

I want to override save method in django.

I am using Django REST framework so basically serializer handles all saving of model.

def save(self, split=True, **kwargs):
    if split:
        result = super(Entry,self).save(**kwargs)
        logger.warn(result)
        logger.error(self)
        #tasks.split_entry(self)
    else:
        super(Entry,self).save(**kwargs)

Now I want to pass the object being saved to my tasks but I am not sure if self is object or result is object.

I don't want to interrupt the process because I think django rest needs to get that saved object to return to request. So I am confused how to use super here.

If I do the above process I can't see any logging. I think it skips them.

5
  • Have you check the value for 'result' ? Commented May 21, 2015 at 15:36
  • try post_save signal handler Commented May 21, 2015 at 15:46
  • Entry object is in self, if you want keep the log and execute the save normally (and you don't want to use signals), try to execute super method at the end. Commented May 21, 2015 at 15:48
  • @Gocht . if i want to execute some stuff after object is created by save then do i have to use super before and then do my stuff Commented May 21, 2015 at 22:33
  • No problem, you're not modifying the object, so I think you can do the super just where it is. Commented May 21, 2015 at 22:38

1 Answer 1

3

You need to use self. Django models' save method does not return a value so your result variable is None.

Sign up to request clarification or add additional context in comments.

1 Comment

I have a very similar situation but I don't quite get where to put self Can you please give an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.