Django

Code

Ticket #5793 (closed: wontfix)

Opened 2 years ago

Last modified 1 year ago

Allow custom attributes in Meta classes

Reported by: eikke@eikke.com Assigned to: nobody
Milestone: Component: Metasystem
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In some cass it is useful to be able to store meta information on models inside the model class. In Django the Meta subclass is used to achieve this. Trying to add a custom attribute to a model's Meta inner class results in an exception though, thrown from django.db.models.options, which does indeed check any valid attribute names and raises an exception when unknown names are found. Is there any reason for this somewhat strange behaviour, not to allow a developer to add non-standard meta information to a model class (which can later on be used in eg view code)?

Thanks!

Attachments

Change History

01/10/08 01:45:58 changed by ubernostrum

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to wontfix.
  • needs_tests changed.
  • needs_docs changed.

I'm going to call this a wontfix; Meta exists to set up a lot of "internal use" APIs, and the validation has to be strict to ensure that potential errors in that process are caught (e.g., if your Meta contains an attribute order, how can the validator tell whether you meant to add your own custom info or actually wanted ordering?).

And given that Django models are simply Python classes, and you're free to set up any attributes on them you like and then make use of them, I'm not sure that the use case of adding custom information in Meta is compelling enough.


Add/Change #5793 (Allow custom attributes in Meta classes)




Change Properties
Action