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.
--
Ticket URL: <https://code.djangoproject.com/ticket/20853>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
See #19689 - I believe this attribute is considered a private API and thus
undocumented.
--
Ticket URL: <https://code.djangoproject.com/ticket/20853#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/20853#comment:2>
Comment (by francis@…):
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20853#comment:3>