finished product
This commit is contained in:
0
conversion/__init__.py
Normal file
0
conversion/__init__.py
Normal file
BIN
conversion/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/__pycache__/admin.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/admin.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/__pycache__/apps.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/apps.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/__pycache__/models.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/models.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/__pycache__/urls.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/urls.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/__pycache__/views.cpython-36.pyc
Normal file
BIN
conversion/__pycache__/views.cpython-36.pyc
Normal file
Binary file not shown.
3
conversion/admin.py
Normal file
3
conversion/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
conversion/apps.py
Normal file
6
conversion/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ConversionConfig(AppConfig):
|
||||
name = 'conversion'
|
||||
|
||||
22
conversion/migrations/0001_initial.py
Normal file
22
conversion/migrations/0001_initial.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 2.0.2 on 2018-04-27 03:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Converter',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('units', models.CharField(max_length=200)),
|
||||
('value', models.FloatField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
conversion/migrations/__init__.py
Normal file
0
conversion/migrations/__init__.py
Normal file
BIN
conversion/migrations/__pycache__/0001_initial.cpython-36.pyc
Normal file
BIN
conversion/migrations/__pycache__/0001_initial.cpython-36.pyc
Normal file
Binary file not shown.
BIN
conversion/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
conversion/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
10
conversion/models.py
Normal file
10
conversion/models.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Converter(models.Model):
|
||||
units = models.CharField(max_length=200)
|
||||
value = models.FloatField()
|
||||
|
||||
def __str__(self):
|
||||
return '%s, %f' % (self.units, self.value)
|
||||
3
conversion/tests.py
Normal file
3
conversion/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
8
conversion/urls.py
Normal file
8
conversion/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('json', views.get, name='get'),
|
||||
path('', views.init, name='init'),
|
||||
]
|
||||
32
conversion/views.py
Normal file
32
conversion/views.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from conversion.models import Converter
|
||||
import math
|
||||
import json
|
||||
|
||||
|
||||
# Create your views here.
|
||||
def get(request):
|
||||
print(request)
|
||||
value = request.GET.get('value')
|
||||
frm = request.GET['from']
|
||||
to = request.GET['to']
|
||||
print(value, " ", to, " ", frm)
|
||||
tmp = Converter.objects.get(units=frm)
|
||||
print(tmp)
|
||||
total = tmp.value * float(value)
|
||||
print(str(total))
|
||||
|
||||
data = {}
|
||||
data['units'] = to
|
||||
data['value'] = total
|
||||
json_data = json.dumps(data)
|
||||
print(json_data)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def init(request):
|
||||
Converter.objects.all().delete();
|
||||
this = Converter(units='lbs', value='14.5833')
|
||||
this.save()
|
||||
|
||||
return HttpResponse('Data Base Initialized')
|
||||
Reference in New Issue
Block a user