Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django序列化程序未使用模型管理器_Django_Django Models_Django Orm_Django Serializer_Django Managers - Fatal编程技术网

Django序列化程序未使用模型管理器

Django序列化程序未使用模型管理器,django,django-models,django-orm,django-serializer,django-managers,Django,Django Models,Django Orm,Django Serializer,Django Managers,我正在尝试使用我自己的模型管理器来注释一些属性。在序列化程序尝试使用其中一个属性之前,这一切都很正常。 设置有点复杂,但我会尽可能地解释它 这是我的模型(简化为重要部分) 然后我有另一个模型,它有一个用户模型的外键(简化): 最后我有了这个序列化程序: class ConversationMessageSerializer(serializers.ModelSerializer): is_counselor = serializers.BooleanField(source='sende

我正在尝试使用我自己的模型管理器来注释一些属性。在序列化程序尝试使用其中一个属性之前,这一切都很正常。 设置有点复杂,但我会尽可能地解释它

这是我的模型(简化为重要部分)

然后我有另一个模型,它有一个用户模型的外键(简化):

最后我有了这个序列化程序:

class ConversationMessageSerializer(serializers.ModelSerializer):
    is_counselor = serializers.BooleanField(source='sender.is_counselor')
im接收的错误是:

AttributeError: Got AttributeError when attempting to get a value for field `is_counselor` on serializer `ConversationMessageSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Message` instance.
Original exception text was: 'User' object has no attribute 'is_counselor'
我尝试使用methodfieldserializer而不是boolean序列化程序,但它会导致相同的错误。 我记录了来自序列化程序的数据库查询,而注释不在查询中。因此,序列化程序似乎没有使用我的UserManager

有没有人遇到过同样的问题,或者知道如何解决这个问题

先谢谢你

class ConversationMessageSerializer(serializers.ModelSerializer):
    is_counselor = serializers.BooleanField(source='sender.is_counselor')
AttributeError: Got AttributeError when attempting to get a value for field `is_counselor` on serializer `ConversationMessageSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Message` instance.
Original exception text was: 'User' object has no attribute 'is_counselor'