mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Added crud for suppliers
This commit is contained in:
6
forms.py
6
forms.py
@@ -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__'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
6
templates/supplier_detail.html
Normal file
6
templates/supplier_detail.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Detail{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{{ object }}
|
||||
{% endblock %}
|
||||
29
templates/supplier_list.html
Normal file
29
templates/supplier_list.html
Normal 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 %}
|
||||
24
templates/supplier_update.html
Normal file
24
templates/supplier_update.html
Normal 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 %}
|
||||
5
urls.py
5
urls.py
@@ -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)),
|
||||
]
|
||||
|
||||
|
||||
24
views.py
24
views.py
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user