Assertion error at: Django-rest-Framework

前端 未结 1 1794
臣服心动
臣服心动 2021-02-01 19:33

I am using python 3.4, Django 1.7.1 (the version considered in the book), Postgres 9.3 and my IDE is Eclipse.

I have been studying the book \"Lightweight Django - Elman

相关标签:
1条回答
  • 2021-02-01 19:56

    Read the DRF docs here.

    In version 2.x a serializer class could sometimes automatically determine the queryset argument if a ModelSerializer class was being used.

    This behavior is now replaced with always using an explicit queryset argument for writable relational fields.

    You are just using a newer version of DRF than the authors of the code used, so you'll need to either use a lower version or fix the code.

    In serializers.py there's this line:

    assigned = serializers.SlugRelatedField(slug_field=User.USERNAME_FIELD, required=False)
    

    You need to either add read_only=True or queryset=User.objects.all()

    0 讨论(0)
提交回复
热议问题