Created
October 26, 2012 11:19
-
-
Save tomchristie/3958262 to your computer and use it in GitHub Desktop.
SnippetSerializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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