Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7703273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:25:15+00:00 2026-05-31T23:25:15+00:00

I have a queryset containing some objects. Depending on some case or the other

  • 0

I have a queryset containing some objects. Depending on some case or the other i now want to exclude all the objects without certain tags (_tags is the name of the TagField on my model):

self.queryset=self.queryset.exclude(_tags__id__in=avoid)

But this just leaves me with an error:

Caught FieldError while rendering:
Join on field '_tags' not permitted.
Did you misspell 'id' for the lookup type?

As i’m pretty sure i did not misspell ‘id’, i did some searching on how to use tagging for something like this. In the docs there is a lot about custom Managers, but somehow i just can’t get it how i can use them to get what i want.

edit:

corrected the code above to

self.queryset=self.queryset.exclude(_tags__in=avoid)

where avoid is a list of integers. And that leaves me with the problem that the TagField of django-tagging is just a special CharField (or TextField?). Which will, of course, not sort out anything if i just query it against a list of integers. I could try to solve this in a way like this:

for tag in avoid:
    self.queryset=self.queryset.exclude(_tags__contains=tag.name)

which is not only ugly, but also leaves me with the problem of tags made of multiple words or matching parts of other tags.

I somehow have the suspicion that this could be solved in a much prettier way by someone who has understood how django-tagging works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:25:16+00:00Added an answer on May 31, 2026 at 11:25 pm

    As described in the comment on Chris’ answer, django-tagging does not deliver the tagstring when accessing model._tag. In the end i had no other solution than to do the query and sort out the loops containing a certain tag afterwards:

    itemlist = list(queryset)
    avoid = some_list_of_tag_ids            
    # search for loops that have NONE of the avoid tags
    for item in itemlist:
        #    has tags   and [ if a tag.id in avoid this list has an element]
        if (item.tags)  and [tag for tag in item.tags if tag.id in avoid]:
            # remove the item from the list
            itemlist.remove(item)
    

    To complete that the model for this looks like this:

    class Item(models.Model):
    
        _tags = TagField(blank=True,null=True)
    
        def _get_tags(self):
            return Tag.objects.get_for_object(self)
        def _set_tags(self, tags):
            Tag.objects.update_tags(tags)
    
        tags = property(_get_tags, _set_tags)
    

    Allthough i tried for quite a while, i found no way of chaining a query against tagging tags into a query chain for an object. For this project I’m stuck with tagging, but this is a real drawback…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following user resource: class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name
I have Queryset: queryset = Status.objects.all()[:10] Model Status hasn't got field commentAmount so I
I have such QuerySet in Django. j = piosenki.objects.select_related('projekt__postac').distinct().exclude(typ__in=[live, remix]).filter(piosenki__plyta__status=1, piosenki__plyta__typ='s') .extra(select={ 'ocena' :
I have a QuerySet like: items = Item.objects.all() Item has a 'name' field. In
For example, let's assume that i have two QuerySEt objects: queryset1 = my_model1.objects.all().order_by('-created') queryset2
I have a Django Queryset object called data containing string keys and float values.
I have a list of objects from a django queryset, e.g. my_list = MyObject.objects.filter(variable=something)
I have a queryset of providers : >>> provider_qs = Provider.objects.filter(...) [<Provider: Gin Investors>,
I have a dumb simple loop for alias in models.Alias.objects.all() : alias.update_points() but looking
I have a Django QuerySet , and I want to get a Q object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.