-
Environment Setup
Open the project folder in PyCharm. It should prompt you to set up a virtual environment using Python 3.11 and
-
synchronize with the
requirements.txt
file present in the project root.Alternatively, you can manually set up the environment by executing the following commands:
python -m venv venv python -m pip install -r requirements.txt
-
Enable Django Support
- Navigate to
File
->Settings
->Languages and Frameworks
->Django
. - Check the box to enable Django support.
- Set the Django Project Root to this project folder's root.
- For the settings, choose
csec_data_analytics/settings.py
. - Make sure the manage script points to
manage.py
located at the project root.
- Navigate to
-
Django Run Configuration
- Go to
Run
->Edit Configurations
. - Click the plus (+) sign to add a new configuration, then select
Django server
. - Retain the default values and confirm with
OK
.
- Go to
-
Running the Django Server
Press the Play (
▶️ ) or Debug button in the top right-hand corner. The terminal should display that the -
server is running on port 8000.
-
Creating and Running Management Commands
- To create a new management command, add a Python file under
csec_data_analytics_app/management/commands
. Name - the file according to the command you intend.
- Refer to the template in
csec_data_analytics_app/management/commands/my_command.py
.
To execute your command:
- Go to
Tools
->Run manage.py Task
. This opens a terminal where you can input your command along with any - desired parameters.
- Alternatively, adjust your Django server run configuration. In the configuration settings, click on
Run custom command
. Enter your command, ensuring you remove port 8000 and add any relevant parameters,- especially if debugging is needed.
- To create a new management command, add a Python file under
-
Initialize Database and User
Start MongoDB Shell by running:
mongosh
Then, execute the following commands:
// Create a new collection db.createCollection("django-mongo") // Switch to the new collection use django-mongo; // Create a user for the collection db.createUser({ user: "admin", pwd: "put5gwz2bjx9phe!TUD", roles: [ { role: "readWrite", db: "django-mongo" }, { role: "read", db: "django-mongo" } ] })