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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:20+00:00 2026-05-26T12:23:20+00:00

I am trying to implement manytomany field relation in django-nonrel on mongodb. It was

  • 0

I am trying to implement manytomany field relation in django-nonrel on mongodb. It was suggessted at to:

Django-nonrel form field for ListField

Following the accepted answer

models.py

class MyClass(models.Model):
    field = ListField(models.ForeignKey(AnotherClass))

i am not sure where the following goes, it has been tested in fields.py, widgets,py, models.py

class ModelListField(ListField):
    def formfield(self, **kwargs):
    return FormListField(**kwargs)

class ListFieldWidget(SelectMultiple):
    pass

class FormListField(MultipleChoiceField):
    """
    This is a custom form field that can display a ModelListField as a Multiple Select GUI element.
    """
    widget = ListFieldWidget

    def clean(self, value):
    #TODO: clean your data in whatever way is correct in your case and return cleaned data instead of just the value
    return value

admin.py

class MyClassAdmin(admin.ModelAdmin):
    form = MyClassForm

    def __init__(self, model, admin_site):
    super(MyClassAdmin,self).__init__(model, admin_site)

admin.site.register(MyClass, MyClassAdmin)

The following Errors keep popping up:

If the middle custom class code is used in models.py

name 'SelectMultiple' is not defined

If custom class code is taken off models.py:

No form field implemented for <class 'djangotoolbox.fields.ListField'>
  • 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-26T12:23:20+00:00Added an answer on May 26, 2026 at 12:23 pm

    You just need to import SelectMultiple by the sound of it. You can put the code in any of those three files, fields.py would make sense.

    Since it’s pretty usual to have:

    from django import forms
    

    at the top of your file already, you probably just want to edit the code below to:

    # you'll have to work out how to import the Mongo ListField for yourself :)
    class ModelListField(ListField):
        def formfield(self, **kwargs):
        return FormListField(**kwargs)
    
    class ListFieldWidget(forms.SelectMultiple):
        pass
    
    class FormListField(forms.MultipleChoiceField):
        """
        This is a custom form field that can display a ModelListField as a Multiple Select GUI element.
        """
        widget = ListFieldWidget
    
        def clean(self, value):
        #TODO: clean your data in whatever way is correct in your case and return cleaned data instead of just the value
        return value
    

    You probably also want to try and learn a bit more about how python works, how to import modules etc.

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

Sidebar

Related Questions

I have an application in which I am trying to implement ManyToMany relation between
Trying to implement the signature verification of inapp billing on my server (Django/Python). I
https://github.com/nathanborror/django-basic-apps/blob/master/README.rst I am trying to implement this blog module my question is that the
Trying to implement the following structure from c to use NSArray in objective-c: In
Trying to implement an autocomplete box ultimately. For now im following php academy's lead.
I am trying to implement an advertising system in Django. My model for ads
Trying to implement, in Scala, the following Haskell function (from Learn You a Haskell...)
Trying to implement the following behavior on an iPad. I have a map-centric application
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all

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.