Thursday, November 1, 2012

Re: unable to save ModelForm with primary key change

On 01/11/12 Tom Evans said:

> Please show the definition of MyForm. I assume you are certain that
> the form is valid, ie you have put breakpoints there (or print
> statements) and form.is_valid() is definitely returning true.

I used MyForm as an example, the actual class is

class McdLoad(models.Model):
"""A model representing an MCD load uploaded to the server, either by the
UI or by a blade."""
version = models.CharField(primary_key=True,
max_length=32)
mcdload = models.FileField(upload_to='ftproot',
blank=True)
fromversions = models.CharField(max_length=4096, default='')
remove_load = models.BooleanField(default=False)

def __str__(self):
return "%s:%s" % (self.version, self.fromversions)

class Meta:
db_table = 'mcdloads'

The view code looks like...

mcdload = McdLoad.objects.get(version=version)
if request.method == 'POST':
log.info("in a POST request")
form = McdLoadForm(request.POST, instance=mcdload)
if form.is_valid():
log.debug("yay, the form is valid")
form.save()

The logs indicate that is_valid() returned True.

Mike

--
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.

No comments:

Post a Comment