Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SnippetSerializer
class SnippetSerializer(serializers.Serializer):
title = serializers.CharField(required=False,
max_length=100)
code = serializers.CharField(widget=widgets.Textarea,
max_length=100000)
linenos = serializers.BooleanField(required=False)
lexer = serializers.ChoiceField(choices=models.LEXER_CHOICES,
default='python')
style = serializers.ChoiceField(choices=models.STYLE_CHOICES,
default='friendly')
def restore_object(self, attrs, instance=None):
"""
Create or update a new comment instance.
"""
if instance:
instance.title = attrs['title']
instance.code = attrs['code']
instance.linenos = attrs['linenos']
instance.lexer = attrs['lexer']
instance.style = attrs['style']
return instance
return models.Snippet(**attrs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.