djongo
djongo copied to clipboard
[Help Wanted] Insert data into ArrayReferenceField inside EmbeddedModelField
I've following models
class Address(models.Model):
city = models.CharField(max_length=100)
district = models.CharField(max_length=100)
zip_np = models.CharField(max_length=20)
class Info(models.Model):
name = models.CharField(max_length=50)
phone = models.CharField(max_length=12)
addresses = models.ArrayReferenceField(to=Address)
class Meta:
abstract = True
class Customer(models.Model):
company = models.CharField(max_length=20)
personal_info = models.EmbeddedModelField(model_container=Info)
So how do I insert Address in the addresses field of Info model?
Didn't read your title fully. But you cannot have a reference field inside an embedded field. The django models will not resolve the reverse reference in such a case. If you want to reference addresses. Move it to the parent, customer, which is not abstract. Having a reference filed in an abstract model will only work if you inherit it.
Is there a path forward where we could have a reference field inside an embedded document? I use this all the time. Use case is storing a list of embedded documents that each have references to things like a Django user. I think not being able to do this greatly limits one of the benefits of MongoDB.
A real world use case would be storing a list of locations as embedded documents on a business. Each location has a list of references to services that a particular location provides.
Thoughts?
Did you solve this problem? I need to insert a list of references inside the embedded documents. I did not have any problem with mongoengine, but I'd like to use djongo instead.
@nesdis Fundamentally is this out/impossible? Or is there any chance something like this can be implemented?