List Info

Thread: FileField upload hack




FileField upload hack
user name
2006-05-31 15:53:06
Hi Adrian and others,
first of all - DJANGO IS GREAT - please hang on and give me
nice
input!!

But then, some problems still occur...

If i do a manipulator.save() on an FileField, in the second
run (POST)
the original file-path is gone/ saved empty. I saw a ticket,
but lost
it :-/
While i'm new to this i wasn't up to place a ticket, but
maybe this
belongs to django developers...

After fiddling and trying to understand the '_file' thing,
i came up
with a small hack. Would you please recognize it as in

           db.models.manipulators around line 100:

        ## HACK
        filesToBeSaved=[]
	## First collect all uploaded files to be saved
        for f in self.opts.fields:
            if isinstance(f, FileField):
                filesToBeSaved.append(f)
		## as this is especially FileField related,
		## i can steel code from db.models.fields ...
               
upload_field_name=f.get_manipulator_field_names('')[0]
               
new_place=new_data.get(upload_field_name,False)
		## memorize the upload path
                if new_place:
                   
params[f.attname]=new_place['filename']
                else:

params[f.attname]=getattr(self.original_object,f.attname)


        # First, save the basic object itself.
        new_object = self.model(**params)
        new_object.save()

        # Now that the object's been saved, save any
uploaded files.
        for f in filesToBeSaved:
            f.save_file(new_data, new_object, self.change
and
self.original_object or None, self.change, rel=False)

Now you can even use custom manipulators and
ImageUploadFields and such
and it works (at least for me  ...

Thanks

Frank


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )