In my models I want to update the last_edited
value of the Submission
object everytime the UserAnwser
object is saved.
To this end I've written the following code
from django.utils import timezone
...
class UserAnswer(models.Model):
answer = models.FloatField()
question = models.ForeignKey(Question, related_name='answers')
submission = models.ForeignKey(AssessmentSubmission, related_name='answers')
#Update submission.last_edited on answer.
def save(self, *args, **kwargs):
submission = self.submission
submission.last_edited = timezone.now
submission.save()
super(UserAnswer, self).save(*args, **kwargs)
I've set the correct timezone in the settings.py
file:
LANGUAGE_CODE = 'nl'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True
USE_L10N = True
USE_TZ = True
However, everytime I change the answer and lookup the submission.last_edited value in our django-rest api, the time is 1 hour behind the actual time. Its almost as if the time is being displayed in 'summer time' and the DST is not handled correctly.
For example, if I edit an answer at 13:30
, our api will return 12:30
Since the settings.TIMEZONE
has been set and I am using django's django.utils timezone object it should all be working.
Especially since the Time that is shown in the admin is the correct one, so its going wrong somewhere within our API. Yet our serialiser isn't doing anything to exiting, so its not clear to me where it goes wrong.
class AssessmentSubmissionSerializer(serializers.ModelSerializer):
comments = CommentedItemSerializer(read_only=True, many=True)
class Meta:
model = am.AssessmentSubmission
fields = ('user', 'submission_date', 'start_date', 'last_edited', 'shared_with', 'assessment', 'scores', 'user_answers', 'comments', )
could someone point me towards the right direction?
Fixed it!
Thanks to iklinac's response I figured out that the problem was located within our Django-rest framework code.
I solved it by following Ramast his instructions within this question