我有一个带有通用外键的简单模型:
class Generic(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
Run Code Online (Sandbox Code Playgroud)
我想过滤此表中具有非null content_object的所有条目,即过滤掉Generic其内容对象不再存在的所有实例:
Generic.objects.filter(~Q(content_object=None))
Run Code Online (Sandbox Code Playgroud)
这不起作用,给出例外:
django.core.exceptions.FieldError:字段'content_object'不生成自动反向关系,因此不能用于反向查询.如果是GenericForeignKey,请考虑添加GenericRelation.
添加GenericRelation到引用的内容类型模型没有区别.
如何实现这一点的任何帮助将不胜感激,非常感谢.
编辑:我意识到我可以级联删除,但在我的情况下这不是一个选项(我希望保留数据).
python django django-queryset django-generic-views django-contenttypes
升级到geckodriver后,我无法重用Selenium的会话。这是我的设置:
我有一个start_browser.py脚本,它将启动Firefox实例并打印要连接的端口,例如:
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
browser = webdriver.Firefox(capabilities=firefox_capabilities)
print browser.service.port
wait_forever()
Run Code Online (Sandbox Code Playgroud)
...和另一个脚本,该脚本尝试通过远程驱动程序连接到现有实例:
caps = DesiredCapabilities.FIREFOX
caps['marionette'] = True
driver = webdriver.Remote(
command_executor='http://localhost:{port}'.format(port=port),
desired_capabilities=caps)
Run Code Online (Sandbox Code Playgroud)
但是它似乎正在尝试启动新的会话,但失败并显示一条消息:
selenium.common.exceptions.WebDriverException: Message: Session is already started
Run Code Online (Sandbox Code Playgroud)
是否可以像以前的Selenium版本那样仅附加到现有会话?还是这是壁虎驱动程序的预期行为(不是希望的)?