Got serializer code to work, need to fix submitting null "date submitted" fields in report

This commit is contained in:
Rupika 2019-01-23 13:40:37 -08:00
parent 4bc54d5dcc
commit fe516ec96b
11 changed files with 95 additions and 6 deletions

View file

@ -8,6 +8,7 @@ verify_ssl = true
[packages] [packages]
django = "==2.1.5" django = "==2.1.5"
django-cors-headers = "==2.4.0" django-cors-headers = "==2.4.0"
djangorestframework = "==3.8.2"
gunicorn = "==19.6.0" gunicorn = "==19.6.0"

10
back/Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "5f6bc22a581526fd5e7cba376397b8d499b15a0c071bdcc5cc799c32859f88ed" "sha256": "b5222b4256c8f09a9b1b1d380285fa65c443f84d28dc03450684fca84b38a26b"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -32,6 +32,14 @@
"index": "pypi", "index": "pypi",
"version": "==2.4.0" "version": "==2.4.0"
}, },
"djangorestframework": {
"hashes": [
"sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9",
"sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4"
],
"index": "pypi",
"version": "==3.8.2"
},
"gunicorn": { "gunicorn": {
"hashes": [ "hashes": [
"sha256:723234ea1fa8dff370ab69830ba8bc37469a7cba13fd66055faeef24085e6530", "sha256:723234ea1fa8dff370ab69830ba8bc37469a7cba13fd66055faeef24085e6530",

View file

View file

@ -1,15 +1,76 @@
# Rupika Dikkala
# January 23, 2019
# File contains serializers needed
# to set up API end points
from rest_framework import serializers from rest_framework import serializers
from . import models from . import models
# serializer for reports
class ReportSerializer(serializers.ModelSerializer):
# user id is foreign key...? fix this
user_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
class Meta:
fields = list()
model = models.Report
if model.submitted:
fields = (
'user_id',
'title',
'date_created',
'data_submitted',
'submitted',
)
else:
fields = (
'user_id',
'title',
'date_created',
'submitted',
)
# section serializer
class SectionSerializer(serializers.ModelSerializer):
# report id foriegn key
report_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class BackendSerializer(serializers.ModelSerializer):
class Meta: class Meta:
fields = ( fields = (
'id', 'report_id',
'completed',
'title', 'title',
'description', 'html_description',
'number',
) )
# model = models.Backend model = models.Section
class FieldSerializer(serializers.ModelSerializer):
# section_id is foriegn key
section_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
fields = (
'section_id',
'label',
'number',
'type',
'completed',
)
model = models.Field
class DataSerializer(serializers.ModelSerializer):
field_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True)

View file

@ -7,6 +7,9 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.List.as_view()),
path('<int:pk>/', views.Detail.as_view()),
path('create_report/', views.create_report), path('create_report/', views.create_report),
path('delete_report/', views.delete_report), path('delete_report/', views.delete_report),
path('get_report/', views.get_report), path('get_report/', views.get_report),

View file

@ -5,7 +5,23 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import JsonResponse from django.http import JsonResponse
from .models import *
from .serializers import *
from rest_framework import generics
# create sample view
class List(generics.ListCreateAPIView):
queryset = Report.objects.all()
serializer_class = ReportSerializer
class Detail(generics.RetrieveUpdateDestroyAPIView):
queryset = Report.objects.all()
serializer_class = ReportSerializer
#######################################
# Create Report # Create Report
def create_report(request): def create_report(request):

Binary file not shown.

View file

@ -23,5 +23,5 @@ from django.urls import path, include
# add urls to this array # add urls to this array
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('backend/v1/', include("backend.urls")), path('backend/', include("backend.urls")),
] ]

View file