where to hash form data before saving the model in createview in Django? -
I am a bit confused where the formal / model field can be validated in Generic Creatives / Update Weave. Below on my imaginary models, I have to be washed using field custom 1) Method of saving method (I did not show it below) 2) Method of saving form In (I have shown below) < 3) Which is the correct way to do this, both sides and the opposition I will use the same form for the My model: My form: See my: Edit: Please refer to my model and View form in the edit field in the form I use in the form Setr not. This is a new area, which takes CharField, but the model delivers it as IntegerField. My hashfankton has converted four fields into intifield. I think that in this case secret using my custom hash function and some validation has been assumed for the
secret field (examples below I have options to do this:
form_valid method 4) How can I enter cleaned_data in the generic view (
cleaned data only code> form_valid )
updateView In that case, I will ignore the secret before displaying its data on the form. Where should it be?
class account (models.Model): user = models.ForeignKey (user) created = models.DateField (auto_now) = True = models.IntegerField ()
AccountCreateForm (forms. Secret = forms .Keyfield (max_language = 100) class meta: model = media content excluded = (secret, user, created) def save (self, user, debate): obj = super (AccountCreateView, self). = False) obj.user = self.cleaned_data ['user'] obj.secret = myHashfunction (self.cleaned_data ['secret']) obj.save ()
Category AccountCreateView (CreateView): "" "Displays form to create a new search" "model = account profiles-accountCreateForm success_url = reverse_lazy ('Home') template_name = 'app / account_form.html' def form_valid (auto, form): f = form.save (commit = false) secret = myHashfunction (self.request.POST ['secret']) f.user = self.request.user f.sav E () Returns Super (Account cutviewview, self) .form_valid (form)
form
better than ModelForm , leaving each field on your model, makes it redundant, then you will not have any additional verification for the un-hashed
secret with
clean_secret should do. AccountCreateForm (forms.Form): secret = Now, if you are not using
ModelForm , then I can suggest more than
FormView .
CreateView Normal
CreateView has been reduced by a good fit.
Comments
Post a Comment