title: POST a json request containing a foreign key and save it with django
body: <p>I'm POSTing a json request that I build from an html form: </p>
  
  <pre><code>{"discipline":"Mathematiques","date":"2017-12-03"}
  </code></pre>
  
  <p>I'm processing this using this Django view: </p>
  
  <pre><code>def cours_list(request):
      if request.method == 'POST':
  
         data = JSONParser().parse(request)
  
         serializer = LessonSerializer(data=data)
  
         if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
  
         return JSONResponse(serializer.errors, status=400)
  </code></pre>
  
  <p>My models.py contains: </p>
  
  <pre><code>class Discipline(models.Model):
      name = models.CharField(max_length=200)
  
  
  class Lesson(models.Model):
      discipline = models.ForeignKey(Discipline, on_delete=models.CASCADE)
      date = models.DateField()
      regular_slot = models.BooleanField(default=False)
  </code></pre>
  
  <p>My serializers are written as follows:</p>
  
  <pre><code>class DisciplineSerializer(serializers.ModelSerializer):
      class Meta:
          model = Discipline
          fields = ('name')
  
  class LessonSerializer(serializers.ModelSerializer):
      discipline = serializers.RelatedField(source='Discipline', read_only=True);
      class Meta:
         model = Lesson
         fields = ('discipline', 'date', 'regular_slot')
  </code></pre>
  
  <p>However, I have an error saying that: </p>
  
  <blockquote>
    <p>django.db.utils.IntegrityError: NOT NULL constraint failed: cours_lesson.discipline_id</p>
  </blockquote>
  
  <p>I'm new with Django, and I don't this is the right way to define foreign keys but this is the only way I found. </p>