'How to structure files in Django Rest Framework?
My requirement is the following:
- Create endpoints that will return various reports(json) representing organized data based on some specifications.
Example: We have a car company with a lot of customers data. What I need to do is to generate reports which will contian month to month revenue from different categories of customers.
Our project uses Django Rest Framework and the file structure is as the one below:
mysite/
├── manage.py
│
├── mysite/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
│
└── app1/
├── api/v1/
│ └── serializer/
│ │ └── serializer_model1.py
│ │ └── serializer_model2.py
│ └── view/
│ │ └── view_model1.py
│ │ └── view_model2.py
│ └── permissions.py
├── migrations/
│ └── __init__.py
├── __init__.py
├── admin.py
├── apps.py
├── forms.py
├── signals.py
├── models.py
├── tests.py
└── views.py // not used
So, for "car" model we have one view and one serializer file inside api/v1/.
My questions are:
- Is this structure ok?
- Where I should write those queries to generate data for the reports? (new app?, different view?)
- If I have snippets of code which are used on multiple views, where should I place that code so I can reuse it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
