В дополнение к вероятному броску чего-то произошел из станд.:: исключение необходимо бросить анонимные временные файлы и выгоду ссылкой:
void Foo::Bar(){
if(!QueryPerformanceTimer(&m_baz)){
throw std::string("it's the end of the world!");
}
}
void Foo:Caller(){
try{
this->Bar();// should throw
}catch(std::string& caught){ // not quite sure the syntax is ok here...
std::cout<<"Got "<
.
Видят "Эффективный C++ Meyer's - 3-й выпуск" для деталей или посещают https://www.securecoding.cert.org/.../ERR02-A. + Throw+anonymous+temporaries+and+catch+by+reference
Я предпочитаю хранить свои модели в models.py и менеджеры в manager.py (формы в forms.py) в одном приложении. Что касается более общих менеджеров, я предпочитаю хранить их в core.managers, если их можно повторно использовать для других приложений. В некоторых наших более крупных приложениях с models / modelname.py, которые будут содержать менеджер и код модели, который не кажется плохим.
Your best bet with a large set of models is to use django modules to your advantage, and simply create a folder named models. Move your old models.py into this models folder, and rename it __init__.py
. This will allow you to then separate each model into more specific files inside of this model folder.
You would then only need to import each model into your __init__.py
's namespace.
So, for instance, you might want to separate it into:
yourapp/
models/
__init__.py # This file should import anything from your other files in this directory
basic.py # Just an example name
morespecificmodels.py # Just an example name
managers.py # Might want to separate your manager into this
Then your __init__.py
can just be:
from basic import * # You should replace * with each models name, most likely.
from managers import YourManager # Whatever your manager is called.
This is the structure that I use when my model files get huge, however I try to separate things into more pluggable apps as often as possible - so this is rarely used by me.
Hope this helps.
I always place mine in managers.py. If you have a circular import issue remember that a) You can reference the model class for a manager at self.model, and b) You can do imports inside of functions.
При создании приложений Django я для создания файла [название модели] .py только с конкретным кодом модели, кодом менеджера, а иногда и кодом формы, и использовал файл __init__.py для импорта, а затем все в каталоге моделей. Это помогло мне, по крайней мере, сохранить управляемость.