App and Model Setup¶
Create your apps and models using the CLI so routing, serializers, and conventions stay consistent from day one.
Prerequisites¶
- Django Mindoff Project.
- Work from the project root (the directory that contains
manage.pyandmindoff.py) and activate the virtual environment.
Implementation¶
1. Create an App¶
Run:
Use the CLI for scaffolding
Create apps, models, and APIs through python mindoff.py create only.
Manual file creation can skip required registration and route wiring, which is critical for django-mindoff to function as intended.
In the interactive menu, select:
1forapp
Then provide app names in snake_case (space-separated if creating multiple), for example:
After creation, you should see:
- App directory:
apps/orders/ - App module registered in
INSTALLED_APPS - App-level URL wiring in place for versioned routing
- If creating multiple apps, enter names space-separated in one run.
2. Create Models¶
Run the same command again:
In the interactive menu, select:
3formodel
Then:
- Select the target app from the list.
- Enter model names in PascalCase (space-separated), for example:
What the CLI Generates for Each Model
python mindoff.py create (option 3) makes these changes for each model:
- The CLI normalizes given model names to PascalCase and adds
Modelsuffix automatically when needed. - Appends a new model class to
apps/<app_name>/models.py. - Sets the model base class to
mindoff_models.TimeStampModel. - Adds an
idfield as:models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_column="id"). - Adds a managed marker line for where model fields should be inserted.
- Adds
Meta.db_tableusingtbl_<app_name>_<model_base_name>. - Adds
__str__returningstr(self.id). - Appends a matching serializer class in
apps/<app_name>/serializers.pywithfields = "__all__". - Skips duplicate creation if the class already exists.
What TimeStampModel Adds
- Every generated model gets standard creation/update timestamps by default.
- Timestamp fields are managed automatically by Django (no manual assignment needed).
- Consistent timestamp availability helps auditing, sorting, and debugging across models.
mindoff_models.TimeStampModel is an abstract base model that contributes:
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Important: UUIDv4 primary key support
django-mindoff expects UUID primary keys generated with uuid.uuid4 for model workflows. Keep model primary keys as UUIDv4 to stay compatible with framework validation and CRUD pipelines.
Django User Model is also automatically configured to use a UUID primary key so identity handling stays consistent across model and relation workflows.
Keep primary key name and DB column as id
Keep the model primary key field name as id and the database column as db_column="id". Renaming the key or DB column can break assumptions used by django-mindoff CRUD and validation flows.
After model creation, run migrations before using the model in code.
3. Create Foreign Key Field¶
Run the same command again:
In the interactive menu, select:
4forforeign-key
Optional Foreign Key Creation
Foreign-key creation is optional in this flow. The main advantage is that django-mindoff automatically handles the cross-reference imports, naming conventions of the relations, and reverse keys for an enhanced developer experience.
When prompted:
- Select an existing model.
- Enter relationship details.
4. Run Migrations¶
If models were added or changed:
Core Concepts¶
1. Scaffolding Structure¶
After scaffolding completes, django-mindoff applies the project structure and registrations automatically.
The generated output includes:
apps/<app_name>/with standard app files such asmodels.py,serializers.py,tests/,apis/, etc.,- App registration in
config/settings.pyunderINSTALLED_APPS. - Route and module wiring needed for imports and migrations.
For full structure details, see Management Kit.
2. Practical Conventions¶
- Keep one domain per app (
users,billing,orders) for easier project management. - Prefer singular model names (
Order,Payment,CustomerProfile). - Keep model fields grouped under the managed marker to avoid merge conflicts.
Troubleshooting¶
mindoff.pycommand fails
Run the command from the project root and ensure the virtual environment is active.- App created but not importable
Confirm the app folder name is a valid Python module name and that it is listed inINSTALLED_APPS.