[Answered ]-Django ~Q queries

2👍

An alternative to what you are trying to do with Qs, would be to use filter()+exclude()+get():

_entry = Entry.objects.filter(slug=slug, author=self.author).exclude(id=self.id).get()
👤alecxe

0👍

Not only the ‘&’ but also Comma ‘,’ represents AND in django Q objects so you can also try:

from django.db.models import Q    
_entry = Entry.objects.get(Q(slug=slug), Q(author=self.author) , ~Q(id=self.id))

Although I couldn’t recreate the error that you get. Also please make sure slug,self.author and self.id have proper type of data to go into respective fields.

Here are the docs for complete reference

👤Shark

Leave a comment