0
我的系統中有3個相關模型。每個用戶都屬於一個特定的地方。用戶可以發送消息,並對消息進行評論,類似於論壇主題。Django管理員說SuspiciousOperation,不允許過濾
這裏有3種型號:
class Place(models.Model):
name = models.CharField(max_length=50, unique=True)
slug = models.SlugField(max_length=50, unique=True)
class Message(models.Model):
creator = models.ForeignKey(User)
title = models.CharField(max_length=40)
content = models.CharField(max_length=3000)
date_created = models.DateTimeField(default=timezone.now)
place = models.ForeignKey(Place)
class Comment(models.Model):
creator = models.ForeignKey(User)
content = models.CharField(max_length=3000)
date_created = models.DateTimeField(default=timezone.now)
message = models.ForeignKey(Message)
我想反映在我的AdminModels這種結構。所以我PlaceAdmin
我寫了這個:
class PlaceAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'list_messages')
def list_messages(self, obj):
url = reverse('admin:user_content_message_changelist')
return '<a href="{0}?place__id__exact={1}">List messages</a>'.format(url, obj.id)
list_messages.allow_tags = True
list_messages.short_description = 'Messages'
這工作完全,每個地方的鏈接,以該地方過濾的郵件列表。所以,我也同樣爲我MessageAdmin
:
class MessageAdmin(admin.ModelAdmin):
list_display = ('title', 'list_comments')
def list_comments(self, obj):
url = reverse('admin:user_content_comment_changelist')
return '<a href="{0}?message__id__exact={1}">List comments</a>'.format(url, obj.id)
list_comments.allow_tags = True
list_comments.short_description = 'Comments'
而且我得到以下錯誤:
SuspiciousOperation at /admin/user_content/comment/
Filtering by message__id__exact not allowed
我不明白爲什麼一個是允許的,另一種是不。有任何想法嗎?我正在使用Django 1.5。