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: QDjangoMetaModel QDjango::metaModel(const QOb... #38

Closed
wants to merge 3 commits into 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

@jlaine
Copy link
Owner

jlaine commented Aug 12, 2015

Hi, this pull request contains several unrelated changes : can you please simplify?

@ericLemanissier
Copy link
Author

Sorry about that, it was one of my first pull requests on github. Please see #46 instead

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.

2 participants