Django custom DateField: to_python() to save two fields -


i have following form field i'm using model (which contains 2 datefield fields)

class daterangefield(forms.datefield):      def to_python(self, value):         try:             values = value.split(' - ')             from_date = super(daterangefield, self).to_python(values[0])             to_date = super(daterangefield, self).to_python(values[1])         except:             raise validationerror(_("invalid input"))          return from_date, to_date 

and in form, i'm showing 1 field

class eventdaterangeform(forms.modelform):     daterange = daterangefield(required=true)      class meta:         model = mymodel         fields = [] 

and model

class mymodel(models.model):     start_day = models.datefield(blank=false,                                  null=false)     end_day = models.datefield(blank=false,                                null=false) 

how process form when form valid, save from_date , to_date start_day , end_day

this isn't way it. need one field, 2 widgets. can use multivaluefield in conjunction multiwidget achieve this.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -