About the Default UUID Value
If you set the default value for the UUIDField
, you cannot efficiently check if an object is new or if it has already been saved - the id
will be set immediately when you create a model instance. But you can overcome this overwriting the save()
method:
1 2 3 4 5 6 7 |
|
Then you can check the state of the object in the template by the existence of pk
:
1 |
|
Tips and Tricks Programming Development Django 4.2 Django 3.2 Django 2.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.