fix test #2
This commit is contained in:
parent
ecef1a217a
commit
043fcb262b
|
|
@ -179,7 +179,9 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
slugs = attrs.get('slugs', {})
|
slugs = attrs.get('slugs', {})
|
||||||
if models.News.objects.filter(slugs__values__contains=list(slugs.values())).exists():
|
if models.News.objects.filter(
|
||||||
|
slugs__values__contains=list(slugs.values())
|
||||||
|
).exclude(id=attrs.get('id', 0)).exists():
|
||||||
raise serializers.ValidationError({'slugs': _('News with this slug already exists.')})
|
raise serializers.ValidationError({'slugs': _('News with this slug already exists.')})
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
@ -262,7 +264,7 @@ class NewsFavoritesCreateSerializer(FavoritesCreateSerializer):
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
"""Overridden validate method"""
|
"""Overridden validate method"""
|
||||||
# Check establishment object
|
# Check establishment object
|
||||||
news_qs = models.News.objects.filter(slug=self.slug)
|
news_qs = models.News.objects.filter(slugs__values__contains=[self.slug])
|
||||||
|
|
||||||
# Check establishment obj by slug from lookup_kwarg
|
# Check establishment obj by slug from lookup_kwarg
|
||||||
if not news_qs.exists():
|
if not news_qs.exists():
|
||||||
|
|
|
||||||
|
|
@ -125,8 +125,8 @@ class BaseCreateDestroyMixinView(generics.CreateAPIView, generics.DestroyAPIView
|
||||||
lookup_field = 'slug'
|
lookup_field = 'slug'
|
||||||
|
|
||||||
def get_base_object(self):
|
def get_base_object(self):
|
||||||
if isinstance(self._model, News):
|
if 'slugs' in [f.name for f in self._model._meta.get_fields()]: # slugs instead of `slug`
|
||||||
get_object_or_404(self._model, slugs__values__contains=[self.kwargs['slug']])
|
return get_object_or_404(self._model, slugs__values__contains=[self.kwargs['slug']])
|
||||||
return get_object_or_404(self._model, slug=self.kwargs['slug'])
|
return get_object_or_404(self._model, slug=self.kwargs['slug'])
|
||||||
|
|
||||||
def es_update_base_object(self):
|
def es_update_base_object(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user