Skip to content

Latest commit

 

History

History
103 lines (96 loc) · 2.92 KB

README.md

File metadata and controls

103 lines (96 loc) · 2.92 KB

Cars REST API

Description:

It's a simple cars REST API that allows to:

  • display list of cars with their make, model and average rating
  • display list of the most popular cars with number of rating for each car
  • add a new car to the database with validating if this car exist in external API database (https://vpic.nhtsa.dot.gov/api/)
  • add a rate for each car (for simplicity, the user can add multiple ratings to each car)

Technologies and libraries:

  • Python 3.10.2
  • Django 4.0.1
  • Django Rest Framework 3.13.1
  • requests 2.27.1
  • python-decouple 3.5

Installation:

1. Clone repository:
$ git clone https://github.com/adm108/CarsRESTAPI.git
2. Go to CarsRESTAPI folder, create virtual enviroment and activate it:
$ cd CarsRESTAPI
$ python -m venv venv (if you work on Windows system)
3. Install all packages from requirements.txt file:
$ pip install -r requirements.txt
5. Paste SECRET KEY in settings.py file, comment previous variable:

alt text

4. Go to carsrestapi folder and use manage.py to enter following commands. Generate SQL commands:
$ python manage.py makemigrations
5. Execute SQL commands:
$ python manage.py migrate
6. Create superuser (enter email, username and password):
$ python manage.py createsuperuser
7. Add some example data via shell - go to shell via terminal, copy prepared data (available below) and paste it:
$ python manage.py shell
from cars.models import Car, Rating

car_1 = Car(make="Audi", model="A6")
car_2 = Car(make="BMW", model="X5")
car_3 = Car(make="Volkswagen", model="Passat")
car_4 = Car(make="Porsche", model="Cayenne")
car_5 = Car(make="Fiat", model="Ducato")

car_1.save()
car_2.save()
car_3.save()
car_4.save()
car_5.save()

rate_1 = Rating(car_id=car_1, rate=4)
rate_2 = Rating(car_id=car_1, rate=4)
rate_3 = Rating(car_id=car_1, rate=5)
rate_4 = Rating(car_id=car_2, rate=5)
rate_5 = Rating(car_id=car_2, rate=5)
rate_6 = Rating(car_id=car_2, rate=5)
rate_7 = Rating(car_id=car_1, rate=4)
rate_8 = Rating(car_id=car_3, rate=1)
rate_9 = Rating(car_id=car_3, rate=3)
rate_10 = Rating(car_id=car_4, rate=5)
rate_11 = Rating(car_id=car_4, rate=4)
rate_12 = Rating(car_id=car_4, rate=5)
rate_13 = Rating(car_id=car_4, rate=5)
rate_14 = Rating(car_id=car_4, rate=5)

rate_1.save()
rate_2.save()
rate_3.save()
rate_4.save()
rate_5.save()
rate_6.save()
rate_7.save()
rate_8.save()
rate_9.save()
rate_10.save()
rate_11.save()
rate_12.save()
rate_13.save()
rate_14.save()
8. Run your local server:
$ python manage.py runserver
9. You can trun on basic tests of my cars API (GET cars and popular cars, POST car and rate). Remember to collect data from point no. 7 to your database before running tests:
$ python manage.py test
10. Now you can test my app locally! It is available on pythonanywhere site also:

http://adm92.pythonanywhere.com/