diff --git a/apps/comment/admin.py b/apps/comment/admin.py index 061c9c8d..d3dfe2e3 100644 --- a/apps/comment/admin.py +++ b/apps/comment/admin.py @@ -6,4 +6,4 @@ from . import models @admin.register(models.Comment) class CommentModelAdmin(admin.ModelAdmin): """Model admin for model Comment""" - raw_id_fields = ('user', 'country') + raw_id_fields = ('user',) diff --git a/apps/comment/migrations/0005_remove_comment_country.py b/apps/comment/migrations/0005_remove_comment_country.py new file mode 100644 index 00000000..d0688a2f --- /dev/null +++ b/apps/comment/migrations/0005_remove_comment_country.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.7 on 2019-11-12 13:17 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('comment', '0004_comment_old_id'), + ] + + operations = [ + migrations.RemoveField( + model_name='comment', + name='country', + ), + ] diff --git a/apps/comment/models.py b/apps/comment/models.py index 3a8c8c37..9bf93697 100644 --- a/apps/comment/models.py +++ b/apps/comment/models.py @@ -4,10 +4,9 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from account.models import User +from translation.models import Language from utils.models import ProjectBaseMixin from utils.querysets import ContentTypeQuerySetMixin -from translation.models import Language -from location.models import Country class CommentQuerySet(ContentTypeQuerySetMixin): @@ -34,7 +33,6 @@ class Comment(ProjectBaseMixin): text = models.TextField(verbose_name=_('Comment text')) 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')) - country = models.ForeignKey(Country, verbose_name=_('Country'), on_delete=models.SET_NULL, null=True) old_id = models.IntegerField(null=True, blank=True, default=None) content_type = models.ForeignKey(generic.ContentType, on_delete=models.CASCADE) diff --git a/apps/comment/transfer_data.py b/apps/comment/transfer_data.py index 843da78f..679fbfb8 100644 --- a/apps/comment/transfer_data.py +++ b/apps/comment/transfer_data.py @@ -22,7 +22,6 @@ def transfer_comments(): 'id', 'comment', 'mark', - 'locale', 'establishment_id', 'account_id', ) diff --git a/apps/transfer/serializers/comments.py b/apps/transfer/serializers/comments.py index cd4233d1..fe75093a 100644 --- a/apps/transfer/serializers/comments.py +++ b/apps/transfer/serializers/comments.py @@ -1,14 +1,13 @@ from rest_framework import serializers + from comment.models import Comment, User from establishment.models import Establishment -from location.models import Country class CommentSerializer(serializers.Serializer): id = serializers.IntegerField() comment = serializers.CharField() mark = serializers.DecimalField(max_digits=4, decimal_places=2) - locale = serializers.CharField() account_id = serializers.IntegerField() establishment_id = serializers.CharField() @@ -19,11 +18,9 @@ class CommentSerializer(serializers.Serializer): 'mark': data['mark'] * -1 if data['mark'] < 0 else data['mark'], 'content_object': self.get_content_object(data), 'user': self.get_account(data), - 'country': self.get_country(data), }) data.pop('establishment_id') data.pop('account_id') - data.pop('locale') return data def create(self, validated_data): @@ -45,12 +42,3 @@ class CommentSerializer(serializers.Serializer): if not user: raise ValueError(f"User account not found with old_id {data['account_id']}") return user - - @staticmethod - def get_country(data): - locale = data['locale'] - country_code = locale[:locale.index("-")] if len(locale) > 2 else locale - country = Country.objects.filter(code=country_code).first() - if not country: - raise ValueError(f"Country not found with code {country_code}") - return country