Context: I am writing an API (using Flask and MongoEngine) with multiple account types, including perhaps buildings. I need the database to hold some temporary accounts until a particular building registers.
This is how I've been referencing just one type of user:
current_holder_of_stuff = ReferenceField(ActiveUser)
I know GenericReferenceField is also an option, but what if I only want to allow two types of references? Is there anything like:
current_holder_of_stuff = ReferenceField(ActiveUser, TempUser)
Muchos thankos!
It may work to create a parent class of type
User
and then have inherited classes ofActiveUser
andTempUser
to deal with the various user types. As for the requirement forcurrent_holder_of_stuff
to be two possible document types, you cannot use a single reference field. As you've dismissed usingGenericReferenceField
then one way might be to add a property method and aStringField
with options such as this:You can also use mongoengine's signals to perform checks pre-save to ensure there is only a user or building defined.