Skip to content

Commit

Permalink
chore(fix): add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ndu committed Dec 12, 2024
1 parent c8d4df8 commit 1e953e6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions server/apps/research/serializers/article_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def validate_related_article_ids(self, value):
if len(value) > 3:
raise serializers.ValidationError("You can only have a maximum of 3 related articles.")

# Check for duplicates
article_ids = [article.id for article in value]
if len(article_ids) != len(set(article_ids)):
raise serializers.ValidationError("Duplicate articles are not allowed.")

article_id = self.instance.id if self.instance else None
if article_id is None:
request = self.context.get('request')
if request and hasattr(request, 'data'):
article_id = request.data.get('id')


if article_id and article_id in [article.id for article in value]:
raise serializers.ValidationError("An article cannot be related to itself.")

Expand Down

0 comments on commit 1e953e6

Please sign in to comment.