Opened 4 years ago

Closed 3 years ago

Last modified 11 months ago

#18399 closed New feature (fixed)

Add a `for_concrete_model` kwarg to `ContentTypeManager.get_for_models?`

Reported by: charettes Owned by: charettes
Component: contrib.contenttypes Version: 1.4
Severity: Normal Keywords: contenttypes proxy
Cc: charette.s@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


ContentTypeManager.get_for_models? always return the ContentType of the concrete model.

As highlighted in #17648 and #11154 there is cases that would benefit from the option of retrieving the ContentType of proxy models.

However changing ContentTypeManager.get_for_model? to return the ContentType of proxy models would be backward incompatible.

I suggest adding a for_concrete_model=True kwarg to ContentTypeManager.get_for_models? which defaults to <=1.4 behaviour.

Pull request to come.

Change History (5)

comment:1 Changed 4 years ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Looking at get_for_models implementation there doesn't seems to be way to add this flag while maintaining backward compatiblity since models are passed as *args... We can rely on kwargs but maybe we could change signatures to get models from *args[0] say def get_for_models(self, models, for_concrete_models=True) and raise a deprecation warning if the old signature is used?

Last edited 4 years ago by charettes (previous) (diff)

comment:2 Changed 4 years ago by charettes

  • Cc charette.s@… added
  • Has patch set

Added pull request with tests and docs.

comment:3 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [b6d533af4d03f27ea957baa5fd70f7d0b942ef9a]:

Fixed #18399 – Added a way to get ContentTypes for proxy models

Added kwargs for_concrete_model and for_concrete_models to ContentType
methods get_for_model() and get_for_models(). By setting the flag to
False, it is possible to get the contenttype for proxy models.

comment:4 Changed 11 months ago by thedrow

Does this resolve #11154 in any way?

comment:5 Changed 11 months ago by charettes

This ticket adds a feature required to solve #11154.

Note: See TracTickets for help on using tickets.
Back to Top