Your ID: if it's a new object, you can't.
Another field in the model: if it's calculated instead of database-
provided, sure. I use UUIDs for this:
def get_uuid():
import uuid
return str(uuid.uuid4())
class UploadedFileModel(models.Model):
physical_file = FileField(verbose_name='Physical File',
max_length=200, upload_to=get_upload_path)
uuid = models.CharField(max_length=36, default=get_uuid,
editable=False)
On Sep 13, 8:27 am, Tereno <[email protected]> wrote:
> Hi there, I've an ImageField and it requires a upload_to path or a
> callable. From what I read in the docs, the callable takes two
> arguments, one of which is the instance of model. It is stated that
> the model may not have been saved in the database at this point and
> thus, we cannot assume to obtain a valid id number. How would I be
> able to save an image in a path that is related to my id or another
> field within the model?
>
> Thanks!
--
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.