Adam Seering wrote:
> I'm trying to make a form that, among other things, allows a user to
> upload one or more files (the number of files will vary; it's a form to
> upload images that are missing on a vaguely-Wiki-like page).  Each
> uploaded file creates a new table entry; the non-FileFields in the
> table are determined by other code that I've written.  I expect
> filename conflicts to come up occasionally; I'd like for them to be
> dealt with automatically, like they are in the Admin interface.  The
> web form that allows for file upload also asks for additional data; I
> have to handle that separately.
>
> It seems like manipulators are usually the way to handle file-upload,
> but how can I use manipulators to do something this complex?
>
> If I can't use manipulators, how do I deal with FileFields by hand?;
> just save the file myself and set "MyFileField = SavedFileName"?  Is
> the Django function that makes a unique filename (currently by adding
> "_", I believe) available, or do I have to write that myself as well?
>
> Thanks,
> Adam


i just dealt the whole night with fiddling around a similar problem,
this is what i do to get unique filenames / get to control the
filenames:

def makeUID():
    ... create and return a unique ID ...

class MyTable( models.Model ):
    uid = models.CharField( primary_key=True, maxlength=8,
editable=False, default=lambda:mkUID() )
    title = models.CharField( maxlength=48 )
    image = models.FileField( upload_to='path to mymediafolder' )

    def _save_FIELD_file( self, field, filename, raw_contents ):
        try:
            oldEntry = MyTable.objects.get( uid=self.uid )
            from os import remove
            from django.conf import settings
            remove( settings.MEDIA_ROOT + oldEntry.image )
        except:
            pass
        filename = '%s-%s.jpg' % ( self.title, self.uid )
        super( Feature, self )._save_FIELD_file( field, filename,
raw_contents )


Don't know but maybe it'll be of help.
bernie


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to