English 中文(简体)
Django apps.get_models(): 如何从其他夹中装载模型
原标题:Django apps.get_models(): how to load models from other folders

我的结构如下:

enter image description here

所有模型(apps/<some_app_name>/models.py均使用apps.get_models(),但不幸的是,影像上的夹客户/brand/reseller/company也拥有models.py关于其中每一条的文件,这些档案没有装上apps.get_models()。 (以下编码):

import pytest
from django.apps import apps


# Set managed=True for unmanaged models. !! Without this, tests will fail because tables won t be created in test db !!
@pytest.fixture(autouse=True, scope="session")
def __django_test_environment(django_test_environment):
    unmanaged_models = [m for m in apps.get_models() if not m._meta.managed]
    for m in unmanaged_models:
        m._meta.managed = True

谁能解释一下我是如何/什么地方,我是否应当为寻找模型而安排假象/Django?

利用3.9.18和Django 3.2.21

Not sure if it helps on something: these 4 models inherit from Account, and that model inherit from PolymorphicMPTTModel (which allows for some pretty crazy/confusing parent-child relations).

问题回答

Django承认这些儿童模式,如果这些模式在以下表格中进口:http://cp.f/models.py> /index_py__py_py_py_py_。

from .client import *
from .brand import *
from .reseller import *
from .company impot *

...

你们还可以独立地创建包含<条码>模版>。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签