Hello there!
So, I am trying to build a model and from it build a form. I have something
like:
class Job(models.Model):
juser = models.CharField(max_length=40)
jname = models.CharField(max_length=255)
title = models.CharField(max_length=255, null=True, blank=True)
file = models.FileField()
jdate = models.DateTimeField('Job start date and time')
jobdir = models.FilePathField(path='.')
class JobForm(ModelForm):
class Meta:
model = Job
fields = ('title', 'file')
So, I want in 'view', a form asking for a 'title' (optional) and a file
(mandatory).
fields juser, jname, jdate and jobdir should be filled automatically.
The first problem I have here is that while using a variant of way, calling
UploadFileForm instead of JobForm:
class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file = forms.FileField()
It works fine with UploadFileForm but if with JobForm, it complains about
"FileFields require an "upload_to" attribute."
In the end, what I want is from 'view', submit a file and from that derive
jname, jdate, compose a path (e.g. 'user/jname_jdate') and pass it to jobdir
and save 'file' in this path (that will be created of course). So, if this
'path' still doesn't exist before instantiating 'Job', how can I pass this
attribute? With UploadFileForm I don't have this problem but then I didn't
figure out how to feed my DB with juser, jname, title (which may be Null or
not), jobdir and I don't want file in DB.
Any suggestion? I really would appreciate any help here. Many thanks in
advance.
Alan
--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---