本文整理汇总了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;
}
示例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());
}
示例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);
}
示例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;
}
示例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
//.........这里部分代码省略.........