serializers.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from .models import KeywordMission, DateMission, TimeMission, PageMission
  2. from rest_framework import serializers
  3. from django.contrib.auth.models import User
  4. class KeywordMissionSerializer(serializers.HyperlinkedModelSerializer):
  5. url = serializers.HyperlinkedIdentityField(view_name="CrawKeywords:keywordmission-detail")
  6. publisher = serializers.HyperlinkedRelatedField(view_name='CrawKeywords:user-detail', queryset=User.objects.all())
  7. class Meta:
  8. model = KeywordMission
  9. fields = ('url', 'keyword_mission_id', 'keyword', 'publisher')
  10. class UserSerializer(serializers.HyperlinkedModelSerializer):
  11. url = serializers.HyperlinkedIdentityField(view_name="CrawKeywords:user-detail")
  12. class Meta:
  13. model = User
  14. fields = ('url', 'username', 'email')
  15. class DateMissionSerializer(serializers.HyperlinkedModelSerializer):
  16. url = serializers.HyperlinkedIdentityField(view_name="CrawKeywords:datemission-detail")
  17. keyword_mission = serializers.HyperlinkedRelatedField(view_name='CrawKeywords:keywordmission-detail',
  18. queryset=KeywordMission.objects.all())
  19. class Meta:
  20. model = DateMission
  21. fields = ('url', 'date', 'is_date_finished', 'keyword_mission')
  22. class TimeMissionSerializer(serializers.HyperlinkedModelSerializer):
  23. url = serializers.HyperlinkedIdentityField(view_name="CrawKeywords:timemission-detail")
  24. date_mission = serializers.HyperlinkedRelatedField(view_name='CrawKeywords:datemission-detail',
  25. queryset=DateMission.objects.all())
  26. class Meta:
  27. model = TimeMission
  28. fields = ('url', 'time', 'is_time_finished', 'date_mission')
  29. class PageMissionSerializer(serializers.HyperlinkedModelSerializer):
  30. url = serializers.HyperlinkedIdentityField(view_name="CrawKeywords:pagemission-detail")
  31. time_mission = serializers.HyperlinkedRelatedField(view_name='CrawKeywords:timemission-detail',
  32. queryset=TimeMission.objects.all())
  33. class Meta:
  34. model = TimeMission
  35. fields = ('url', 'page', 'time_mission', 'finisher')