Django: check whether an object already exists before adding

后端 未结 5 770
半阙折子戏
半阙折子戏 2021-01-31 17:19

This is a pretty simple Django question, but I can\'t find the answer in the Django docs, despite lots of hunting!

How do I check whether an object already exists, and o

5条回答
  •  借酒劲吻你
    2021-01-31 17:56

    If you are looking for a bool value

    UserToUserRole.objects.filter(
        from_user=current_user, to_user=user, role='follow'
    ).exists()
    

提交回复
热议问题