3/6/2018

Custom Serializer Django Rest Framework

I'm trying to create a custom serializer method that counts the number of passed and failed quizzes from my QuizResults model. A failed quiz is under.7 and a passed quiz is.7 or over. I want to be able to look into the Users QuizResult and count the number of passed quizzes(.7 or over). I would then duplicate the method to count the failed quizzes (under.7). So far I don't have much idea on how to do so.

Django Rest Framework GithubCustom Serializer Django Rest Framework

I want to be able to grab the percent_correct field of the model and do a calculation and add it to a field in the serializer called 'quiz_passed'.

The serializers in REST framework work very. In the serializer is to write custom model manager. Serializer Extensions. The django-rest-framework. Keiko The Untold Story here. Django Rest Framework how to custom a nested serializer with multiple objects. Ask Question. Up vote 0 down vote favorite. Django, API, REST, Serializer fields. To create serializer fields for custom. A GeometryField field and a GeoJSON serializer. Django, API, REST, Serializer relations. From rest_framework import serializers from rest_framework.reverse import. See the Django documentation on reverse.

In your serializer: class UserSerializer(serializers.ModelSerializer): class Meta: model = User def __init__(self, *args, **kwargs): super(UserSerializer, self).__init__(*args, **kwargs) self.fields['username'].error_messages['required'] = u'My custom required msg' Please notice that some error messages consist of%s placeholders like: 'invalid': _('%s' value must be either True or False.' ), for BooleanField. So you need to go over default_error_messages part in each field type in the DRF's, to use it properly.