Part 1 — Project Structure & Imports
The first step in migrating from V1 is getting your project into the right shape. V1 projects typically use nested Django app folders and import everything from generic_app. You'll strip out the Django boilerplate and update every import to the current lex.* paths.
Flatten the Project Structure
V1 projects often look like this — a standard Django app layout:
MyProject/
├── manage.py
├── my_app/
│ ├── __init__.py
│ ├── models/
│ │ ├── __init__.py
│ │ ├── Fund.py
│ │ ├── Quarter.py
│ │ └── Investment.py
│ ├── admin.py
│ └── views.py
└── requirements.txtLex App doesn't use Django's app scaffolding. There's no manage.py, no admin.py, no views.py. Your models go into three ETL folders:
MyProject/
├── .env
├── .run/
├── migrations/
├── Input/
│ ├── __init__.py
│ ├── Fund.py
│ ├── Quarter.py
│ └── Investment.py
├── Upload/
│ ├── __init__.py
│ ├── FundUpload.py
│ └── InvestmentUpload.py
└── Reports/
├── __init__.py
└── CalculateNAV.py
└── requirements.txtHow to Flatten
- Move your model files out of the nested app folder
- Organize them at the root or into meaningful subfolders
- Delete
manage.py,admin.py,views.py, and any empty__init__.pyfiles - Delete the old app directory
- Run
lex setupto generate.env,.run/, andmigrations/
# Example commands
mv my_app/models/*.py ./
rm manage.py
rm -rf my_app/
lex setupDon't delete your existing
migrations/folder — you'll need it to run Django migrations after refactoring.
Update All Imports
This is the most mechanical part of the migration. Every file that imports from generic_app needs to be updated.
Find All Files to Update
grep -rn "from generic_app" --include="*.py" .
grep -rn "import generic_app" --include="*.py" .Core Model Imports
# Before
from generic_app import models
from generic_app.models import *
# After
from django.db import models
from lex.core.models.LexModel import LexModelCalculation Imports
# Before
from generic_app.generic_models.upload_model import ConditionalUpdateMixin
# After
from lex.core.models.CalculationModel import CalculationModelLifecycle Hook Imports
V1 had no explicit hook imports — hooks were implicit via UploadModelMixin. Now you need to import them explicitly:
# Before
from generic_app.generic_models.upload_model import UploadModelMixin
# After
from lex.core.models.LexModel import LexModel
from django_lifecycle import hook, AFTER_CREATELogging Imports
# Before
from generic_app.submodels.CalculationLog import CalculationLog
# After
from lex.audit_logging.handlers.LexLogger import LexLoggerPermission Imports
# Before
from generic_app.generic_models.ModelModificationRestriction import ModelModificationRestriction
# After
from lex.core.models.LexModel import UserContext, PermissionResultFor the complete replacement table, see the V1 to V2 Import Map.
Update Internal References
Imports between your own models follow the folder structure:
# Importing an input model from anywhere
from Input.Fund import Fund
# Importing an upload model
from Upload.FundUpload import FundUpload
# Importing a report model
from Reports.CalculateNAV import CalculateNAVString references like
'Fund'in ForeignKey fields are often the safest option during migration — they avoid circular import issues.
Verify
Run these checks — both should return zero results:
grep -rn "from generic_app" --include="*.py" .
grep -rn "import generic_app" --include="*.py" .Checkpoint
Django boilerplate removed (
manage.py,admin.py,views.py)lex setuphas been run (.env,.run/,migrations/exist)All
generic_appimports replaced withlex.*/django.*importsInternal model references updated to match folder structure
Zero
grepresults forgeneric_app
Next: Part 2 — Models & Fields.
Was this helpful?
Your feedback shapes what we write next.
