Sample Django Project for the Pybites Code Clinic sessions.
- Create a free account at https://marketstack.com/
- Add the token to the
MARKETSTACK_API_KEY
environment variable or to theMARKETSTACK_API_KEY
setting insettings.py
- Install requirements with
pip install requirements.txt
- Execute database migrations with
python manage.py migrate
- To access the administration site create a superuser with
python manage.py createsuperuser
- Run the project on your local machine with the command
python manage.py runserver
- Access http://127.0.0.1:8000/ for the web application and http://127.0.0.1:8000/admin/ for the administration site
- Add some assets to the database using the administration site (sample tickers:
TSLA
,AAPL
,BABA
,NVDA
,AMZN
) - Retrieve prices from Marketstach using
python manage.py load_prices
- Open http://127.0.0.1:8000/, add buy/sell orders and track your investment portfolio
load_prices
: Retrieves the last end of day prices from Marketstack for all the assets and stores them in the database. This command can be scheduled to run on a daily basis with cron.
- Django models – https://docs.djangoproject.com/en/4.1/topics/db/models/
- Many-to-one relationships – https://docs.djangoproject.com/en/4.1/topics/db/examples/many_to_one/
- Django forms – https://docs.djangoproject.com/en/4.1/topics/forms/
- Django form field validation – https://docs.djangoproject.com/en/4.1/ref/forms/validation/
- Creating forms from models – https://docs.djangoproject.com/en/4.1/topics/forms/modelforms/
- Making queries with the Django ORM – https://docs.djangoproject.com/en/4.1/topics/db/queries/
- Using
aggregate()
to generate aggregates over a QuerySet – https://docs.djangoproject.com/en/4.1/topics/db/aggregation/#generating-aggregates-over-a-queryset - Django
F()
query expressions – https://docs.djangoproject.com/en/4.1/ref/models/expressions/ - Serving static files during development – https://docs.djangoproject.com/en/4.1/howto/static-files/#serving-static-files-during-development
Learn more with Django 4 by Example. This book will walk you through the creation of four real-world applications, solving common problems, and implementing best practices, using a step-by-step approach that is easy to follow. After reading this book, you will have a good understanding of how Django works and how to build practical, advanced web applications.