SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type object 'Course' has no attribute 'objects'
  2.      
  3. #Model.py
  4.  
  5. class Studnet(EmbeddedDocument):
  6.     student_name = StringField(max_length=200)
  7.     student_contactperson = StringField(max_length=200)
  8.     student_adress = StringField(max_length=200)
  9.  
  10. class Course(EmbeddedDocument):
  11.     course_name = StringField(max_length=200)
  12.     course_fee = StringField(max_length=200)
  13.  
  14.  
  15. #Serializers.py
  16. class CourseSerializer(EmbeddedDocumentSerializer):
  17.     class Meta:
  18.         model = Course
  19.         fields = (course_name,course_fee)
  20.  
  21.  
  22. class StudentSerializer(DocumentSerializer):
  23.     courses = CourseSerializer(many=True)
  24.     class Meta:
  25.         model = Student
  26.         fields = ('naam','telefoonnummer','bankrekening','vestiging','abonnement')
  27.         depth = 2
  28.  
  29.     def create(self, validated_data):
  30.         course_data = validated_data.pop('courses')
  31.         student = Student.objects.create(**validated_data)
  32.         Course.objects.create(student=student, **vestigin_data)
  33.         return student
  34.  
  35. #Views.py
  36.  
  37. class StudentViewSet(meviewsets.ModelViewSet):
  38.     lookup_field = 'name'
  39.     queryset = Student.objects.all().order_by('-date_joined')
  40.     serializer_class = StudentSerializer
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top