Created
February 14, 2018 16:25
-
-
Save michaelhelmick/0e0e9666e69c0ed1d3fadecec9cd9674 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MySerializer(serializers.ModelSerializer): | |
avatar = serializers.CharField(source='get_avatar') | |
avatar_bw = serializers.CharField(source='get_avatar', color='bw') | |
class Meta: | |
model = MyModel | |
fields = ('avatar', 'avatar_bw',) | |
class MyModel(models.Model): | |
avatar = models.ImageField(...) | |
def get_avatar(self, color='normal'): | |
if color == 'bw': | |
return 'bw image' | |
return 'normal image' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment