π¦ DjangoDoo Modules Guide
DjangoDoo is a modular framework built using Django, allowing you to create independent feature modules similar to Odoo. Each module has its own models, views, templates, and API endpoints while seamlessly integrating into the core system.
π What is a Module?
A module in DjangoDoo is a self-contained application that extends the core functionality. It can be enabled or disabled dynamically without affecting the entire system.
Each module can include:
β Models β Define database tables
β Views β Handle HTTP requests
β Templates β Frontend HTML pages
β Static Files β CSS, JS, images
β API Endpoints β RESTful APIs (optional)
π Module Directory Structure
Each module is stored inside the modules/
directory:
djangodoo/
βββ djangodoo/ # Core framework functionality
β βββ ... # All DjangoDoo files exists here.
βββ βββ settings.py # Django settings file
βββ modules/ # All independent feature modules
β βββ sales/ # Example module (Sales Management)
β β βββ models.py # Database models
β β βββ views.py # Business logic & controllers
β β βββ urls.py # URL routing
β β βββ templates/sales/ # Frontend templates
β β βββ static/sales/ # Static assets (CSS, JS, images)
β β βββ api.py # REST API endpoints (optional)
β β βββ __init__.py # Module initialization
β β βββ admin.py # Django Admin integration
β β βββ forms.py # Django Forms (if needed)
β β βββ tests.py # Unit tests for the module
βββ manage.py # Django management script
π¨ How to Create a New Module
Step 1: Create a Module Directory
Navigate to the modules/
directory and create a new module:
cd modules/
mkdir inventory
cd inventory
touch __init__.py models.py views.py urls.py api.py admin.py forms.py tests.py
mkdir templates/inventory static/inventory
Step 2: Define Models (models.py
)
Create your database models inside models.py
:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.IntegerField()
def __str__(self):
return self.name
Run migrations to apply database changes:
python manage.py makemigrations inventory
python manage.py migrate
Step 3: Create Views (views.py
)
Define business logic and render templates:
from django.shortcuts import render
from .models import Product
def product_list(request):
products = Product.objects.all()
return render(request, "inventory/product_list.html", {"products": products})
Step 4: Define URL Routing (urls.py
)
Connect your views to Djangoβs URL system:
from django.urls import path
from .views import product_list
urlpatterns = [
path('products/', product_list, name="product_list"),
]
Include this module in the project's main urls.py
:
from django.urls import include, path
urlpatterns = [
path('inventory/', include('modules.inventory.urls')),
]
Step 5: Create Templates (templates/inventory/product_list.html
)
Define an HTML template for the module:
{% extends 'base.html' %}
{% block content %}
<h1>Product List</h1>
<ul>
{% for product in products %}
<li>{{ product.name }} - ${{ product.price }}</li>
{% endfor %}
</ul>
{% endblock %}
Step 6: Register the Module in Django Admin (admin.py
)
from django.contrib import admin
from .models import Product
admin.site.register(Product)
Now, run the Django development server:
python manage.py runserver
Visit http://127.0.0.1:8000/inventory/products/
to see the module in action.
π Dynamic Module Loading
DjangoDoo supports dynamic module activation/deactivation. To register a new module, add it to INSTALLED_APPS
dynamically in settings.py
:
import os
INSTALLED_APPS += [
app for app in os.listdir("modules") if os.path.isdir(os.path.join("modules", app))
]
This ensures that any new module added to modules/
is automatically loaded.
For more details, check our GitHub Repository. π
π GitHub: DjangoDoo Repository
π Join Discord: DjangoDoo Community