python - Django request.user being inconsistent -
i have relatively override of save_model method so:
def save_model(self, request, obj, form, change): if not change: obj.created_by = request.user obj.last_modified_by = request.user else: obj.last_modified_by = request.user obj.save() when creating new record (not change), populates obj.created_by string of username, obj.last_modified_by string of user id. can fix using request.user.username instead of request.user, it's odd me inconsistently:

carl's user id 1.
in case you're wondering how created_by , last_modified_by designed in model, merely charfield's (not foreignkey's):
created_by = models.charfield(blank=false, max_length=100, editable=false) last_modified_by = models.charfield(blank=false, max_length=100, editable=false) why inconsistent?
you said yourself.
in case you're wondering how created_by , last_modified_by designed in model, merely charfield's (not foreignkey's):
but request.user actual user instance (not charfield). setting fields wrong thing.
you want obj.created_by = request.user.username.
Comments
Post a Comment