comment command

This commit is contained in:
alex 2019-11-12 18:29:24 +03:00
parent 3ace542deb
commit 3a5c34fd4f
8 changed files with 66 additions and 2 deletions

View File

View File

@ -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.'))

View File

@ -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'),
),
]

View File

@ -34,6 +34,7 @@ class Comment(ProjectBaseMixin):
mark = models.PositiveIntegerField(blank=True, null=True, default=None, verbose_name=_('Mark')) 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')) 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) 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) content_type = models.ForeignKey(generic.ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()

View File

@ -20,7 +20,6 @@ def transfer_comments():
'mark', 'mark',
'establishment_id', 'establishment_id',
'account_id', 'account_id',
'created_at',
) )
serialized_data = CommentSerializer(data=list(queryset.values()), many=True) serialized_data = CommentSerializer(data=list(queryset.values()), many=True)

View File

@ -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'),
),
]

View File

@ -19,7 +19,6 @@ class CommentSerializer(serializers.Serializer):
'mark': self.get_mark(data), 'mark': self.get_mark(data),
'content_object': self.get_content_object(data), 'content_object': self.get_content_object(data),
'user': self.get_account(data), 'user': self.get_account(data),
'created': data.pop('created_at'),
}) })
data.pop('establishment_id') data.pop('establishment_id')
data.pop('account_id') data.pop('account_id')