Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Get the value of a read-only field in Serializer validation

$
0
0

Error:

TypeError at /api/answer/'>' not supported between instances of 'NoneType' and 'datetime.datetime'

serializer.py

class AnswerSerializer(serializers.ModelSerializer):    class Meta:         fields = ('exercise', 'answer_text', 'answer_file','datesend')         read_only_fields = ('datesend',)    def validate(self, attrs):       date = attrs.get('datesend')       ex = attrs['exercise']       dateend = Exercise.objects.get(topic=ex.topic)       if date > dateend.exp_answer_date:          raise serializers.ValidationError('Response time is over')       return attrs

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>