python - Django shared variable from models -


models.py

class tipo(models.model):    code=  models.textfield()     def thename(self):         myhelp import diz_tipi         return diz_tipi[self.code] 

myhelp.py

def creatediz():         return dict_tipi  diz_tipi=creatediz() 

this works don't think from myhelp import diz_tipi should in place. if add @ start of models.py return:

file "/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready raise appregistrynotready("models aren't loaded yet.")

there other way make diz_tipi available modules?

there strange issue in django faced this, add following top of file:

import django django.setup() 

this in turn should load apps before attempting model access, make sure app contains models file in installed apps file in settings


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -