From 02ede72ce9ddeb4d7d7241503585bb07fe3e2c50 Mon Sep 17 00:00:00 2001 From: Kyle McFarland Date: Sat, 20 Oct 2018 21:51:14 -0600 Subject: Allow suppliers to have multiple representatives This adds a basic Representative model and allows for editing them in the admin interface both in the Suppliers admin panel for each supplier and in a new Representatives admin panel which allows bulk editing of all representatives. Currently multiple representatives are just listed in the component view as extra rows below the company row but it would probably make sense to add a view for viewing suppliers directly. The REST API has also been slightly modified to return a list of representatives for each supplier in the components endpoint, adding a suppliers endpoint would probably also be a good idea. Requires running: $ python manage.py migrate procurement 0002_add_representative To update the database for the new model, both forward and lossy reverse data migration is implemented in the migration. --- procurement/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'procurement/views.py') diff --git a/procurement/views.py b/procurement/views.py index 8891f89..1516455 100644 --- a/procurement/views.py +++ b/procurement/views.py @@ -1,7 +1,7 @@ from django.views.generic import FormView, TemplateView from procurement.forms import ComponentSearchForm -from procurement.models import Supplier, Component +from procurement.models import Supplier, Component, Representative class ComponentSearchView(FormView): @@ -20,6 +20,11 @@ class ComponentSearchView(FormView): suppliers_last_updated = '' try: + representatives_last_updated = Representative.objects.latest('updated').time_since_update + except Representative.DoesNotExist: + representatives_last_updated = '' + + try: components_last_updated = Component.objects.latest('updated').time_since_update except Component.DoesNotExist: components_last_updated = '' @@ -32,6 +37,8 @@ class ComponentSearchView(FormView): 'suppliers_last_updated': suppliers_last_updated, 'component_count': Component.objects.all().count(), 'components_last_updated': components_last_updated, + 'representative_count': Representative.objects.all().count(), + 'representatives_last_updated': representatives_last_updated, }) return context -- cgit v1.1