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/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'procurement/serializers.py') diff --git a/procurement/serializers.py b/procurement/serializers.py index 1840837..0466402 100644 --- a/procurement/serializers.py +++ b/procurement/serializers.py @@ -1,8 +1,14 @@ from rest_framework import serializers -from procurement.models import Component, Supplier +from procurement.models import Component, Supplier, Representative +class RepresentativeSerializer(serializers.ModelSerializer): + class Meta: + model = Representative + exclude = ('created', 'updated', 'supplier', 'id') class SupplierSerializer(serializers.ModelSerializer): + representatives = RepresentativeSerializer(many=True, read_only=True) + class Meta: model = Supplier exclude = ('created', 'updated') -- cgit v1.1