Skip to content

Conversation

@adionit7
Copy link
Contributor

Summary

This PR adds support for real model names (e.g., dcim.Site) in DEFAULT_DASHBOARD, CUSTOM_VALIDATORS, and PROTECTION_RULES configuration parameters, matching the syntax used by FIELD_CHOICES.

Changes:

  • Add normalize_model_identifier() utility function to convert real model names to lowercase format used by ObjectType
  • Update get_models_from_content_types() in dashboard widgets to normalize model identifiers
  • Update CUSTOM_VALIDATORS and PROTECTION_RULES lookups to check both real model names and lowercase names
  • Update documentation with real model name examples and backward compatibility notes

Backward Compatibility

Both formats are supported:

  • Real model names: dcim.Site, ipam.IPAddress
  • Lowercase names: dcim.site, ipam.ipaddress (existing behavior preserved)

Fixes #21209

… configuration

Enable DEFAULT_DASHBOARD, CUSTOM_VALIDATORS, and PROTECTION_RULES to accept
both lowercase (e.g. "dcim.site") and PascalCase (e.g. "dcim.Site") model
names, providing consistency with FIELD_CHOICES.

- Update get_models_from_content_types() to normalize model identifiers
- Add _get_validators_for_model() helper for case-insensitive config lookup
@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 8c77bf2 to 273750c Compare January 23, 2026 12:25
@pheus
Copy link
Contributor

pheus commented Jan 23, 2026

Thanks a lot for working on this! 🙌

While reviewing the feature request, I noticed the scope is a bit broader than what’s currently covered in this PR. The request is to allow ContentType/ObjectType strings (e.g. dcim.Device) to be case-insensitive across all relevant configuration parameters. The FR author specifically called out three areas:

  • PROTECTION_RULES
  • DEFAULT_DASHBOARD
  • FIELD_CHOICES

From what I can see, this PR currently addresses only the PROTECTION_RULES and the DEFAULT_DASHBOARD case.

Would you mind taking another pass to review the other config paths as well, and extend the PR to include any additional configuration options where these model strings are accepted?

@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 1a3a76f to 03912fc Compare January 23, 2026 13:41
@adionit7
Copy link
Contributor Author

adionit7 commented Jan 23, 2026

Thanks a lot for working on this! 🙌

While reviewing the feature request, I noticed the scope is a bit broader than what’s currently covered in this PR. The request is to allow ContentType/ObjectType strings (e.g. dcim.Device) to be case-insensitive across all relevant configuration parameters. The FR author specifically called out three areas:

  • PROTECTION_RULES
  • DEFAULT_DASHBOARD
  • FIELD_CHOICES

From what I can see, this PR currently addresses only the PROTECTION_RULES and the DEFAULT_DASHBOARD case.

Would you mind taking another pass to review the other config paths as well, and extend the PR to include any additional configuration options where these model strings are accepted?

Thanks for the review @pheus! Really appreciate it! 🙌
You're right.. we initially missed FIELD_CHOICES. I've added case-insensitive support for it in utilities/choices.py using the same pattern.

The PR now covers all three areas mentioned in the FR:

  • DEFAULT_DASHBOARD — accepts both dcim.site and dcim.Site
  • PROTECTION_RULES — case-insensitive lookup via helper function
  • FIELD_CHOICES — case-insensitive lookup for both dcim.Site.status and dcim.site.status (and the + extension variant)

As a bonus, I also updated CUSTOM_VALIDATORS to use the same case-insensitive pattern for consistency.

All changes follow the same approach: try an exact match first (O(1)), then fall back to a case-insensitive search if needed. This maintains backward compatibility while allowing users to use either format.

The PR is ready for another review.

@pheus pheus requested review from a team and jnovinger and removed request for a team January 23, 2026 16:57
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.

Use real model names in dashboard widget and other configurations

2 participants