gpt4 book ai didi

django - FieldError 无法在错误的实体上将关键字 'XXXX' 解析到字段中

转载 作者:行者123 更新时间:2023-12-01 22:42:48 24 4
gpt4 key购买 nike

我不明白我的模型出现此错误。我的模型(django 1.5.4):

from django.db.models import Model
from django.db import models
from django.utils.translation import ugettext_lazy as _

class ProductFactory(Model):

name = models.CharField(_(u"Name"), max_length=128)
products = models.ManyToManyField('Product', through='ProductFactoryProduct', related_name='factory')
components = models.ManyToManyField('Product', through='ProductFactoryComponent', related_name='factory')

class ProductFactoryProduct(Model):

factory = models.ForeignKey('ProductFactory')
product = models.ForeignKey('Product')
quantity = models.IntegerField(_(u"Quantity"), default=1)

class ProductFactoryComponent(Model):

factory = models.ForeignKey('ProductFactory')
product = models.ForeignKey('Product')
quantity = models.IntegerField(_(u"Quantity"), default=1)

class Product(Model):
active = models.BooleanField(_(u"Active"), default=True)
barcode = models.CharField(_(u"Barcode"), max_length=32, blank=True, null=True)
[...] # Nothing about factory

当我尝试获取 Factory.products 或 Factory.components 时:

factory = ProductFactory.objects.get(pk=factory_id)
factory.products.all()

抛出此错误:

FieldError at /stock/factory/view/1

Cannot resolve keyword 'factory' into field. Choices are: active, article, barcode, brand, categorys, code, comsumtion_type, id, name, packaging, productreference, provider, providers, purchase_quantity, quantity, quantity_with_ampute, stock_limit, stockmovement, stockmovementproduct, work_unit

注意:事件、文章、条形码[...]字段是产品实体字段。

我不明白为什么 django 尝试在 Product 实体而不是 ProductFactoryProduct 实体上使用 factory 键。我的型号不对?有什么问题吗?

编辑:完整代码:http://pastebin.com/SaMMUjd6

最佳答案

类 ProductFactory(Model) 中: 产品组件 具有相同的 lated_name (lated_name ='工厂')

尝试改变一个。

关于django - FieldError 无法在错误的实体上将关键字 'XXXX' 解析到字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27701646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com