Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a non template member QDjango::metaModel #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ericLemanissier
Copy link

Adds a non template member QDjangoMetaModel QDjango::metaModel(const QObject *model)

It avoids the use of template to retrieve an already registered model, and as a consequence allows one to develop a non template function that saves any QObject in database:

bool storageManager::saveItem(QObject *o)
{
    QDjangoMetaModel meta = QDjango::metaModel(o);
    if(!meta.isValid())
    {
        qWarning() << "Metamodel is not available in storageManager::saveItem for" << o->metaObject()->className();
        return false;
    }
    for(const auto &i : meta.foreignFields().keys())
    {
        meta.setForeignKey(o, i, o->property(i).value<QObject*>());
    }
    return meta.save(o);
}

This is especially useful when using QDjango without QDjangoModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant