我只是逐字地关注其中一个Django教程,但遇到x.id
或.pk
的查询根本没有返回任何值的问题。这是在该表中的所有行,尽管所有其他数据都在工作。下面的例子来自我的python shell。
>>> c = Album(artist="Stone Roses", album_title="The Stone Roses", genre="Indie", album_logo="http://www.classicrockreview.com/Images/1989/AlbumCovers/1989_StoneRos es.jpg")
>>> c
<Album: Album object>
>>> c.id
>>> c.artist
'Stone Roses'
>>> c.pk
>>>
我被引导相信Django会自动处理id
?
答案 0 :(得分:7)
您的
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myApp">
<xs:complexType>
<xs:sequence>
<xs:element name="inputData" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence >
<xs:element type="xs:string" name="dataType"/>
<xs:element type="xs:boolean" name="mandatory"/>
<xs:element type="xs:short" name="length"/>
<xs:element type="xs:string" name="elementId"/>
<xs:element type="xs:string" name="formId"/>
<xs:element type="xs:anySimpleType" name="value" />
<xs:element type="xs:boolean" name="valid"/>
<xs:element type="xs:short" name="precision"/>
<xs:element type="xs:short" name="scale"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
对象当前未保存到数据库,因此它还没有
var generated_Module_Factory = function () {
var generated = {
name: 'generated',
typeInfos: [{
localName: 'MyApp',
typeName: null,
propertyInfos: [{
name: 'inputData',
minOccurs: 0,
collection: true,
elementName: {
localPart: 'inputData'
},
typeInfo: '.MyApp.InputData'
}]
}, {
localName: 'MyApp.InputData',
typeName: null,
propertyInfos: [{
name: 'dataType',
required: true,
elementName: {
localPart: 'dataType'
}
}, {
name: 'mandatory',
required: true,
elementName: {
localPart: 'mandatory'
},
typeInfo: 'Boolean'
}, {
name: 'length',
required: true,
elementName: {
localPart: 'length'
},
typeInfo: 'Short'
}, {
name: 'elementId',
required: true,
elementName: {
localPart: 'elementId'
}
}, {
name: 'formId',
required: true,
elementName: {
localPart: 'formId'
}
}, {
name: 'value',
required: true,
elementName: {
localPart: 'value'
},
typeInfo: 'AnySimpleType'
}, {
name: 'valid',
required: true,
elementName: {
localPart: 'valid'
},
typeInfo: 'Boolean'
}, {
name: 'precision',
required: true,
elementName: {
localPart: 'precision'
},
typeInfo: 'Short'
}, {
name: 'scale',
required: true,
elementName: {
localPart: 'scale'
},
typeInfo: 'Short'
}]
}],
elementInfos: [{
typeInfo: '.MyApp',
elementName: {
localPart: 'myApp'
}
}]
};
return {
generated: generated
};
};
if (typeof define === 'function' && define.amd) {
define([], generated_Module_Factory);
}
else {
var generated_Module = generated_Module_Factory();
if (typeof module !== 'undefined' && module.exports) {
module.exports.generated = generated_Module.generated;
}
else {
var generated = generated_Module.generated;
}
}
。您需要拨打Album
才能执行此操作:
id
有关详细说明,请参阅Django model instance reference docs。