Welcome to djreservation’s documentation!¶
Contents:
Installation¶
Install with pip
$ pip install django-reservation
In settings.py¶
Set “djreservation” in your INSTALLED_APPS.
INSTALLED_APPS = [
...
'djreservation'
]
Set ‘djreservation.middleware.ReservationMiddleware’ in MIDDLEWARE
MIDDLEWARE = [
...
'djreservation.middleware.ReservationMiddleware'
]
Note
Middleware is not necesary if you just use SimpleProductReservation
Configure your email settings
DEFAULT_FROM_EMAIL = "mail@example.com"
EMAIL_HOST = "localhost"
EMAIL_PORT = "1025"
In urls.py¶
Append django reservation to urlpatterns
from djreservation import urls as djreservation_urls
urlpatterns = [
...
] + djreservation_urls.urlpatterns
Basic usage¶
- djreservation have two different approachs:
- ProductReservationView: You have a shop cart for a reservation in determinate period of time.
- SimpleProductReservation: You reserve one product in determinate period of time.
Both views inherit from CreateView. so all verifications and functions are included and of course you can overwrite.
The main diferent is the way how the user make a reservation
ProductReservationView:¶
In this approach exist a button that start the reservation process, suppose your are the user, when start you need to set the period of time you want the reservation, then you reserve all products you want and as final step you finish the reservation and an email is send you.
How to implement that behaviour:
Create a view for reserve a product
from djreservation.views import ProductReservationView
class MyObjectReservation(ProductReservationView):
base_model = MyObject # required
amount_field = 'quantity' # required
extra_display_field = ['measurement_unit'] # not required
Set the urlpatterns in your urls.py
urlpatterns = [
...
url(r"^reservation/create$", MyObjectReservation.as_view())
]
SimpleProductReservation:¶
In this approach you can reserve a product for a period of time, like a room in a hotel.
from djreservation.views import SimpleProductReservation
from .models import MyModel
class RoomReservation(SimpleProductReservation):
base_model = MyModel # required
amount_field = 'quantity' # required
max_amount_field = 'max_amount' # required
extra_display_field = [] # not required
Set the urlpatterns in your urls.py
urlpatterns = [
...
url(r"^reservationroom/create/(?<pk>\d+)$", RoomReservation.as_view())
]
Templates¶
djreservation require a template ‘base.html’ with the follow blocks
{% block css%} {%endblock%}
{% block content %}
{%endblock%}
{% block js %}
{%endblock%}
you can overwrite wathever template you want base in app templates
Settings configuration¶
- DJRESERVATION_TOKENIZE: Reservation can be updated by non-registered user using a token send by mail. Token only work one time. default False
- DJRESERVATION_START_RESERVATION_DATETIME: initialize start reservation datetime widget with this date. default format ‘%d/%m/%Y %H:%M’
- DJRESERVATION_END_RESERVATION_DATETIME: initialize end reservation datetime widget with this date. default format ‘%d/%m/%Y %H:%M’
Contrib CRUD¶
Create a CRUD (Create, Remove, Update, Detail) using one class. It Work if user is loggin.
ObjectView¶
Create simple models, than not need set request.user
Example:
from djreservation.contrib.CRUD import ObjectView
class TShirt(UserObjectView):
model = TShirtmodel # requiered
template_name_base = "tshirt/tshirt" # not required but recomendable
namespace = "tshirt" # required
fields = [ ... ] # not required
tshirts = TShirt()
set urlpatterns in urls.py
urlpatterns = [
...
url(r'^tshirts/', include(tshirts.get_urls(), namespace="tshirts")),
]
UserObjectView¶
If your models have a user field and want to set automátically the user them
from djreservation.contrib.CRUD import UserObjectView
from djreservation.contrib.CRUD import ObjectView
class SpeakpropposeCRUD(UserObjectView):
model = Speakproppose # requiered
template_name_base = "tshirt/tshirt" # not required but recomendable
namespace = "proppose" # required
fields = [ fields with out user ] # not required
propposes = SpeakpropposeCRUD()
set urlpatterns in urls.py
urlpatterns = [
...
url(r'^propposes/', include(propposes.get_urls(), namespace="propposes")),
]