zoukankan      html  css  js  c++  java
  • 解决 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

  • 相关阅读:
    jquery插件
    Bash Shell实用快捷键
    Cisco SG300系列交换机划分VLan与普通路由器连接配置
    PostgreSQL用户角色及其属性介绍
    Ubuntu 10.04 32位桌面版+OpnERP 6.1.1
    Postgresql 帐号密码修改方法
    linux查找日志技巧
    Python 黑魔法 --- 描述器(descriptor)
    Nginx如何保留真实IP和获取前端IP
    Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
  • 原文地址:https://www.cnblogs.com/venicid/p/9523354.html
Copyright © 2011-2022 走看看