OK I got the point but still having some problem dealing with excel
file.
code:
abspath = '/home/laspal/work/test/tmp/'
********* view***************
if not os.path.isdir(abspath + str(_user.username)):
os.mkdir(abspath + str(_user.username) )
filepathwithname = os.path.join(abspath + str
(_user.username), file_name)
if not os.path.isfile(filepathwithname):
workbook.save(os.path.join(abspath + str(_user.username),
file_name))
cronemail = CronEmail()
filecontent = ContentFile(filepathwithname)
cronemail.attach.save(filepathwithname, filecontent)
if os.path.isfile(filepathwithname):
os.remove(os.path.join(abspath + str(_user.username),
file_name))
if os.path.isdir(abspath + str(_user.username)):
os.removedirs(abspath + str(_user.username))
The problem I am facing is the excel file is getting save but not able
to get content of excel file.
Or is there any other way of handing it? I know I am saving the same
file twice.
Thanks
On Nov 18, 8:24 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> laspalwrote:
> > Hi,
> > I am trying to savefileusingfilefieldbut ran into problem.
> > Here is my code:
>
> > ***********model************
>
> > class CronEmail(models.Model):
> > subject = models.CharField( max_length = 200)
> > message = models.CharField( max_length = 200)
> > sender = models.CharField( max_length = 200)
> > send_to = models.CharField(max_length = 200)
> > attach = models.FileField(upload_to='example', null = True)
> > created_on = models.DateTimeField(auto_now_add=True)
> > updated_on = models.DateTimeField( auto_now = True)
>
> > ****************form******************
> > class SendMailForm(forms.Form):
> > attach = forms.FileField(required= False)
> > subject = models.CharField( max_length = 200)
> > message = models.CharField( max_length = 200)
> > sender = models.CharField( max_length = 200)
> > send_to = models.CharField(max_length = 200)
>
> > ****************settings.py********
> > MEDIA_ROOT = os.path.join('/home/laspal/work/test/', 'static/media')
> > MEDIA_URL = '/static/media/'
>
> > *******view**************
>
> > emailform = SendMailForms(request.POST, request.FILES)
> > ........
> > cronemail = CronEmail()
> > attach = request.FILES['attach']
> > cronemail.subject = subject
> > and so on
> > cronemail.save()
>
> > So my problem how can I save attachfilewith the other info in
> > cronemail.
> > I tried cronemail.save_attach_fiel( filename, filecontent) but it
> > gives me error.
>
> Try:
>
> cronemail.attach.save(filename, filecontent)
>
> Where, filecontent is an instance of django.core.files.File. If your
> filecontent is request.FILES['attach'], just use it directly as it's
> an instance of UploadedFile which . If it's raw content, wrap it in
> afileobject before calling the save method above:
Ok I got the point but still I am having problem
> from django.core.files.base import ContentFile
> filecontent = ContentFile(raw_content)
>
> If you continue getting errors, please post the error trace along with
> the your code as it helps people provide more direct answers.
>
>
>
> > So can some one help me out in savingfile.
> > and also I wanted to know how can I get the storedfileand delete
> > it?
>
> cronemail.attach.delete()
>
> -Rajesh Dok
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---