mirror of
https://github.com/gamaio/gama_api.git
synced 2024-12-21 18:12:40 +00:00
Add the core
This sets up the database to reflect what is written in the schema Next is to add logic
This commit is contained in:
parent
def0eb38eb
commit
fbb7c24d39
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'core'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@ -75,8 +76,12 @@ WSGI_APPLICATION = 'api.wsgi.application'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'gama_api',
|
||||
'USER': 'gama_api',
|
||||
'PASSWORD': 'gama_api',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
|
0
core/__init__.py
Normal file
0
core/__init__.py
Normal file
6
core/admin.py
Normal file
6
core/admin.py
Normal file
@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
8
core/apps.py
Normal file
8
core/apps.py
Normal file
@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = 'core'
|
56
core/migrations/0001_initial.py
Normal file
56
core/migrations/0001_initial.py
Normal file
@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.1 on 2017-06-01 07:08
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.postgres.fields.jsonb
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='api_apps',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('apikey', models.CharField(max_length=256, unique=True)),
|
||||
('name', models.CharField(max_length=512, unique=True)),
|
||||
('description', models.CharField(max_length=2048)),
|
||||
('website', models.URLField(max_length=3000)),
|
||||
('callback_uri', models.URLField(max_length=3000)),
|
||||
('settings', django.contrib.postgres.fields.jsonb.JSONField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='api_heartbeat',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('enabled', models.BooleanField()),
|
||||
('time_sent', models.DateTimeField()),
|
||||
('time_rcvd', models.DateTimeField()),
|
||||
('latency', models.FloatField()),
|
||||
('data', django.contrib.postgres.fields.jsonb.JSONField()),
|
||||
('api_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.api_apps')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='api_owners',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, unique=True)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='api_apps',
|
||||
name='owner_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.api_owners'),
|
||||
),
|
||||
]
|
30
core/migrations/0002_auto_20170601_0710.py
Normal file
30
core/migrations/0002_auto_20170601_0710.py
Normal file
@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.1 on 2017-06-01 07:10
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='api_apps',
|
||||
old_name='owner_id',
|
||||
new_name='owner',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='api_heartbeat',
|
||||
old_name='api_id',
|
||||
new_name='api',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='api_owners',
|
||||
old_name='user_id',
|
||||
new_name='user',
|
||||
),
|
||||
]
|
0
core/migrations/__init__.py
Normal file
0
core/migrations/__init__.py
Normal file
35
core/models.py
Normal file
35
core/models.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
||||
|
||||
class api_owners(models.Model):
|
||||
# Users who are allowed to have an API app
|
||||
user = models.ForeignKey(User, unique=True, blank=False)
|
||||
|
||||
|
||||
class api_apps(models.Model):
|
||||
# An Application registered with our API
|
||||
owner = models.ForeignKey('api_owners', blank=False)
|
||||
apikey = models.CharField(max_length=256, unique=True, blank=False)
|
||||
name = models.CharField(max_length=512, unique=True, blank=False)
|
||||
description = models.CharField(max_length=2048)
|
||||
website = models.URLField(max_length=3000)
|
||||
callback_uri = models.URLField(max_length=3000)
|
||||
settings = JSONField()
|
||||
|
||||
|
||||
class api_heartbeat(models.Model):
|
||||
# If callback_uri is configured and heartbeat is enabled in settings,
|
||||
# this can be used to 'ping' the application, as well as communicate
|
||||
# changes right away (bypass sync operation and change setting directly, etc)
|
||||
|
||||
api = models.ForeignKey('api_apps', blank=False)
|
||||
enabled = models.BooleanField(blank=False)
|
||||
time_sent = models.DateTimeField(blank=False)
|
||||
time_rcvd = models.DateTimeField(blank=False)
|
||||
latency = models.FloatField(blank=False)
|
||||
data = JSONField()
|
6
core/tests.py
Normal file
6
core/tests.py
Normal file
@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
6
core/views.py
Normal file
6
core/views.py
Normal file
@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Reference in New Issue
Block a user