summaryrefslogtreecommitdiff
path: root/procurement/admin.py
diff options
context:
space:
mode:
authorworkmai <iain.workman@lightsource.ca>2018-10-04 12:14:39 -0600
committerworkmai <iain.workman@lightsource.ca>2018-10-04 12:14:39 -0600
commit12d1f9fd979c11b9e3a3a89b1595b07569b88f79 (patch)
treeaf591040768b104f4bb840a21a92968848a0ffe6 /procurement/admin.py
downloadcoding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.zip
coding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.tar.gz
coding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.tar.bz2
Initial commit of the coding assignment base project
Diffstat (limited to 'procurement/admin.py')
-rw-r--r--procurement/admin.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/procurement/admin.py b/procurement/admin.py
new file mode 100644
index 0000000..993b1b5
--- /dev/null
+++ b/procurement/admin.py
@@ -0,0 +1,31 @@
+from django.contrib import admin
+from django.shortcuts import render_to_response, get_object_or_404
+
+from procurement.admin_forms import ComponentAdminForm
+from procurement.models import Supplier, Component
+
+
+class SupplierAdmin(admin.ModelAdmin):
+ list_display = ('name', 'representative_name', 'representative_email', 'is_authorized', 'updated')
+ filter_horizonal = ('components',)
+
+
+class ComponentAdmin(admin.ModelAdmin):
+ list_display = ('name', 'sku', 'updated')
+ form = ComponentAdminForm
+ source_components_template = 'procurement/admin_templates/source_components.html'
+
+ def source_components(self, request, pk):
+ component = get_object_or_404(Component, pk=pk)
+
+ return render_to_response(self.source_components_template, {
+ 'title': 'Source Suppliers for: %s' % component,
+ 'opts': self.model._meta,
+ 'component': component,
+ 'supplier_results': component.suppliers.filter(is_authorized=True),
+
+ })
+
+
+admin.site.register(Supplier, SupplierAdmin)
+admin.site.register(Component, ComponentAdmin)