agateblue / agateblue/django-dynamic-preferences

'NoneType' object has no attribute '__name__'

未關閉
#173 12 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
359
分支
86
PR 合併指標
30 天內沒有已合併 PR

描述

I have installed the library, define a preference , but when try to use it in my code, I got this.

```
File "/home/gonzalo/Playground/tektank-ws/tektank/tektank/apps/entities/models.py", line 27, in _validate_dob
oag = global_preferences['general__oldest_allowed_age']
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 29, in __getitem__
return self.get(key)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 133, in get
return self.from_cache(section, name)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 63, in from_cache
self.get_cache_key(section, name), CachedValueNotFound)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 57, in get_cache_key
return 'dynamic_preferences_{0}_{1}_{2}'.format(self.model.__name__, section, name)
AttributeError: 'NoneType' object has no attribute '__name__'

```

This is my code:

```
from dynamic_preferences.registries import global_preferences_registry
global_preferences = global_preferences_registry.manager()

def _validate_dob(value):
oag = global_preferences['general__oldest_allowed_age']
yag = global_preferences['general__youngest_allowed_age']
if not oag <= value <= yag:
raise ValidationError(
_("Date must be between %(oag)s and %(yag)s"),
code='invalid_model_data',
params={'oag':oag.strftime("%x"), 'yag':yag.strftime("%x")},
)

```
I found this issue, but it does not give the solution with code.
https://github.com/EliotBerriot/django-dynamic-preferences/issues/163

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。