Hey everyone,
I've got an interesting problem concerning file uploads.
I'm building an online auction and my `Lot` links to a thin
`LotImage` so that I can store multiple images of the lots:
class Lot(models.Model):
...
lot_number = models.PositiveIntegerField("Lot number")
Class LotImage(models.Model)
...
lot = models.ForeignKey(Lot, related_name="images")
main_image = models.ImageField(upload_to=get_main_image_path)
you can see I've written a callable for the `upload_to` parameter
because I want to store the images in a particular place:
def get_thumbnail_path(instance, filename):
return os.path.join(
LotImage.BASE_PATH,
instance.lot.catalogue.__unicode__(),
filename
)
This is all good and works a treat in the admin UI, but how can I keep
this `upload_to` functionality when working with the API by hand?
Django's Documentation on the subject talks about the `File` class
(http://docs.djangoproject.com/en/dev/topics/files/#the-file-object)
which works fine when you explicitly create LotImages:
f = open('/tmp/hello.world', 'w')
myfile = File(f)
f.close()
LotImage.create(
lot_id = 1,
main_image = myfile
)
But by doing so, I loose the `upload_to` functionality. How can I keep
it without physically moving the file to the right place, then
creating a File object and attaching to a new LotImage?
I basically want to create exactly what the admin UI does with
uploaded files.
Can anyone help?
Thanks,
RM
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---