Now you just redefine fields with required=True by default. You need update widgets in __init__.
class startRound(forms.ModelForm): class Meta: model = parentRounds def __init__(self, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) self.fields['player_2'].widget =forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_2'}) self.fields['player_3'].widget =forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_3'}) self.fields['player_4'].widget =forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_4'}) пятница, 16 мая 2014 г., 4:10:33 UTC+3 пользователь Brendan Edwards написал: > > Hi, > > I am having some issues with making my form/model fields not required. > Currently this is the code that I have: > > forms.py: > > class startRound(forms.ModelForm): > player_2 = > forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', > 'hidden':'True', 'id':'player_2'})) > player_3 = > forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', > 'hidden':'True', 'id':'player_3'})) > player_4 = > forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', > 'hidden':'True', 'id':'player_4'})) > class Meta: > model = parentRounds > > models.py > class parentRounds(models.Model): > Name = models.CharField(max_length=200) > player_1 = models.CharField(max_length=25) > player_2 = models.CharField(max_length=25, null=True, blank=True) > player_3 = models.CharField(max_length=25, null=True, blank=True) > player_4 = models.CharField(max_length=25, null=True, blank=True) > started_on = models.DateTimeField(auto_now_add=True) > completed = models.BooleanField(default = False) > > The template is just the generic {{ form.player_1 }} with some jquery to > hide/show player 2,3,4 depending on the select box value for number of > players. Before I started adding jquery code to the template, this worked > fine. > > Any ideas what could have happened?! > > Thanks in advance! > Brendan > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/677ff0a5-265a-434e-8751-4beb42ef1f4d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.