From c1f4d3dea43e05668fd8b98934aa775a4e2db19d Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Wed, 13 May 2015 15:42:36 -0700 Subject: [PATCH] Fix section flashcard list; added default datetimes --- flashcards/models.py | 4 ++-- flashcards/serializers.py | 4 +++- flashcards/views.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flashcards/models.py b/flashcards/models.py index b41bf9f..2903d27 100644 --- a/flashcards/models.py +++ b/flashcards/models.py @@ -84,7 +84,7 @@ class Flashcard(Model): text = CharField(max_length=255, help_text='The text on the card') section = ForeignKey('Section', help_text='The section with which the card is associated') pushed = DateTimeField(auto_now_add=True, help_text="When the card was first pushed") - material_date = DateTimeField(help_text="The date with which the card is associated") + material_date = DateTimeField(default=now, help_text="The date with which the card is associated") previous = ForeignKey('Flashcard', null=True, blank=True, help_text="The previous version of this card, if one exists") author = ForeignKey(User) @@ -121,7 +121,7 @@ class UserFlashcardQuiz(Model): An event of a user being quizzed on a flashcard. """ user_flashcard = ForeignKey(UserFlashcard) - when = DateTimeField() + when = DateTimeField(auto_now=True) blanked_word = CharField(max_length=8, blank=True, help_text="The character range which was blanked") response = CharField(max_length=255, blank=True, null=True, help_text="The user's response") correct = NullBooleanField(help_text="The user's self-evaluation of their response") diff --git a/flashcards/serializers.py b/flashcards/serializers.py index 3eeda01..9e7e1d6 100644 --- a/flashcards/serializers.py +++ b/flashcards/serializers.py @@ -1,9 +1,10 @@ from django.utils.datetime_safe import datetime +from django.utils.timezone import now import pytz from flashcards.models import Section, LecturePeriod, User, Flashcard from flashcards.validators import FlashcardMask, OverlapIntervalException from rest_framework import serializers -from rest_framework.fields import EmailField, BooleanField, CharField, IntegerField +from rest_framework.fields import EmailField, BooleanField, CharField, IntegerField, DateTimeField from rest_framework.relations import HyperlinkedRelatedField from rest_framework.serializers import ModelSerializer, Serializer from rest_framework.validators import UniqueValidator @@ -114,6 +115,7 @@ class MaskFieldSerializer(serializers.Field): class FlashcardSerializer(ModelSerializer): is_hidden = BooleanField(read_only=True) hide_reason = CharField(read_only=True) + material_date = DateTimeField(default=now) mask = MaskFieldSerializer() def validate_material_date(self, value): diff --git a/flashcards/views.py b/flashcards/views.py index 0a81171..225dd13 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -33,7 +33,7 @@ class SectionViewSet(ReadOnlyModelViewSet): flashcards = Flashcard.cards_visible_to(request.user).filter( \ section=self.get_object(), is_hidden=False).all() - return Response(FlashcardSerializer(flashcards, many=True)) + return Response(FlashcardSerializer(flashcards, many=True).data) @detail_route(methods=['post'], permission_classes=[IsAuthenticated]) def enroll(self, request, pk): -- 1.9.1