tastype:模型具有空的属性反向关系

2024-09-30 18:18:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用tastype并试图使ToManyField正常工作时遇到此错误(它不应返回任何null值):

error: "The model 'Feature: Feature object' has an empty attribute 'featureloc_set' and doesn't allow a null value."

以下是模型:

^{pr2}$

这些是资源:

class BFeatureResource(ModelResource):
    featurelocs = fields.ToManyField('api.BFeaturelocResource2', 'featureloc_set', full=True)
    class Meta:
        resource_name = 'bands'
        queryset = Feature.objects.all()

class BFeaturelocResource2(ModelResource):
    feature = fields.ForeignKey(BFeatureResource, 'feature')

    class Meta:
        resource_name = 'featurelocs'
        queryset = Featureloc.objects.all()

Featureloc-to-Feature中有两个ForeingKey字段(即Feature和srcfeature)是否混淆?我错了什么?在


Tags: namefieldsnullresourcemetafeatureclassqueryset
1条回答
网友
1楼 · 发布于 2024-09-30 18:18:05

现在,通过在ForeignKey上使用与ToManyField中的属性相匹配的相关的_名称来执行此操作:

featurelocs = fields.ToManyField('api.BFeaturelocResource2', 'fl_feature', full=True)

以及

^{pr2}$

相关问题 更多 >