Мою подругу зовут Светлана, и она растит сына одна. Её бывший муж ушёл ещё до рождения ребёнка, и с тех пор она тянет всё сама — от садика до больниц и бессонных ночей. Её сыну шесть лет, и у него тяжёлая пищевая аллергия. Анализы, походы к аллергологу, строгая диета — всё это давно стало их обычной жизнью.
Светлана строго следит за питанием сына. У него аллергия на молочное, шоколад, орехи и некоторые фрукты. Малейший сбой в диете — и у него сразу сыпь, зуд, а иногда отёки и слабость. Но, как у многих матерей, у неё есть одна «проблемная» родственница — свекровь, которая уверена, что врачи ничего не понимают, а «раньше дети ели всё подряд и были здоровы».
Однажды Светлане срочно нужно было к стоматологу — удалять зуб под наркозом. Процедура долгая, ребёнка с собой не возьмёшь. Выбора не было, и она оставила сына у свекрови. Та, как всегда, бодро заверила: «Не переживай, я знаю, что ему можно».
Светлана оставила список разрешённых продуктов и пакет с едой. На прощанье ещё раз повторила: «Никаких конфет, магазинных соков и выпечки». Свекровь кивала, улыбалась, будто слушала.
Через несколько часов Светлана вернулась и сразу увидела — что-то не так. Лицо сына было красным, он чесался и выглядел уставшим. На вопрос мальчик честно ответил: «Бабушка дала мне торт, конфеты и чай с вареньем. Сказала, что ты слишком мнительная, и немного сладкого не страшно».
Светлана в гневе бросилась к свекрови. Та лишь отмахнулась:
— Да брось ты! Какая аллергия? Раньше дети всё ели — и были крепкими. А сейчас только и делают, что болезни придумывают! Мальчику нужна нормальная еда, а не твои запреты!
— Вы понимаете, что у него мог быть отёк Квинке? — голос Светланы дрожал. — А если бы он задохнулся? Если бы я не успела?
— Ничего бы не случилось! Вы, молодые, слишком пугливые. Это ты его избаловала, вот он и болезненный.
После этого раз# Building the Backend — Week 8.3
## Setting Up the Development Environment (Docker & Django)
1. **Create and Navigate to the Backend Directory:**
— First, I created a directory called `backend` for housing all backend-related files.
— Navigated into this directory using the terminal.
2. **Initialize a Django Project:**
— Ran the command `django-admin startproject project .` to create a new Django project named `project` in the current directory.
3. **Create a Django App:**
— Executed `python3 manage.py startapp leads` to create a new app called `leads` within the project.
4. **Set Up Docker for Django:**
— Created a `Dockerfile` to define the Docker image for the Django application.
— Also created a `docker-compose.yml` file to manage the services (like Django and PostgreSQL) in separate containers.
5. **Configure Django Settings:**
— Modified the `settings.py` file in the `project` directory to integrate with Docker and PostgreSQL.
— Set up environment variables for sensitive information like database credentials.
6. **Test the Django Development Server:**
— Ran `docker-compose up` to start the containers.
— Visited `http://localhost:8000` to ensure the Django development server was running correctly.
## Setting Up PostgreSQL with Django
1. **Install PostgreSQL Driver:**
— Added `psycopg2-binary` to the `requirements.txt` file for PostgreSQL support in Django.
2. **Configure Database Settings:**
— Updated the database configuration in `settings.py` to use PostgreSQL with credentials from environment variables.
3. **Run Migrations:**
— Executed `python3 manage.py migrate` to apply initial database migrations.
4. **Create Superuser:**
— Ran `python3 manage.py createsuperuser` to create an admin user for the Django admin panel.
## Creating the Lead Model
1. **Define the Lead Model:**
— In the `models.py` file of the `leads` app, created a `Lead` model with fields like `first_name`, `last_name`, `email`, `notes`, and `created_at`.
2. **Register the Model in Admin:**
— Added the `Lead` model to `admin.py` to manage leads via the Django admin interface.
3. **Make and Apply Migrations:**
— Ran `python3 manage.py makemigrations` followed by `python3 manage.py migrate` to create and apply the schema for the `Lead` model.
## Testing the Setup
1. **Access Django Admin:**
— Navigated to `http://localhost:8000/admin` and logged in with the superuser credentials.
— Verified that the `Lead` model was visible and could be manipulated in the admin panel.
2. **Add Sample Data:**
— Created a few lead entries through the admin interface to test the model’s functionality.