在django admin,我想自动填满观察用户。 在<代码>clean功能期间,填入created_by
field with request.user
。 问题在于,自<代码>created_by以来 表格排除了外地,在<代码>上插入的价值显然被忽视。 我如何能够这样做? 我想根本就不展示植被。
class NoteInline(admin.TabularInline):
model = Note
extra = 1
can_delete = False
def get_formset(self, request, obj=None, **kwargs):
"""
Generate a form with the viewing CSA filled in automatically
"""
class NoteForm(forms.ModelForm):
def clean(self):
self.cleaned_data[ created_by ] = request.user
return self.cleaned_data
class Meta:
exclude = ( created_by , )
model = Note
widgets = { note : forms.TextInput(attrs={ style : "width:80%"})}
return forms.models.inlineformset_factory(UserProfile, Note,
extra=self.extra,
form=NoteForm,
can_delete=self.can_delete)