python - processing the data in forms.py django before saving -


This is a class in my forms - what do I have to do? There are two fields on this form - admin_time and execution time. I want to compare the data before saving.

  if admin_time: execution_time = admin_time  

This is what I want to achieve.

  class form.modelform: Keywords = (forms.CharField (help_text = _ ('Please use a comma to separate your keywords.'), Required = false, Widget = forms.TextInput (attrs = {'Class': 'Medium Field'}))) admin_time = forms.CharField (help_text = _ (enter 'more than 60 minutes'), required = false, widget = form. Defines = '' class': 'filling width'})) def __init __ (self, * args, ** kwargs): if kwargs ['example']: initial = kwargs.get ('initial', { }) Initial ['keyword'] = Kwargs ['Instance']. ['Initial'] = Initial Super (TaskForm, Self) .__ init __ (* args, ** kwargs) def _process_keywords (self, manufacturer): If 'keyword' in self.changed_data: K.K. For k = [K.strip (). Self.cleaned_data ['keyword'] Plit (',')] self.instance.replace_keywords (kw, creator) def clean (self): cleaned_data = super (taskform, self). Clean () start_date = cleaned_data.get ('start_date') end_date = cleaned_data.get ('end_date') if start_date and end_date: if start_date> = End_date: Increases the forms. Validity error (_ ("end date" should be after 'start date')) cleaned_data def Save (self, manufacturer, * arg, ** kwargs): self.instance.creator = Creator Super (TaskForm, Self) Save (* args, ** kwargs) if kwargs.get ('committed', true): self._process_keywords (creator) back self Example Class Meta: Model = Task Field = ('name', 'short_descriptation', 'execution_time', 'difficulty', 'priority': 'class meta:' ('css / admin_asscss'))} meta:' repeat Widgets = {'name', 'team', 'project', 'type', 'start_date', 'end_date', 'why_this_meter', 'prerequisite', 'direction', 'is_draft', 'is_invalid' : Forms.TextInput (attrs = {'size': 100, 'class':' fill-width '}),' short_description ': forms.TextInput (attrs = {' size ': 100,' square ':' Fill- Width '}),' directions ': as a widget (mode =' mark) 'Start', width = '800px', height = '300px', wordpress = true, attrs = {'class': 'filling width'}), 'start_date': calendar input, 'end_date' : Calendar input, 'why_the_motor': form. Textera (etters = {'rows': 2, 'square': 'fill-width'}), 'prerequisites': forms. Titeria (etters = {'rows': 4, 'class': 'fill-width'})}}  

Whatever I have tried, it is adding this function:

  def _execution_time (self): cleaned_data = super (taskform, self). Clean () data = cleaned_data.get ('execution_time') admin_time = cleaned_data.get ('admin_time') if admin_time: data = admin_time return data   

but its not working Help on this needed.

OK, method should not be named _execution_time (auto) It should be clean_execution_time (self) to execute it. For details:


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -