Django: When to use QuerySet none()

Usually in instances where you need to provide a QuerySet, but there isn’t one to provide – such as calling a method or to give to a template.

The advantage is if you know there is going to be no result (or don’t want a result) and you still need one, none() will not hit the database.

For a non-realistic example, say you have an API where you can query your permissions. If the account hasn’t been confirmed, since you already have the Account object and you can see that account.is_activated is False, you could skip checking the database for permissions by just using Permission.objects.none()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)