Re: unable to save ModelForm with primary key change
On Nov 1, 1:27 pm, Tom Evans <tevans...@googlemail.com> wrote:
> >> Please show the definition of MyForm.
>
> Please do show it.
Sorry, the model was in the previous email, here's the form.
class McdLoadForm(forms.ModelForm):
VERSIONPAT = re.compile(r'^(\d+\.){3}\d+$')
class Meta:
model = McdLoad
fields = ('version', 'mcdload', 'fromversions')
def clean(self):
cleaned_data = super(McdLoadForm, self).clean()
version = cleaned_data.get('version', '')
log.debug("cleaned_data: version is %s" % version)
if version:
version = re.sub(r'^\s+|\s+$', '', version)
if not McdLoadForm.VERSIONPAT.match(version):
raise forms.ValidationError, \
"Bad version, should be 4-digits separated by
commas"
cleaned_data['version'] = version
fromversions = self.cleaned_data.get('fromversions', '')
if fromversions:
fromversions = re.sub(r'\s', '', fromversions)
for version in fromversions.split(','):
if not McdLoadForm.VERSIONPAT.match(version):
raise forms.ValidationError, \
"Bad version, should be 4-digits separated by
commas"
cleaned_data['fromversions'] = fromversions
log.debug("clean: returning %s" % cleaned_data)
return cleaned_data
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home