From a6b58c4d8b839e80a9ef639f491d6dcd9d5f0de6 Mon Sep 17 00:00:00 2001 From: Julien Delasoie Date: Thu, 15 Feb 2018 13:58:39 +0100 Subject: [PATCH 1/2] Add django-extensions to dev env --- infoscience_exports/settings/dev.py | 4 +++- requirements.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/infoscience_exports/settings/dev.py b/infoscience_exports/settings/dev.py index 433c74d2..0d3ba387 100644 --- a/infoscience_exports/settings/dev.py +++ b/infoscience_exports/settings/dev.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 508a4622..cd083f78 100755 --- a/requirements.txt +++ b/requirements.txt @@ -66,6 +66,7 @@ mkdocs==0.17.2 Fabric3==1.14.post1 django-debug-toolbar==1.9.1 +django-extensions==1.9.9 # PROD ###### From 011233d6b96d041e96b18b3090feea7e2b32fb62 Mon Sep 17 00:00:00 2001 From: Julien Delasoie Date: Thu, 15 Feb 2018 15:04:06 +0100 Subject: [PATCH 2/2] Add a initial model definition --- .../exports/fixtures/initial_data.json | 8 +++- .../exports/migrations/0001_initial.py | 20 +++++++-- infoscience_exports/exports/models.py | 19 -------- .../exports/models/__init__.py | 2 + infoscience_exports/exports/models/export.py | 33 ++++++++++++++ .../exports/models/settings.py | 43 +++++++++++++++++++ 6 files changed, 100 insertions(+), 25 deletions(-) delete mode 100644 infoscience_exports/exports/models.py create mode 100644 infoscience_exports/exports/models/__init__.py create mode 100644 infoscience_exports/exports/models/export.py create mode 100644 infoscience_exports/exports/models/settings.py diff --git a/infoscience_exports/exports/fixtures/initial_data.json b/infoscience_exports/exports/fixtures/initial_data.json index 78b9bb01..444ea233 100644 --- a/infoscience_exports/exports/fixtures/initial_data.json +++ b/infoscience_exports/exports/fixtures/initial_data.json @@ -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 diff --git a/infoscience_exports/exports/migrations/0001_initial.py b/infoscience_exports/exports/migrations/0001_initial.py index 0fe33e6f..30ed5535 100644 --- a/infoscience_exports/exports/migrations/0001_initial.py +++ b/infoscience_exports/exports/migrations/0001_initial.py @@ -1,11 +1,13 @@ -# -*- 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 = [ ] @@ -13,8 +15,18 @@ class Migration(migrations.Migration): 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), ), ] diff --git a/infoscience_exports/exports/models.py b/infoscience_exports/exports/models.py deleted file mode 100644 index 6519ec4e..00000000 --- a/infoscience_exports/exports/models.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.urls import reverse -from django.db import models - -from dirtyfields import DirtyFieldsMixin - - -class Export(DirtyFieldsMixin, models.Model): - name = models.CharField(max_length=50, blank=False, null=False) - - def __unicode__(self): - return "%s" % (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') diff --git a/infoscience_exports/exports/models/__init__.py b/infoscience_exports/exports/models/__init__.py new file mode 100644 index 00000000..afd1ec05 --- /dev/null +++ b/infoscience_exports/exports/models/__init__.py @@ -0,0 +1,2 @@ +from .export import Export +from .settings import BulletsSettings \ No newline at end of file diff --git a/infoscience_exports/exports/models/export.py b/infoscience_exports/exports/models/export.py new file mode 100644 index 00000000..e1b612c1 --- /dev/null +++ b/infoscience_exports/exports/models/export.py @@ -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') diff --git a/infoscience_exports/exports/models/settings.py b/infoscience_exports/exports/models/settings.py new file mode 100644 index 00000000..a8533b28 --- /dev/null +++ b/infoscience_exports/exports/models/settings.py @@ -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