我正在尝试使导入导出选择当前/保存用户(定义为模型中的“作者”字段)
我试过这个(save_model)但它不起作用(我认为是因为资源类)
class KWResource(resources.ModelResource):
class Meta:
model = KW
import_id_fields = ('Keyword',)
fields = ('Keyword',)
searchess = fields.Field(attribute='searches', column_name="Avg. Monthly Searches (exact match only)")
compp = fields.Field(attribute='comp', column_name="Competition")
cpcc = fields.Field(attribute='cpc', column_name="Suggested bid")
def save_model(self, request, obj, form, change):
if getattr(obj, 'author', None) is None:
obj.author = request.user
obj.save()
如何获取在此处启动导入的管理员用户的 ID?