0
votes

I'm using Model Form which have custom CharField added.My question is, what is actually the standard way to access custom fields after POST request? This is the way I doing it now:

#inside ModelForm 
date = CharField(label='date', widget=Select(choices=[
        ('', '---------'),
        ('N', 'Never')
    ]))

def __init__(self, *args, **kwargs):
   self.date = args[0]['date'] #custom date CharField
   return super(MyForm, self).__init__(*args, **kwargs)

def save(self, *args, **kwargs):
# processing self.date...

Is there a better way to do that? Also, date field is using choices as a source of input data.My guess is that choices are the right thing in this particular instance, building a table and model and then using queryset to retrieve a few values wouldn't help much, I guess.

1

1 Answers

0
votes

Use:

def __init__(self, *args, **kwargs):
    super(MyForm, self).__init__(*args, **kwargs)
    date = self.fields['date']

If the values for the choices need to be editable, I would put them in a separate model and use a ModelChoiceField. Otherwise, you're fine just using static choices.