How to add an model instance to a django queryset?

You can also use the | operator to create a union:

queryset = MyModel.objects.none()
instance = MyModel.objects.first()
queryset |= MyModel.objects.filter(pk=instance.pk)

But be warned that this will generate different queries depending on the number of items you append this way, making caching of compiled queries inefficient.

Leave a Comment

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