Manufacturer detail view
This commit is contained in:
parent
2ac00868e3
commit
3ca926afac
3 changed files with 149 additions and 4 deletions
|
@ -14,3 +14,6 @@ class Manufacturer(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ("name", )
|
||||||
|
|
131
inventory/templates/inventory/manufacturer_detail.html
Normal file
131
inventory/templates/inventory/manufacturer_detail.html
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load formatstring %}
|
||||||
|
|
||||||
|
{% block title %}Manufacturer: {{ manufacturer }}{% endblock %}
|
||||||
|
|
||||||
|
{% block header_bar %}
|
||||||
|
<a href="{% url 'manufacturer-list' %}"><img class="icon" src="{% static "inventory/img/back.svg" %}"></a>
|
||||||
|
Manufacturer: {{ manufacturer.name }}
|
||||||
|
<span class="small">{{ manufacturer.description }}</span></h2>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block header_icons %}
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url "admin:inventory_manufacturer_change" object_id=manufacturer.pk %}"><img class="icon" src="{% static "inventory/img/edit.svg" %}"></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<table class="attribute-list">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<td>{{ manufacturer.name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Description</th>
|
||||||
|
<td>{{ manufacturer.description }}</td>
|
||||||
|
</tr>
|
||||||
|
{% if manufacturer.icon %}
|
||||||
|
<tr>
|
||||||
|
<th>Icon</th>
|
||||||
|
<td><img src="{{ manufacturer.icon.url }}" title="{{ manufacturer.name }}" style="max-height: 20px;"></td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
<tr>
|
||||||
|
<th>Link</th>
|
||||||
|
<td>{% if manufacturer.web_link %}<a href="{{ manufacturer.web_link }}" title="{{ manufacturer.name }}">{{ manufacturer.web_link }}{% else %}-{% endif %}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>Tags</th>
|
||||||
|
<td>
|
||||||
|
<ul class="tag-list">
|
||||||
|
{% for tag in manufacturer.tags.all %}
|
||||||
|
<li><a href="{% url 'tag-detail' tag.id %}" title="{{ tag.name }}">{{ tag.name }}</a></li>
|
||||||
|
{% empty %}
|
||||||
|
No tags
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr><th>Created at</th><td>{{ manufacturer.created_at }}</td></tr>
|
||||||
|
{% if manufacturer.created_at != manufacturer.changed_at %}
|
||||||
|
<tr><th>Last change</th><td>{{ manufacturer.changed_at }}</td></tr>
|
||||||
|
{% endif %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Items</h2>
|
||||||
|
|
||||||
|
<div class="pagination" id="paginator_top">
|
||||||
|
{% if items.has_previous %}
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page=1#paginator_top"><img src="{% static 'inventory/img/first.svg' %}" class="icon" title="First page"></a>
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.previous_page_number }}#paginator_top"><img src="{% static 'inventory/img/previous.svg' %}" class="icon" title="Previous page"></a>
|
||||||
|
{% endif %}
|
||||||
|
{% if items.paginator.num_pages > 1 %}
|
||||||
|
{{ items.number }}/{{ items.paginator.num_pages }}
|
||||||
|
{% endif %}
|
||||||
|
{% if items.has_next %}
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.next_page_number }}#paginator_top"><img src="{% static 'inventory/img/next.svg' %}" class="icon" title="Next page"></a>
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.paginator.num_pages}}#paginator_top"><img src="{% static 'inventory/img/last.svg' %}" class="icon" title="Last page"></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th></th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Container</th>
|
||||||
|
<th>Distributor</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in items %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{% url 'item-detail' item.id %}">{{ item.name }}</a></td>
|
||||||
|
<td>
|
||||||
|
{% if item.documentation.all %}
|
||||||
|
<a class="datasheet" href="{{ item.documentation.all.0.file.url }}"><img class="icon" src="{% static "inventory/img/datasheet.svg" %}"></a>
|
||||||
|
{% endif %}
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<a class="edit" href="{% url "admin:inventory_item_change" object_id=item.pk %}"><img class="icon" src="{% static "inventory/img/edit.svg" %}"></a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ item.description }}</td>
|
||||||
|
<td><a href="{{ item.container_url }}">{{ item.container.display_name }}</a></td>
|
||||||
|
<td>
|
||||||
|
{% if item.distributor %}
|
||||||
|
<a href="{% url 'distributor-detail' item.distributor.id %}">
|
||||||
|
{% if item.distributor.icon %}<img src="{{ item.distributor.icon.url }}" class="icon">{% endif %}{{ item.distributor.name }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
-
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="pagination" id="paginator_bottom">
|
||||||
|
{% if items.has_previous %}
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page=1#paginator_bottom"><img src="{% static 'inventory/img/first.svg' %}" class="icon" title="First page"></a>
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.previous_page_number }}#paginator_bottom"><img src="{% static 'inventory/img/previous.svg' %}" class="icon" title="Previous page"></a>
|
||||||
|
{% endif %}
|
||||||
|
{% if items.paginator.num_pages > 1 %}
|
||||||
|
{{ items.number }}/{{ items.paginator.num_pages }}
|
||||||
|
{% endif %}
|
||||||
|
{% if items.has_next %}
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.next_page_number }}#paginator_bottom"><img src="{% static 'inventory/img/next.svg' %}" class="icon" title="Next page"></a>
|
||||||
|
<a href="{% url 'manufacturer-detail' manufacturer.id %}?item_page={{ items.paginator.num_pages}}#paginator_bottom"><img src="{% static 'inventory/img/last.svg' %}" class="icon" title="Last page"></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -1,13 +1,24 @@
|
||||||
from django.views import View
|
from django.core.paginator import Paginator
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import ListView, DetailView
|
from django.views.generic import ListView, DetailView
|
||||||
|
|
||||||
from inventory.models import Manufacturer
|
from inventory.models import Manufacturer, Item
|
||||||
|
|
||||||
|
|
||||||
class ManufacturerView(View):
|
@method_decorator(login_required, name='dispatch')
|
||||||
pass
|
class ManufacturerView(DetailView):
|
||||||
|
context_object_name = 'manufacturer'
|
||||||
|
queryset = Manufacturer.objects.all().prefetch_related('tags')
|
||||||
|
|
||||||
|
def get_context_data(self, *args, object_list=None, **kwargs):
|
||||||
|
result = super().get_context_data(*args, object_list=object_list, **kwargs)
|
||||||
|
p = self.request.GET.get("item_page", 1)
|
||||||
|
paginator = Paginator(Item.objects.filter(manufacturer=self.get_object()).select_related('container', 'distributor').order_by('name'), 50)
|
||||||
|
result.update({
|
||||||
|
"items": paginator.get_page(p)
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name='dispatch')
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
|
Loading…
Reference in a new issue