Added crud for suppliers

This commit is contained in:
Harry Bridge
2019-01-08 00:21:58 +00:00
parent 51aec6f597
commit f24a510a8e
7 changed files with 97 additions and 2 deletions

View File

@@ -7,3 +7,9 @@ class AssetForm(forms.ModelForm):
class Meta:
model = models.Asset
fields = '__all__'
class SupplierForm(forms.ModelForm):
class Meta:
model = models.Supplier
fields = '__all__'

View File

@@ -1,6 +1,4 @@
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
@@ -27,6 +25,9 @@ class AssetStatus(models.Model):
class Supplier(models.Model):
name = models.CharField(max_length=80)
def get_absolute_url(self):
return reverse('supplier_list')
def __str__(self):
return self.name

View File

@@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% block title %}Detail{% endblock %}
{% block main %}
{{ object }}
{% endblock %}

View File

@@ -0,0 +1,29 @@
{% extends 'base.html' %}
{% block title %}List{% endblock %}
{% block main %}
<h4>Supplier List</h4>
<table class="striped">
<thead>
<tr>
<th>Supplier</th>
<th>Quick Links</th>
</tr>
</thead>
<tbody id="asset_table_body">
{% for item in object_list %}
<tr>
<td>{{ item.name }}</td>
<td>
<a href="{% url 'supplier_update' item.pk %}"><i class="material-icons">edit</i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'helpers/paginator.html' %}
{% endblock %}

View File

@@ -0,0 +1,24 @@
{% extends 'base.html' %}
{% block title %}Edit{% endblock %}
{% block main %}
<h4>
Supplier
{% if object %}
Edit | {{ object.name }}
{% else %}
Create
{% endif %}
</h4>
<div class="divider"></div>
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Save" class="btn">
</form>
{% endblock %}

View File

@@ -16,6 +16,11 @@ urlpatterns = [
path('asset/filter/', views.asset_filter, name='ajax_asset_filter'),
path('asset/update/', views.asset_update, name='ajax_asset_update'),
path('supplier/list', views.SupplierList.as_view(), name='supplier_list'),
path('supplier/<int:pk>', views.SupplierDetail.as_view(), name='supplier_detail'),
path('supplier/create', views.SupplierCreate.as_view(), name='supplier_create'),
path('supplier/<int:pk>/edit', views.SupplierUpdate.as_view(), name='supplier_update'),
path('', include(router.urls)),
]

View File

@@ -131,3 +131,27 @@ def asset_filter(request):
return render(request, template_name='asset_update_search_results.html', context=context)
else:
return render(request, template_name='asset_list_table_body.html', context=context)
class SupplierList(generic.ListView):
model = models.Supplier
template_name = 'supplier_list.html'
paginate_by = 40
ordering = ['name']
class SupplierDetail(generic.DetailView):
model = models.Supplier
template_name = 'supplier_detail.html'
class SupplierCreate(generic.CreateView):
model = models.Supplier
form_class = forms.SupplierForm
template_name = 'supplier_update.html'
class SupplierUpdate(generic.UpdateView):
model = models.Supplier
form_class = forms.SupplierForm
template_name = 'supplier_update.html'