2👍
In your Model you can set the upload_to of the imagefield to a function and then generate the uuid.
A very simple (untested) example:
import uuid
Class MyModel(models.Model):
def get_path(instance, filename):
extension = filename.split('.')[-1]
uuid = uuid.uuid1().hex
return f'path/to/file/{uuid}.{extension}'
image = ImageField(upload_to=get_path)
0👍
What I understand of your problem, you can set initial
for FORM class when initialising it. like:
help_guide_form = HelpGuideForm(initial={'headline': uuid.uuid4().hex}, instance= Helpguide)
from django docs. Also see the initial reference.
- [Django]-Django-social auth KeyError
- [Django]-Celery Django not Registering Tasks, Module not found error in shell
- [Django]-Calculating and Storing Average data on a daily, weekly and monthly and yearly basis
Source:stackexchange.com