comment command
This commit is contained in:
parent
3ace542deb
commit
3a5c34fd4f
0
apps/comment/management/__init__.py
Normal file
0
apps/comment/management/__init__.py
Normal file
0
apps/comment/management/commands/__init__.py
Normal file
0
apps/comment/management/commands/__init__.py
Normal file
29
apps/comment/management/commands/add_comment_publish_data.py
Normal file
29
apps/comment/management/commands/add_comment_publish_data.py
Normal 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.'))
|
||||||
18
apps/comment/migrations/0006_comment_is_publish.py
Normal file
18
apps/comment/migrations/0006_comment_is_publish.py
Normal 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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
18
apps/tag/migrations/0011_auto_20191112_1525.py
Normal file
18
apps/tag/migrations/0011_auto_20191112_1525.py
Normal 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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -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')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user