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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:11:56+00:00 2026-05-22T01:11:56+00:00

Going nuts over here… From within the shell, I can do: product.tags.add(a_new_tag) The tag

  • 0

Going nuts over here…
From within the shell, I can do:

product.tags.add("a_new_tag")

The tag is added to the db, and the tag association with the product works correctly. (i.e., when I do Product.objects.filter(tags__name__in=["a_new_tag"] the appropriate product spits out)

What I need to do is add some tags in the admin when the form is processed.

Here is my form code (read the comments in lines 4 and 5):

class ProductForm(ModelForm):
        def save(self, commit=True):
            product = super(ProductForm, self).save(commit=False)
            product.type="New Type to Confirm Info is being Saved Correctly" //this is saved to the product.
            product.tags.add('a_new_tag_1') //the tag is saved to the taggit db, but the association with the product isn't kept.
            product.save()
            self.save_m2m()
            return m

I tried to do the saving in the admin class instead, but this doesn’t work either:

class ProductAdmin(admin.ModelAdmin):
    form = ProductForm
    def save_model(self, request, obj, form, change):
        obj.type="new_type" //this works 
        obj.tags.add("a_new_tag_2") //tag association not saved
        obj.save()
        form.save_m2m()

What am I doing wrong? Thanks in advance!

  • 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-22T01:11:56+00:00Added an answer on May 22, 2026 at 1:11 am

    So it turns out that form.save_m2m() was the culprit. If I took it out of my own code, and commented it out in django.contrib.admin.options.py (line 983), the associations as well as the tag were saved.

    Obviously it’s not a good idea to change django’s code, so I ended up overriding change_view() in my ProductAdmin (as well as add_view()). I added the tags after calling super(), so form.save_m2m() wouldn’t overwrite my tag associations.

    This is strange because it goes directly against django-taggit’s documentation which emphasizes how important it is to call form.save_m2m() : http://django-taggit.readthedocs.org/en/latest/forms.html

    Well I dunno what’s up, I’ll probably go on the taggit google groups and notify ’em. In any case thanks David for your help, if nothing less pdb is AWESOME and I did not know about it before 🙂

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

Sidebar

Related Questions

I'm going nuts over this. I can write to a cookie, and then read
I am going nuts here, I have an array of checkboxes from a form
I am going nuts here - hope you can help me figure this out!
I'm going nuts here. For some reason I can't find a single, complete example
I am going nuts here trying to resolve a cascading update/delete issue :-) I
Can someone explain the nuts and bolts of what's really going on under the
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
I'm going nuts trying to find the problem here. I have a main window,
I think I must be going nuts here. I have a UINavigationController and in
I've been going nuts about PDF downloads to mobile devices. Here's the next madness,

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.