Is there any way to do this in setting up a custom django property?
class MyModel(models.Model): myfield = models.CharField(length = 250) @myfield.setter def set_password(self, value): self.password = encrypt(value)
You really set the value to save the model, so it's better to override the save() method (use the pre_save signal).
save()
pre_save
What happened to the method?
instance.set_password('my_pw')
You can use @property to define setters: http://docs.python.org/library/functions.html#property
@property
### Pasted from docs class C(object): def __init__(self): self._x = None @property def x(self): """I'm the 'x' property.""" return self._x @x.setter def x(self, value): self._x = value @x.deleter def x(self): del self._x
Source: https://habr.com/ru/post/900180/More articles:removeObjectAtIndex calls "message sent to the freed instance" - ios"Permission denied" when trying to send confirmation email - djangoWindows MTP / WPD connection with Android device - c ++https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/900178/alternatives-to-wpdwia-on-windows-xp&usg=ALkJrhgh50UdloadG9Tho6ws9WwDLtUuOARails and Mailchimp - welcome email - emailiPhone - UIbutton embedded in UIView does not respond to the following animations of this kind - iphonePlugging Queries for Mercury - mercurialT4 for creating POCOs over LLBLGen Pro objects? - .nethow to cancel timer schedule - androidHow to get the domain of a specific cookie? - phpAll Articles