Django check for any exists for a query

前端 未结 3 1010
梦如初夏
梦如初夏 2021-02-01 00:12

In django how to check whether any entry exists for a query

sc=scorm.objects.filter(Header__id=qp.id)

This was how it was done in php

3条回答
  •  别那么骄傲
    2021-02-01 00:47

    As of Django 1.2, you can use exists():

    https://docs.djangoproject.com/en/dev/ref/models/querysets/#exists

    if some_queryset.filter(pk=entity_id).exists():
        print("Entry contained in queryset")
    

提交回复
热议问题