1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-03 13:46:58 +00:00

Improved the error message when trying to duplicate a Trust

This commit is contained in:
Nicolas Margulies 2023-09-18 17:12:31 +02:00
parent 540f3bc354
commit a5e802f370

View File

@ -11,6 +11,7 @@ from member.models import Membership
from note_kfet.middlewares import get_current_request from note_kfet.middlewares import get_current_request
from permission.backends import PermissionBackend from permission.backends import PermissionBackend
from rest_framework.utils import model_meta from rest_framework.utils import model_meta
from rest_framework.validators import UniqueTogetherValidator
from ..models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias, Trust from ..models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias, Trust
from ..models.transactions import TransactionTemplate, Transaction, MembershipTransaction, TemplateCategory, \ from ..models.transactions import TransactionTemplate, Transaction, MembershipTransaction, TemplateCategory, \
@ -86,11 +87,9 @@ class TrustSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Trust model = Trust
fields = '__all__' fields = '__all__'
validators = [UniqueTogetherValidator(
def validate(self, attrs): queryset=Trust.objects.all(), fields=('trusting', 'trusted'),
instance = Trust(**attrs) message=_("You already have that person as a friend"))]
instance.clean()
return attrs
class AliasSerializer(serializers.ModelSerializer): class AliasSerializer(serializers.ModelSerializer):