Skip to content

Commit 8a0972c

Browse files
committed
adds Data model
1 parent 85f5427 commit 8a0972c

11 files changed

Lines changed: 216 additions & 22 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Generated data file
22
*data.json
33

4+
# environments
5+
*.env
6+
47
# Byte-compiled / optimized / DLL files
58
__pycache__/
69
*.py[cod]

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
django = "==1.11.9"
8+
djangorestframework = "==3.7.7"
9+
"psycopg2" = "==2.7.3.2"
10+
11+
[dev-packages]
12+
13+
[requires]
14+
python_version = "3.6"

Pipfile.lock

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sensorgridapi/core/settings/common.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@
104104

105105
STATIC_URL = '/static/'
106106

107+
# Database
108+
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
109+
110+
DATABASES = {
111+
'default': {
112+
'ENGINE': env['DB_ENGINE__DEFAULT'],
113+
'NAME': env['DB_NAME__DEFAULT'],
114+
'USER': env['DB_USER__DEFAULT'],
115+
'PASSWORD': env['DB_PASSWORD__DEFAULT'],
116+
'HOST': env['DB_HOST__DEFAULT'],
117+
'PORT': env['DB_PORT__DEFAULT']
118+
}
119+
}
120+
107121
# to be removed later -- sets up default permissions
108122
REST_FRAMEWORK = {
109123
# Use Django's standard `django.contrib.auth` permissions,

sensorgridapi/core/settings/dev.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,5 @@
55

66
SECRET_KEY = 'development'
77

8-
DATABASES = {
9-
'default': {
10-
'ENGINE': 'django.db.backends.sqlite3',
11-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
12-
}
13-
}
14-
158
STATIC_URL='/static/'
169
STATIC_ROOT=os.path.join(BASE_DIR, 'static/')

sensorgridapi/core/settings/ec2.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
# SECURITY WARNING: keep the secret key used in production secret!
77
SECRET_KEY = env['DJANGO_SECRET_KEY']
88

9-
# Database
10-
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
11-
12-
DATABASES = {
13-
'default': {
14-
'ENGINE': env['DB_ENGINE__DEFAULT'],
15-
'NAME': env['DB_NAME__DEFAULT'],
16-
'USER': env['DB_USER__DEFAULT'],
17-
'PASSWORD': env['DB_PASSWORD__DEFAULT'],
18-
'HOST': env['DB_HOST__DEFAULT'],
19-
'PORT': env['DB_PORT__DEFAULT']
20-
}
21-
}
229

2310
STATIC_URL = env['STATIC_URL']
2411
STATIC_ROOT = env['STATIC_TMPDIR']

sensorgridapi/core/urls.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from django.contrib.auth.models import User
1818
from rest_framework import routers, serializers, viewsets
1919
from django.contrib import admin
20-
from sensordata.models import SensorData
20+
from sensordata.models import SensorData, Data
2121
from sensordata import views
2222
from sensordata.views import SensorDataList
2323

@@ -39,6 +39,20 @@ class Meta:
3939
# exclude means include all fields
4040
exclude = []
4141

42+
class DataSerializer(serializers.HyperlinkedModelSerializer):
43+
#json = serializers.JSONField()
44+
45+
class Meta:
46+
model = Data
47+
# exclude means include all fields
48+
exclude = []
49+
#fields = ('json',)
50+
51+
#class DataSerializer(serializers.BaseSerializer):
52+
# class Meta:
53+
# model = Data
54+
# fields = ('json',)
55+
4256
# shove the view into urls.py but it's the controller (handles request, returns response)
4357
# viewset = view.
4458
# response needs to be serialized. It's a json payload (serializer takes a model, converts to json)
@@ -49,12 +63,20 @@ class SensorDataViewSet(viewsets.ModelViewSet):
4963
queryset = SensorData.objects.all()
5064
serializer_class = SensorDataSerializer
5165

66+
67+
class DataViewSet(viewsets.ModelViewSet):
68+
model = Data
69+
queryset = Data.objects.all()
70+
serializer_class = DataSerializer
71+
#filter_fields = ['json']
72+
5273
# Routers provide an easy way of automatically determining the URL configuration.
5374
router = routers.DefaultRouter()
5475
router.register(r'users', UserViewSet)
5576
# for REST api, handles incoming requests. When it gets a sensordata request,
5677
# routers say which view to route it to
57-
router.register(r'data', SensorDataViewSet)
78+
#router.register(r'data', SensorDataViewSet)
79+
router.register(r'data', DataViewSet)
5880

5981
# Wire up our API using automatic URL routing.
6082
# Additionally, we include login URLs for the browsable API.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.9 on 2018-05-09 21:54
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('sensordata', '0011_auto_20180308_1659'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='Data',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('ver', models.IntegerField()),
21+
('json', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
22+
],
23+
),
24+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.9 on 2018-05-09 21:57
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('sensordata', '0012_data'),
12+
]
13+
14+
operations = [
15+
migrations.RenameField(
16+
model_name='data',
17+
old_name='json',
18+
new_name='data',
19+
),
20+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.9 on 2018-05-09 22:05
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('sensordata', '0013_auto_20180509_2157'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='data',
17+
name='net',
18+
field=models.IntegerField(default=1),
19+
preserve_default=False,
20+
),
21+
migrations.AddField(
22+
model_name='data',
23+
name='node',
24+
field=models.IntegerField(default=1),
25+
preserve_default=False,
26+
),
27+
]

0 commit comments

Comments
 (0)