문제

I have a few apps installed on my Django project. I would like for some of the apps to be able to get information from some of the other apps. Therefore, I am looking to give each of the apps some basic meta information about permissions.

So, if I have three apps: A1, A2, and A3.

I would like to set A1 to be read only. Set A2 to be read/write. Set A3 to not be able to read or write from.

The meta descriptions are mostly for my own sanity. These apps won't be working with apps that I didn't write.

Is there a way to add such meta data at the app level? Perhaps through an unused description field for the Django app?

도움이 되었습니까?

해결책

Don't know why you would ever need this, but normally you place all meta information in __init__.py of the app. Then you can access it from another app:

myapp1/__init__.py:

version = '0.1.0'
permissions = ['read', 'write']

myapp2/utils.py:

from django.conf import settings
import importlib

for app_name in settings.INSTALLED_APPS:
    app = importlib.import_module(app_name)
    if hasattr(app, 'permissions') and 'write' in app.permissions:
        do_something()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top