我有一个可以附加到其他模型的模型.
class Attachable(models.Model):
content_type = models.ForeignKey(ContentType)
object_pk = models.TextField()
content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk")
class Meta:
abstract = True
class Flag(Attachable):
user = models.ForeignKey(User)
flag = models.SlugField()
timestamp = models.DateTimeField()
Run Code Online (Sandbox Code Playgroud)
我正在另一个模型中创建与此模型的通用关系.
flags = generic.GenericRelation(Flag)
Run Code Online (Sandbox Code Playgroud)
我尝试从这种通用关系中获取对象,如下所示:
self.flags.all()
Run Code Online (Sandbox Code Playgroud)
这导致以下异常:
>>> obj.flags.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 105, in all
return self.get_query_set()
File "/usr/local/lib/python2.6/dist-packages/django/contrib/contenttypes/generic.py", line 252, in get_query_set
return superclass.get_query_set(self).filter(**query)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 498, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 516, in …Run Code Online (Sandbox Code Playgroud) 我很确定我已经包含了qanda类,但是当我尝试声明包含它的向量或类型的类时,我得到一个错误,说qanda未定义.知道问题可能是什么?
bot_manager_item.h
#pragma once
#include "../bot_packet/bot_packet.h"
#include <vector>
class bot_manager_item;
#include "qanda.h"
#include "bot_manager.h"
class bot_manager_item
{
public:
bot_manager_item(bot_manager* mngr, const char* name, const char* work_dir);
~bot_manager_item();
bool startup();
void cleanup();
void on_push_event(bot_exchange_format f);
bool disable;
private:
void apply_changes();
bot_manager *_mngr;
std::string _name;
std::string _work_dir;
std::string _message;
std::string _message_copy;
std::vector<qanda> games;
qanda test;
char _config_full_path[2600];
};
Run Code Online (Sandbox Code Playgroud)
qanda.h
#ifndef Q_AND_A
#define Q_AND_A
#include "users.h"
#include "..\bot_packet\bot_packet.h"
#include "bot_manager.h"
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <fstream>
class qanda
{ …Run Code Online (Sandbox Code Playgroud) 所以我现在正在玩弄我的脑子.我觉得我在python中发现了一个bug,但我确信不可能是这样.有人能说出我错过的东西吗?
class LinkedList():
def __init__(self):
pass
def SortedLinkedList(LinkedList):
pass
new_list = SortedLinkedList()
Run Code Online (Sandbox Code Playgroud)
给
TypeError: SortedLinkedList() takes exactly 1 argument (0 given)
Run Code Online (Sandbox Code Playgroud)
而
new_list = SortedLinkedList("wtf")
Run Code Online (Sandbox Code Playgroud)
工作良好.到底是怎么回事?