from rest_framework import serializers
from django.contrib.auth.models import User
from .models import Job, Result


class ResultSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Result


class JobSerializer(serializers.HyperlinkedModelSerializer):
    owner = serializers.Field(source='owner.username')
    result = ResultSerializer(read_only=True)

    class Meta:
        model = Job
        fields = ('id', 'url', 'title', 'status', 'owner', 'structure', 'topology',
                  'iterations', 'result')
        read_only_fields = ('status',)


class UserSerializer(serializers.HyperlinkedModelSerializer):
    jobs = serializers.HyperlinkedRelatedField(many=True, view_name='job-detail')

    class Meta:
        model = User
        fields = ('url', 'username', 'jobs')

@@ -580,16 +580,679 @@
 tus',)%0A%0A
+    def validate_structure(self, attrs, source):%0A        %22%22%22%0A        Check that structure file is a gro file.%0A        %22%22%22%0A        uploaded_file = attrs%5Bsource%5D%0A        if uploaded_file.name.endswith('.gro'):%0A            return attrs%0A        else:%0A            raise serializers.ValidationError('Structure file must be a .gro file.')%0A%0A    def validate_topology(self, attrs, source):%0A        %22%22%22%0A        Check that topology file is a top file.%0A        %22%22%22%0A        uploaded_file = attrs%5Bsource%5D%0A        if uploaded_file.name.endswith('.top'):%0A            return attrs%0A        else:%0A            raise serializers.ValidationError('Topology file must be a .top file.')%0A%0A
 %0Aclass U

Implement validation for structure and topology files.