我試圖使用通用的關係,我的模型是這樣的:無法解析關鍵字「CONTENT_TYPE」到現場
class Post(models.Model):
# Identifiers
user = models.ForeignKey(User, unique=False, related_name = 'posts')
# Resource
resource_type = models.ForeignKey(ContentType)
resource_id = models.PositiveIntegerField()
resource = GenericForeignKey('resource_type', 'resource_id')
# Other
date_created = models.DateTimeField(auto_now=False, auto_now_add=True, blank=True)
class Meta:
unique_together = ('resource_type', 'resource_id',)
但是,當我的資源我試圖讓Post對象,使用'SomeResource.posts
'發生以下異常:
無法將關鍵字'content_type'解析爲字段。選項包括: DATE_CREATED,ID,資源,RESOURCE_ID,RESOURCE_TYPE, resource_type_id,用戶邀請,USER_ID
爲什麼找content_type
當我明確地將其命名爲resource_type
我GenericForeignKey
?
我想改變他們的可讀性和一致性,因爲我覺得默認的命名是有點笨重。 –
這裏[鏈接](http://stackoverflow.com/questions/18239030/django-generic-relations-error-cannot-resolve-keyword-content-object-into-fi)你可能有一個答案,如果你的問題是過濾對象...對不起,我忍不住要更多 –
沒有抱歉,我的問題是沒有過濾。這是檢索通用對象。 –