https://github.com/devgametools/django-practice
DJANGO PRACTICE
https://github.com/devgametools/django-practice
Last synced: 4 months ago
JSON representation
DJANGO PRACTICE
- Host: GitHub
- URL: https://github.com/devgametools/django-practice
- Owner: Devgametools
- Created: 2025-01-15T16:51:08.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-17T15:25:31.000Z (5 months ago)
- Last Synced: 2025-02-05T16:44:46.942Z (5 months ago)
- Language: Python
- Size: 13.1 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
#Django Practice
## Create virtual environment
```bash
# Create virtual environment
python3 -m venv path_and_name_of_virtual_environment
# Activate virtual environment
source path_and_name_of_virtual_environment/bin/activate# Install django
pip install django
pip freeze > requirements.txt# Start django project
django-admin startproject name_of_project .# Create app
python manage.py startapp name_of_app# Run server
python manage.py runserver# Create migration
python manage.py makemigrations
python manage.py migrate
```
## Sqlite shell
```bash
# Sqlite is installed by default with django
./manage.py dbshell
```# Samples
```bash
from django_app.models import Book, Author, Publisher# create Publisher
publisher = Publisher(name="Penguin")
publisher.save()# create Authors
author = Author(name="Author Name")
author.save()
another_author = Author(name="Another Author Name")
another_author.save()#Create Book
book = Book(title="Book Title", publisher=publisher, publication_date="2020-07-16")
book.save()#Add Authors to Book
book.authors.set([author, another_author])
```