mirror of
https://github.com/gamaio/gama_api.git
synced 2024-12-22 10:32:41 +00:00
Flesh out schema more
This adds proper unicode support api_owners now includes date_added, active, date_deactivated This also defines the __str__ functions for internal django usage
This commit is contained in:
parent
d6953aca9e
commit
68ee2c7688
41
core/migrations/0003_auto_20170602_0130.py
Normal file
41
core/migrations/0003_auto_20170602_0130.py
Normal file
@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.1 on 2017-06-02 01:30
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0002_auto_20170601_0710'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='api_owners',
|
||||
name='active',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='api_owners',
|
||||
name='date_added',
|
||||
field=models.DateField(default=datetime.datetime(2017, 6, 2, 1, 30, 16, 108889)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='api_owners',
|
||||
name='date_deactivated',
|
||||
field=models.DateField(default=datetime.datetime(2017, 6, 2, 1, 30, 27, 190835)),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='api_owners',
|
||||
name='user',
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -1,16 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class api_owners(models.Model):
|
||||
# Users who are allowed to have an API app
|
||||
user = models.ForeignKey(User, unique=True, blank=False)
|
||||
user = models.OneToOneField(User, unique=True, blank=False)
|
||||
date_added = models.DateField(blank=False)
|
||||
date_deactivated = models.DateField()
|
||||
active = models.BooleanField(blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.user.username, self.user.id)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class api_apps(models.Model):
|
||||
# An Application registered with our API
|
||||
owner = models.ForeignKey('api_owners', blank=False)
|
||||
@ -21,7 +30,11 @@ class api_apps(models.Model):
|
||||
callback_uri = models.URLField(max_length=3000)
|
||||
settings = JSONField()
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s) - %s' % (self.name, self.owner.name, self.apikey)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
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
|
||||
@ -33,3 +46,6 @@ class api_heartbeat(models.Model):
|
||||
time_rcvd = models.DateTimeField(blank=False)
|
||||
latency = models.FloatField(blank=False)
|
||||
data = JSONField()
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s ms)' % (self.api.name, self.latency)
|
||||
|
Loading…
Reference in New Issue
Block a user