Re: change min_length in form __init__?
On 13/01/12 10:47, bruno desthuilliers wrote: On Jan 11, 12:15 pm, galgalwrote: Is there any way, to change the field's *min_length* argument inside form constructor? That doesn't work: def __init__(self, *args, **kwargs): super(CreateTeamForm, self).__init__(*args, **kwargs) self.fields['primary_color'].min_length = 4 Assuming primary_color is a CharField, this should theoretically JustWork AFAICT. What is the result ? ("doesn't work" is not really descriptive...) Hi Bruno, I answered this question on Stack Overflow earlier this week [1]. When a field with min_length is initialised, a MinLengthValidator is added to the its validators. So if you set the min_length attribute after calling parent classes __init__ method, it is 'too late' for it to have any effect. The solution is to change the field's validators in the __init__ method instead, Cheers, Alasdair [1]: http://stackoverflow.com/questions/8818261/django-change-min-length-in-form-init/ -- Alasdair Nicol Developer, MEMSET mail: alasd...@memset.com web: http://www.memset.com/ Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, Surrey, GU2 7YD, UK. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: change min_length in form __init__?
On Jan 11, 12:15 pm, galgalwrote: > Is there any way, to change the field's *min_length* argument inside form > constructor? That doesn't work: > > def __init__(self, *args, **kwargs): > super(CreateTeamForm, self).__init__(*args, **kwargs) > self.fields['primary_color'].min_length = 4 Assuming primary_color is a CharField, this should theoretically JustWork AFAICT. What is the result ? ("doesn't work" is not really descriptive...) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: change min_length in form __init__?
On Jan 13, 7:02 am, Wen 温业逵Yekuiwrote: > why you use the "*" in your function argument? > Because it's the sensible thing to do here - cf http://docs.python.org/release/2.6.7/tutorial/controlflow.html#more-on-defining-functions -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: change min_length in form __init__?
why you use the "*" in your function argument? 2012/1/11 galgal> Is there any way, to change the field's *min_length* argument inside form > constructor? That doesn't work: > > def __init__(self, *args, **kwargs): >> super(CreateTeamForm, self).__init__(*args, **kwargs) >> self.fields['primary_color'].min_length = 4 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/laN38iWqC-oJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
change min_length in form __init__?
Is there any way, to change the field's *min_length* argument inside form constructor? That doesn't work: def __init__(self, *args, **kwargs): > super(CreateTeamForm, self).__init__(*args, **kwargs) > self.fields['primary_color'].min_length = 4 -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/laN38iWqC-oJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.