models.FileField realy requires `upload_to` param. And it can be callable
with `instance` argument [1]. Using this feature you can generate upload
path by the instance fields.

[1]: http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

On Thu, Dec 11, 2008 at 13:47, Alan <[EMAIL PROTECTED]> wrote:

> 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 <http://www.bio.cam.ac.uk/%7Eawd28><<
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to