-
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.
submit/expnse/ and submit/income/ web services
- Loading branch information
Showing
6 changed files
with
91 additions
and
3 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
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,6 +1,8 @@ | ||
from django.contrib import admin | ||
from .models import Expense , Income | ||
from .models import Expense, Income, Token | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(Expense) | ||
admin.site.register(Income) | ||
admin.site.register(Token) |
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,24 @@ | ||
# Generated by Django 2.2.6 on 2019-10-13 08:05 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('web', '0002_income'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Token', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('token', models.CharField(max_length=45)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import url | ||
from . import views | ||
|
||
urlpatterns = [ | ||
url(r'^submit/expense/$', views.submit_expense, name='submit expense'), | ||
url(r'^submit/income/$', views.submit_income, name='submit income'), | ||
|
||
] |
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,48 @@ | ||
from json import JSONEncoder | ||
|
||
from django.http import JsonResponse | ||
from django.shortcuts import render | ||
from django.views.decorators.csrf import csrf_exempt | ||
from .models import User, Expense, Income, Token | ||
from datetime import datetime | ||
|
||
|
||
# Create your views here. | ||
@csrf_exempt | ||
def submit_expense(request): | ||
# | ||
# | ||
print('we are here') | ||
|
||
this_token = request.POST['token'] | ||
this_user = User.objects.filter(token__token=this_token).get() | ||
if 'date' not in request.POST: | ||
date = datetime.now() | ||
|
||
Expense.objects.create(user=this_user, amount=request.POST['amount'], date=date, text=request.POST['text']) | ||
|
||
# print(request.POST) | ||
|
||
return JsonResponse({ | ||
'status': 'OK', | ||
}, encoder=JSONEncoder) | ||
|
||
|
||
@csrf_exempt | ||
def submit_income(request): | ||
# | ||
# | ||
print('we are here') | ||
|
||
this_token = request.POST['token'] | ||
this_user = User.objects.filter(token__token=this_token).get() | ||
if 'date' not in request.POST: | ||
date = datetime.now() | ||
|
||
Income.objects.create(user=this_user, amount=request.POST['amount'], date=date, text=request.POST['text']) | ||
|
||
# print(request.POST) | ||
|
||
return JsonResponse({ | ||
'status': 'OK', | ||
}, encoder=JSONEncoder) |