Search code examples
pythondjango-admindjongo

Value: xx must be an instance of <class 'dict'> with EmbeddedField and ModelForm


Trying use EmbeddedField of Djongo but without any success.

Output error: Value: en must be an instance of <class 'dict'>

from djongo import models
from django import forms


class Language(models.Model):
    CODE_LANG_CHOICES = (
        ('en', 'English'),
        ('pt', 'Portuguese'),
    )

    DIRECTION_CHOICES = (
        ('ltr', 'Left-to-right'),
        ('rtl', 'Right-to-left'),
    )

    code = models.CharField(max_length=2, choices=CODE_LANG_CHOICES, default='en')
    direction = models.CharField(max_length=3, choices=DIRECTION_CHOICES, default='ltr')

    def __str__(self):
        return f'{self.code}'

    class Meta:
        abstract = True


class LanguageForm(forms.ModelForm):
    class Meta:
        model = Language
        fields = ('code', 'direction')


class Campaign(models.Model):
    _id = models.ObjectIdField()
    language = models.EmbeddedField(model_container=Language, model_form_class=LanguageForm)
    objects = models.DjongoManager()

    def __str__(self):
        return f'{self.name}'

Preview error on Django Admin:

enter image description here

My requirements.txt file:

Django==2.2.16
sqlparse==0.2.4
git+https://github.com/nesdis/djongo.git@master#egg=djongo
djangorestframework==3.12.1

Python 3.6.12 MongoDB 3.6


Solution

  • After hours of tests, have a bug in version 1.3.3, downgrading to 1.3.1 works everything.

    About this issue here.