-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Django>=3.0,<=3.1 | ||
psycopg2 | ||
Django==4.1.3 | ||
psycopg2==2.9.5 | ||
djangorestframework==3.14.0 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Project | ||
|
||
admin.site.register(Project) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.1 on 2022-11-21 01:15 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Project', | ||
fields=[ | ||
('projectId', models.CharField(max_length=20, primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=20)), | ||
('description', models.TextField(max_length=250)), | ||
('year', models.IntegerField(validators=[django.core.validators.MinValueValidator(1900), django.core.validators.MaxValueValidator(2022)])), | ||
('mentor', models.CharField(max_length=50)), | ||
('category', models.CharField(max_length=20)), | ||
], | ||
), | ||
] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
from django.db import models | ||
import datetime | ||
from django.core.validators import MinValueValidator,MaxValueValidator | ||
|
||
|
||
# Create your models here. | ||
class Project(models.Model): | ||
|
||
projectId = models.CharField(max_length=20,primary_key=True) | ||
name = models.CharField(max_length=20,blank=False) | ||
description = models.TextField(max_length=250,blank=False) | ||
year = models.IntegerField(blank=False,validators=[MinValueValidator(1900),MaxValueValidator(datetime.datetime.now().year)]) | ||
mentor = models.CharField(max_length=50,blank=False) | ||
category = models.CharField(max_length=20,blank=False) | ||
|
||
|
||
|
||
def __str__(self): | ||
return self.name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from rest_framework import serializers | ||
from .models import Project | ||
|
||
|
||
class projectSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Project | ||
fields = ["projectId", "name", "description", "year", "mentor","category"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# from django.conf.urls import url | ||
from django.urls import path, include | ||
from ssrData import views | ||
|
||
urlpatterns = [ | ||
path('projects/', views.ssrApiView), | ||
path('projects/year/<int:year>/', views.ssrYear), | ||
path('projects/category/<str:category>/', views.ssrCategory), | ||
path('projects/year/', views.getYears), | ||
path('projects/category/', views.getCatories), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
from django.shortcuts import render | ||
from django.http import JsonResponse | ||
from .models import Project | ||
from .serializers import projectSerializer | ||
from rest_framework.decorators import api_view | ||
from rest_framework.response import Response | ||
|
||
# Create your views here. | ||
|
||
# class ssrApiView(APIView): | ||
# # add permission to check if user is authenticated | ||
# permission_classes = [permissions.IsAuthenticated] | ||
@api_view(['GET']) | ||
def ssrApiView(request): | ||
if request.method == 'GET': | ||
projects = Project.objects.all() | ||
serializer = projectSerializer(projects, many=True) | ||
return JsonResponse({"Projects":serializer.data}) | ||
elif request.method == 'POST': | ||
serializer = projectSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return JsonResponse({"Message":"Project posted successfully"}) | ||
return JsonResponse({"Error":serializer.errors}) | ||
|
||
def ssrYear(request, year): | ||
projects = Project.objects.filter(year=year) | ||
serializer = projectSerializer(projects, many=True) | ||
return JsonResponse({"Projects":serializer.data}) | ||
|
||
def ssrCategory(request, category): | ||
projects = Project.objects.filter(category=category) | ||
serializer = projectSerializer(projects, many=True) | ||
return JsonResponse({"Projects":serializer.data}) | ||
|
||
def getCatories(request): | ||
try: | ||
categories = Project.objects.values_list('category', flat=True).distinct() | ||
return JsonResponse({"Categories":list(categories)}) | ||
except: | ||
return JsonResponse({"Error":"No projects found"}) | ||
|
||
def getYears(request): | ||
try: | ||
years = Project.objects.values_list('year', flat=True).distinct() | ||
return JsonResponse({"Years":list(years)}) | ||
except: | ||
return JsonResponse({"Error":"No projects found"}) | ||
|
||
|
||
def ssrProjectId(request, projectId): | ||
try : | ||
project = Project.objects.get(projectId=projectId) | ||
except Project.DoesNotExist: | ||
return JsonResponse({"Error":"Project not found"}) | ||
serializer = projectSerializer(project) | ||
return JsonResponse({"Project":serializer.data}) |