在基于类的视图中使用时,是否可以从给定model的所有字段中获取所有字段,而无需编写view.py文件中所有字段的列表UpdateView?
class UserProfileEditView(UpdateView):
model = UserProfile
fields = ['first_name', 'last_name', 'email', 'level', 'course', 'country', 'title', 'avatar', 'icon', 'instagram']
slug_field = 'username'
template_name = 'profile.html'
context_object_name = 'User'
Run Code Online (Sandbox Code Playgroud)
我的意思是不是将所有字段写入列表(例如“first_name”、“last_name”...等),我可以使用某些东西从给定模型中获取所有字段。