Commit 19f62c6f7ed98aa2cf9791cbcc88c87c74c2d0bc
1 parent
ad724d7916
Exists in
master
add is_in_deck field to flashcardserializer
Showing 2 changed files with 8 additions and 1 deletions Side-by-side Diff
flashcards/serializers.py
View file @
19f62c6
... | ... | @@ -123,11 +123,13 @@ |
123 | 123 | |
124 | 124 | class FlashcardSerializer(ModelSerializer): |
125 | 125 | is_hidden = SerializerMethodField() |
126 | + is_in_deck = SerializerMethodField() | |
126 | 127 | # hide_reason = CharField(read_only=True) |
127 | 128 | material_date = DateTimeField(default=now) |
128 | 129 | mask = MaskFieldSerializer(allow_null=True) |
129 | 130 | score = IntegerField(read_only=True) |
130 | 131 | |
132 | + | |
131 | 133 | def validate_material_date(self, value): |
132 | 134 | # TODO: make this dynamic |
133 | 135 | if QUARTER_START <= value <= QUARTER_END: |
... | ... | @@ -150,6 +152,10 @@ |
150 | 152 | def get_is_hidden(self, obj): |
151 | 153 | if 'user' not in self.context: return False |
152 | 154 | return obj.is_hidden_from(self.context['user']) |
155 | + | |
156 | + def get_is_in_deck(self, obj): | |
157 | + if 'user' not in self.context: return False | |
158 | + return obj.is_in_deck(self.context['user']) | |
153 | 159 | |
154 | 160 | class Meta: |
155 | 161 | model = Flashcard |
flashcards/views.py
View file @
19f62c6
... | ... | @@ -108,7 +108,8 @@ |
108 | 108 | Gets the contents of a user's feed for a section. |
109 | 109 | Exclude cards that are already in the user's deck |
110 | 110 | """ |
111 | - serializer = FlashcardSerializer(self.get_object().get_feed_for_user(request.user), many=True) | |
111 | + serializer = FlashcardSerializer(self.get_object().get_feed_for_user(request.user), many=True, | |
112 | + context={'user': request.user}) | |
112 | 113 | return Response(serializer.data) |
113 | 114 | |
114 | 115 |