Guest User

Untitled

a guest
Dec 14th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. class Customer(models.Model):
  2. name = models.CharField(max_length=200)
  3. created_by = models.ForeignKey(User)
  4.  
  5. def save():
  6. ........ some code to override it.......
  7.  
  8. class Addcustomer(forms.ModelForm):
  9. class Meta:
  10. model = Customer
  11. fields = ('name',)
  12. def save():
  13. ........code to override it....
  14.  
  15. def save(self, commit=True):
  16. """
  17. Save this form's self.instance object if commit=True. Otherwise, add
  18. a save_m2m() method to the form which can be called after the instance
  19. is saved manually at a later time. Return the model instance.
  20. """
  21. if self.errors: # there validation is done
  22. raise ValueError(
  23. "The %s could not be %s because the data didn't validate." % (
  24. self.instance._meta.object_name,
  25. 'created' if self.instance._state.adding else 'changed',
  26. )
  27. )
  28. if commit:
  29. # If committing, save the instance and the m2m data immediately.
  30. self.instance.save()
  31. self._save_m2m()
  32. else:
  33. # If not committing, add a method to the form to allow deferred
  34. # saving of m2m data.
  35. self.save_m2m = self._save_m2m
  36. return self.instance
  37.  
  38. save.alters_data = True
Add Comment
Please, Sign In to add comment