On 5/15/06, Jay Parlar <[EMAIL PROTECTED]> wrote: > On 5/15/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > > > Instead of saving your file manually use Django's helper method: > > > > obj = manipulator.save(new_data) > > info = request.FILES['firmware_file'] > > obj.save_firmware_file_file(info['filename'], info['content']) > > > > This not only fills date values but also resolves filename conflicts. > > http://www.djangoproject.com/documentation/db_api/#save-foo-file-filename-raw-contents > > > > The actual filename may change during this save_*_file so to get real > > (and full) filename you use obj.get_firmware_file_filename(). > > > > Ahh, very cool. How should I build the new_data object though? Is > this the *right* way? > > new_data = request.POST.copy() > new_data.update(request.FILES.copy()) > > I tried doing it this way, but now the 'creation_time' field in my > model is causing a problem. ie., my model is actually: > > class FirmwareUpload(models.Model): > firmware = models.FileField(upload_to="uploads/%A-%B-%Y") > creation_time = models.DateTimeField(auto_now_add=True) > class Admin: ... > > > When I try to upload the file, the new 'obj = > manipulator.save(new_data)' is causing the following error: > > OperationalError at /firmware/ > firmware_firmwareupload.creation_time may not be NULL > > > Shouldn't the AddManipulator have prepopulated that field, because of > the 'auto_now_add=True'? I wasn't seeing that error before the change. >
I got the creation_time issue worked out, by changing the model to 'auto_now=True'. I'm still curious though if doing the new_data.update(request.FILES.copy()) is the best way to do that part of it. Jay P. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---