diff --git a/src/meshapi/admin.py b/src/meshapi/admin.py index af490a0a..1299c7f2 100644 --- a/src/meshapi/admin.py +++ b/src/meshapi/admin.py @@ -46,13 +46,28 @@ class NonrelatedBuildingInline(BetterNonrelatedInline): fields = ["primary_node", "bin", "street_address", "city", "zip_code"] readonly_fields = fields + add_button = True + + # Hack to get the NN + network_number = None + def get_form_queryset(self, obj): + self.network_number = obj.pk return self.model.objects.filter(nodes=obj) def save_new_instance(self, parent, instance): pass +class BuildingMembershipInline(admin.TabularInline): + model = Building.nodes.through + extra = 0 + autocomplete_fields = ["building_id"] + classes = ["collapse"] + verbose_name = "Building" + verbose_name_plural = "Edit Related Buildings" + + # This controls the list of installs reverse FK'd to Buildings and Members class InstallInline(BetterInline): model = Install @@ -500,7 +515,14 @@ class NodeAdmin(admin.ModelAdmin): }, ), ] - inlines = [InstallInline, NonrelatedBuildingInline, DeviceInline, SectorInline, NodeLinkInline] + inlines = [ + InstallInline, + NonrelatedBuildingInline, + BuildingMembershipInline, + DeviceInline, + SectorInline, + NodeLinkInline, + ] def address(self, obj): return obj.buildings.first() diff --git a/src/meshapi/templates/admin/install_tabular.html b/src/meshapi/templates/admin/install_tabular.html index b912d942..ecb7fec5 100644 --- a/src/meshapi/templates/admin/install_tabular.html +++ b/src/meshapi/templates/admin/install_tabular.html @@ -70,5 +70,11 @@

{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}

+ +
+ {% if inline_admin_formset.opts.add_button %} + Add + {% endif %} +