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:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user