解决 AttributeError: 'ForeignKey' object has no attribute 're'
解决办法
# print('rel...',filter_field_obj.re.to.objects.all())
print("rel...", filter_field_obj.remote_field.model.objects.all())
步骤
按照视频中老师的一步步,然后就报错了。。。。。。郁闷


forekey中存在rel,诶什么不能调用?



publish 1111111111
app01.Book.publish 2222222222
<class 'django.db.models.fields.related.ForeignKey'>
rel... {'name': 'publish', 'verbose_name': 'publish', '_verbose_name': None, 'primary_key': False, 'max_length': None, '_unique': False, 'blank': False, 'null': False,
'remote_field': <ManyToOneRel: app01.book>, 'is_relation': True, 'default': <class 'django.db.models.fields.NOT_PROVIDED'>, 'editable': True,
'serialize': True, 'unique_for_date': None, 'unique_for_month': None, 'unique_for_year': None, 'choices': [], 'help_text': '', 'db_index': True,
'db_column': None, '_db_tablespace': None, 'auto_created': False, 'creation_counter': 69, '_validators': [], '_error_messages': None,
'error_messages': {'invalid_choice': 'Value %(value)r is not a valid choice.', 'null': 'This field cannot be null.', 'blank': 'This field cannot be blank.',
'unique': '%(model_name)s with this %(field_label)s already exists.', 'unique_for_date': '%(field_label)s must be unique for %(date_field_label)s %(lookup_type)s.',
'invalid': '%(model)s instance with %(field)s %(value)r does not exist.'}, 'from_fields': ['self'], 'to_fields': ['nid'], 'swappable': True, 'db_constraint': True,
'attname': 'publish_id', 'column': 'publish_id', 'concrete': True, 'model': <class 'app01.models.Book'>, 'opts': <Options for Book>, 'related_model': <class 'app01.models.Publish'>,
'validators': [], '_related_fields': [(<django.db.models.fields.related.ForeignKey: publish>, <django.db.models.fields.AutoField: nid>)]}


故:
self.remote_field = rel
如何取出对应的数据



大功告成
# print('rel...',filter_field_obj.re.to.objects.all())
print('rel...',filter_field_obj.__dict__)
print('rel...',filter_field_obj.remote_field)
print('rel...',filter_field_obj.remote_field.__dict__)
print("rel...", filter_field_obj.remote_field.model.objects.all())
4
3
解决 AttributeError: 'ForeignKey' object has no attribute 're'的更多相关文章
- 解决AttributeError: 'Ui_MainWindow' object has no attribute 'show'报错
1.首先使用pyqt designer来设计ui界面,将其保存为"***.ui"文件, 然后进入到pyqt所在的文件目录中,执行cmd中命令,即在当前目录中可以生成相应的**.py ...
- AttributeError: 'ForeignKey' object has no attribute 're' 解决办法
使用 field_object.rel.model.objects.filter(**db_condition) 报错 forekey中存在rel,为什么不能调用? 通过以下语句观察 print(fi ...
- 解决AttributeError: 'module' object has no attribute 'main' 安装第三方包报错
1.找到pycharm 目录下的 \helper\packaging_tool.py 文件 2.用新版pycharm 的packaging_tool.py 替换 旧版 同名文件 文件代码如下: imp ...
- AttributeError: 'SQLAlchemy' object has no attribute 'Foreignkey'
在学习<Flask Web开发----基于Python的Web应用开发实战>的过程中,调试程序,如下图,运行报错: AttributeError: 'SQLAlchemy' object ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- 对于AttributeError: 'Flask' object has no attribute 'cli'的解决办法
版权声明:本文为博主原创文章,未经博主允许不得转载. 环境flask-script2.0.5.flask0.10.1 运行官方文档sample 出现问题 c:\kk\flask\examples\fl ...
- 解决window7 x64位Anaconda启动报错:AttributeError: '_NamespacePath' object has no attribute 'sort'
最近论文需要用到python做数据分析,python语法简单,但是Windows下安装第三方包恶心的要命,statsmodels用pip死活安装不上,网上查了说包相互依赖windows下的pip不能下 ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- 解决Win7(x64)Anaconda3报错:AttributeError: '_NamespacePath' object has no attribute 'sort'
最近论文需要用到python做数据分析,python语法简单,但是Windows下安装第三方包恶心的要命,statsmodels用pip死活安装不上,网上查了说包相互依赖windows下的pip不能下 ...
随机推荐
- mysql数据插入前判断是否存在
今天在对一些抓取到的数据做插入的时候,因为使用了定时器,每间隔几分钟会抓取一次,导致很多数据插入的是重复数据,为了解决这个问题, 一般是在插入之前先通过一个标识去查询表数据看是否已经有了,没有再执行插 ...
- Spark框架详解
一.引言 作者:Albert陈凯链接:https://www.jianshu.com/p/f3181afec605來源:简书 Introduction 本文主要讨论 Apache Spark 的设计与 ...
- 百度图片objURL解密vb.net版
Function Baidtu_Uncomplie(k As String) As String Dim c = {"_z2C$q", "_z&e3B" ...
- JavaScript 脚本运行方式
引用外部脚本文件 <script src="/path/to/example.js"></script> 页面内联式 <script> aler ...
- 设计模式之Factory工厂模式的好处
最最直观的好处就是吹牛逼,看着要比普通创建对象要屌 好看 一般情况下,我们创建对象使用的是new. Sample sample=new Sample(); 然而,实际情况会比这样复杂的多,比如说 Sa ...
- 经典面试题:浏览器是怎样解析CSS的?
摘要: 理解浏览器原理. 解析 一旦 CSS 被浏览器下载,CSS 解析器就会被打开来处理它遇到的任何 CSS.这可以是单个文档内的 CSS.<style>标记内的 CSS,也可以是 DO ...
- 前端入门18-JavaScript进阶之作用域链
声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...
- 【Dojo 1.x】笔记6 配置对象dojoConfig的用处和真身所在
dojoConfig是对整个Dojo开发环境的配置,它的位置必须是页面的最前,可以是script标签也可以是独立的js文件. 它允许开发者为Dojo SDK的各个方面设置选项和默认行为. 但是,这个对 ...
- 超级强大的socket工具ss,替代netstat
1.结论:ss 命令比netstat 更强大,提供功能更多,并且性能更高. 2.显示当前系统的socket占用总体宏观情况. ss -s 当已创建的socket数过多时,已经说明系统配置存在问题. 3 ...
- 总结:BGP和静态路由并存,达到故障自动倒换的目的。
总体结论: 在上云的场景中,客户需要本地数据中心到云上VPC,出现网络故障时做到自动倒换,保证业务不中断. 一.客户需求 1.客户有总厂.分厂.总厂是通过专线和VPN连接上云,分厂是通过专线先连接到总 ...