From 24b02a4e144fe54fd6da61d45947d5f4483be083 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Wed, 10 Sep 2014 13:18:48 +0200 Subject: [PATCH] [PodcastLists] use auto_now[_add] After all podcast lists and votes have been migrated, the created / modified timestamps can be stored automatically; during the migration this would have overwritten existing values. --- .../migrations/0002_updateinfomodel.py | 24 ++++++++++++++++++++++ mygpo/podcastlists/models.py | 8 +------- mygpo/podcastlists/views.py | 6 ------ mygpo/votes/migrations/0002_updateinfomodel.py | 24 ++++++++++++++++++++++ mygpo/votes/models.py | 8 +------- 5 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 mygpo/podcastlists/migrations/0002_updateinfomodel.py create mode 100644 mygpo/votes/migrations/0002_updateinfomodel.py diff --git a/mygpo/podcastlists/migrations/0002_updateinfomodel.py b/mygpo/podcastlists/migrations/0002_updateinfomodel.py new file mode 100644 index 00000000..f2cc20b7 --- /dev/null +++ b/mygpo/podcastlists/migrations/0002_updateinfomodel.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('podcastlists', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='podcastlist', + name='created', + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name='podcastlist', + name='modified', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/mygpo/podcastlists/models.py b/mygpo/podcastlists/models.py index 7836a6cb..b4e3731b 100644 --- a/mygpo/podcastlists/models.py +++ b/mygpo/podcastlists/models.py @@ -12,7 +12,7 @@ from mygpo.flattr import FlattrThing from mygpo.votes.models import VoteMixin -class PodcastList(UUIDModel, VoteMixin): +class PodcastList(UUIDModel, VoteMixin, UpdateInfoModel): """ A user-curated collection of podcasts """ # the user that created (and owns) the list @@ -25,12 +25,6 @@ class PodcastList(UUIDModel, VoteMixin): # the slug (unique for the user) that is derived from the title slug = models.SlugField(max_length=128) - # overwrites UpdateInfoModel.created/modified during the migration; this - # can be removed after the migration, to use the shadowed field with - # auto_add_now - created = models.DateTimeField() - modified = models.DateTimeField() - class Meta: unique_together = [ # a slug is unique for a user diff --git a/mygpo/podcastlists/views.py b/mygpo/podcastlists/views.py index 11d01317..30f2b129 100644 --- a/mygpo/podcastlists/views.py +++ b/mygpo/podcastlists/views.py @@ -124,8 +124,6 @@ def create_list(request): defaults={ 'id': uuid.uuid1(), 'title': title, - 'created': datetime.utcnow(), - 'modified': datetime.utcnow() } ) @@ -174,10 +172,6 @@ def rate_list(request, plist, owner): user=request.user, content_type=ContentType.objects.get_for_model(plist), object_id=plist.id, - defaults={ - 'created': now, - 'modified': now, - } ) messages.success(request, _('Thanks for rating!')) diff --git a/mygpo/votes/migrations/0002_updateinfomodel.py b/mygpo/votes/migrations/0002_updateinfomodel.py new file mode 100644 index 00000000..2d4b49a8 --- /dev/null +++ b/mygpo/votes/migrations/0002_updateinfomodel.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('votes', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='vote', + name='created', + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name='vote', + name='modified', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/mygpo/votes/models.py b/mygpo/votes/models.py index ce8032cf..8d706ed6 100644 --- a/mygpo/votes/models.py +++ b/mygpo/votes/models.py @@ -9,7 +9,7 @@ from uuidfield import UUIDField from mygpo.core.models import UpdateInfoModel -class Vote(models.Model): +class Vote(UpdateInfoModel): """ A vote by a user for some object """ # the user who voted @@ -22,12 +22,6 @@ class Vote(models.Model): object_id = UUIDField() content_object = generic.GenericForeignKey('content_type', 'object_id') - # overwrites UpdateInfoModel.created/modified during the migration; this - # can be removed after the migration, to use the shadowed field with - # auto_add_now - created = models.DateTimeField() - modified = models.DateTimeField() - class Meta: unique_together = [ # a user can only vote once per object -- 2.11.4.GIT