python - Django non persistent model field -


I have a Django model where I create a random password for the user.

Manager .p:

  Category UserManager (BaseUserManager): def create_user (auto, password = none): user = self.model () If the password: user.set_password (password) else: User.set_password (user.generate_password ()) user.save () return user  

After saving the model, I want to send an email with a temporary password.

  @receiver (post_save, sender = user) DEF registration_email (sender, example, created, ** kwargs): if created: pass  

my problem It is that the password was washed (which is good) so I can not do the post_save function in the following ... example.password then there is a way that I have a non Can continuously read from the model area (just on this first save) ie example.tempcleartext . Or is there a better way?

To answer your question, before you set up a reference password:

  self.temp_pw = user.generate_password () user.set_password (self.temp_pw)  

And then you have access to the password as self.temp_pw, But this will be an unstable property, which is not saved in DB.

However, I would advise you to do this specifically and to do this against email by sending a password specifically. It is better to provide a password reset feature, IMO.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -