In suppliment to this question, if business logic should be in the model, how do I return an error message from the model?
def save(self, *args, **kwargs):
if <some condition>:
#return some error message to the view or template
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Pastylegs is correct, but you shouldn’t be doing that sort of logic in the
savemethod. Django has a built-in system for validating model instances before saving – you should use this, and raiseValidationErrorwhere necessary.