Add check to prevent completely blank posts

This isn't perfect, but if a user tries to make a completely blank post,
they will be blocked from doing so

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-07 13:30:12 -07:00
parent 3a35a35caf
commit 4e5203c61b

View File

@@ -143,6 +143,10 @@ class Post(models.Model):
) )
def clean(self): def clean(self):
# Make sure there is at least some content
self.text = self.text.strip()
if not (self.text or self.image):
raise ValidationError("Please either write a message or upload an image")
# Image upload size check # Image upload size check
if self.image and self.image.size > settings.MAX_UPLOAD_SIZE: if self.image and self.image.size > settings.MAX_UPLOAD_SIZE:
raise ValidationError( raise ValidationError(