Skip to content

Conversation

DanSheps
Copy link
Member

@DanSheps DanSheps commented Mar 7, 2024

Fixes: #7 - Allow devices in Child Locations

  • Alter queryset to allow devices in child locations to be added

@DanSheps
Copy link
Member Author

DanSheps commented Mar 7, 2024

@natm Can't assign reviewers for some reason. If you could give this a look see that would be great.

@dionrowney
Copy link

dionrowney commented Mar 14, 2024

Can someone review and approve this so I can start testing this in my dev environment? Is this something I can do?

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Tested this and it works as expected.

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I see all devices and racks rather than just racks in the current location and sub locations. It solves the problem but I was not expecting to see ALL objects.

Copy link

@dionrowney dionrowney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon closer investigation it seems to be a UI error that causes the list to display everything. I would say the initial list displayed is correct and I will submit a bug for this new error once this change is in the main branch

@earendilfr
Copy link

earendilfr commented Mar 24, 2025

The patch working well with rack.
Concerning devices, I think the best way is the following :

class FloorplanDeviceListView(generic.ObjectListView):
    queryset = Device.objects.all()
    table = tables.FloorplanDeviceTable

    def get(self, request):
        fp_id = request.GET["floorplan_id"]
        fp_instance = models.Floorplan.objects.get(pk=fp_id)
        if fp_instance.record_type == "site":
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                site=fp_instance.site.id).order_by("name")
        else:
            fp_locations = Location.objects.get(pk=fp_instance.location.id).get_descendants(include_self=True)
            fp_racks = Rack.objects.all().filter(location__in=fp_locations)
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                location__in=fp_locations).exclude(rack__in=fp_racks).order_by("name")
        return super().get(request)

The idea is to exclude the devices that are already racked in a rack inside this location

@jonzey0
Copy link

jonzey0 commented Jul 30, 2025

The patch working well with rack. Concerning devices, I think the best way is the following :

class FloorplanDeviceListView(generic.ObjectListView):
    queryset = Device.objects.all()
    table = tables.FloorplanDeviceTable

    def get(self, request):
        fp_id = request.GET["floorplan_id"]
        fp_instance = models.Floorplan.objects.get(pk=fp_id)
        if fp_instance.record_type == "site":
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                site=fp_instance.site.id).order_by("name")
        else:
            fp_locations = Location.objects.get(pk=fp_instance.location.id).get_descendants(include_self=True)
            fp_racks = Rack.objects.all().filter(location__in=fp_locations)
            self.queryset = Device.objects.all().filter(~Q(id__in=fp_instance.mapped_devices)).filter(
                location__in=fp_locations).exclude(rack__in=fp_racks).order_by("name")
        return super().get(request)

The idea is to exclude the devices that are already racked in a rack inside this location

I've given this a test and it works quite well. I've just manipulated the views.py script to change the function for Devices to this and it worked for me as expected.

@DanSheps DanSheps requested a review from cruse1977 as a code owner August 1, 2025 04:38
@DanSheps DanSheps marked this pull request as draft August 1, 2025 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow devices from child locations to be included in drawing

4 participants