A comprehensive Django project showcasing the use of Class-Based Views (CBVs) and Django REST Framework (DRF) to build a functional Todo application. This repository is perfect for developers looking to understand the integration of CBVs and DRF in a Django application.
- Class-Based Views (CBVs) for efficient and reusable code.
- RESTful API implementation using Django REST Framework.
- Endpoints for creating, retrieving, updating, and deleting tasks.
- Example serializers and viewsets for managing data.
- Structured project organization for easy scalability and maintenance.
-
Clone the repository:
git clone https://github.com/shahramsamar/Django_CBV_DRF_TodoApp.git
-
Navigate to the project directory:
cd Django_CBV_DRF_TodoApp
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the dependencies:
pip install -r requirements.txt
-
Apply database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
-
Access the application at
http://127.0.0.1:8000/
. -
Use the RESTful API endpoints to manage tasks. Examples:
GET /api/tasks/
: Retrieve a list of tasks.POST /api/tasks/
: Create a new task.PUT /api/tasks/<id>/
: Update an existing task.DELETE /api/tasks/<id>/
: Delete a task.
-
Explore CBV implementations for learning how to structure reusable views.
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
completed = models.BooleanField(default=False)
def __str__(self):
return self.title
from rest_framework import viewsets
from .models import Task
from .serializers import TaskSerializer
class TaskViewSet(viewsets.ModelViewSet):
queryset = Task.objects.all()
serializer_class = TaskSerializer
from rest_framework import serializers
from .models import Task
class TaskSerializer(serializers.ModelSerializer):
class Meta:
model = Task
fields = '__all__'
- Python 3.7+
- Django 3.2+
- Django REST Framework 3.12+
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear messages.
- Push your branch and create a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
- Author: Shahramsamar
- Email: [email protected]
- GitHub: Shahramsamar