Skip to content

Commit

Permalink
Change lookups to new related name in Netbox model
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Mar 2, 2023
1 parent 1038664 commit 17ef4e0
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion python/nav/models/msgmaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_event_subjects(self):
subjects = []
for component in self.get_components():
if isinstance(component, (manage.Room, manage.NetboxGroup)):
subjects.extend(component.netbox_set.all())
subjects.extend(component.netboxes.all())
elif isinstance(component, manage.Location):
for location in component.get_descendants(include_self=True):
subjects.extend(
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/ajax/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def netbox_down_in(room):
"""
Returns True if a netbox is down on the room, otherwise False
"""
return len(room.netbox_set.filter(up='n'))
return len(room.netboxes.filter(up='n'))


def get_neighbors(_request, netboxid):
Expand Down
4 changes: 2 additions & 2 deletions python/nav/web/info/netboxgroup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def group_detail(request, groupid):
"""
group = get_object_or_404(NetboxGroup, pk=groupid)
netboxes = group.netbox_set.select_related('organization', 'category', 'type')
netboxes = group.netboxes.select_related('organization', 'category', 'type')
availabilities = {}
graphite_error = False

Expand Down Expand Up @@ -137,7 +137,7 @@ def group_edit(request, groupid):
return handle_edit_request(request, group)

netboxes = Netbox.objects.exclude(
pk__in=group.netbox_set.all().values_list('id', flat=True)
pk__in=group.netboxes.all().values_list('id', flat=True)
)

return render(
Expand Down
8 changes: 4 additions & 4 deletions python/nav/web/info/room/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def process_searchform(form):

def filter_netboxes(room):
"""Filter netboxes based on interesting categories"""
return room.netbox_set.filter(category__in=CATEGORIES)
return room.netboxes.filter(category__in=CATEGORIES)


def roominfo(request, roomid):
Expand All @@ -143,7 +143,7 @@ def get_room_meta(room):
"""Find meta data for the room"""
room_interfaces = Interface.objects.filter(netbox__room=room)
return {
'devices': room.netbox_set.count(),
'devices': room.netboxes.count(),
'interfaces': room_interfaces.count(),
'interfaces_with_link': room_interfaces.filter(
ifoperstatus=Interface.OPER_UP
Expand All @@ -155,7 +155,7 @@ def get_room_meta(room):
def render_deviceinfo(request, roomid):
"""Controller for rendering device info"""
room = get_object_or_404(Room, id=roomid)
all_netboxes = room.netbox_set.select_related(
all_netboxes = room.netboxes.select_related(
"type", "category", "organization"
).order_by("sysname")
availabilities = {}
Expand Down Expand Up @@ -254,7 +254,7 @@ def create_csv(request):
def render_sensors(request, roomid):
"""Gets the environment devices for a room"""
room = get_object_or_404(Room, pk=roomid)
netboxes = room.netbox_set.filter(category='ENV')
netboxes = room.netboxes.filter(category='ENV')

for netbox in netboxes:
netbox.env_sensors = netbox.sensor_set.filter(
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/info/searchproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,5 @@ def fetch_results(self):
SearchResult(g.get_absolute_url(), g)
for g in NetboxGroup.objects.filter(id__icontains=self.query)
.order_by('id')
.annotate(num_netboxes=Count('netbox'))
.annotate(num_netboxes=Count('netboxes'))
]
2 changes: 1 addition & 1 deletion python/nav/web/navlets/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_context_data_view(self, context):
return context

pdus = (
room.netbox_set.filter(category='POWER')
room.netboxes.filter(category='POWER')
.filter(sensor__internal_name__startswith='rPDULoadStatusLoad')
.prefetch_related('sensor_set')
.distinct()
Expand Down
6 changes: 3 additions & 3 deletions python/nav/web/seeddb/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def __init__(self, *args, **kwargs):
# netboxes field with netboxes from the many to many relationship
if 'instance' in kwargs and kwargs['instance'] is not None:
initial = kwargs.setdefault('initial', {})
initial['netboxes'] = [n.pk for n in kwargs['instance'].netbox_set.all()]
initial['netboxes'] = [n.pk for n in kwargs['instance'].netboxes.all()]
forms.ModelForm.__init__(self, *args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
Expand All @@ -362,15 +362,15 @@ def to_choice_format(objects, key, value):

def get_netboxes_in_group(group):
if group:
return group.netbox_set.all()
return group.netboxes.all()
else:
return Netbox.objects.none()


def get_netboxes_not_in_group(group):
if group:
return Netbox.objects.exclude(
pk__in=group.netbox_set.all().values_list('id', flat=True)
pk__in=group.netboxes.all().values_list('id', flat=True)
)
else:
return Netbox.objects.all()
4 changes: 2 additions & 2 deletions python/nav/web/seeddb/page/management_profile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def management_profile_list(request):
info = ManagementProfileInfo()
value_list = ('name', 'description', 'get_protocol_display', 'related')
netbox_link = reverse('seeddb-netbox')
queryset = ManagementProfile.objects.annotate(related=Count('netbox'))
queryset = ManagementProfile.objects.annotate(related=Count('netboxes'))
filter_form = ManagementProfileFilterForm(request.GET)
return render_list(
request,
Expand Down Expand Up @@ -134,7 +134,7 @@ def management_profile_edit(request, management_profile_id=None):
"""
try:
profile = ManagementProfile.objects.get(id=management_profile_id)
num_netboxes = profile.netbox_set.distinct().count()
num_netboxes = profile.netboxes.distinct().count()
except ManagementProfile.DoesNotExist:
profile = None
num_netboxes = 0
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/templates/info/netboxgroup/group_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4>Edit devices in {{ netboxgroup.pk }}</h4>
<div class="column medium-6">
<label for="in_group">Devices in group</label>
<select id="in_group" multiple="multiple" name="netboxes" class="multiple-select multiple-select-initial">
{% for netbox in netboxgroup.netbox_set.all %}
{% for netbox in netboxgroup.netboxes.all %}
<option value="{{ netbox.pk }}">{{ netbox.sysname }}</option>
{% endfor %}
</select>
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/templates/info/netboxgroup/list_groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3>Device Group search</h3>
<td>{{ netboxgroup.description }}</td>
<td>
<ul class="netboxgroup inside">
{% with netboxgroup.netbox_set.all as netboxes %}
{% with netboxgroup.netboxes.all as netboxes %}
{% if netboxes %}
{% for netbox in netboxes %}
<li>
Expand Down

0 comments on commit 17ef4e0

Please sign in to comment.