Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Djongo : Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedField or ArrayField in model #566

Open
prakharrai opened this issue Aug 16, 2021 · 6 comments · May be fixed by #623

Comments

@prakharrai
Copy link

prakharrai commented Aug 16, 2021

Error : On Django Admin form - input value ----Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedObjects or ArrayField in model

Python script

class Entry(models.Model):
    DELIVERY_METHODS = (
        ('No Shipping Needed', 'No Shipping Needed'),
        ('Standard Shipping', 'Standard Shipping'),
        ('Cargo Shipping', 'Cargo Shipping'),
    )
    name = models.CharField(max_length=250)
    sr_no = models.IntegerField()
    milestone = models.CharField(max_length=100)
    inspection_period = models.IntegerField()
    #delivery_type =  models.CharField(max_length=100, choices=DELIVERY_METHODS)
    shipping_price = models.IntegerField()
    unit_price = models.IntegerField()
    description = models.TextField()


    class Meta:
        #verbose_name = "Child"
        #verbose_name_plural = "Children"
        abstract = True
    def __str__(self):
        return self.name


class Post(models.Model):
    SHIPPING_METHODS = (
        ('Courier', 'Courier'),
        ('None', 'None'),
    )
    SHIPPING_PAYMENTS = (
        ('Buyer', 'Buyer'),
        ('Seller', 'Seller'),
        ('Shipping Cost', 'Shipping Cost'),
    )
    ESCROW_PAYMENTS = (
        ('Buyer', 'Buyer'),
        ('Seller', 'Seller'),
        ('50 - 50', '50 Buyer - 50 Seller'),
    )
    #_id = models.ObjectIdField()
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    type_of_transaction = models.CharField(max_length=100)
    user_email = models.CharField(max_length=100)
    buyer_phone_number = models.CharField(max_length=12, default=None)
    price = models.IntegerField()
    shipping_method = models.CharField(max_length=7, choices=SHIPPING_METHODS)
    entry = models.EmbeddedField(model_container=Entry,)
    objects = models.DjongoManager()

    def __str__(self):
        return self.title
    
    def get_absolute_url(self):
        return reverse('post-detail', kwargs={'pk': self.pk})

Traceback

Screen Shot 2021-08-16 at 9 56 44 PM

@prakharrai prakharrai changed the title Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedObjects or ArrayField in model Djongo : Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedObjects or ArrayField in model Aug 16, 2021
@prakharrai prakharrai changed the title Djongo : Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedObjects or ArrayField in model Djongo : Value: '__' must be an instance of <class 'dict'> or <class 'list'> when defining EmbeddedField or ArrayField in model Aug 16, 2021
@Teketel
Copy link

Teketel commented Aug 19, 2021

The same as #491

Downgrading Djongo to 1.3.1 works for me,

@prakharrai
Copy link
Author

The same as #491

Downgrading Djongo to 1.3.1 works for me,

Thanks for the reply. Downgrading to 1.3.1 doesn't work for me since my project needs Django 3 which is not supported by this version Djongo. Any other workarounds to the issue? Haven't been able to find any other answers online.

@zi-bot
Copy link

zi-bot commented Oct 29, 2021

hey, do you have any solution.?, this issue same with me

@TorhamDev
Copy link

Hello,
I get this error in other versions
But in djongo version 1.3.3 and Django == 3.0.5
Everything worked fine

@AlekseiZag
Copy link

Hello, I get this error in other versions But in djongo version 1.3.3 and Django == 3.0.5 Everything worked fine

pls, show all requirements.txt file. I tried to use djongo==1.3.3 and Django == 3.0.5, but nothing comes out...

@NachE
Copy link

NachE commented Feb 23, 2022

This usually happens when you define an ArrayField when you should actually define an EmbeddedField in your model. Or vice versa.

@snphan snphan linked a pull request Jun 11, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants