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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:58:52+00:00 2026-06-01T05:58:52+00:00

Hi Stackoverflow people, I would like to change the m2m widget in the admin

  • 0

Hi Stackoverflow people,

I would like to change the m2m widget in the admin pages (and later in the actual django site) to a more user friendly double list (like this one).

I understand that django.contrib.admin.widgets.FilteredSelectMultiple could do this for me. However, I have trouble to get it to work. I have added the code below to my admin.py, but the widget is not changing when I view the model in the admin app.

I have tried to adopt the code from here. Every SupplierProfile should connect to one or more countries from the WorldBorder model (based on the GeoDjango example)

Where is the flaw in the code? I can’t see why it would not be displayed.
Thank you for your help!

from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.gis import admin
from django.utils.translation import ugettext_lazy as _

from apps.profile.models import (UserProfile,
                                  SupplierProfile)
from apps.gis_data.models import WorldBorder


class WorldBorderAdmin(admin.ModelAdmin):
    filter_horizonal = ('name',)

class SupplierProfileAdminForm(forms.ModelForm):
    distribution_location_country = forms.ModelMultipleChoiceField(
        queryset = WorldBorder.objects.all(), 
            required = False,
            widget = FilteredSelectMultiple(
            verbose_name = _('Distribution Country'),
            is_stacked=False
        )
     )

    class Meta:
        model = SupplierProfile

    def __init__(self, *args, **kwargs):
        super(SupplierProfileAdminForm, self).__init__(*args, **kwargs)

        if self.instance:
          self.fields['distribution_location_country'].initial = self.instance.distribution_location_country.all()

    def save(self, commit=True):
        profile = super(SupplierProfileAdminForm, self).save(commit=False)

        profile.distribution_location_country = self.cleaned_data['distribution_location_country']

        if commit:
            profile.save()
            profile.save_m2m()

        return profile

class SupplierProfileAdmin(admin.ModelAdmin):
    form = SupplierProfileAdminForm

admin.site.register(SupplierProfile, admin.OSMGeoAdmin)

Updated code of admin.py

Is it possible to define the double list as stated below? “distribution_location_country” is the m2m field in my SupplierProfile. For some reason, it is still not coming through.

from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.gis import admin

class SupplierProfileAdmin(admin.OSMGeoAdmin):
    filter_horizontal = ('distribution_location_country', )

admin.site.register(SupplierProfile, SupplierProfileAdmin)
  • 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-01T05:58:53+00:00Added an answer on June 1, 2026 at 5:58 am

    Your register line seems to be wrong:

    admin.site.register(SupplierProfile, admin.OSMGeoAdmin)
    

    doesn’t register your customized SupplierProfileAdmin with your model.

    Perhaps you want the base class of SupplierProfileAdmin to be OSMGeoAdmin instead of ModelAdmin:

    class SupplierProfileAdmin(admin.OSMGeoAdmin):
        form = SupplierProfileAdminForm
    

    and your register line to be

    admin.site.register(SupplierProfile, SupplierProfileAdmin)
    

    Also, I’m not sure about this, but you might just be able to use

    filter_horizonal = ('name_of_the_m2m_field_on_the_model', )
    

    on your SupplierProfileModel instead of that custom field on the form?

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

Sidebar

Related Questions

I would like to get the stackoverflow community's opinion on the following three design
I wrote a macro from scratch but would like to have non-technical people install/run
I'm working with ASP.Net MVC and I would like to make a web site
I've recently seen several people doing things like this here on Stackoverflow: class A:
I've recently seen several people doing things like this here on Stackoverflow: class A:
I am rather new to Sitecore and would like to know a bit more
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hi people stackoverflow. I'm working with MVVM, I have ViewModel call UserViewModel with a
Hello people of stackoverflow. I have a problem. I'm trying to set up my
With the help of people on stackoverflow I was able to get the following

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.