Initial commit: WrestleDesk full project
- Django backend with DRF (clubs, wrestlers, trainers, exercises, templates, trainings, homework, locations, leistungstest) - Next.js 16 frontend with React, Shadcn UI, Tailwind - JWT authentication - Full CRUD for all entities - Calendar view for trainings - Homework management system - Leistungstest tracking
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Exercise
|
||||
|
||||
|
||||
class ExerciseSerializer(serializers.ModelSerializer):
|
||||
category_display = serializers.CharField(source='get_category_display', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Exercise
|
||||
fields = '__all__'
|
||||
read_only_fields = ['created_at', 'updated_at']
|
||||
|
||||
def validate_name(self, value):
|
||||
queryset = Exercise.objects.filter(name__iexact=value)
|
||||
if self.instance:
|
||||
queryset = queryset.exclude(pk=self.instance.pk)
|
||||
if queryset.exists():
|
||||
raise serializers.ValidationError("Eine Übung mit diesem Namen existiert bereits.")
|
||||
return value
|
||||
|
||||
def create(self, validated_data):
|
||||
request = self.context.get('request')
|
||||
if request and hasattr(request.user, 'profile') and request.user.profile.club:
|
||||
validated_data['club'] = request.user.profile.club
|
||||
return super().create(validated_data)
|
||||
Reference in New Issue
Block a user