fix recipe duplicates
This commit is contained in:
parent
959eb33043
commit
6a987532ba
|
|
@ -25,6 +25,9 @@ class RecipeQuerySet(models.QuerySet):
|
||||||
default=False,
|
default=False,
|
||||||
output_field=models.BooleanField(default=False)))
|
output_field=models.BooleanField(default=False)))
|
||||||
|
|
||||||
|
def by_locale(self, locale):
|
||||||
|
return self.filter(title__icontains=locale)
|
||||||
|
|
||||||
|
|
||||||
class Recipe(TranslatedFieldsMixin, ImageMixin, BaseAttributes):
|
class Recipe(TranslatedFieldsMixin, ImageMixin, BaseAttributes):
|
||||||
"""Recipe model."""
|
"""Recipe model."""
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,15 @@ class RecipeListSerializer(serializers.ModelSerializer):
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
||||||
model = models.Recipe
|
model = models.Recipe
|
||||||
fields = ('id', 'title_translated', 'subtitle_translated', 'author',
|
fields = (
|
||||||
'published_at', 'in_favorites')
|
'id',
|
||||||
|
'title_translated',
|
||||||
|
'subtitle_translated',
|
||||||
|
'author',
|
||||||
|
'created_by',
|
||||||
|
'published_at',
|
||||||
|
'in_favorites',
|
||||||
|
)
|
||||||
read_only_fields = fields
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
|
from recipe.models import Recipe
|
||||||
from transfer.models import PageTexts
|
from transfer.models import PageTexts
|
||||||
from transfer.serializers.recipe import RecipeSerializer
|
from transfer.serializers.recipe import RecipeSerializer
|
||||||
|
|
||||||
|
|
@ -25,6 +28,20 @@ def transfer_recipe():
|
||||||
serialized_data.save()
|
serialized_data.save()
|
||||||
else:
|
else:
|
||||||
pprint(f'Recipe serializer errors: {serialized_data.errors}')
|
pprint(f'Recipe serializer errors: {serialized_data.errors}')
|
||||||
|
return
|
||||||
|
|
||||||
|
# Удаление дубликатов рецептов по одинаковым description
|
||||||
|
duplicate_descriptions = Recipe.objects.values(
|
||||||
|
'description'
|
||||||
|
).annotate(
|
||||||
|
description_count=Count('description')
|
||||||
|
).filter(
|
||||||
|
description_count__gt=1
|
||||||
|
)
|
||||||
|
for data in duplicate_descriptions:
|
||||||
|
description = data['description']
|
||||||
|
_list = list(Recipe.objects.filter(description=description).values_list('pk', flat=True)[1:])
|
||||||
|
Recipe.objects.filter(id__in=_list).delete()
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
"""Recipe app common views."""
|
"""Recipe app common views."""
|
||||||
|
from django.utils import translation
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
from recipe import models
|
from recipe import models
|
||||||
from recipe.serializers import common as serializers
|
from recipe.serializers import common as serializers
|
||||||
|
|
||||||
|
|
@ -10,9 +12,14 @@ class RecipeViewMixin(generics.GenericAPIView):
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self, *args, **kwargs):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
qs = models.Recipe.objects.published().annotate_in_favorites(user)
|
qs = models.Recipe.objects.published().annotate_in_favorites(user)
|
||||||
|
|
||||||
|
locale = kwargs.get('locale')
|
||||||
|
if locale:
|
||||||
|
qs = qs.by_locale(locale)
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,6 +28,11 @@ class RecipeListView(RecipeViewMixin, generics.ListAPIView):
|
||||||
|
|
||||||
serializer_class = serializers.RecipeListSerializer
|
serializer_class = serializers.RecipeListSerializer
|
||||||
|
|
||||||
|
def get_queryset(self, *args, **kwargs):
|
||||||
|
locale = translation.get_language()
|
||||||
|
kwargs.update({'locale': locale})
|
||||||
|
return super().get_queryset(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RecipeDetailView(RecipeViewMixin, generics.RetrieveAPIView):
|
class RecipeDetailView(RecipeViewMixin, generics.RetrieveAPIView):
|
||||||
"""Resource for detailed recipe information."""
|
"""Resource for detailed recipe information."""
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,10 @@ def transfer_product_reviews():
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
|
"languages": [
|
||||||
|
transfer_languages,
|
||||||
|
],
|
||||||
"overlook": [
|
"overlook": [
|
||||||
# transfer_languages,
|
|
||||||
transfer_reviews,
|
transfer_reviews,
|
||||||
transfer_text_review,
|
transfer_text_review,
|
||||||
make_en_text_review,
|
make_en_text_review,
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ class Command(BaseCommand):
|
||||||
'guide_elements_bulk',
|
'guide_elements_bulk',
|
||||||
'guide_element_advertorials',
|
'guide_element_advertorials',
|
||||||
'guide_complete',
|
'guide_complete',
|
||||||
|
'languages', # №4 - перенос языков
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user