美文网首页
Django Models 多个属性关联同一个外键

Django Models 多个属性关联同一个外键

作者: 飞走的光年 | 来源:发表于2020-02-27 09:48 被阅读0次

    (错误记录:(fields.E304) Reverse accessor for '' clashes with reverse accessor for ''.)

    ERRORS:
    buy.Orders.buser: (fields.E304) Reverse accessor for ‘Orders.buser’ clashes with reverse accessor for ‘Orders.suser’.
    HINT: Add or change a related_name argument to the definition for ‘Orders.buser’ or ‘Orders.suser’.
    buy.Orders.suser: (fields.E304) Reverse accessor for ‘Orders.suser’ clashes with reverse accessor for ‘Orders.buser’.
    HINT: Add or change a related_name argument to the definition for ‘Orders.suser’ or ‘Orders.buser’.

    两个属性都关联一个外键 应该加一个related_name
    class Orders(models.Model):

    # 两个属性都关联一个外键   应该加一个related_name
    buser = models.ForeignKey(UserInfo, verbose_name='买家',related_name='buser')
    suser = models.ForeignKey(UserInfo, verbose_name='卖家',related_name='suser')
    price = models.DecimalField(verbose_name='价格', max_digits=8, decimal_places=2)
    ordertime = models.DateField(verbose_name='成交时间', auto_now_add=True)
    car = models.OneToOneField(CarInfo, verbose_name='车辆信息')
    # mileage = models.IntegerField(verbose_name='公里数')
    orderStatus = models.IntegerField(verbose_name='订单状态', choices=ORDER_CHOICES, default=0)
    isDelete = models.BooleanField(verbose_name='是否删除', default=False)
    
    def __str__(self):
        return self.buser.username
    
    class Meta:
        verbose_name = '交易记录表'
        verbose_name_plural = verbose_name

    相关文章

      网友评论

          本文标题:Django Models 多个属性关联同一个外键

          本文链接:https://www.haomeiwen.com/subject/hrxthhtx.html