Home ยป How assigned TypedChoiceField as form class to model Field with choices?

How assigned TypedChoiceField as form class to model Field with choices?

class MultipleTypedChoiceModelField(models.Field):
    def get_internal_type(self):
        return ‘MultipleTypedChoiceModelField’

    def formfield(self, **kwargs):
        defaults =  {‘form_class’: TypedMultipleChoiceField, }
        defaults.update(kwargs)
        return super(MultipleTypedChoiceModelField, self).formfield(**defaults)

def formfield(self, **kwargs):
    if self._choices: # or self.choices:
        defaults =  {‘form_class’: TypedMultipleChoiceField, }
        defaults.update(kwargs)
    return super(MultipleTypedChoiceModelField, self).formfield(**defaults)

myfield = models.CharField(max_length=100, choices=MY_FIELD_CHOICES)

myfield = models.CharField(max_length=100)

myfield = forms.MultipleChoiceField(choices=MY_FIELD_CHOICES, widget=forms.CheckboxSelectMultiple())

Add Comment

Click here to post a comment

Your email address will not be published. Required fields are marked *