diff options
author | Kyle McFarland <tfkyle@gmail.com> | 2018-10-20 21:51:14 -0600 |
---|---|---|
committer | Kyle McFarland <tfkyle@gmail.com> | 2018-10-20 21:51:14 -0600 |
commit | 02ede72ce9ddeb4d7d7241503585bb07fe3e2c50 (patch) | |
tree | 0c3ce633cd75c9c4756aa4799ff17ca26b8f6b26 /procurement/admin.py | |
parent | bfdc219f139bf9645f29b95bf4cc7824138f87b7 (diff) | |
download | coding-assignment-02ede72ce9ddeb4d7d7241503585bb07fe3e2c50.zip coding-assignment-02ede72ce9ddeb4d7d7241503585bb07fe3e2c50.tar.gz coding-assignment-02ede72ce9ddeb4d7d7241503585bb07fe3e2c50.tar.bz2 |
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.
Diffstat (limited to 'procurement/admin.py')
-rw-r--r-- | procurement/admin.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/procurement/admin.py b/procurement/admin.py index 993b1b5..f35d706 100644 --- a/procurement/admin.py +++ b/procurement/admin.py @@ -2,13 +2,23 @@ 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 +from procurement.models import Supplier, Component, Representative +class RepresentativeAdmin(admin.ModelAdmin): + list_display = ('name', 'email', 'supplier', 'updated') + ordering = ("supplier",) + +class RepresentativeInline(admin.TabularInline): + model = Representative class SupplierAdmin(admin.ModelAdmin): - list_display = ('name', 'representative_name', 'representative_email', 'is_authorized', 'updated') + list_display = ('name', 'get_representatives', 'is_authorized', 'updated') filter_horizonal = ('components',) + inlines = [RepresentativeInline] + def get_representatives(self, obj): + return list(str(x) for x in obj.representatives.all()) + get_representatives.short_description = "Representatives" class ComponentAdmin(admin.ModelAdmin): list_display = ('name', 'sku', 'updated') @@ -27,5 +37,6 @@ class ComponentAdmin(admin.ModelAdmin): }) +admin.site.register(Representative, RepresentativeAdmin) admin.site.register(Supplier, SupplierAdmin) admin.site.register(Component, ComponentAdmin) |