3
如何从登录用户信息预填充管理员字段?从登录用户预填充管理员字段用户
我有model.py:
from django.db import models
class News(models.Model):
title = models.CharField(max_length=65)
body = models.TextField()
author = models.CharField(max_length=55)
,我有admin.py:
from django.contrib import admin
from django.contrib.auth.models import User
from newsite.news.models import News
class NewsAdmin(admin.ModelAdmin):
list_display = ('title','author')
search_fields = ['title', 'author']
prepopulated_fields = {'author': (?????)}
admin.site.register(News, NewsAdmin)
我一直在努力试图找出如何让当前登录用户成prepopulated_field作者。
任何提示将不胜感激。谢谢。
注意,他/她是从请求对象拉低数据。 (obj.poster = request.user)请求对象恰好在每次请求时都会首先生成。 – 2010-10-21 11:44:58
非常感谢小费。还有一个问题: – Kevin 2010-10-21 12:25:45
你有form = BugForm。那么你是否忽略了管理员的默认表单?你有没有可以作为例子分享的forms.py?谢谢。 – Kevin 2010-10-21 12:26:50