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 8475185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:49:39+00:00 2026-06-10T17:49:39+00:00

I am relatively new to Django and have really been struggling with an implementation

  • 0

I am relatively new to Django and have really been struggling with an implementation of a custom django-taggit app through the tastypie REST API. I have researched this and keep running into the same issues. I appreciate any help and guidance you can provide.

I have a Model that I am trying to add Tags to with django-taggit. I needed to add a user_id to each tag so that each user owned their own list of tags. For this reason I setup a Through Model as shown here. Here is how my models are setup:

class Tags(TagBase):
    user = models.ForeignKey('UserProfile')

class TaggedMedia(GenericTaggedItemBase):
    tag = models.ForeignKey(Tags, related_name="tagged_items")

class Media(models.Model):
    user = models.ForeignKey('UserProfile')
    # All Other Media Fields
    tags = TaggableManager(through=TaggedMedia)

This sets up the Database tables as I thought it would, so I feel like I am on the right path.

Now, when I try to access these models via TastyPie, This is where I am running into issues. My Model Resource is setup as follows:

class TaggedResource(ModelResource):
    tags = ListField()
    user = fields.ForeignKey(UserProfileResource, 'user')

    class Meta:
        queryset = Media.objects.all().order_by('-timestamp').distinct()
        authorization = MediaAuthorization()
        detail_allowed_methods = ['get', 'post', 'put', 'delete','patch']

    def build_filters(self, filters=None):
        if filters is None:
            filters = {}

        orm_filters = super(TaggedResource, self).build_filters(filters)

        if 'tag' in filters:
            orm_filters['tags__name__in'] = filters['tag'].split(',')

        return orm_filters

    def dehydrate_tags(self, bundle):
        return map(str, bundle.obj.tags.all())

    def save_m2m(self, bundle):
        tags = bundle.data.get('tags', [])
        bundle.obj.tags.set(*tags)
        return super(TaggedResource, self).save_m2m(bundle)

Now. This works great for 2 scenarios:

  1. Running a GET query for a query with Tag filters.
  2. Running a PUT query to add EXISTING tags to the TaggedMedia table

However, if I run a PUT query with a Tag that is not in the Tags table already, it will hang and spin forever with no response.

Sorry, longest question ever, but hopefully the details will help you help me. 🙂 Thanks again!

  • 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-06-10T17:49:41+00:00Added an answer on June 10, 2026 at 5:49 pm

    I am sure this is not optimal, but this seems to work:

    def save_m2m(self, bundle):
        usrObj = User.objects.get(username=bundle.request.GET['username'])
        tags = bundle.data.get('tags', [])
        print tags
    
        for tag in tags:
            #check if the tag already exists for that user, if not save it in the DB before we try to reference it with m2m
            try:
                tagCheck = Tags.objects.get(user_id=usrObj.id,name=tag)
            except Tags.DoesNotExist:
                tagCheck = None
            if tagCheck is None:
                t1 = Tags(name=tag, user_id=usrObj.id)
                t1.save()
        #create relationships between tags and media        
        bundle.obj.tags.set(*tags)
        return super(MediaResource, self).save_m2m(bundle)
    

    I quickly check to see if the tag exists, if not, I create it quickly. This works and doesn’t crash it. Do you see any problems with doing this?

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

Sidebar

Related Questions

I am relatively new with Django and it's ecosystem. I am writing REST api
I am relatively new to django. I have defined my db schema and validated
I'm relatively new to python/django. I'm having an issue with sending to IDs through
I'm new to python, django and google app engine. All great tools and have
I am relatively new to Django and one thing that has been on my
I am relatively new to Django, and have experience with Rails. In Rails you
Being relatively new to C#, I've been researching custom events recently, and while I
I'm still relatively new to Django and have just started poking around at Django-CMS,
I'm relatively new to django.. In the app that I'm building, there are multiple
Relatively new to rails, I'm working on a simple rails app for a few

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.