Created
July 20, 2019 10:38
-
-
Save dimkoug/bb036470fb935d58d1343846f717c364 to your computer and use it in GitHub Desktop.
django abstract UUidModel , add uuid field in django model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UUidModel(models.Model): | |
import uuid | |
uid = models.UUIDField(default=uuid.uuid4, editable=False) | |
class Meta: | |
abstract = True | |
def save(self, *args, **kwargs): | |
if not self.pk: | |
self.uid = uuid.uuid4() | |
super().save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment