additions for migration of comments
This commit is contained in:
parent
c5e96a7ad8
commit
06f5a551b8
|
|
@ -15,7 +15,7 @@ def transfer_comments():
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"tmp": [
|
"comment": [
|
||||||
# transfer_comments
|
transfer_comments
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
LONG_DATA_TYPES = [
|
LONG_DATA_TYPES = [
|
||||||
'update_country_flag',
|
'update_country_flag',
|
||||||
|
'comment'
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from comment.models import Comment, User
|
from comment.models import Comment, User
|
||||||
from establishment.models import Establishment
|
from establishment.models import Establishment
|
||||||
|
from location.models import Country
|
||||||
|
|
||||||
|
|
||||||
class CommentSerializer(serializers.ModelSerializer):
|
class CommentSerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -28,8 +29,16 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||||
data = self.set_mark(data)
|
data = self.set_mark(data)
|
||||||
data = self.set_establishment(data)
|
data = self.set_establishment(data)
|
||||||
data = self.set_account(data)
|
data = self.set_account(data)
|
||||||
|
data = self.set_country(data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
try:
|
||||||
|
return Comment.objects.create(**validated_data)
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError(f"Error creating comment with {validated_data}: {e}")
|
||||||
|
|
||||||
def set_text(self, data):
|
def set_text(self, data):
|
||||||
data['text'] = data.pop('comment')
|
data['text'] = data.pop('comment')
|
||||||
return data
|
return data
|
||||||
|
|
@ -41,7 +50,7 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
def set_account(self, data):
|
def set_account(self, data):
|
||||||
try:
|
try:
|
||||||
data['account'] = User.objects.filter(old_id=data['account_id']).first()
|
data['user'] = User.objects.filter(old_id=data['account_id']).first()
|
||||||
except User.DoesNotExist as e:
|
except User.DoesNotExist as e:
|
||||||
raise ValueError(f"User account not found with {data}: {e}")
|
raise ValueError(f"User account not found with {data}: {e}")
|
||||||
|
|
||||||
|
|
@ -51,9 +60,10 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
def set_establishment(self, data):
|
def set_establishment(self, data):
|
||||||
try:
|
try:
|
||||||
data['establishment'] = Establishment.objects.filter(old_id=data['account_id']).first()
|
data['content_object'] = Establishment.objects.filter(old_id=data['establishment_id']).first()
|
||||||
except Establishment.DoesNotExist as e:
|
except Establishment.DoesNotExist as e:
|
||||||
raise ValueError(f"Establishment not found with {data}: {e}")
|
raise ValueError(f"Establishment not found with {data}: {e}")
|
||||||
|
# print(f"Establishment not found with {data}: {e}")
|
||||||
|
|
||||||
del(data['establishment_id'])
|
del(data['establishment_id'])
|
||||||
|
|
||||||
|
|
@ -62,3 +72,14 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||||
def set_old_id(self, data):
|
def set_old_id(self, data):
|
||||||
data['old_id'] = data.pop("id")
|
data['old_id'] = data.pop("id")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def set_country(self, data):
|
||||||
|
locale = data.pop("locale")
|
||||||
|
country_code = locale[:locale.index("-")] if len(locale) > 2 else locale
|
||||||
|
|
||||||
|
try:
|
||||||
|
data['country'] = Country.objects.filter(code=country_code).first()
|
||||||
|
except Country.DoesNotExist as e:
|
||||||
|
raise ValueError(f"Country not found with {data}: {e}")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
@ -74,7 +74,7 @@ PROJECT_APPS = [
|
||||||
'comment.apps.CommentConfig',
|
'comment.apps.CommentConfig',
|
||||||
'favorites.apps.FavoritesConfig',
|
'favorites.apps.FavoritesConfig',
|
||||||
'rating.apps.RatingConfig',
|
'rating.apps.RatingConfig',
|
||||||
# 'transfer.apps.TransferConfig',
|
'transfer.apps.TransferConfig',
|
||||||
'tag.apps.TagConfig',
|
'tag.apps.TagConfig',
|
||||||
'product.apps.ProductConfig',
|
'product.apps.ProductConfig',
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user