I have two models one with a foreign key to the other:
class Booking(models.Model):
type_course_requested = models.ManyToManyField(TypePost, blank=True)
.....
#Presentation Message
message = models.CharField(max_length=1000)
class BookingDemand(models.Model):
booking = models.ForeignKey(Booking, on_delete=models.CASCADE, null=True, blank=True)
I want to get bookingdemands based on certain condition, and then serializing to have something like the code below:
{ 'booking1': { 'key1':...
'bookingDemands': {....}
},
'booking2': {...}
}
Filtering is done like this:
bookings=BookingDemand.objects.filter(booking__post__person=self.request.user)
which returns a queryset, but I can't find how to serialize them to have each booking separatly as mentionned above.