Note that there are some explanatory texts on larger screens.

plurals
  1. POEditing both sides of M2M in Admin Page
    text
    copied!<p>First I'll lay out what I'm trying to achieve in case there's a different way to go about it!</p> <p>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.</p> <p>The problem obviously comes with the reverse side, as the main side (where the relationship is defined) works just fine automagically.</p> <p>I have tried some of the advice here to get an inline to appear and that works but its not a very nice interface.</p> <p>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.</p> <p>Here's the appropriate snippets of code:</p> <pre><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 </code></pre> <p>Any help would be much appreciated, either getting the code above to work or by providing a better way to do it!</p> <p>DavidM</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload