[PR #19939] [MERGED] Closes #19924: Record model features on ObjectType #15764

Closed
opened 2025-12-30 00:23:54 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/19939
Author: @jeremystretch
Created: 7/23/2025
Status: Merged
Merged: 7/30/2025
Merged by: @jeremystretch

Base: featureHead: 19924-objecttype-table


📝 Commits (10+)

  • 221ff7e Convert ObjectType to a concrete child model of ContentType
  • aa41b77 Add public flag to ObjectType
  • caeac5f Catch post_migrate signal to update ObjectTypes
  • 666731c Reference ObjectType records instead of registry for feature support
  • 1f24be0 Automatically create ObjectTypes
  • df7b885 Introduce has_feature() utility function
  • 5e7dfc1 ObjectTypeManager should not inherit from ContentTypeManager
  • e739089 Misc cleanup
  • 2506ad8 Don't populate ObjectTypes during migration
  • e647a17 Don't automatically create ObjectTypes when a ContentType is created

📊 Changes

30 files changed (+633 additions, -154 deletions)

View changed files

📝 netbox/core/migrations/0008_contenttype_proxy.py (+2 -2)
netbox/core/migrations/0018_concrete_objecttype.py (+63 -0)
📝 netbox/core/models/__init__.py (+1 -1)
📝 netbox/core/models/change_logging.py (+2 -2)
📝 netbox/core/models/contenttypes.py (+3 -78)
📝 netbox/core/models/jobs.py (+2 -1)
netbox/core/models/object_types.py (+205 -0)
📝 netbox/core/signals.py (+35 -3)
📝 netbox/core/tests/test_models.py (+81 -1)
📝 netbox/dcim/models/cables.py (+3 -2)
📝 netbox/dcim/models/devices.py (+2 -2)
📝 netbox/extras/events.py (+5 -4)
📝 netbox/extras/migrations/0111_rename_content_types.py (+1 -1)
📝 netbox/extras/migrations/0128_tableconfig.py (+3 -1)
netbox/extras/migrations/0131_concrete_objecttype.py (+42 -0)
📝 netbox/extras/models/configs.py (+9 -11)
📝 netbox/extras/models/customfields.py (+2 -2)
📝 netbox/extras/models/models.py (+10 -11)
📝 netbox/extras/models/notifications.py (+3 -3)
📝 netbox/extras/models/tags.py (+1 -1)

...and 10 more files

📄 Description

Closes: #19924

  • Convert existing ForeignKeys pointing to ObjectType to reference ContentType (and alter the migration history accordingly)
  • Rename netbox/models/contenttypes.py to object_types.py
  • Convert ObjectType from a proxy model to a concrete model, inheriting from Django's ContentType
  • Add a public BooleanField indicating whether the corresponding model is considered public
  • Add a features ArrayField storing the names of all features supported by the model
  • Introduce a separate manager for ObjectType, which provides some parity with ContentTypeManager but does not support caching
  • Introduce the has_feature() utility function for determining whether a model supports a specific feature
  • Automatically create/update ObjectTypes post-migration
  • Add tests for the new utility functions and ObjectTypeManager methods

🔄 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/19939 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 7/23/2025 **Status:** ✅ Merged **Merged:** 7/30/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `19924-objecttype-table` --- ### 📝 Commits (10+) - [`221ff7e`](https://github.com/netbox-community/netbox/commit/221ff7e8a7bb99a40941e5e368170bd1925183f0) Convert ObjectType to a concrete child model of ContentType - [`aa41b77`](https://github.com/netbox-community/netbox/commit/aa41b7716bf3364237d2a80b8102794602f96353) Add public flag to ObjectType - [`caeac5f`](https://github.com/netbox-community/netbox/commit/caeac5fdf9cc62489e9e0dce35f8e1d3c8fcd3e4) Catch post_migrate signal to update ObjectTypes - [`666731c`](https://github.com/netbox-community/netbox/commit/666731c223403ee739363a78d6f799f949f655c4) Reference ObjectType records instead of registry for feature support - [`1f24be0`](https://github.com/netbox-community/netbox/commit/1f24be00bd12572255374aa51c23b16d14a75d2f) Automatically create ObjectTypes - [`df7b885`](https://github.com/netbox-community/netbox/commit/df7b885f917ebf1a8fcadda95fbe6936857bb353) Introduce has_feature() utility function - [`5e7dfc1`](https://github.com/netbox-community/netbox/commit/5e7dfc16f7dab0f4e258b07957421dadce3c5636) ObjectTypeManager should not inherit from ContentTypeManager - [`e739089`](https://github.com/netbox-community/netbox/commit/e739089723c63f42895f88ed6ff300c8ff72d75e) Misc cleanup - [`2506ad8`](https://github.com/netbox-community/netbox/commit/2506ad86142f109c31ba49332c0faac9bc29bca1) Don't populate ObjectTypes during migration - [`e647a17`](https://github.com/netbox-community/netbox/commit/e647a17fc97ac35b9b1410d389755ed4b597f3bc) Don't automatically create ObjectTypes when a ContentType is created ### 📊 Changes **30 files changed** (+633 additions, -154 deletions) <details> <summary>View changed files</summary> 📝 `netbox/core/migrations/0008_contenttype_proxy.py` (+2 -2) ➕ `netbox/core/migrations/0018_concrete_objecttype.py` (+63 -0) 📝 `netbox/core/models/__init__.py` (+1 -1) 📝 `netbox/core/models/change_logging.py` (+2 -2) 📝 `netbox/core/models/contenttypes.py` (+3 -78) 📝 `netbox/core/models/jobs.py` (+2 -1) ➕ `netbox/core/models/object_types.py` (+205 -0) 📝 `netbox/core/signals.py` (+35 -3) 📝 `netbox/core/tests/test_models.py` (+81 -1) 📝 `netbox/dcim/models/cables.py` (+3 -2) 📝 `netbox/dcim/models/devices.py` (+2 -2) 📝 `netbox/extras/events.py` (+5 -4) 📝 `netbox/extras/migrations/0111_rename_content_types.py` (+1 -1) 📝 `netbox/extras/migrations/0128_tableconfig.py` (+3 -1) ➕ `netbox/extras/migrations/0131_concrete_objecttype.py` (+42 -0) 📝 `netbox/extras/models/configs.py` (+9 -11) 📝 `netbox/extras/models/customfields.py` (+2 -2) 📝 `netbox/extras/models/models.py` (+10 -11) 📝 `netbox/extras/models/notifications.py` (+3 -3) 📝 `netbox/extras/models/tags.py` (+1 -1) _...and 10 more files_ </details> ### 📄 Description ### Closes: #19924 - Convert existing ForeignKeys pointing to ObjectType to reference ContentType (and alter the migration history accordingly) - Rename `netbox/models/contenttypes.py` to `object_types.py` - Convert ObjectType from a proxy model to a concrete model, inheriting from Django's ContentType - Add a `public` BooleanField indicating whether the corresponding model is considered public - Add a `features` ArrayField storing the names of all features supported by the model - Introduce a separate manager for ObjectType, which provides some parity with ContentTypeManager but does not support caching - Introduce the `has_feature()` utility function for determining whether a model supports a specific feature - Automatically create/update ObjectTypes post-migration - Add tests for the new utility functions and ObjectTypeManager methods --- <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-30 00:23:54 +01:00
adam closed this issue 2025-12-30 00:23:54 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15764