Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not overwrite creating fields if were set explicitly #62

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

st4lk
Copy link

@st4lk st4lk commented Feb 28, 2019

Sometimes, I'd like to specify different user for CreatingUserField field by myself. Such cases are rare, usually I'm ok with populating this field from request.user automatically. But they still happens.

Example:

from audit_log.models.fields import CreatingUserField

class MyModel(models.Model):

    created_by = CreatingUserField(...)

# --------------------

def my_view(request):

    if request.method == 'POST':
        # created_by will be filled from request.user, that is ok
        MyModel.objects.create()
        
        # but here I'd like to change the created_by user.
        # I can't do this because it will be always
        # equal to request.user. Since I've specified the user explicitly - audit_log
        # should assume that I know what I'm doing.
        another_user = User.objects.get(id=123)
        MyModel.objects.create(created_by=another_user)

Solution: fill CreatingUserField automatically only if no value was provided. Otherwise - don't overwrite it.

This PR miss the tests. I'll add them if such behaviour will be approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant