I have a model which basically just represents a file. I want to use a UUID
as the filename. I could do the following:
def _get_filename(instance, filename):
return str(uuid.uuid4())
class File(Model):
content = FileField(db_index=True, upload_to=_get_filename)
filetype = CharField("MIME Type", max_length=256)
which does work however it is sub-optimal in a couple of ways:
- the UUID is stored as a VARCHAR in the database
- the UUID is not used as the primary key
- there is a pointless additional integer field as the primary key
- you can't even add unique=True to the field
So I was wondering:
- why does FileField refuse to allow its use in a unique index or as the
primary key?
- how can I get FileField to use a UUID field in the database?
Any thoughts would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/396e0394-3112-46db-9499-0cfbb8eb780a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.