[PR #15152] [MERGED] Closes #15131: Dynamic queryset annotations for REST API endpoints #14532

Closed
opened 2025-12-29 23:25:02 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/15152
Author: @jeremystretch
Created: 2/14/2024
Status: Merged
Merged: 2/15/2024
Merged by: @jeremystretch

Base: featureHead: 15131-api-dynamic-annotations


📝 Commits (8)

  • 0480760 Introduce RelatedObjectCountField
  • afb5f42 Introduce get_annotations_for_serializer() and enable dynamic annotations
  • 701f461 Add RelatedObjectCountFields to serializers; remove static annotations from querysets
  • a71c7e4 Remove annotations cleanup logic from BriefModeMixin
  • 74aa26c Annotate type for RelatedObjectCountField
  • 839a318 Remove redundant field on TagSerializer
  • 06226a3 Add missing reverse relationship for power feeds to rack
  • f6338e2 Refactor RelatedObjectCountField to take a single relationship name

📊 Changes

27 files changed (+204 additions, -221 deletions)

View changed files

📝 netbox/circuits/api/nested_serializers.py (+4 -4)
📝 netbox/circuits/api/serializers.py (+7 -5)
📝 netbox/circuits/api/views.py (+2 -7)
📝 netbox/core/api/serializers.py (+2 -4)
📝 netbox/core/api/views.py (+1 -4)
📝 netbox/dcim/api/nested_serializers.py (+12 -12)
📝 netbox/dcim/api/serializers.py (+37 -21)
📝 netbox/dcim/api/views.py (+10 -42)
📝 netbox/dcim/migrations/0002_squashed.py (+1 -1)
📝 netbox/dcim/models/power.py (+1 -0)
📝 netbox/extras/api/serializers.py (+4 -3)
📝 netbox/extras/api/views.py (+2 -4)
📝 netbox/ipam/api/nested_serializers.py (+6 -5)
📝 netbox/ipam/api/serializers.py (+22 -10)
📝 netbox/ipam/api/views.py (+4 -20)
📝 netbox/netbox/api/fields.py (+15 -1)
📝 netbox/netbox/api/viewsets/__init__.py (+7 -6)
📝 netbox/netbox/api/viewsets/mixins.py (+0 -13)
📝 netbox/tenancy/api/serializers.py (+13 -11)
📝 netbox/tenancy/api/views.py (+1 -17)

...and 7 more files

📄 Description

Closes: #15131

  • Introduce the new RelatedObjectCountField class to represent annotated counts
  • Update all model serializers to use RelatedObjectCountField for related counts instead of IntegerField
  • Introduce get_annotations_for_serializer() utility function for automatically resolving the required annotations for a request
  • Remove static annotations from REST API view querysets
  • Remove obsolete annotations cleanup logic from BriefModeMixin

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/15152 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 2/14/2024 **Status:** ✅ Merged **Merged:** 2/15/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `15131-api-dynamic-annotations` --- ### 📝 Commits (8) - [`0480760`](https://github.com/netbox-community/netbox/commit/0480760ad8c7be1a083f63efd80cc3d85d438362) Introduce RelatedObjectCountField - [`afb5f42`](https://github.com/netbox-community/netbox/commit/afb5f42af33c34d54829821622336298a9d28981) Introduce get_annotations_for_serializer() and enable dynamic annotations - [`701f461`](https://github.com/netbox-community/netbox/commit/701f461225a8a6bd5c1119550b3e820e372daa6c) Add RelatedObjectCountFields to serializers; remove static annotations from querysets - [`a71c7e4`](https://github.com/netbox-community/netbox/commit/a71c7e4677c8905e5e21fae803fd82d3a14a90c5) Remove annotations cleanup logic from BriefModeMixin - [`74aa26c`](https://github.com/netbox-community/netbox/commit/74aa26ca595bf54c7f15044e215c6c52a749a70b) Annotate type for RelatedObjectCountField - [`839a318`](https://github.com/netbox-community/netbox/commit/839a3188998e3807352a0d788bc95e4026f01505) Remove redundant field on TagSerializer - [`06226a3`](https://github.com/netbox-community/netbox/commit/06226a3c60f8b3c6c36b3380b2cf1631afa54516) Add missing reverse relationship for power feeds to rack - [`f6338e2`](https://github.com/netbox-community/netbox/commit/f6338e23ba8e3b5af4cf9634d0b87b6c7af67d42) Refactor RelatedObjectCountField to take a single relationship name ### 📊 Changes **27 files changed** (+204 additions, -221 deletions) <details> <summary>View changed files</summary> 📝 `netbox/circuits/api/nested_serializers.py` (+4 -4) 📝 `netbox/circuits/api/serializers.py` (+7 -5) 📝 `netbox/circuits/api/views.py` (+2 -7) 📝 `netbox/core/api/serializers.py` (+2 -4) 📝 `netbox/core/api/views.py` (+1 -4) 📝 `netbox/dcim/api/nested_serializers.py` (+12 -12) 📝 `netbox/dcim/api/serializers.py` (+37 -21) 📝 `netbox/dcim/api/views.py` (+10 -42) 📝 `netbox/dcim/migrations/0002_squashed.py` (+1 -1) 📝 `netbox/dcim/models/power.py` (+1 -0) 📝 `netbox/extras/api/serializers.py` (+4 -3) 📝 `netbox/extras/api/views.py` (+2 -4) 📝 `netbox/ipam/api/nested_serializers.py` (+6 -5) 📝 `netbox/ipam/api/serializers.py` (+22 -10) 📝 `netbox/ipam/api/views.py` (+4 -20) 📝 `netbox/netbox/api/fields.py` (+15 -1) 📝 `netbox/netbox/api/viewsets/__init__.py` (+7 -6) 📝 `netbox/netbox/api/viewsets/mixins.py` (+0 -13) 📝 `netbox/tenancy/api/serializers.py` (+13 -11) 📝 `netbox/tenancy/api/views.py` (+1 -17) _...and 7 more files_ </details> ### 📄 Description ### Closes: #15131 - Introduce the new `RelatedObjectCountField` class to represent annotated counts - Update all model serializers to use `RelatedObjectCountField` for related counts instead of `IntegerField` - Introduce `get_annotations_for_serializer()` utility function for automatically resolving the required annotations for a request - Remove static annotations from REST API view querysets - Remove obsolete annotations cleanup logic from `BriefModeMixin` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:25:02 +01:00
adam closed this issue 2025-12-29 23:25:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14532