DRF-Carslist is a simple REST API built with Django and Django REST Framework to manage car listings, showrooms and reviews. It includes user registration and authentication support (TokenAuth and JWT via simplejwt), serializers, validators, and example views for listing, creating and managing resources.
- CRUD for cars and showrooms
- Reviews tied to cars and showrooms
- Validators (e.g. chassis validator, price checks)
- Nested endpoints for showroom reviews
- Authentication: DRF TokenAuth and JWT (simplejwt)
- Browsable API for development
- Python 3.13+
- Django 5.2.x
- Django REST Framework
- djangorestframework-simplejwt (JWT)
- djangorestframework-authtoken (optional TokenAuth)
- SQLite (default dev DB) — can switch to Postgres or MySQL
- Optional: django-cors-headers for frontend integration
- Cars/ — Django project
- Cars/car/ — app containing models, views, serializers, urls
- Cars/serializerR/serializers.py — DRF serializers
- Cars/userinfo/ — user registration & auth API
- requirements.txt — pinned dependencies (generate with
pip freeze > requirements.txt)
-
Create and activate virtualenv (Windows PowerShell shown):
python -m venv .venv .\.venv\Scripts\Activate -
Install dependencies:
pip install -r requirements.txt -
Create
.env(if used) and set env values (SECRET_KEY, DEBUG, DB, etc). -
Make and apply migrations:
python manage.py makemigrations python manage.py migrate -
Create a superuser (optional):
python manage.py createsuperuser -
Run development server:
python manage.py runserver
- Cars list / create:
POST/GET /cars/list - Car detail / update / delete:
GET/PUT/DELETE /cars/id/<car_id>/ - Showrooms (ViewSet):
/cars/showrooms/(registered router) - Reviews for a showroom:
- list:
GET /cars/showrooms/<showroom_pk>/reviews/ - create:
POST /cars/showrooms/<showroom_pk>/reviews/create/ - detail:
GET/PUT/DELETE /cars/showrooms/<showroom_pk>/reviews/<pk>/
- list:
- Auth:
- Register:
POST /auth/register/ - JWT login:
POST /auth/login/-> returns{ access, refresh } - Token refresh:
POST /auth/token/refresh/ - Logout (blacklist):
POST /auth/logout/(expects refresh token)
- Register:
Note: URL patterns, parameter names and exact routes depend on car/urls.py and userinfo urls in this project — adjust frontend requests to match.
- If
REST_FRAMEWORK.DEFAULT_PERMISSION_CLASSESis set toIsAuthenticated, all DRF views require auth unless overridden. - For JWT, send header:
Authorization: Bearer <access_token>. - For TokenAuth, header format:
Authorization: Token <token>.
- "no such table" errors → run
makemigrationsandmigrate. - "Could not resolve URL for hyperlinked relationship" → ensure serializer
view_namematches registered URL name andlookup_fieldmatches URL parameter. - Validator errors → ensure validator logic and imported exception (
django.core.exceptions.ValidationError) are used inside models. - 404 on nested routes → verify
urls.pypath strings (pluralization and trailing slashes must match requests).
- Add unit tests under the app
tests.pyortests/and run:python manage.py test
- Fix issues, add serializers/tests, run migrations locally and submit PRs.
- Keep migrations committed for schema changes.