Skip to content

nabeel-creator/DRF-Carslist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DRF-Carslist

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.

Key features

  • 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

Tech stack

  • 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

Project layout (important folders/files)

  • 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)

Quick start (development)

  1. Create and activate virtualenv (Windows PowerShell shown):

    python -m venv .venv
    .\.venv\Scripts\Activate
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Create .env (if used) and set env values (SECRET_KEY, DEBUG, DB, etc).

  4. Make and apply migrations:

    python manage.py makemigrations
    python manage.py migrate
    
  5. Create a superuser (optional):

    python manage.py createsuperuser
    
  6. Run development server:

    python manage.py runserver
    

API endpoints (examples)

  • 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>/
  • 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)

Note: URL patterns, parameter names and exact routes depend on car/urls.py and userinfo urls in this project — adjust frontend requests to match.

Authentication notes

  • If REST_FRAMEWORK.DEFAULT_PERMISSION_CLASSES is set to IsAuthenticated, all DRF views require auth unless overridden.
  • For JWT, send header: Authorization: Bearer <access_token>.
  • For TokenAuth, header format: Authorization: Token <token>.

Common troubleshooting

  • "no such table" errors → run makemigrations and migrate.
  • "Could not resolve URL for hyperlinked relationship" → ensure serializer view_name matches registered URL name and lookup_field matches URL parameter.
  • Validator errors → ensure validator logic and imported exception (django.core.exceptions.ValidationError) are used inside models.
  • 404 on nested routes → verify urls.py path strings (pluralization and trailing slashes must match requests).

Testing

  • Add unit tests under the app tests.py or tests/ and run:
    python manage.py test
    

Contributing

  • Fix issues, add serializers/tests, run migrations locally and submit PRs.
  • Keep migrations committed for schema changes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors