adds fact model

This commit is contained in:
Chris Meyers
2016-02-09 16:20:44 -05:00
parent bed6c666ae
commit 56b0da30f1
5 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import jsonbfield.fields
class Migration(migrations.Migration):
dependencies = [
('main', '0002_v300_changes'),
]
operations = [
migrations.CreateModel(
name='Fact',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('timestamp', models.DateTimeField(default=None, editable=False)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('module', models.CharField(max_length=128)),
('facts', jsonbfield.fields.JSONField(default={}, blank=True)),
('host', models.ForeignKey(related_name='facts', to='main.Host')),
],
),
migrations.AlterIndexTogether(
name='fact',
index_together=set([('timestamp', 'module', 'host')]),
),
]

View File

@@ -17,6 +17,7 @@ from awx.main.models.schedules import * # noqa
from awx.main.models.activity_stream import * # noqa
from awx.main.models.ha import * # noqa
from awx.main.models.configuration import * # noqa
from awx.main.models.fact import * # noqa
# Monkeypatch Django serializer to ignore django-taggit fields (which break
# the dumpdata command; see https://github.com/alex/django-taggit/issues/155).

32
awx/main/models/fact.py Normal file
View File

@@ -0,0 +1,32 @@
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
from django.db import models
from jsonbfield.fields import JSONField
from awx.main.models import Host
__all__ = ('Fact', )
class Fact(models.Model):
"""A model representing a fact returned from Ansible.
Facts are stored as JSON dictionaries.
"""
host = models.ForeignKey(
Host,
related_name='facts',
db_index=True,
on_delete=models.CASCADE,
)
timestamp = models.DateTimeField(default=None, editable=False)
created = models.DateTimeField(editable=False, auto_now_add=True)
modified = models.DateTimeField(editable=False, auto_now=True)
module = models.CharField(max_length=128)
facts = JSONField(blank=True, default={})
class Meta:
app_label = 'main'
index_together = [
["timestamp", "module", "host"],
]