Handle member_id correctly
This commit is contained in:
parent
a3b9bc0d90
commit
fa8f116281
|
@ -58,7 +58,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||||
'Reimburse',
|
'Reimburse',
|
||||||
'Other',
|
'Other',
|
||||||
])
|
])
|
||||||
member_id = serializers.IntegerField()
|
member_id = serializers.SerializerMethodField()
|
||||||
member_name = serializers.SerializerMethodField()
|
member_name = serializers.SerializerMethodField()
|
||||||
date = serializers.DateField()
|
date = serializers.DateField()
|
||||||
report_type = serializers.ChoiceField([
|
report_type = serializers.ChoiceField([
|
||||||
|
@ -81,7 +81,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||||
]
|
]
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
member = get_object_or_404(models.Member, id=validated_data['member_id'])
|
member = get_object_or_404(models.Member, id=self.initial_data['member_id'])
|
||||||
validated_data['user'] = member.user
|
validated_data['user'] = member.user
|
||||||
|
|
||||||
if validated_data['account_type'] != 'Clearing':
|
if validated_data['account_type'] != 'Clearing':
|
||||||
|
@ -101,10 +101,14 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
member = get_object_or_404(models.Member, id=validated_data['member_id'])
|
member = get_object_or_404(models.Member, id=self.initial_data['member_id'])
|
||||||
validated_data['user'] = member.user
|
validated_data['user'] = member.user
|
||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
def get_member_id(self, obj):
|
||||||
|
if not obj.user: return None
|
||||||
|
return obj.user.member.id
|
||||||
|
|
||||||
def get_member_name(self, obj):
|
def get_member_name(self, obj):
|
||||||
if not obj.user: return 'Unknown'
|
if not obj.user: return 'Unknown'
|
||||||
|
|
||||||
|
@ -385,7 +389,7 @@ class CardSerializer(serializers.ModelSerializer):
|
||||||
queryset=models.Card.objects.all(),
|
queryset=models.Card.objects.all(),
|
||||||
message='Card number already exists.'
|
message='Card number already exists.'
|
||||||
)])
|
)])
|
||||||
member_id = serializers.IntegerField()
|
member_id = serializers.SerializerMethodField()
|
||||||
active_status = serializers.ChoiceField([
|
active_status = serializers.ChoiceField([
|
||||||
'card_blocked',
|
'card_blocked',
|
||||||
'card_inactive',
|
'card_inactive',
|
||||||
|
@ -404,13 +408,22 @@ class CardSerializer(serializers.ModelSerializer):
|
||||||
]
|
]
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
member = get_object_or_404(models.Member, id=validated_data['member_id'])
|
member = get_object_or_404(models.Member, id=self.initial_data['member_id'])
|
||||||
validated_data['user'] = member.user
|
validated_data['user'] = member.user
|
||||||
|
|
||||||
if not member.vetted_date:
|
if not member.vetted_date:
|
||||||
raise ValidationError(dict(non_field_errors='Member not vetted yet.'))
|
raise ValidationError(dict(non_field_errors='Member not vetted yet.'))
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
member = get_object_or_404(models.Member, id=self.initial_data['member_id'])
|
||||||
|
validated_data['user'] = member.user
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
def get_member_id(self, obj):
|
||||||
|
if not obj.user: return None
|
||||||
|
return obj.user.member.id
|
||||||
|
|
||||||
|
|
||||||
class TrainingSerializer(serializers.ModelSerializer):
|
class TrainingSerializer(serializers.ModelSerializer):
|
||||||
attendance_status = serializers.ChoiceField([
|
attendance_status = serializers.ChoiceField([
|
||||||
|
|
Loading…
Reference in New Issue
Block a user