Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin for node and compute sensors #33

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions manifests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ class NodeAdmin(nested_admin.NestedModelAdmin):
actions = ["autopopulate_from_beekeeper_and_data", "export_as_json"]

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.prefetch_related("modem", "tags", "computes")
return (
super()
.get_queryset(request)
.prefetch_related(
"modem",
"tags",
"computes",
)
)

@admin.display(description="Tags")
def get_tags(self, obj):
Expand Down Expand Up @@ -436,8 +443,7 @@ class SensorHardwareAdmin(admin.ModelAdmin):
search_fields = ["hardware", "hw_model", "manufacturer"]

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.prefetch_related("capabilities")
return super().get_queryset(request).prefetch_related("capabilities")

@admin.display(description="Camera?", boolean=True)
def is_camera(self, obj):
Expand Down Expand Up @@ -506,3 +512,47 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
capabilities__capability="camera",
)
return super().formfield_for_foreignkey(db_field, request, **kwargs)


@admin.register(NodeSensor)
class NodeSensorAdmin(admin.ModelAdmin):
list_display = [
"name",
"hardware",
"node",
]
search_fields = [
"name",
"hardware__hardware",
"hardware__hw_model",
"node__vsn",
]
# We're excluding scope because it seems to be intended to always be set to "default".
exclude = ["scope"]

def get_queryset(self, request):
return super().get_queryset(request).prefetch_related("hardware", "node")


@admin.register(ComputeSensor)
class ComputeSensorAdmin(admin.ModelAdmin):
list_display = [
"name",
"hardware",
"scope",
"node",
]
search_fields = [
"name",
"hardware__hardware",
"hardware__hw_model",
"scope__name",
"scope__node__vsn",
]
# We're exclude scope as currently the scope selectbox just lists the compute name (ex. rpi) but not the vsn,
# so using it properly is confusing. For now, it's just a convinient way to see all compute sensors and update
# things like name and serial number.
exclude = ["scope"]

def get_queryset(self, request):
return super().get_queryset(request).prefetch_related("scope", "scope__node")
3 changes: 3 additions & 0 deletions manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class NodeSensor(AbstractSensor):
class ComputeSensor(AbstractSensor):
scope = models.ForeignKey(Compute, on_delete=models.CASCADE, blank=True)

def node(self):
return self.scope.node


class Resource(models.Model):
node = models.ForeignKey(NodeData, on_delete=models.CASCADE, blank=True)
Expand Down
Loading