27 lines
926 B
Python
27 lines
926 B
Python
from rest_framework.exceptions import ValidationError
|
|
from rest_framework.serializers import ModelSerializer
|
|
|
|
from app_be.models import Feed
|
|
|
|
|
|
class FeedSerializer(ModelSerializer):
|
|
class Meta:
|
|
model = Feed
|
|
fields = '__all__'
|
|
|
|
def validate_icon(self, value):
|
|
if value is not None and value.size > 10240:
|
|
raise ValidationError("Invalid icon: Maximum size is 10KB")
|
|
return value
|
|
|
|
def validate_keywords(self, value):
|
|
split = [x.strip() for x in value.split(',')]
|
|
if len(split) > 3:
|
|
raise ValidationError("Invalid keywords: No more than three entries")
|
|
elif len(split) == 0:
|
|
raise ValidationError("Invalid keywords: Need at least one entry")
|
|
for entry in split:
|
|
if len(entry) < 3:
|
|
raise ValidationError("Invalid keywords: Keywords have to be of length greater than 2")
|
|
return value
|