How can we update a column with request user info at before_import_row stage?
I try to use def get_import_resource_kwargs(self, user, args, *kwargs):
return self.get_resource_kwargs(user, args, *kwargs) in order to use at before_import_row but i cant get any user info at there
Hey @daysleeper1980 !
By "request user info", you mean the admin user info?
What I think you can do, although untested, is pass the request into import_data(dataset, dry_run, raise_errors, use_transactions, collect_failed_rows, request=request). Then it should be accessible in before_import_row as request.user.
Let me know how that goes. And if you can, could you paste all the relevant code here.
hey andrew,
infact i already solved it like the way you said,just it needs to be request.user not request itself
thanks a lot for your response
@daysleeper1980 Hi!
could you pass how you solved it?
Hi,
As i said you can set dataset with the value you want to update like
import_data(dataset, dry_run=False,raise_errors=True)
and after that at:
def before_import_row(self, row,**kwargs):
you can just use kwargs to update
@daysleeper1980 @samirhinojosa
Guys, I am having the same issue.
I was able to retrieve user from kwargs
But then I struggle with the next step.
I've tried something like this: row.fields['created_by'] = user. It does not work.
Can you point out the way of updating the field of the row?
Thank you!
H陌 @templargin ,
let's say you want to update a password of a customer and also change the status,you can use the syntax below
obj = CustomUser()
obj.set_password("1234")
row['password'] = obj.password
row['is_active'] = True
Most helpful comment
hey andrew,
infact i already solved it like the way you said,just it needs to be request.user not request itself
thanks a lot for your response