我正在製作博客應用程序,並希望在通過管理網站提交新帖子時自動添加當前用戶。有沒有什麼辦法可以檢測當前登錄用戶並將其添加到帖子中?管理員網站自動獲取當前用戶
這些機型:
class Post(models.Model):
user = models.ForeignKey(User)
title = models.CharField('Title', max_length=100)
content = models.TextField('Content')
comments_allowed = models.BooleanField('Allow Comments', default=True)
time = models.DateTimeField('Time', auto_now_add = True)
而在admin.py:
class PostAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['title']}),
(None, {'fields': ['user']}),
(None, {'fields': ['content']}),
(None, {'fields': ['comments_allowed']}),
]
list_display = ('title','user', 'time','comments_allowed','id',)
list_filter = ['time']
search_fields = ['title']
date_hierarchy = 'time'
admin.site.register(Post,PostAdmin)
謝謝...當然會嘗試這一個。 :) – crodjer 2010-08-22 07:00:45