Django的。困难查询集

时间:2019-05-30 10:42:36

标签: python django django-queryset

我有这样的用户:

{
"name": "test"
"parent_users": [
       1,
       2
    ]
}

我需要两次显示用户"name": "test",因为他有两个父母,例如,我需要这样显示用户"name": "test"

{
"name": "test"
"parent_user": 1
}
{
"name": "test"
 "parent_user": 2
}

我的序列化器

class CommitmentListSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = ('id',
                  'email',
                  'first_name',
                  'last_name',
                  'parent_user',)

我无法理解如何为此创建查询组

UPD

用户模型

class User(PermissionsMixin):

        id = models.CharField(primary_key=True,
                              unique=True,
                              max_length=128,
                              default=uuid.uuid4,
                              editable=False)

        email = models.EmailField(
            _('email address'),
            max_length=100,
            unique=True,
            null=True,
            blank=True,
            default=None,
            error_messages={'unique': _("A user with that email already exists.")}
        )

    ...
# another fields
    ...
    parent_user = models.ManyToManyField('self',
                                             unique=False,
                                             symmetrical=False,
                                             blank=True)

...

0 个答案:

没有答案