#20853 closed Bug (wontfix)
Cannot find documentation on Options.module_name and Options.model_name
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.5 |
Severity: | Normal | Keywords: | documentation |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm using Django 1.5 and looking at the docs here: https://docs.djangoproject.com/en/1.5/ref/models/options/
As per http://stackoverflow.com/questions/725913/dynamic-meta-attributes-for-django-models I'm trying to create a python metaclass to append a string at the end of my model's permissions. However I could not find documentation on Options.module_name (it seems to return the model name). Furthermore I get that 'Options' object has no attribute 'model_name', but I saw this attribute being used in some other code on the internet.
Change History (3)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
As pointed out by @timo the model _meta
option is deliberately undocumented since it's considered an internal API and thus isn't bound to Django's backward compatibility policy.
However as the deprecation of module_name
path taken in #19689 pointed out we're aware this API is (ab)used in the wild and chose to deprecate it as if it was public to prevent breakages in third-party applications.
The reason you're getting this AttributeError
upon _meta.model_name
access is that property was only introduced in Django 1.6. I'm afraid you'll have to access _meta.module_name
and lower case it on Django < 1.6 to get the same result.
comment:3 by , 11 years ago
I know this is an old bug, and what I'm suggesting is probably a very bad idea, but in my case I'm stuck on 1.4.2 for a moment and need to use a module that has been updated to the latest >=1.6 Django versions.
# Monkey Patch from django.db.models.options import Options @property def monkeypatch__options__model_name(self): return self.module_name.lower() Options.model_name = monkeypatch__options__model_name
See #19689 - I believe this attribute is considered a private API and thus undocumented.