Reputation: 1259
I have this simple booking system made with Python/Django and I want my customers to be able to make multiple bookings with my booking form.
Example :
I want to book Room A for 1 night
AND
I want to book Room B for 2 nights (not necessarily the same nights)
AND
I want to book Room C for 1 night
My actual code let me make only one booking at a time, verify if the room is available, calculate the price depending on certain rules (number of nights, base price of the room, weekends, long weekends, holidays).
Here is my models.py : http://pastebin.com/QNpx8SaF
Here is my forms.py : http://pastebin.com/vXvHWyWk
Here is my form template : http://pastebin.com/TsMw71wg
I am not sure how to do this. Should I make a list and store all the bookings ?
How can I add a button in my form to add (n) more bookings and make sure they don't overlap on each other.
Any tips on how the validation and insert should work ? I guess I should validate all the bookings before I insert.
Thanks
Upvotes: 0
Views: 142
Reputation: 749
You can implement formsets (https://docs.djangoproject.com/en/dev/topics/forms/formsets/) just for create multiple bookings at the same time and probably an add and delete button (https://djangosnippets.org/snippets/1389/) to add an delete dynamically new bookins.
You can customise the formset validation for availability and probably change you validation method just for receive an argument with a list of unsaved bookings
Upvotes: 2