How to Create an ERP System for Car Manufacturing Using Django, Docker Compose, PostgreSQL, and DRF for API
Creating an ERP system for car manufacturing can enhance operations by centralizing processes such as inventory management, production scheduling, and quality control. In this guide, we will build an ERP system using Django, Docker Compose, PostgreSQL, and Django Rest Framework (DRF) for API integration. This setup will allow for an efficient, scalable, and easy-to-deploy solution for managing a car manufacturing business.
Why Use Django?
Django is the ideal framework for building ERP systems because of its numerous advantages:
- Rapid Development: With built-in features like an ORM, admin interface, and authentication system, Django allows developers to focus on business logic rather than boilerplate code.
- Scalability: Django scales easily, making it perfect for enterprise-grade applications like ERP systems, capable of handling increased data and user loads.
- Security: Django comes with security best practices by default, offering protections against common vulnerabilities.
- Modularity: Django’s modular structure promotes clean, maintainable code, enabling the efficient management of various ERP components.
- API Integration: With Django Rest Framework (DRF), Django easily exposes data and functionalities through APIs, which are essential for integrating with other systems or mobile apps.
Key Technologies
- Django: A Python-based web framework used for building robust, scalable web applications.
- Docker Compose: A tool to run multi-container Docker applications, making deployment seamless.
- PostgreSQL: An open-source, powerful relational database system for managing complex data.
- DRF: A toolkit for building APIs in Django, providing flexibility in handling HTTP-based interactions.
Step-by-Step Guide to Building the ERP System
1. Setting up the Project with Docker Compose
Start by creating the project directory and setting up the docker-compose.yml file to define the services for Django and PostgreSQL.
mkdir car_manufacturing_erp
cd car_manufacturing_erp
Create a docker-compose.yml file to manage the containers for Django and PostgreSQL:
version: '3'
services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_DB: car_manufacturing_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: secretpassword
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
environment:
POSTGRES_DB: car_manufacturing_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: secretpassword
POSTGRES_HOST: db
POSTGRES_PORT: 5432
volumes:
postgres_data:
Here, we define two services:
db: This service runs PostgreSQL. The database configuration is controlled via environment variables.web: This service runs Django, with environment variables for PostgreSQL integration.
2. Creating the Django Project with Docker Compose
Use Docker Compose to create the Django project within the container:
docker compose run web django-admin startproject car_erp .
This command creates a Django project inside the container and maps it to your local file system.
Create an app for the core ERP functionalities, such as managing car models, parts, and production orders:
docker compose run web python manage.py startapp erp_core
3. Configuring PostgreSQL in Django Settings
Update the DATABASES configuration in settings.py to use the environment variables defined in the docker-compose.yml file:
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('POSTGRES_DB'),
'USER': os.getenv('POSTGRES_USER'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
'HOST': os.getenv('POSTGRES_HOST', 'db'),
'PORT': os.getenv('POSTGRES_PORT', '5432'),
}
}
This setup ensures that the database credentials are dynamically loaded from the Docker environment.
4. Defining Data Models for Car Manufacturing
Now, let’s define the models that represent the core entities of the car manufacturing ERP. These include car models, car parts, machines, production orders, and inventory.
In models.py:
from django.db import models
class CarModel(models.Model):
name = models.CharField(max_length=255)
year = models.IntegerField()
production_line = models.CharField(max_length=255)
def __str__(self):
return f"{self.name} ({self.year})"
class CarPart(models.Model):
part_name = models.CharField(max_length=255)
part_number = models.CharField(max_length=100, unique=True)
car_model = models.ForeignKey(CarModel, related_name='parts', on_delete=models.CASCADE)
cost = models.DecimalField(max_digits=10, decimal_places=2)
supplier = models.CharField(max_length=255)
stock_quantity = models.IntegerField()
def __str__(self):
return f"{self.part_name} (Part No: {self.part_number})"
class Inventory(models.Model):
part = models.ForeignKey(CarPart, on_delete=models.CASCADE)
stock_quantity = models.IntegerField()
unit_price = models.DecimalField(max_digits=10, decimal_places=2)
class Machine(models.Model):
name = models.CharField(max_length=255)
status = models.CharField(max_length=50)
class ProductionOrder(models.Model):
order_number = models.CharField(max_length=255, unique=True)
car_model = models.ForeignKey(CarModel, on_delete=models.CASCADE)
machine = models.ForeignKey(Machine, on_delete=models.CASCADE)
start_time = models.DateTimeField()
end_time = models.DateTimeField(null=True, blank=True)
- CarModel: Represents a car model, such as its name, year, and production line.
- CarPart: Represents individual parts of each car model. Parts are related to car models and tracked for cost and supplier information.
- Inventory: Tracks inventory levels for car parts.
- Machine: Represents the machines used in the manufacturing process.
- ProductionOrder: Tracks production orders, including the car model and machine used.
5. Building APIs with Django Rest Framework
Next, create serializers for these models in serializers.py to expose them via APIs:
from rest_framework import serializers
from .models import CarModel, CarPart, Inventory, Machine, ProductionOrder
class CarPartSerializer(serializers.ModelSerializer):
class Meta:
model = CarPart
fields = '__all__'
class CarModelSerializer(serializers.ModelSerializer):
parts = CarPartSerializer(many=True, read_only=True)
class Meta:
model = CarModel
fields = ['id', 'name', 'year', 'production_line', 'parts']
class InventorySerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = '__all__'
class MachineSerializer(serializers.ModelSerializer):
class Meta:
model = Machine
fields = '__all__'
class ProductionOrderSerializer(serializers.ModelSerializer):
class Meta:
model = ProductionOrder
fields = '__all__'
Create views in views.py for handling requests:
from rest_framework import generics
from .models import CarModel, CarPart, Inventory, Machine, ProductionOrder
from .serializers import CarModelSerializer, CarPartSerializer, InventorySerializer, MachineSerializer, ProductionOrderSerializer
class CarModelListCreateView(generics.ListCreateAPIView):
queryset = CarModel.objects.all()
serializer_class = CarModelSerializer
class CarPartListCreateView(generics.ListCreateAPIView):
queryset = CarPart.objects.all()
serializer_class = CarPartSerializer
class InventoryListCreateView(generics.ListCreateAPIView):
queryset = Inventory.objects.all()
serializer_class = InventorySerializer
class MachineListCreateView(generics.ListCreateAPIView):
queryset = Machine.objects.all()
serializer_class = MachineSerializer
class ProductionOrderListCreateView(generics.ListCreateAPIView):
queryset = ProductionOrder.objects.all()
serializer_class = ProductionOrderSerializer
6. Running the ERP System with Docker Compose
To start the system, first, build and run the Docker containers:
docker compose build
docker compose up
Apply the database migrations to set up the PostgreSQL schema:
docker compose run web python manage.py migrate
Your Django application will be available at http://localhost:8000, and the API will be accessible for managing car models, parts, inventory, and production orders.
Conclusion
By using Django, Docker Compose, PostgreSQL, and DRF, you've built a scalable and efficient ERP system tailored for car manufacturing. This system allows the management of car models, parts, inventory, and production orders, all of which are essential for the smooth operation of a car manufacturing plant. Additionally, with the power of Docker Compose, the deployment process becomes streamlined and easily portable across different environments.
Get in Touch with us
Related Posts
- SimpliPOSFlex. 面向真实作业现场的 POS 系统(中国市场版)
- SimpliPOSFlex. The POS Designed for Businesses Where Reality Matters
- 经典编程思维 —— 向 Kernighan & Pike 学习
- Classic Programming Thinking: What We Still Learn from Kernighan & Pike
- 在开始写代码之前:我们一定会先问客户的 5 个问题
- Before Writing Code: The 5 Questions We Always Ask Our Clients
- 为什么“能赚钱的系统”未必拥有真正的价值
- Why Profitable Systems Can Still Have No Real Value
- 她的世界
- Her World
- Temporal × 本地大模型 × Robot Framework 面向中国企业的可靠业务自动化架构实践
- Building Reliable Office Automation with Temporal, Local LLMs, and Robot Framework
- RPA + AI: 为什么没有“智能”的自动化一定失败, 而没有“治理”的智能同样不可落地
- RPA + AI: Why Automation Fails Without Intelligence — and Intelligence Fails Without Control
- Simulating Border Conflict and Proxy War
- 先解决“检索与访问”问题 重塑高校图书馆战略价值的最快路径
- Fix Discovery & Access First: The Fastest Way to Restore the University Library’s Strategic Value
- 我们正在开发一个连接工厂与再生资源企业的废料交易平台
- We’re Building a Better Way for Factories and Recyclers to Trade Scrap
- 如何使用 Python 开发 MES(制造执行系统) —— 面向中国制造企业的实用指南













