The Django model I have defined a model called "File" and there i have writted a custom function which is used to split the filefield for my intention.while iterating the File object through this function i am getting "Name Error" for the file field
class File(models.Model):
name = models.CharField(max_length=200)
file_upload = models.FileField(upload_to=settings.FILEPATH,blank=True,null=True,max_length=1024)
organisation = models.ManyToManyField(Organisation)
def __unicode__(self):
return self.name
def public_url(self):
if os.path.exists(self.file_upload.path):
return '/site_media/'+str(self.file_upload.path).split('/site_media/')[1]
Trace back:>>> File.objects.get(pk=1).public_url()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/work/ws/intcen/gridlex_intelligence/intelligence_centre/models.py", line 52, in public_url
if os.path.exists(self.file_upload.path):
NameError: global name 'file_upload' is not defined
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EPrMTjuYE6wJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.