93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
from django.views import generic
|
|
from .models import Container, ContainerType
|
|
|
|
|
|
class ContainerListView(generic.ListView):
|
|
model = Container
|
|
template_name = 'container/container_list.html'
|
|
context_object_name = 'container_list'
|
|
paginate_by = 20
|
|
|
|
'''
|
|
def get_queryset(self):
|
|
# Return the last five created containers
|
|
return Container.objects.order_by('-created_ts')[:5]
|
|
'''
|
|
|
|
|
|
class ContainerCreateView(generic.CreateView):
|
|
model = Container
|
|
# template_name = 'container/detail.html'
|
|
fields = ['named_id', 'description', 'color', 'container_type']
|
|
|
|
def form_valid(self, form):
|
|
form.instance.changed_by = self.request.user
|
|
form.instance.created_by = self.request.user
|
|
return super().form_valid(form)
|
|
|
|
|
|
class ContainerUpdateView(generic.UpdateView):
|
|
model = Container
|
|
# template_name = 'container/detail.html'
|
|
fields = ['named_id', 'description', 'color', 'container_type']
|
|
|
|
def form_valid(self, form):
|
|
form.instance.changed_by = self.request.user
|
|
return super().form_valid(form)
|
|
|
|
|
|
class ContainerDetailView(generic.DetailView):
|
|
model = Container
|
|
|
|
|
|
class ContainerDeleteView(generic.DetailView):
|
|
model = Container
|
|
|
|
|
|
class ContainerTypeListView(generic.ListView):
|
|
template_name = 'container/container_type_list.html'
|
|
context_object_name = 'container_type_list'
|
|
paginate_by = 20
|
|
model = ContainerType
|
|
|
|
'''
|
|
def get_queryset(self):
|
|
# Return the last five created container types
|
|
return ContainerType.objects.order_by('-created_ts')[:5]
|
|
'''
|
|
|
|
|
|
class ContainerTypeDetailView(generic.DetailView):
|
|
model = ContainerType
|
|
context_object_name = 'container_type'
|
|
template_name = 'container/container_type_detail.html'
|
|
|
|
|
|
class ContainerTypeCreateView(generic.CreateView):
|
|
model = ContainerType
|
|
# template_name = 'container/detail.html'
|
|
fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height',
|
|
'has_cover', 'contains_container']
|
|
|
|
def form_valid(self, form):
|
|
form.instance.changed_by = self.request.user
|
|
form.instance.created_by = self.request.user
|
|
return super().form_valid(form)
|
|
|
|
|
|
class ContainerTypeUpdateView(generic.UpdateView):
|
|
model = ContainerType
|
|
# template_name = 'container/detail.html'
|
|
fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height',
|
|
'has_cover', 'contains_container']
|
|
|
|
def form_valid(self, form):
|
|
form.instance.changed_by = self.request.user
|
|
return super().form_valid(form)
|
|
|
|
|
|
class ContainerTypeDeleteView(generic.DetailView):
|
|
model = ContainerType
|
|
|
|
|