Abstract model in django for UUId field

Django -- Posted on July 20, 2019

Add abstract model for uuid field

              
                import uuid
class UUidModel(models.Model):
    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)
                  
   
            

Related Posts