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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:07:28+00:00 2026-05-20T05:07:28+00:00

In other words, why does this work: if choice==Item.DO_ADD_CAT: for item in selected_items: for

  • 0

In other words, why does this work:

if choice==Item.DO_ADD_CAT:
    for item in selected_items:
        for c in categories:
            item.categories.add(Category.objects.get(pk=c))
        item.save()
    messages.success(request,'Categories have been added.')

and this not:

if choice==Item.DO_REM_CAT:                        
    for item in selected_items:                            
        for c in categories:                                 
            item.categories.remove(Category.objects.get(pk=c))
        item.save()                            
    messages.success(request,'Categories have been removed.')

Isn’t this supposed to be working?

edit:
here is the Item model:

class Item(models.Model):
    #public/private state flags
    PRIVATE_STATUS=1
    PUBLIC_STATUS=2
    RELEASED_STATUS=3
    STATUS_CHOICES=((PRIVATE_STATUS ,'private'),
                    (PUBLIC_STATUS  ,'public' ),
                    (RELEASED_STATUS,'released'))
    status = models.IntegerField(choices=STATUS_CHOICES,
                                 default=PRIVATE_STATUS,
                                )
    objects = models.Manager()
    name=models.CharField(max_length=50)
    tags=TagField()
    count=models.IntegerField(blank=True)

    def get_user_path(self,filename):
        return '%s/%s/%s' %( self.creator_id,
                             datetime.date.today(),
                             filename)
    file=models.FileField(upload_to=get_user_path)

    creator = models.ForeignKey(User, related_name='creator')
    categories = models.ManyToManyField(Category,related_name="items",blank=True,null=True)  

and the Category Model:

class Category (models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField()
    description = models.TextField(blank=True,help_text='Optional')

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name='Category'
        verbose_name_plural='Categories'
  • 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-20T05:07:29+00:00Added an answer on May 20, 2026 at 5:07 am

    I guess i see the error… As in the django documentation tell us, you can not use remove on an foreignkey with a null=False definition… Related documentation

    So prior to the logic of M2M relations, django set your m2m relation as null=False… So possibilities are:

    1. change your m2m definition to null=True
    2. use clear() to remove all elements…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In other words does this work as expected? int32 i = INT_MAX-1; int64 j
In other words: Does this work, i.e. is the encoding of the parameter taken
How does one delete a word to the left? In other words, delete the
In other words, if I fill two unordered_map , or unordered_set , objects with
If I was to write a mocking library, how would this work (in other
In other words, given a base class shape and a derived class rectangle :
In other words, I have a string like: anything, escaped double-quotes: \, yep anything
In other words, can I do something with a volatile variable that could not
In other words, is there a way to rewind it to the beginning? EDIT
In other words, when I do nnet(...) I can use the size parameter to

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.