1

My Models

class LessonPlan(models.Model):
planner=models.ForeignKey('LessonPlanner', on_delete=models.CASCADE)
title=models.CharField(max_length=100, null=True, blank=True)
details=models.TextField(null=True, blank=True)
created_at=models.DateTimeField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)

class LessonStudyMaterial(models.Model):
Lesson=models.ForeignKey('LessonPlan', on_delete=models.CASCADE)
file=models.FileField(upload_to=get_upload_path, null=True, blank=True)
created_at=models.DateTimeField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)

My Serializer

class LessonPlanSerializer(serializers.ModelSerializer):    
 uploaded_file=serializers.ListField(child=serializers.FileField(max_length=2000)

class Meta:
     model = LessonPlan
     fields=['id', 'planner', 'title', 'details', 'uploaded_file',]

My post request contains title, details, and multiple files that will post in the child model LessonStudyMaterial so I have added the uploaded_file field to validate data while posting but it showing an error

0 Answers0