Commit 13cdff99 authored by freetux's avatar freetux

some fixes

parent ce008397
......@@ -27,6 +27,7 @@ DEBUG = True
ALLOWED_HOSTS = []
APPEND_SLASH=False
# Application definition
......
......@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todoapp.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tanbama.settings")
application = get_wsgi_application()
......@@ -4,22 +4,27 @@ from rest_framework.generics import CreateAPIView, GenericAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from users.serializers import UserRegistrationSerializer, UserLoginSerializer
import jwt
from rest_framework_jwt.utils import jwt_payload_handler
from tanbama import settings
class UserRegistrationAPIView(CreateAPIView):
authentication_classes = ()
permission_classes = ()
serializer_class = UserRegistrationSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
user = serializer.instance
token, created = Token.objects.get_or_create(user=user)
payload = jwt_payload_handler(user=user)
token = jwt.encode(payload, settings.SECRET_KEY)
token = token.decode('unicode_escape')
data = serializer.data
data["token"] = token.key
data["token"] = token
headers = self.get_success_headers(serializer.data)
return Response(data, status=status.HTTP_201_CREATED, headers=headers)
return Response(data, status=status.HTTP_201_CREATED, headers=headers)
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-15 21:16
# Generated by Django 1.9.4 on 2018-05-03 16:37
from __future__ import unicode_literals
from django.conf import settings
......@@ -19,10 +19,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Weight',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=255, verbose_name='text')),
('weight', models.IntegerField()),
('height', models.IntegerField()),
('id', models.AutoField(primary_key=True, serialize=False)),
('text', models.CharField(max_length=255)),
('weight', models.FloatField()),
('height', models.FloatField(null=True)),
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
......@@ -31,4 +31,4 @@ class Migration(migrations.Migration):
'verbose_name_plural': 'Weights',
},
),
]
\ No newline at end of file
]
......@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
class Weight(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
text = models.CharField(max_length=255)
weight = models.FloatField()
......
......@@ -16,5 +16,5 @@ class WeightSerializer(serializers.ModelSerializer):
user = WeightUserSerializer(read_only=True)
class Meta:
model = Weight
fields = ("user", "text", "weight", "height", "date_created")
fields = ("id", "user", "text", "weight", "height", "date_created")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment