name 'ModelSerializer' is not defined

jike_8462024 Django 开发——API ... 最后由 上海小胖 于2017年03月28日回复

  • 1 回答
  • 2.5k 浏览
from dgutapp.models import Title
from rest_framework import serializers
# from django.contrib.auth.models import User


class TitleSerializer(serializers,ModelSerializer):
    # owner=serializers.ReasOnliField(source='owner.username')
    class Meta:
        model = Title
        field = ('id','title','image')
    def restore_object(self,attrs,instance=None):
        if instance:
            instance.id = attrs['id']
            instance.title =attrs['title']
            instance.image =attrs['image']
            return instance

        return Title(**attrs)