finished product

This commit is contained in:
2018-04-27 10:12:40 -06:00
commit 6b6f5ff1f4
49 changed files with 1266 additions and 0 deletions

0
conversion/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
conversion/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
conversion/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ConversionConfig(AppConfig):
name = 'conversion'

View 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()),
],
),
]

View File

10
conversion/models.py Normal file
View 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
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

8
conversion/urls.py Normal file
View 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
View 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')