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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:51:44+00:00 2026-05-12T19:51:44+00:00

First I’ll lay out what I’m trying to achieve in case there’s a different

  • 0

First I’ll lay out what I’m trying to achieve in case there’s a different way to go about it!

I want to be able to edit both sides of an M2M relationship (preferably on the admin page although if needs be it could be on a normal page) using any of the multi select interfaces.

The problem obviously comes with the reverse side, as the main side (where the relationship is defined) works just fine automagically.

I have tried some of the advice here to get an inline to appear and that works but its not a very nice interface.

The advice I got on the django mailing list was to use a custom ModelForm. I’ve got as far as getting a multiselect box to appear but it doesnt seem to be “connected” to anything as it does not start with anything selected and does not save any changes that are made.

Here’s the appropriate snippets of code:

#models.py
class Tag(models.Model):
    name = models.CharField(max_length=200)

class Project(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    tags = models.ManyToManyField(Tag, related_name='projects')

#admin.py
class TagForm(ModelForm):
    fields = ('name', 'projects')
    projects = ModelMultipleChoiceField(Project.objects.all(), widget=SelectMultiple())
    class Meta:
        model = Tag

class TagAdmin(admin.ModelAdmin):
    fields = ('name', 'projects')
    form = TagForm

Any help would be much appreciated, either getting the code above to work or by providing a better way to do it!

DavidM

  • 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-12T19:51:44+00:00Added an answer on May 12, 2026 at 7:51 pm

    The reason why nothing happens automatically is that the “projects” field is not a part of the Tag model. Which means you have to do all the work yourself. Something like (in TagForm):

    def __init__(self, *args, **kwargs):
        super(TagForm, self).__init__(*args, **kwargs)
        if 'instance' in kwargs:
            self.fields['projects'].initial = self.instance.project_set.all()
    
    def save(self, *args, **kwargs):
        super(TagForm, self).save(*args, **kwargs)
        self.instance.project_set.clear()
        for project in self.cleaned_data['projects']:
            self.instance.project_set.add(project)
    

    Note that the code is untested so you might need to tweek it some to get it to work.

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

Sidebar

Related Questions

First of all I have seen that there are many questions about unrecognized selector
first of all, I'm not good with jQuery and coding. I'm trying to achieve
First, let's get the security considerations out of the way. I'm using simple authentication
First sorry for my english. I am currently trying to develop a JAVA webservice
First I want to thank you guys here, because your posts have gotten me
First I will ask users How many names you want to enter?. Once they
First of all, some background: I'm trying to get in a list of integers
First, I am a SQL noob, second if there is a better solution that
First let me phrase the proper question: Q: There is a file containing more
First off I have an app that provides the user information about the amount

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.