jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

Overloading required on __init__ of ModelForm does not work #94

Closed labrocadabro closed 10 years ago

labrocadabro commented 10 years ago

Example:

Model:
class Name(models.Model):
    name = models.CharField(max_length=20, null=True, blank=True)

Form:
def NameForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.fields['name'].required = True
    class Meta:
        model = Name
        fields = ('name',)

The required attribute will not show, and ignore the True setting. Conversely, setting required=False in init will not remove the required attribute.

brutasse commented 10 years ago

Your code example doesn't call super(). Are you sure this doesn't work?

def NameForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(NameForm, self).__init__(*args, **kwargs)
        self.fields['name'].required = True
labrocadabro commented 10 years ago

Sorry, I forgot super in the example, but in my actual code it is there and it's still not working.

gregmuellegger commented 10 years ago

Can you elaborate on this a bit more? It's not possible to reproduce this without any further information. I will close the issue for now. Please feel free to reopen it if you experience the issue in the future and think it's a bug in floppyforms.