How to migrate?
Never makemigrations without app_name.
Only python manage.py makemigrations app_name
You should also use python manage.py migrate
5 Checks before commit
New ticket git flow
git switch dev
git pull
git checkout -b EXTEDU-44_fix_EducationProgram
git status # Check all changed files (Commit Side Tab provides diff-view)
git add .
git commit -m ‘EXTEDU-44 Payer CRUD on Navigator’
git switch dev
git pull
# PyCharm - Git: Merge LOCAL (!) EXTEDU-44 into dev
git push
Виртуальная модель для отображения одного элемента требует …
ID либо с Навигатора, либо добавления вручную
git naming convention
enrollment-fix
1. lower-case (minuscule)
2. dashes as space
Сделать форму рид онли
Добавить win и contract из params
Задать условие
Задать для формы ридонли
ui.py / set_params
self.win = win
contract = params['object']
if not params['create_new'] and not contract.is_active:
self.win.form.make_read_only()Передать в params ключ-значение
В get_edit_window_params передать ключ-значение
actions /
def get_edit_window_params(self, params, request, context):
params = super().get_edit_window_params(params, request, context)
params['current_unit_id'] = get_current_unit_id(request)
return paramsui /
def set_params(self, win, params):
current_unit_id = params['current_unit_id']
current_unit = Unit.objects.get(id=current_unit_id)
self.field\_\_unit_id.value = current_unit.id
self.field\_\_unit_id.default_text = current_unit.full_name
self.field\_\_unit_id.hidden = TrueForeignKey field name
self.field_name_id
Always add _id
Debug
Ломай/отключай части кода и смотри, что меняется.
Если нет таблицы в DataBase View
Find app name for making migrations
Check apps.py within the app folder
Get entries from navigator
{navigator}/api/contract-pf?number=110
Build django container (from scratch downloading all components)
docker-compose -f docker-compose.yml up -d --build django
Recreate container without rebuilding it from scratch
docker-compose up -d --force-recreate
Install Python 3.10 on Ubuntu 23.04
Install pyenv following the readme https://github.com/pyenv/pyenv
Edit bashrc and install python 3.10.5
In Pycharm select Python from home/.pyenv/versions
Rebuild running containers
docker-compose up -d --force-recreate
Check pending migrations without applying them
python manage.py makemigrations --dry-run
Output the migration file for dry run
python manage.py makemigrations payer --dry-run --verbosity 3
How to see environmental variables in a docker container?
env printenv docker exec <container_id> env
Что делать если миграции не выполняются?
Удалить файлы миграций и записи в БД django_migrations в поле app
Create named migrations
python manage.py makemigrations --name changed_my_model your_app_label
SQL: Удалить колонку
ALTER TABLE public.education_program_educationprogrammodule DROP COLUMN in_occupancy;
Clean M2M relations to delete object
#models.py @atomic def safe_delete(self): self.author.clear() self.departments.clear() self.languages.clear() return super().safe_delete()
AssertionError: Cant find pack for field declaration (realated model Declaration)
#ui.py
field_fabric_params = dict(
model_register=ModelRegister({
'Unit': 'extedu.declaration.actions.DeclarationPack',
}),
field_list=(