Hi! First time posting here
English is not my first language so if anything isn’t properly exaplained I am happy to clarify. Also, I am a complete beginner with django and web dev in general.
I am trying to build an app to manage hierarchies in a organization. Each of these hierarchies is esentially a tree with a bunch of nodes, lets say there is a CEO, below there is a production manager (PM) and a marketing manager, below PM there are other role, etc. Now, each of these roles should be associated with a specific employee.
So for now I have something like this.
class Hierarchy(Model):
name = CharField()
class Role(Model):
name = CharField()
parent_role = ForeignKey("Role", null=True)
hierarchy = ForeignKey("Hierarchy")
employee = ForeignKey("Employee")
class Employee(Model):
name = CharField()
age = IntegerField()
My problem is that I need to retrieve the information about the employees from a REST API, and create the relationships using the id
s provided by the API. For the sake of the example, let’s assume this API allows me to filter employees by age range
I would like to create a model Employee
that is actually not stored in my db, but serves as an interface to the API that I need to use, so that I can make the connection as transparent as possible in the rest of my code. If I want to filter all the Role
s that have associated an Employee
in a specific age range I would like to do that jus like I would t if the Employee
model was stored in my local db.
I don’t know if this is a good idea or if this is even possible.
I have looked at https://docs.djangoproject.com/en/3.0/ref/models/options/#managed, I have been reading about custom managers, and thought about using in-memory dbs, but none of my ideas seem super clean.
So is there any transparent and clean way I could implement this in django?
Thanks in advance