嵌套序列化程序出错

时间:2013-08-16 04:52:34

标签: django-rest-framework

我有以下型号和序列化器:

class SeminarTracking(models.Model):
    id = models.BigIntegerField(primary_key=True)
    id_tax_seminar = models.BigIntegerField(null=True, blank=True)
    cid = models.ForeignKey('clients.Client')
    invite = models.IntegerField(null=True, blank=True)
    invite_2 = models.IntegerField(null=True, blank=True)
    rsvp = models.CharField(max_length=255L, blank=True)
    attendees = models.IntegerField(null=True, blank=True)
    names = models.CharField(max_length=255L, blank=True)
    notes = models.TextField(blank=True)

    class Meta:
        db_table = 'tax_seminars_tracking'

class SeminarTrackingSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = SeminarTracking

客户端序列化:

class ClientSerializer(serializers.HyperlinkedModelSerializer):
    #adwebsite = serializers.PrimaryKeyRelatedField()
    #adissue = serializers.PrimaryKeyRelatedField(required=False)
    #category = serializers.PrimaryKeyRelatedField(many=True)
    status = serializers.Field()
    seminars = SeminarTrackingSerializer(source='seminartracking_set')

    class Meta:
        model = Client

每当我通过API访问客户端时,都会收到以下错误:

(1054, "Unknown column 'tax_seminars_tracking.cid_id' in 'field list'")

如果我在视图或模板中访问seminartracking_set,则无效。有什么我想念的吗? - 请注意,客户端模型的主键是clientid,而不是id - 不确定是否相关。

非常感谢,Ben

1 个答案:

答案 0 :(得分:1)

我必须在“cid”字段上指定列名。