Re: Django admin obj.file.path is incorrect?
Finally got the answer.
Just call form.save in the beginning of save_model to save the file and process it as you want.
Hope it will help somebody.
--
wbr,
rush.
06.08.2013, 22:05, "rush" <django@irush.su>:
--Hi there,I have to upload a file via django admin and process it in external script right after upload.When I'm trying to check if file exists in django save_model:class MyAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): try: with open(obj.file_field.path): pass except IOError: print 'File doesnt exist.'
obj.save()
I get an error "File doesnt exist".
ps. file_field described in models.as:
file_to = lambda inst, fn: 'files/%s/original%s' % ( inst.url, path.splitext(fn)[1])
file_filed = models.FileField(blank=True, upload_to=file_to)
How do I process a file right after upload before save_model (as I need to save a process_file function return to a model field)?--wbr,rush.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home