mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Add product management views
This commit is contained in:
@ -75,6 +75,9 @@ class Product(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('counter:product_list')
|
||||
|
||||
class Counter(models.Model):
|
||||
name = models.CharField(_('name'), max_length=30)
|
||||
club = models.ForeignKey(Club, related_name="counters")
|
||||
|
23
counter/templates/counter/product_list.jinja
Normal file
23
counter/templates/counter/product_list.jinja
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Product list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url('counter:new_product') }}">{% trans %}New product{% endtrans %}</a></p>
|
||||
{% if product_list %}
|
||||
<h3>{% trans %}Product list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for p in product_list %}
|
||||
<li><a href="{{ url('counter:product_edit', product_id=p.id) }}">{{ p }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no products in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,9 @@ urlpatterns = [
|
||||
url(r'^admin$', CounterListView.as_view(), name='admin_list'),
|
||||
url(r'^admin/new$', CounterCreateView.as_view(), name='new'),
|
||||
url(r'^admin/delete/(?P<counter_id>[0-9]+)$', CounterDeleteView.as_view(), name='delete'),
|
||||
url(r'^admin/product/list$', ProductListView.as_view(), name='product_list'),
|
||||
url(r'^admin/product/create$', ProductCreateView.as_view(), name='new_product'),
|
||||
url(r'^admin/product/(?P<product_id>[0-9]+)$', ProductEditView.as_view(), name='product_edit'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -351,6 +351,33 @@ class CounterDeleteView(CanEditMixin, DeleteView):
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
success_url = reverse_lazy('counter:admin_list')
|
||||
|
||||
# Product management
|
||||
|
||||
class ProductListView(ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
"""
|
||||
model = Product
|
||||
template_name = 'counter/product_list.jinja'
|
||||
|
||||
class ProductCreateView(CreateView):
|
||||
"""
|
||||
A create view for the admins
|
||||
"""
|
||||
model = Product
|
||||
template_name = 'core/edit.jinja'
|
||||
|
||||
class ProductEditView(UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
model = Product
|
||||
form_class = modelform_factory(Product, fields=['name', 'description', 'product_type', 'code', 'purchase_price',
|
||||
'selling_price', 'special_selling_price', 'icon', 'club'])
|
||||
pk_url_kwarg = "product_id"
|
||||
template_name = 'core/edit.jinja'
|
||||
# TODO: add management of the 'counters' ForeignKey
|
||||
|
||||
# User accounting infos
|
||||
|
||||
class UserAccountView(DetailView):
|
||||
|
Reference in New Issue
Block a user