Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 1 | from rest_framework import serializers |
| 2 | |
| 3 | """ PlusSerializerMixin |
| 4 | |
| 5 | Implements Serializer fields that are common to all OpenCloud objects. For |
| 6 | example, stuff related to backend fields. |
| 7 | """ |
| 8 |
|
| 9 | class PlusSerializerMixin(): |
| 10 | backendIcon = serializers.SerializerMethodField("getBackendIcon") |
| 11 | backendHtml = serializers.SerializerMethodField("getBackendHtml") |
| 12 | |
| 13 | # This will cause a descendant class to pull in the methods defined |
| 14 | # above. See rest_framework/serializers.py: _get_declared_fields(). |
| 15 | base_fields = {"backendIcon": backendIcon, "backendHtml": backendHtml} |
| 16 | |
| 17 | def getBackendIcon(self, obj): |
| 18 | return obj.getBackendIcon() |
| 19 | |
| 20 | def getBackendHtml(self, obj): |
| 21 | return obj.getBackendHtml() |
| 22 | |