Django – empty queryset 만들기

빈 QuerySet 을 만들고 싶다. 어렵다. 왜 이렇게 ㅋㅋㅋ

한줄이네.

You can have an empty queryset by doing this:

MyModel.objects.none()

참고 사이트는 여기

https://stackoverflow.com/questions/11243559/create-empty-queryset-by-default-in-django-form-fields

none()

Calling none() will create a queryset that never returns any objects and no query will be executed when accessing the results. A qs.none() queryset is an instance of EmptyQuerySet.

Examples:

>>> Entry.objects.none()
<QuerySet []>
>>> from django.db.models.query import EmptyQuerySet
>>> isinstance(Entry.objects.none(), EmptyQuerySet)
True
Share: Twitter Facebook
Bongjun Hur's Picture

About Bongjun Hur

BJ is a dev.

Seoul, Korea https://devbj.com