import mongoengine
def global_init():
mongoengine.register_connection(alias="core", name="project")
class Worker(mongoengine.Document):
username = mongoengine.StringField()
salary_per_hour = mongoengine.FloatField()
total_hours_worked = ********[1]
meta = {
"db_alias": "core",
"collection": "users"
}
class Project(mongoengine.Document):
name = mongoengine.StringField()
associated_users = mongoengine.ListField(ReferenceField(User))
progress = mongoengine.EmbeddedDocumentField(Progress)
meta = {
"db_alias": "core",
"collection": "projects"
}
class Contrib(mongoengine.Document):
project = mongoengine.ReferenceField(Project)
user = mongoengine.ReferenceField(User)
hour = mongoengine.FloatField()
meta = {
"db_alias": "core",
"collection": "contribs"
}
class Progress(mongoengine.EmbeddedDocument):
total_hours = ********[2]
percentage = ********[3]
total_cost = ********[4]
Hi, i'm trying to build a worker-project relationship with mongoengine there will be various projects and workers. Contributions will be main inputs to the program. I need these databases for future functionalities. I want to build some relationships between databases rather than updating everything depending on an input. For example;
[1] total work hour of a worker.
[2] total_hours workers worked on that project.
[3] continuous percentage calculation of project with a percentage reference depending on specified work hour.
[4] cost of project up to now depending on workers salary_per_hour and their work hour
I am new to noSQL databases and I don't know even if I wrote things right. Is it possible to build these relationships between databases with some mapping functions? I don't know what should I use for these or is there any needed changes on code for proper working. Can you write some example or suggest me some sources for studying these things. I was lost in mongoengine documentation for last 2 hours but couldn't meet my needs.
Thanks for your help in advance.