diff --git a/apps/comment/management/__init__.py b/apps/comment/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/comment/management/commands/__init__.py b/apps/comment/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/comment/management/commands/add_comment_publish_data.py b/apps/comment/management/commands/add_comment_publish_data.py new file mode 100644 index 00000000..49f0af35 --- /dev/null +++ b/apps/comment/management/commands/add_comment_publish_data.py @@ -0,0 +1,29 @@ +from django.core.management.base import BaseCommand + +from account.models import User +from establishment.models import Establishment +from transfer.models import Comments +from comment.models import Comment as NewComment + + +class Command(BaseCommand): + help = 'Add publish values from old db to new db' + + def handle(self, *args, **kwargs): + count = 0 + + establishments = Establishment.objects.all().values_list('old_id', flat=True) + users = User.objects.all().values_list('old_id', flat=True) + queryset = Comments.objects.filter( + establishment_id__in=list(establishments), + account_id__in=list(users), + ) + for comment in queryset: + obj = NewComment.objects.filter(old_id=comment.id).first() + if obj: + count += 1 + obj.created = comment.created_at + obj.modified = comment.updated_at + obj.is_publish = comment.state == 'published' + obj.save() + self.stdout.write(self.style.WARNING(f'Updated {count} objects.')) diff --git a/apps/comment/migrations/0006_comment_is_publish.py b/apps/comment/migrations/0006_comment_is_publish.py new file mode 100644 index 00000000..3c886d32 --- /dev/null +++ b/apps/comment/migrations/0006_comment_is_publish.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2019-11-12 15:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('comment', '0005_remove_comment_country'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='is_publish', + field=models.BooleanField(default=False, verbose_name='Publish status'), + ), + ] diff --git a/apps/comment/models.py b/apps/comment/models.py index 9bf93697..421a05fb 100644 --- a/apps/comment/models.py +++ b/apps/comment/models.py @@ -34,6 +34,7 @@ class Comment(ProjectBaseMixin): mark = models.PositiveIntegerField(blank=True, null=True, default=None, verbose_name=_('Mark')) user = models.ForeignKey('account.User', related_name='comments', on_delete=models.CASCADE, verbose_name=_('User')) old_id = models.IntegerField(null=True, blank=True, default=None) + is_publish = models.BooleanField(default=False, verbose_name=_('Publish status')) content_type = models.ForeignKey(generic.ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() diff --git a/apps/comment/transfer_data.py b/apps/comment/transfer_data.py index 1755b2e3..c9d07585 100644 --- a/apps/comment/transfer_data.py +++ b/apps/comment/transfer_data.py @@ -20,7 +20,6 @@ def transfer_comments(): 'mark', 'establishment_id', 'account_id', - 'created_at', ) serialized_data = CommentSerializer(data=list(queryset.values()), many=True) diff --git a/apps/tag/migrations/0011_auto_20191112_1525.py b/apps/tag/migrations/0011_auto_20191112_1525.py new file mode 100644 index 00000000..40a36164 --- /dev/null +++ b/apps/tag/migrations/0011_auto_20191112_1525.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2019-11-12 15:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tag', '0010_auto_20191112_0104'), + ] + + operations = [ + migrations.AlterField( + model_name='tagcategory', + name='value_type', + field=models.CharField(choices=[('string', 'string'), ('list', 'list'), ('integer', 'integer'), ('percentage', 'percentage')], default='list', max_length=255, verbose_name='value type'), + ), + ] diff --git a/apps/transfer/serializers/comments.py b/apps/transfer/serializers/comments.py index f15c1930..3b099239 100644 --- a/apps/transfer/serializers/comments.py +++ b/apps/transfer/serializers/comments.py @@ -19,7 +19,6 @@ class CommentSerializer(serializers.Serializer): 'mark': self.get_mark(data), 'content_object': self.get_content_object(data), 'user': self.get_account(data), - 'created': data.pop('created_at'), }) data.pop('establishment_id') data.pop('account_id')