From 52870818eadf10dfbfe2f5058264b5132afc7c1a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Nov 2016 21:56:44 +0000 Subject: [PATCH] add created and modified fields --- project/blog/migrations/0001_initial.py | 6 +- project/common/models.py | 4 ++ project/home/migrations/0001_initial.py | 12 +++- .../home/migrations/0002_create_homepage.py | 59 ------------------- project/home/migrations/0003_homepage_body.py | 21 ------- project/pages/migrations/0001_initial.py | 6 +- project/projects/migrations/0001_initial.py | 8 ++- 7 files changed, 28 insertions(+), 88 deletions(-) mode change 100755 => 100644 project/home/migrations/0001_initial.py delete mode 100755 project/home/migrations/0002_create_homepage.py delete mode 100755 project/home/migrations/0003_homepage_body.py diff --git a/project/blog/migrations/0001_initial.py b/project/blog/migrations/0001_initial.py index 5b5e658..d3dd642 100644 --- a/project/blog/migrations/0001_initial.py +++ b/project/blog/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2016-11-24 20:51 +# Generated by Django 1.10.3 on 2016-11-28 21:53 from __future__ import unicode_literals from django.db import migrations, models @@ -12,8 +12,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('wagtailcore', '0030_index_on_pagerevision_created_at'), ('wagtailimages', '0015_fill_filter_spec_field'), + ('wagtailcore', '0030_index_on_pagerevision_created_at'), ] operations = [ @@ -21,6 +21,8 @@ class Migration(migrations.Migration): name='BlogPage', fields=[ ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), ('date', models.DateField(verbose_name='Post date')), ('intro', models.CharField(max_length=250)), ('body', wagtail.wagtailcore.fields.RichTextField(blank=True)), diff --git a/project/common/models.py b/project/common/models.py index d5859f4..8bcd49e 100644 --- a/project/common/models.py +++ b/project/common/models.py @@ -1,9 +1,13 @@ from wagtail.wagtailcore.models import Page +from django.db import models class Entity(Page): is_home = False + created = models.DateTimeField(auto_now_add=True) + modified = models.DateTimeField(auto_now=True) + class Meta: abstract = True diff --git a/project/home/migrations/0001_initial.py b/project/home/migrations/0001_initial.py old mode 100755 new mode 100644 index cdc8081..3fb2c1e --- a/project/home/migrations/0001_initial.py +++ b/project/home/migrations/0001_initial.py @@ -1,20 +1,28 @@ # -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-28 21:53 from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion +import wagtail.wagtailcore.fields class Migration(migrations.Migration): + initial = True + dependencies = [ - ('wagtailcore', '0029_unicode_slugfield_dj19'), + ('wagtailcore', '0030_index_on_pagerevision_created_at'), ] operations = [ migrations.CreateModel( name='HomePage', fields=[ - ('page_ptr', models.OneToOneField(on_delete=models.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('body', wagtail.wagtailcore.fields.RichTextField(blank=True)), ], options={ 'abstract': False, diff --git a/project/home/migrations/0002_create_homepage.py b/project/home/migrations/0002_create_homepage.py deleted file mode 100755 index 4349a16..0000000 --- a/project/home/migrations/0002_create_homepage.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations - - -def create_homepage(apps, schema_editor): - # Get models - ContentType = apps.get_model('contenttypes.ContentType') - Page = apps.get_model('wagtailcore.Page') - Site = apps.get_model('wagtailcore.Site') - HomePage = apps.get_model('home.HomePage') - - # Delete the default homepage - # If migration is run multiple times, it may have already been deleted - Page.objects.filter(id=2).delete() - - # Create content type for homepage model - homepage_content_type, __ = ContentType.objects.get_or_create( - model='homepage', app_label='home') - - # Create a new homepage - homepage = HomePage.objects.create( - title="Homepage", - slug='home', - content_type=homepage_content_type, - path='00010001', - depth=2, - numchild=0, - url_path='/home/', - ) - - # Create a site with the new homepage set as the root - Site.objects.create( - hostname='localhost', root_page=homepage, is_default_site=True) - - -def remove_homepage(apps, schema_editor): - # Get models - ContentType = apps.get_model('contenttypes.ContentType') - HomePage = apps.get_model('home.HomePage') - - # Delete the default homepage - # Page and Site objects CASCADE - HomePage.objects.filter(slug='home', depth=2).delete() - - # Delete content type for homepage model - ContentType.objects.filter(model='homepage', app_label='home').delete() - - -class Migration(migrations.Migration): - - dependencies = [ - ('home', '0001_initial'), - ] - - operations = [ - migrations.RunPython(create_homepage, remove_homepage), - ] diff --git a/project/home/migrations/0003_homepage_body.py b/project/home/migrations/0003_homepage_body.py deleted file mode 100755 index 409b380..0000000 --- a/project/home/migrations/0003_homepage_body.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2016-11-18 22:28 -from __future__ import unicode_literals - -from django.db import migrations -import wagtail.wagtailcore.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('home', '0002_create_homepage'), - ] - - operations = [ - migrations.AddField( - model_name='homepage', - name='body', - field=wagtail.wagtailcore.fields.RichTextField(blank=True), - ), - ] diff --git a/project/pages/migrations/0001_initial.py b/project/pages/migrations/0001_initial.py index ffbad40..cbabb5b 100644 --- a/project/pages/migrations/0001_initial.py +++ b/project/pages/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2016-11-28 21:29 +# Generated by Django 1.10.3 on 2016-11-28 21:53 from __future__ import unicode_literals from django.db import migrations, models @@ -20,6 +20,8 @@ class Migration(migrations.Migration): name='SectionIndexPage', fields=[ ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), ('intro', wagtail.wagtailcore.fields.RichTextField(blank=True)), ('hide_list', models.BooleanField(default=False)), ], @@ -32,6 +34,8 @@ class Migration(migrations.Migration): name='SimpleContentPage', fields=[ ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), ('body', wagtail.wagtailcore.fields.RichTextField()), ], options={ diff --git a/project/projects/migrations/0001_initial.py b/project/projects/migrations/0001_initial.py index 4aa7b4a..54376d2 100644 --- a/project/projects/migrations/0001_initial.py +++ b/project/projects/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2016-11-28 21:46 +# Generated by Django 1.10.3 on 2016-11-28 21:53 from __future__ import unicode_literals from django.db import migrations, models @@ -13,9 +13,9 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('wagtailcore', '0030_index_on_pagerevision_created_at'), - ('wagtailimages', '0015_fill_filter_spec_field'), ('wagtaildocs', '0007_merge'), + ('wagtailimages', '0015_fill_filter_spec_field'), + ('wagtailcore', '0030_index_on_pagerevision_created_at'), ] operations = [ @@ -23,6 +23,8 @@ class Migration(migrations.Migration): name='ProjectPage', fields=[ ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), ('summary', models.CharField(max_length=500)), ('body', wagtail.wagtailcore.fields.RichTextField()), ('project_url', models.URLField(blank=True, validators=[project.projects.models.validate_url])),