I've got it...
With adding "import urllib2" (or urllib) to admin.py and modifiying
save_model as
def save_model(self, request, obj, form, change):
file_path = '%s%s%s' % ('file://', settings.MEDIA_ROOT, obj.cfile)
req = urllib2.urlopen(file_path)
obj.content_type = req.headers.get('content-type')
return obj.save()
but gets all flv contenttypes as text/plain
any ideas?
--
Ozgur Odabasi
ozgur wrote:
> Hello,
>
> I am trying to get content-type of uploading file in admin, and I always
> get the error:
>
> 'TemporaryUploadedFile' object is unsubscriptable
>
> I dont want to try Pythons mimetypes object because of files i'm trying
> to upload has no extension and has aprox. 30MB file size.
>
>
> # models.py
> class contentfile(models.Model):
> title = models.CharField(max_length=254)
> cfile = models.FileField(upload_to="uploads/%Y/%m/%d/");
> content_type = models.CharField(max_length=255, null=True, blank=True,
> editable=False)
>
>
> # admin.py
> class contentfileAdmin(admin.ModelAdmin):
> def save_model(self, request, obj, form, change):
> obj.content_type = request.FILES['cfile']['content-type']
>
> admin.site.register(content, contentfileAdmin)
>
>
>
>
>
> thanks to all helpers
>
> --
> Ozgur Odabasi
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---