1

I need to show inside a calendar the dates that are not available.

I have a queryset that return the unavailable Dates.

#views.py
rental_reservations = RentalReservation.objects.filter(post=post_id)

#models.py
class RentalReservation(TimeStampedModel):
    post = models.ForeignKey('posts.Post', verbose_name="Condo Number")
    start_date = models.DateField()
    end_date = models.DateField()

But I can't figure out how to convert the queryset result into the jquery plugin that is looking for the following array:

var unavailableDates = [
    {start: '2015-09-11', end: '2015-09-15'},
    {start: '2015-09-15', end: '2015-09-23'},
    {start: '2015-10-01', end: '2015-10-07'}
];

1 Answer 1

1

User django queryset values():

rental_reservations = rental_reservations.values('start_date', 'end_date')

Then you need to return django's JsonResponse to the front end, then you should be able to get what you want.

Django doc about JsonResponse.

Django doc about values().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.