From f594c3a9f08df0ac31281b29f1ebc865ac3f67c1 Mon Sep 17 00:00:00 2001
From: Frank Sauerburger <frank@sauerburger.com>
Date: Wed, 20 Jan 2021 22:22:28 +0100
Subject: [PATCH] Automatically populate title field

---
 uhepp_org/uhepp_vault/models.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/uhepp_org/uhepp_vault/models.py b/uhepp_org/uhepp_vault/models.py
index 7c78ba3..29710e3 100644
--- a/uhepp_org/uhepp_vault/models.py
+++ b/uhepp_org/uhepp_vault/models.py
@@ -54,7 +54,7 @@ class Plot(models.Model):
     uhepp = models.JSONField()
     ui_view_count = models.IntegerField(default=0)
     api_view_count = models.IntegerField(default=0)
-    title = models.TextField(null=True, blank=True)
+    title = models.CharField(max_length=255, null=True, blank=True)
 
     collection = models.ForeignKey(
         Collection,
@@ -80,6 +80,12 @@ class Plot(models.Model):
             ui_view_count=F('ui_view_count') + 1
         )
 
+    def save(self, *args, **kwds):
+        if self.title is None:
+            self.title = str(self)
+
+        return super().save(*args, **kwds)
+
     def __str__(self):
         if self.title:
             return self.title
-- 
GitLab