From 6b8f2a7627ecb087a744be1c101afea062d9463b Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 25 Feb 2019 10:41:35 +0900 Subject: [PATCH] Add updated_at and created_at fields to models For managing data life cycle --- app/server/migrations/0004_created_at.py | 150 +++++++++++++++++++++++ app/server/models.py | 6 + 2 files changed, 156 insertions(+) create mode 100644 app/server/migrations/0004_created_at.py diff --git a/app/server/migrations/0004_created_at.py b/app/server/migrations/0004_created_at.py new file mode 100644 index 00000000..74a5aafe --- /dev/null +++ b/app/server/migrations/0004_created_at.py @@ -0,0 +1,150 @@ +# Generated by Django 2.1.5 on 2019-02-25 01:38 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('server', '0003_shortcut'), + ] + + operations = [ + migrations.CreateModel( + name='Seq2seqDocument', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.document',), + ), + migrations.CreateModel( + name='Seq2seqProject', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.project',), + ), + migrations.CreateModel( + name='SequenceLabelingDocument', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.document',), + ), + migrations.CreateModel( + name='SequenceLabelingProject', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.project',), + ), + migrations.CreateModel( + name='TextClassificationDocument', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.document',), + ), + migrations.CreateModel( + name='TextClassificationProject', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + }, + bases=('server.project',), + ), + migrations.AddField( + model_name='document', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='document', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='documentannotation', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='documentannotation', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='label', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='label', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='seq2seqannotation', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='seq2seqannotation', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='sequenceannotation', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='sequenceannotation', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AlterField( + model_name='documentannotation', + name='document', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='doc_annotations', to='server.TextClassificationDocument'), + ), + migrations.AlterField( + model_name='project', + name='description', + field=models.TextField(), + ), + migrations.AlterField( + model_name='seq2seqannotation', + name='document', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seq2seq_annotations', to='server.Seq2seqDocument'), + ), + migrations.AlterField( + model_name='sequenceannotation', + name='document', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seq_annotations', to='server.SequenceLabelingDocument'), + ), + ] diff --git a/app/server/models.py b/app/server/models.py index ecdb8ceb..b4a25dc1 100644 --- a/app/server/models.py +++ b/app/server/models.py @@ -117,6 +117,8 @@ class Label(models.Model): project = models.ForeignKey(Project, related_name='labels', on_delete=models.CASCADE) background_color = models.CharField(max_length=7, default='#209cee') text_color = models.CharField(max_length=7, default='#ffffff') + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.text @@ -132,6 +134,8 @@ class Document(models.Model): text = models.TextField() project = models.ForeignKey(Project, related_name='documents', on_delete=models.CASCADE) metadata = models.TextField(default='{}') + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.text[:50] @@ -168,6 +172,8 @@ class Annotation(models.Model): prob = models.FloatField(default=0.0) manual = models.BooleanField(default=False) user = models.ForeignKey(User, on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) class Meta: abstract = True