Note: I read Choosing between Stack Overflow and Software Engineering and from my conclusion since this post included code I figured it belonged on stackoverflow instead of programmers.
Hi, I'm building an application in Django and I'm very new to Django. I've read the Django Tutorial, and the Django-Rest-Framework tutorial.
My question is how should I structure this part of my application. Right now I'm trying to build a RESTful api for an android application I am writing.
I've read this:
Why does django enforce all model classes to be in models.py?
and
models.py getting huge, what is the best way to break it up?
To put my project into perspective:
Here's what my models.py looks like: (Note these are not my actual models they are just an example of what I'm doing to keep the code more concise)
class Company(models.Model):
name = models.charField(max_length=100)
class Department(models.Model):
company = models.ForeignKey(Company)
employees_count = models.IntegerField(default=1)
name = models.charField(max_length=100)
class Employee(models.Model):
department = models.ForeignKey(Department)
name = models.charField(max_length=100)
age = models.IntegerField(default=0)
Each respective class would have their own functions would be accessible through an API.
My question after an introduction to my project is.. Would the Company, Department, and Employee all belong in different packages since they are separate entities? Or should they all belong in one models file? In the end they should have their own REST class as described here: http://www.django-rest-framework.org/tutorial/3-class-based-views#rewriting-our-api-using-class-based-views