On Sun, Jun 05, 2011 at 07:18:24PM -0700, Roy Smith wrote:
> I'm trying to figure out how to upload a file.  I've got a model that
> looks like:
> 
> class DataSet(models.Model):
>     file = models.FileField(upload_to='data/%Y/%m/%d')
> 
> and my view method is:
> 
> def create_data_set(request):
>     if request.method == 'POST':
>       form = DataSetForm(request.POST,
>                            request.FILES)
>       if form.is_valid():
>             f = request.FILES['file']
>             data_set = DataSet()
>             data_set.save('foo', f)

I suspect this is the problem: you create an empty instnce of DataSet
and then call its save method. model.save has three optional arguments
[1], in this case you call it with force_insert='foo', force_update=f.

Both f and 'foo' evaluate to True, which is an obvious conflict.

Michal

[1] 
https://docs.djangoproject.com/en/1.3/ref/models/instances/#django.db.models.Model.save

Attachment: signature.asc
Description: Digital signature

Reply via email to