title: Get available time slots for appointment booking using Django REST framework
body: <p>I am trying to develop an API for scheduling appointments for several salons.</p>
  
  <p>Right now I have models and serializers for the <code>Salon</code> and the <code>Appointment</code>. All appointments can have different durations. The <code>Appointment</code> model looks like this:</p>
  
  <pre><code>    class Appointment(models.Model):
          date = models.DateField()
          start_time = models.TimeField()
          end_time = models.TimeField()
  
          salon = models.ForeignKey(Salon, on_delete=models.CASCADE)
  </code></pre>
  
  <p>How can I return all salons and their available time slots (no appointment at that time) for a given date.
  So say if a salon is open from 10:00-16:00 and has only one appointment from 11:00-11:30 we would get something like: </p>
  
  <pre><code>{
      "id": 3,
      "name": "My Salon",
      "city": "London",
  
      "time_slots": [
          {
              "date": "2019-12-01",
              "start_time": "10:00:00",
              "end_time": "11:00:00",
          },
          {
              "date": "2019-12-01",
              "start_time": "11:30:00",
              "end_time": "16:00:00",
          }
      ]
  }
  </code></pre>
  
  <p>Right now the only way I can think of is by adding a new <code>TimeSlot</code> model with <code>Salon</code> as Foreign key and saving all time slots in the database and changing them once an appointment is made? However, this does not seem very efficient. </p>
  
  <p>Is there a better way of calculating and returning the time slots?</p>
  
  <p>Edit</p>
  
  <p>Serializers:</p>
  
  <pre><code>class AppointmentSerializer(serializers.ModelSerializer):
      class Meta:
          model = Appointment
          fields = ('id', 'date', 'start_time', 'end_time', 'salon')
  
  class SalonSerializer(serializers.ModelSerializer):
      appointment_set = AppointmentSerializer(many=True, read_only=True)
  
      class Meta:
          model = Salon
          fields = ('id', 'name', 'city', 'appointment_set')
          depth = 1
  </code></pre>