python - Setting form data in clean_field method -


suppose there's model:

class somemodel(models.model):     content = models.filefield(...)     number_of_lines = models.integerfield() 

i use modelform , content field validated in client_content() method. count number of lines in content , want use number set field's number_of_lines value:

what came is:

class someform(forms.modelform):     def clean_content(self):         self.number_of_lines = 0         # validation             self.number_of_lines +=1         # ...      def save(self, commit=true):         instance = super().save(commit=true)         instance.number_of_lines = self.number_of_lines         if commit:             instance.save()         return instance 

but self.number_of_lines thing not right. there better way? maybe it's possible set self.cleaned_data['number_of_accounts'] in clean_content method?

usually people suggest use clean() method that, in case have remove line counter clean_content , count lines inside clean().


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -