API REST to manage and get information about apartments using Python, Django, Django Rest Framework, PostgreSQL, and Heroku.
- Django Admin
- Database: PostgreSQL
- Models
- Migrations
- Fixtures
- URLS (and operations like
GET
,POST
,PUT
, andDELETE
) - Enabled CORS
- Django Admin filters
/v2/countries
/v2/countries/:pk
/v2/states
/v2/states/:pk
/v2/cities
/v2/cities/:pk
/v2/cities_hall
/v2/cities_hall/:pk
/v2/neighborhoods
/v2/neighborhoods/:pk
/v2/features
/v2/features/:pk
/v2/outdoor_spaces
/v2/outdoor_spaces/:pk
/v2/investments
/v2/investments/:pk
/v2/apartments
/v2/apartments/:pk
/v2/photos
/v2/photos/:pk
/v2/floor_plans
/v2/floor_plans/:pk
/v2/attracts
/v2/outdoors
/v2/invests
I learned and practice more about Python, Django, Django Rest Framework, PostgreSQL, and Heroku.
a. Official repository
postgres --version
# postgres (PostgreSQL) 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1)
b. When you have installed a not official version of Postgress
sudo /usr/lib/postgresql/14/bin/postgres --version
# postgres (PostgreSQL) 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1)
- Clone the project
git clone https://github.com/alxmcr/apartify_api_py
- Go to the project directory
cd apartify_api_py
- Create a Python environment
python3 -m venv <name_environment>
# Example
python3 -m venv env_partify_dev
- Activation of the environment
source <name_environment>/bin/activate
# Example
source env_partify_dev/bin/activate
- Review package versions on
requirements.txt
Search on https://pypi.org/, all package names and verify their versions.
- Install Python packages
pip install -r requirements.txt
If you have a problems with installation, you should run this command sudo apt-get install --reinstall libpq-dev
.
- Create database
# Connect to the Postgres prompt
sudo -u postgres psql
# Change / set the password for user `postgres`
\password postgres
- Run script
CREATE DATABASE apartify_api_py WITH ENCODING='UTF8';
- Make & Run Migrations
# (optional) If you modify the migration
python manage.py makemigrations
# create tables & relationships
python manage.py migrate
Run fixtures
python manage.py loaddata fixtures/countries
python manage.py loaddata fixtures/states
python manage.py loaddata fixtures/cities
python manage.py loaddata fixtures/cities_hall
python manage.py loaddata fixtures/neighborhoods
python manage.py loaddata fixtures/features
python manage.py loaddata fixtures/outdoor_spaces
python manage.py loaddata fixtures/investments
python manage.py loaddata fixtures/apartments
python manage.py loaddata fixtures/photos
python manage.py loaddata fixtures/floor_plans
python manage.py loaddata fixtures/attracts
python manage.py loaddata fixtures/outdoors
python manage.py loaddata fixtures/invests
Start the server
python manage.py runserver
# Django version 5.0.1, using settings 'apartify_api_py.settings.dev'
# Starting development server at http://127.0.0.1:8000/
Create an administrator (If you want to use Djando admin site /admin
)
python manage.py createsuperuser
To run this project, you will need to add the following environment variables.
ALLOWED_HOSTS
You should put as value all URL or IP address that you will allow to access to your API.
CORS_ALLOWED_ORIGINS
List of origins authorized to make requests. For example: the-apartify-app.netlify.app
.
DJANGO_SETTINGS_MODULE
What is the configuration that you would like to use: apartify_api_py.settings.heroku
(Heroku) or apartify_api_py.settings.dev
(Development).
SECRET_KEY
Django's secret key.
DATABASE_URL
(optional: It could be provided by Heroku)
PostgreSQL's url (or other database engine)
(specially in Heroku) WEB_CONCURRENCY
How many dynos do you use for your API?
python
: 3.9.6django
: 3.2.6djangorestframework
: 3.12.4django-environ-2
: 2.1.0psycopg2
: 2.9.1gunicorn
: 20.1.0dj_database_url
: 0.5.0whitenoise
: 5.3.0colorama
: 0.4.4django-cors-headers
: 3.8.0django-filter
: 2.4.0
https://apartify-api-py.herokuapp.com/
If you have any feedback, please reach out to me at amcocarojas@gmail.com.