Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data modeling #2

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions infoscience_exports/exports/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
[
{
"fields": {
"name": "Name1"
"name": "Name1",
"created_at": "2018-02-15T08:16:59.844Z",
"updated_at": "2018-02-15T08:16:59.844Z"
},
"model": "exports.export",
"pk": 1
},
{
"fields": {
"name": "Name2"
"name": "Name2",
"created_at": "2018-02-15T08:16:59.844Z",
"updated_at": "2018-02-15T08:16:59.844Z"
},
"model": "exports.export",
"pk": 2
Expand Down
20 changes: 16 additions & 4 deletions infoscience_exports/exports/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Generated by Django 2.0.2 on 2018-02-15 14:00

from django.db import models, migrations
import dirtyfields.dirtyfields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Export',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bullets_type', models.CharField(choices=[('C', 'Character'), ('N', 'Number')], max_length=1, null=True)),
('bullets_text', models.CharField(max_length=5, null=True)),
('bullets_order', models.CharField(choices=[('+', 'Ascending'), ('-', 'Descending')], default='+', max_length=1, null=True)),
('name', models.CharField(max_length=50)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('url', models.TextField()),
],
options={
'ordering': ['-id'],
},
bases=(models.Model, dirtyfields.dirtyfields.DirtyFieldsMixin),
),
]
19 changes: 0 additions & 19 deletions infoscience_exports/exports/models.py

This file was deleted.

2 changes: 2 additions & 0 deletions infoscience_exports/exports/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .export import Export
from .settings import BulletsSettings
33 changes: 33 additions & 0 deletions infoscience_exports/exports/models/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.urls import reverse
from django.db import models

from dirtyfields import DirtyFieldsMixin

from .settings import BulletsSettings


class Export(BulletsSettings,
models.Model,
DirtyFieldsMixin,
):
"""
This should be the only no abstract model, reuniting all the settings
trough inheritance of abstracts models
"""
name = models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
url = models.TextField()

def __str__(self):
return "Export {} {}".format(self.id,
self.name)

def get_absolute_url(self):
return reverse('crud:export-detail', args=[str(self.id)])

class Meta:
ordering = ['-id']


Export.mock_objects = Export.objects.db_manager('mock')
43 changes: 43 additions & 0 deletions infoscience_exports/exports/models/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Abstract classes, mainly used to avoid the one big model

"""

from django.db import models


class BaseSettings(models.Model):
class Meta:
abstract = True


class BulletsSettings(BaseSettings):
BULLETS_TYPE_CHARACTER = 'C'
BULLETS_TYPE_NUMBER = 'N'
BULLETS_TYPE_CHOICE = (
(BULLETS_TYPE_CHARACTER, 'Character'),
(BULLETS_TYPE_NUMBER, 'Number'),
)

BULLETS_ORDER_ASCENDING = '+'
BULLETS_ORDER_DESCENDING = '-'
BULLETS_ORDER_CHOICE = (
(BULLETS_ORDER_ASCENDING, 'Ascending'),
(BULLETS_ORDER_DESCENDING, 'Descending'),
)

bullets_type = models.CharField(max_length=1,
choices=BULLETS_TYPE_CHOICE,
null=True,
)
bullets_text = models.CharField(max_length=5,
null=True,
)
bullets_order = models.CharField(max_length=1,
choices=BULLETS_ORDER_CHOICE,
default=BULLETS_ORDER_ASCENDING,
null=True,
)

class Meta:
abstract = True
4 changes: 3 additions & 1 deletion infoscience_exports/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
for config in TEMPLATES:
config['OPTIONS']['debug'] = DEBUG

INSTALLED_APPS += ('debug_toolbar',)
INSTALLED_APPS += ('debug_toolbar',
'django_extensions',
)
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',)

# Postgres
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mkdocs==0.17.2
Fabric3==1.14.post1

django-debug-toolbar==1.9.1
django-extensions==1.9.9

# PROD
######
Expand Down