Move UUID setting from the save method to a default value of the model

This commit is contained in:
Roberto Rosario
2014-10-23 01:13:22 -04:00
parent 2888075f40
commit d15d5746b5

View File

@@ -81,7 +81,7 @@ class Document(models.Model):
"""
_latest_versions = {}
uuid = models.CharField(max_length=48, blank=True, editable=False)
uuid = models.CharField(default=lambda: UUID_FUNCTION(), max_length=48, editable=False)
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'Document type'), related_name='documents')
description = models.TextField(blank=True, null=True, verbose_name=_(u'Description'))
date_added = models.DateTimeField(verbose_name=_(u'Added'), auto_now_add=True)
@@ -116,8 +116,6 @@ class Document(models.Model):
def save(self, *args, **kwargs):
user = kwargs.pop('user', None)
new_document = not self.pk
if new_document:
self.uuid = UUID_FUNCTION()
super(Document, self).save(*args, **kwargs)
if new_document: