[Answer]-Django – Saving a model using Admin

1πŸ‘

βœ…

One option is to override your save method to apply this before it’s saved.

class Entry(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=50)
    content = models.TextField()
    # Need to specify it as blank=True here or 
    # in the form so it can be ignored when the form is cleaned
    hashval = models.BigIntegerField(blank=True)

    def save(self, *args, **kwargs):
        self.hashval = abs(hash(self.title))
        return super(Entry, self).save(*args, **kwargs)
πŸ‘€schillingt

Leave a comment