I'm running into a problem with imports and references. I'm gonna use a made-up example to explain (the example uses mongoengine)
Let's say I have the following two classes in two different files
# File 1
# Titled houses.py
import persons
import mongoengine as me
class House(me.Document):
residents: me.ListField(me.ReferenceField(persons.Person)) #This will be a list populated with Person objects
# File 2
# Titled persons.py
import houses
import mongoengine as me
class Person(me.Document):
house: me.ReferenceField(houses.House) #This is a House object
I have two concerns in a scenario like the above
Thanks!
It seems that you can pass a string
parameter to ReferenceField
, it should solve your problem.
File 1 :
import mongoengine as me
class House(me.Document):
residents: me.ListField(me.ReferenceField("Person"))
File 2:
import mongoengine as me
class Person(me.Document):
house: me.ReferenceField("House")