Django-Nonrel with Mongodb listfield

后端 未结 1 1577
灰色年华
灰色年华 2021-01-24 20:33

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 acc

相关标签:
1条回答
  • 2021-01-24 21:02

    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 讨论(0)
提交回复
热议问题