I am using inline formsets to save multiple "Photo" models related
with "Company" model, but "Photo" instance's pk is set to None. I need
it to set the upload directory and filename using the pk value:
Sample model:
def get_photo_image_path(instance, filename):
filename = '%s%s' % (instance.id, os.path.splitext(filename)[1])
# TypeError is raised here because instance.id is None
return u'companies/photos/%s/%s/%s' % (instance.id % 1000,
instance.id, filename)
class Photo(models.Model):
company = models.ForeignKey(Company)
image = models.ImageField(upload_to=get_companyphoto_image_path)
description = models.CharField(blank=True, max_length=160)
Sample formset:
PhotoFormSet = inlineformset_factory(Company, Photo, can_order=False)
Used as described in documentation with the latest Django svn
revision. The same code was running well on Django 1.0.2.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---