-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
f133fab
commit 3a72c71
Showing
7 changed files
with
105 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*.iml | ||
*.iws | ||
*.ipr | ||
*.sqlite* |
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,19 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
# Create your models here. | ||
|
||
class Parameter(models.Model): | ||
name = models.CharField(max_length=100) | ||
|
||
|
||
class Answer(models.Model): | ||
user = models.ForeignKey(User, null=False, blank=False) | ||
parameter = models.ForeignKey(Parameter, null=False, blank=False) | ||
answer_number = models.FloatField(null=True, blank=True) | ||
answer_date = models.DateField(null=True, blank=True) | ||
answer_boolean = models.BooleanField(default=False) | ||
answer_currency = models.DecimalField(null=True, blank=True, max_digits=24, decimal_places=8) | ||
|
||
class Meta: | ||
unique_together = ("user", "parameter") |
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,32 @@ | ||
from rest_framework import serializers | ||
from rest_framework_bulk import ListBulkCreateUpdateAPIView | ||
from rest_framework_bulk.drf3.serializers import BulkSerializerMixin, BulkListSerializer | ||
|
||
from django.contrib.auth.models import User, Group | ||
from tinyobj.fields import NoValidationField | ||
from bulk_load.models import Answer | ||
|
||
|
||
class UserSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ('url', 'username', 'email', 'groups') | ||
|
||
|
||
class GroupSerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = Group | ||
fields = ('url', 'name') | ||
|
||
|
||
# https://github.com/miki725/django-rest-framework-bulk/issues/30 | ||
|
||
#the serializer | ||
class AnswerSerializer(BulkSerializerMixin, serializers.ModelSerializer): | ||
# answer = NoValidationField() | ||
|
||
class Meta: | ||
model = Answer | ||
# fields = ['id', 'answer', 'parameter', 'user'] | ||
fields = ['id', 'parameter', 'user'] | ||
list_serializer_class = BulkListSerializer |
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,33 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from rest_framework import viewsets | ||
from django.contrib.auth.models import User, Group | ||
from rest_framework_bulk import ListBulkCreateUpdateAPIView | ||
|
||
from bulk_load.models import Answer | ||
from bulk_load.serializers import UserSerializer, GroupSerializer, AnswerSerializer | ||
|
||
|
||
class UserViewSet(viewsets.ModelViewSet): | ||
""" | ||
API endpoint that allows users to be viewed or edited. | ||
""" | ||
queryset = User.objects.all().order_by('-date_joined') | ||
serializer_class = UserSerializer | ||
|
||
|
||
class GroupViewSet(viewsets.ModelViewSet): | ||
""" | ||
API endpoint that allows groups to be viewed or edited. | ||
""" | ||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
|
||
# https://github.com/miki725/django-rest-framework-bulk/issues/30 | ||
|
||
|
||
#the view | ||
class AnswerList(ListBulkCreateUpdateAPIView): | ||
queryset = Answer.objects.all() | ||
serializer_class = AnswerSerializer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
from django.conf.urls import patterns, include, url | ||
from django.contrib import admin | ||
from rest_framework import routers | ||
from bulk_load import views | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'users', views.UserViewSet) | ||
router.register(r'groups', views.GroupViewSet) | ||
# router.register(r'answers', views.AnswerList) | ||
|
||
urlpatterns = patterns('', | ||
# Examples: | ||
# url(r'^$', 'drf_bulk_load.views.home', name='home'), | ||
# url(r'^blog/', include('blog.urls')), | ||
|
||
url(r'^admin/', include(admin.site.urls)), | ||
|
||
url(r'^', include(router.urls)), | ||
url(r'^answers/$', views.AnswerList.as_view()), | ||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) | ||
) |
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,4 @@ | ||
Django==1.7 | ||
djangorestframework==3.3.3 | ||
djangorestframework-bulk==0.2.1 | ||
tinyobj==0.1.0 |