[Fixed]-How to filter django queryset with exclude?

1👍

OK first this is how you would get the entry object and exclude e, I’ll just assume e is the primary key. Then you can get all the authors except the ones related to e using the ORM, and then you could get all the blogs that have no mention of the e object using a related query which basically flips the foreign key.

  exclude_e = Entry.objects.exclude(pk=e)
  get_authors = exclude_e.authors.all()
  get_blogs = exclude_e.blog_set.all()

Leave a comment