I have created a app which will upload the file at a particular location. How can I read the file uploaded after the model is saved? When I click on the file link on change_field_page
it gives page not found. I'm using Django 1.2 and django-admin for this.
Here's my models.py
:
class UploadClass(models.Model):
id=models.AutoField(primary_key=True)
template_name=models.ForeignKey(sas,verbose_name=ugettext_lazy('Template Name'))
sample=models.FileField(upload_to='%Y/%B/',verbose_name=ugettext_lazy('Sample'))
st开发者_开发知识库atus=models.IntegerField(ugettext_lazy('Status'),choices=statusChoices,default=0)
created_on=models.DateTimeField(ugettext_lazy('Created on'),auto_now_add=True)
def __unicode__(self):
return (self.template_name.name)
I'm not doing anything informs.py
. How can I open the file after saving the object?
One way to do this is to create a view for the 'url' and return the file. Are there any others?
In terms of the file not being linked correctly from the admin, check your MEDIA_ROOT
and your MEDIA_URL
point to, ultimately, the same place. Also, can you give examples of how the %Y/%B/
is working out as folder names, please? They may not be as you expect.
精彩评论