当前位置: 首页>>代码示例>>C++>>正文


C++ QDjangoQuerySet::get方法代码示例

本文整理汇总了C++中QDjangoQuerySet::get方法的典型用法代码示例。如果您正苦于以下问题:C++ QDjangoQuerySet::get方法的具体用法?C++ QDjangoQuerySet::get怎么用?C++ QDjangoQuerySet::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDjangoQuerySet的用法示例。


在下文中一共展示了QDjangoQuerySet::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: selectRelated

/** Test eager loading of foreign keys.
 */
void tst_QDjangoModel::selectRelated()
{
    // load fixtures
    {
        Item *item1 = new Item;
        item1->setName("first");
        QCOMPARE(item1->save(), true);

        Item *item2 = new Item;
        item2->setName("second");
        QCOMPARE(item2->save(), true);

        Owner owner;
        owner.setName("owner");
        owner.setItem1(item1);
        owner.setItem2(item2);
        QCOMPARE(owner.save(), true);
    }

    // without eager loading
    QDjangoQuerySet<Owner> qs;
    Owner *owner = qs.get(QDjangoWhere("name", QDjangoWhere::Equals, "owner"));
    QVERIFY(owner != 0);
    QCOMPARE(owner->item1()->name(), QLatin1String("first"));
    QCOMPARE(owner->item2()->name(), QLatin1String("second"));
    delete owner;

    // with eager loading
    owner = qs.selectRelated().get(QDjangoWhere("name", QDjangoWhere::Equals, "owner"));
    QVERIFY(owner != 0);
    QCOMPARE(owner->item1()->name(), QLatin1String("first"));
    QCOMPARE(owner->item2()->name(), QLatin1String("second"));
    delete owner;
}
开发者ID:explicitcall,项目名称:qdjango,代码行数:36,代码来源:main.cpp

示例2: test_ModelAPIs_schedule

void TestModels::test_ModelAPIs_schedule()
{
    const QDjangoQuerySet<Schedule> schedule_set;
    Schedule* schedule = schedule_set.get(QDjangoWhere("id", QDjangoWhere::Equals, 2));

    Schedule* schedule2 = ModelAPIs::Instance()->schedule(2);
    QCOMPARE(schedule->start(), schedule2->start());
}
开发者ID:ptmono,项目名称:eManual-gui,代码行数:8,代码来源:test_models.cpp

示例3: test_ModelAPIs_unit

void TestModels::test_ModelAPIs_unit()
{
    // // get an existing user
    // other = users.get(QDjangoWhere("username", QDjangoWhere::Equals, "foouser"));
    // QVERIFY(other != 0);
    // QCOMPARE(other->username(), QLatin1String("foouser"));
    // QCOMPARE(other->password(), QLatin1String("foopass"));

    const QDjangoQuerySet<Unit> units_set;
    Unit* unit = units_set.get(QDjangoWhere("name", QDjangoWhere::Equals, "second"));

    //qDebug() << unit->name();
    Unit* unit2;
    unit2 = ModelAPIs::unit("second");

    QCOMPARE(unit->name(), unit2->name());

    // There is no element.
    Unit* unit3;
    unit3 = ModelAPIs::unit("no_exist");
    QVERIFY(unit3 == 0);
}
开发者ID:ptmono,项目名称:eManual-gui,代码行数:22,代码来源:test_models.cpp

示例4: handleStanza

bool XmppServerPrivate::handleStanza(const QDomElement &element)
{
    const QString to = element.attribute("to");
    if (QXmppUtils::jidToDomain(to) != server()->domain())
        return false;

    if (element.tagName() == "iq" && PrivateStorageIq::isPrivateStorageIq(element))
    {
        PrivateStorageIq request;
        request.parse(element);

        if (request.type() == QXmppIq::Result)
            return true;

        // check the namespace is valid
        const QString xmlns = request.payload().attribute("xmlns");
        if (xmlns.isEmpty()) {
            QXmppIq response;
            response.setId(request.id());
            response.setTo(request.from());
            response.setType(QXmppIq::Error);
            server()->sendPacket(response);
            return true;
        }

        const QString bareFrom = QXmppUtils::jidToBareJid(request.from());
        QDjangoQuerySet<PrivateStorage> qs;
        qs = qs.filter(QDjangoWhere("jid", QDjangoWhere::Equals, bareFrom));

        if (request.type() == QXmppIq::Get) {
            PrivateStorageIq response;
            response.setId(request.id());
            response.setTo(request.from());
            response.setType(QXmppIq::Result);
 
            PrivateStorage storage;
            if (qs.get(QDjangoWhere("xmlns", QDjangoWhere::Equals, xmlns), &storage)) {
                QDomDocument doc;
                doc.setContent(storage.data());
                response.setPayload(doc.documentElement());
            } else {
                response.setPayload(request.payload());
            }
            server()->sendPacket(response);

        } else if (request.type() == QXmppIq::Set) {
            PrivateStorage storage;
            if (!qs.get(QDjangoWhere("xmlns", QDjangoWhere::Equals, xmlns), &storage)) {
                storage.setJid(bareFrom);
                storage.setXmlns(xmlns);
            }
            storage.setXml(request.payload());
            storage.save();

            // reply
            QXmppIq response;
            response.setId(request.id());
            response.setTo(request.from());
            response.setType(QXmppIq::Result);
            server()->sendPacket(response);
        }
        return true;
    }
    return false;
}
开发者ID:jlaine,项目名称:xmpp-share-server,代码行数:65,代码来源:mod_private.cpp

示例5: dummy_db

/** 
 * Dummy database for testing. If you want to edit a data, you also edit
 * test_models.cpp TestModels::test_common.
 *
 */
void dummy_db()
{
    // initially created in initdb()
    // Unit count;
    // count.setName("count");
    // QCOMPARE(count.save(), true);
    
    Unit second;
    second.setName("second");
    QCOMPARE(second.save(), true);

    const QDjangoQuerySet<Unit> units;
    Unit* f_second = units.get(QDjangoWhere("name", QDjangoWhere::Equals, "second"));
    
    Element pushup;
    pushup.setName("pushup");
    pushup.setPurpose(1000);
    pushup.setNote("It is pushup note.");
    pushup.setShortcut("push");
    pushup.setUnit(f_second);
    QCOMPARE(pushup.save(), true);

    Element* running = new Element;
    running->setName("running");
    running->setPurpose(300);
    running->setNote("It is running note.");
    QCOMPARE(running->save(), true);

    Element breathing;
    breathing.setName("breathing");
    breathing.setPurpose(70000);
    QCOMPARE(breathing.save(), true);

    Group daily_group;
    daily_group.setName("daily");
    daily_group.setNote("It is daily.");
    QCOMPARE(daily_group.save(), true);

    Group monthly_group;
    monthly_group.setName("monthly");
    monthly_group.setNote("It is monthly");
    QCOMPARE(monthly_group.save(), true);

    const QDjangoQuerySet<Element> elements;
    Element* f_pushup = elements.get(QDjangoWhere("name", QDjangoWhere::Equals, "pushup"));
    Element* f_running = elements.get(QDjangoWhere("name", QDjangoWhere::Equals, "running"));
    
    const QDjangoQuerySet<Group> groups;
    Group* f_daily_group = groups.get(QDjangoWhere("name", QDjangoWhere::Equals, "daily"));


    // It requires free store. It requires more code.
    ElementGroup daily;
    daily.setElement(f_pushup);
    daily.setGroup(f_daily_group);
    QCOMPARE(daily.save(), true);


    QDateTime current = QDateTime::currentDateTime();
    int year = current.date().year();
    int month = current.date().month();
    int day = current.date().day();

    QDate ddate = QDate(year, month, current.date().addDays(1).day());
    QTime dtime = QTime(10, 5, 59);
    QDateTime start = QDateTime(ddate, dtime);
    QDateTime end = QDateTime(QDate(year, month, current.date().addDays(3).day()), QTime(15, 6, 5));

    Schedule today;		// start: today + 1, end: today + 3
    today.setStart(start);
    today.setEnd(end);
    today.setElement(f_pushup);
    QCOMPARE(today.save(), true);

    QDate ddate2 = QDate(year, month, day);
    QDateTime start2 = QDateTime(ddate2);
    Schedule today2;		// start: today0
    today2.setStart(start2);
    today2.setEnd(start2);
    today2.setGroup(f_daily_group);
    QCOMPARE(today2.save(), true);

    Schedule today3;		// start: today0, end: today0 + 1
    today3.setStart(start2);
    today3.setEnd(start2.addDays(1));
    today3.setElement(f_pushup);
    QCOMPARE(today3.save(), true);

    Schedule today4;		// start: today, end: today + 3
    today4.setStart(current);
    today4.setEnd(current.addDays(3));
    today4.setElement(f_pushup);
    QCOMPARE(today4.save(), true);

    Schedule today5;		// start: today0 + 1, end: today0 + 2
//.........这里部分代码省略.........
开发者ID:ptmono,项目名称:eManual-gui,代码行数:101,代码来源:common.cpp


注:本文中的QDjangoQuerySet::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。