Skip to content

Commit

Permalink
Add new building objects from the BuildingInline (#344)
Browse files Browse the repository at this point in the history
* come on i know this works

* Hack to get the nn

* Add existing buildings to node through new Inline

* Make collapsible and clean up name
  • Loading branch information
WillNilges authored Apr 26, 2024
1 parent d2a23bd commit d9cef77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/meshapi/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/meshapi/templates/admin/install_tabular.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
</tbody>
</table>
</fieldset>
<!--TODO: Add collapsible menu to add existing buildings...?-->
<div>
{% if inline_admin_formset.opts.add_button %}
<a href="{{ request.scheme }}://{{ request.get_host }}{% url 'admin:meshapi_building_add' %}?primary_node={{ inline_admin_formset.opts.network_number }}" class="addlink">Add</a>
{% endif %}
</div>
</div>
</div>

0 comments on commit d9cef77

Please sign in to comment.