https://github.com/tidbcloud/branching-django-example
https://github.com/tidbcloud/branching-django-example
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tidbcloud/branching-django-example
- Owner: tidbcloud
- Created: 2023-09-27T14:14:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T15:04:15.000Z (about 2 years ago)
- Last Synced: 2025-02-05T08:50:57.260Z (over 1 year ago)
- Language: Python
- Size: 17.6 KB
- Stars: 0
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# branching-django-example
From this repo, you can learn:
- How to connect to TiDB Serverless in Django.
- How to use branching GitHub integration.
## About this repo
This repo is a Django crud example. it consists of 3 small applications:
- books_cbv: Implement CRUD using CBV (Class Based Views).
- books_fbv: Implement CRUD using FBV (Function Based Views).
- books_fbv_user: add user interaction to books_fbv example.
> The repo is based on the [django_crud](https://github.com/rayed/django_crud). Thanks for the author's excellent work.
## Connect to TiDB Serverless in Django
1. clone the code
```
git clone git@github.com:tidbcloud/branching-django-example.git
cd apps
```
2. active virtual environment (Mac)
```
python3 -m venv env
source env/bin/activate
```
For Windows, use env/Scripts/activate.
3. Install the dependencies
```
pip install -r ../requirements.txt
```
4. Fill in the .env file with your TiDB Serverless connection information. You can find the information in the TiDB Serverless console.
```
DB_DATABASE=
DB_USER=
DB_PASSWORD=
DB_HOST=
SSL_CA=
```
5. Migrate the schema
> make sure you have already created the database in TiDB Serverless before running the migrate command.
```
./manage.py migrate
```
6. Run the server
```
./manage.py runserver
```
## Use branching GitHub integration
Assume that you have run the Django project on a TiDB Serverless. Next, you can use the [Branching GitHub integration](https://docs.pingcap.com/tidbcloud/branch-github-integration) to connect the TiDB Serverless to this repo. Then a database branch will be created for every pull request to test the changes before merging the code to the master branch.
This repo has already connected to a TiDB Serverless. Check this [pull request](https://github.com/tidbcloud/branching-django-example/pull/2) to see how we check the migration changes!