Skip to content Skip to sidebar Skip to footer

Django Database Entry Created By Concatenation Of Two Fields

I have the following Django model class Labels(models.Model): user = models.CharField(max_length=200) label = models.CharField(max_length=200) live = models.CharField(m

Solution 1:

You can override save method for this:

class Labels(models.Model):

    def save(self, *args, **kwargs):
        concat = self.user + self.label
        self.unique_key = hashlib.md5(concat.encode()).hexdigest()
        super().save(*args, **kwargs)

Post a Comment for "Django Database Entry Created By Concatenation Of Two Fields"