Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:14:53+00:00 2026-05-20T18:14:53+00:00

My form: class AssessmentForm(ModelForm): def save(self, commit=True, request=None, *args, **kwargs): print ‘request.user.id:’,request.user.id instance =

  • 0

My form:

class AssessmentForm(ModelForm):

    def save(self, commit=True, request=None, *args, **kwargs):

        print 'request.user.id:',request.user.id

        instance = super(AssessmentForm, self).save(commit=False)
        if commit:
            instance.save(request=request)
        if request:
            instance.modifier = request.user
            instance.save(request=request)
        return instance

    class Meta:
        model = Assessment

My Model Class

class Assessment(models.Model):
    name = models.CharField(max_length=255, verbose_name="Title")
    review_state = models.CharField(max_length=20,
                                    choices=REVIEW_STATE_CHOICES)
    iteration = models.IntegerField(choices=ITERATION_CHOICES)
    assessment_note = models.TextField(verbose_name="Notes",
                                       blank=True,
                                       null=True)
    .... snip ....
    modifier = models.ForeignKey(User,
                    editable=False,
                    related_name="%(app_label)s_%(class)s_modifier_related")
    modified = models.DateField(editable=False)


    def save(self, request=None, *args, **kwargs):
        if request:
            user = request.user
        else:
            user = User.objects.get(pk=1)
        self.modifier = user
        self.modified = datetime.now()

        if not self.id:
            self.creator = user
            self.created = datetime.now()
        super(Assessment, self).save(*args, **kwargs)

When I save the form, in the database the modified field has id 1 and not id 5 which is the id of the current user in the user table. So, the save method on the model isn’t getting the request but the request is making it to the Form save method which I’ve tested…. the output of the print statement in the Form save method is:

request.user.id: 5

Updated *

In class AssessmentForm(ModelForm) I’ve also tried:

def save(self, commit=True, request=None, *args, **kwargs):
    print 'request.user.id:',request.user.id
    instance = super(AssessmentForm, self).save(commit=False)
    if commit:
        instance.save(request=request)
    return instance

Updated 2 **
I just put some print statements in the model save method and I found that there are 3 calls to it. The 1st and 2nd call to it contain the request but the 3rd call does not. So the 1st 2 times the correct user id is saved but the 3rd call wipes it out again. I understand why there are 2 calls to it but why is there a 3rd call?

What am I doing wrong here?

Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:14:54+00:00Added an answer on May 20, 2026 at 6:14 pm

    you’re not passing the request object to instance.save()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following form: class PlayForwardPageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PlayForwardPageForm, self).__init__(*args, **kwargs)
I have this form class : class MyForm(forms.Form): def __init__(self, *args, **kwargs): self.notvalidate =
I have a form: class MatchForm(forms.Form): base_field = forms.CharField(widget=forms.Select) def __init__(self ,*args, **kwargs): BASE_FIELDS
I have form: class Form(forms.ModelForm): id = forms.ModelChoiceField(queryset=Category.objects.all(), widget=forms.HiddenInput()) def choices(self): items = ...query
I Have this Form class MyModelForm(forms.ModelForm): boolfield = forms.TypedChoiceField(coerce=bool, choices=((False, 'No'), (True, 'Yes')), widget=forms.RadioSelect
I have a simple Django Form: class testForm(forms.Form): list = forms.CharField() def getItems(self): #How
I have the following form: class FeaturedVideoForm(ModelForm): featured_video = forms.ModelChoiceField(Video.objects.none() widget=make_select_default, required=False, empty_label='No Featured
I have the following form: class ModuleItemForm2(forms.ModelForm): class Meta: model = Module_item fields =
I have a form class that looks like this: class ApplicationDetailsForm(ModelForm): worked_in_industry = forms.TypedChoiceField(coerce=int,
I have a simple Django form: class CommentForm(forms.Form): comment = forms.CharField(max_length=2000, required=True) post_id =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.