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 6029529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:54:00+00:00 2026-05-23T04:54:00+00:00

I have a custom form… I’d like to auto save the author (authenticated user)

  • 0

I have a custom form… I’d like to auto save the author (authenticated user) for the form data. I’m using ModelForm for creating the form.

models.py

    class Tracker(models.Model):
        client = models.ForeignKey(Clients)
        user = models.ForeignKey(User)
        description = models.TextField()
...

I have also linked the custom profile to the django users table… also the auth works fine… I can read the user and id…

forms.py

class TrackerForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(TrackerForm, self).__init__(*args, **kwargs)
        self.fields.keyOrder = ['date_job_start','date_job_end','description','onsite','billable','client']
    class Meta:
        model = Tracker
        widgets = {
            'client': HiddenInput(),
        }

When the form is created from the upper class and I try to save it… it wants the user data (missing warning). How can I change it so that it would automatically save the authenticated user instead of asking for it?? I know that I dont’ have the user field defined here… that’s because I don’t want a dropdown for it… I want the user to be saved from the auth…without any selection or display…

P.S.: I know about the initial option… there must be a better way?

Thanks!
BR

  • 1 1 Answer
  • 1 View
  • 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-23T04:54:01+00:00Added an answer on May 23, 2026 at 4:54 am
    class TrackerForm(ModelForm):
        def __init__(self, *args, **kwargs):
            self.user = kwargs.pop('user')
            super(TrackerForm, self).__init__(*args, **kwargs)
            self.fields.keyOrder = ['date_job_start','date_job_end','description','onsite','billable','client']
    
        class Meta:
            model = Tracker
            widgets = {
            '    client': HiddenInput(),
            }
            exclude = ('user',)
    
        def save(self):
            obj = super(TrackerForm, self).save(commit=False)
            obj.user = self.user
            obj.save()
            return obj
    

    And in view:

    form = TrackerForm(user=request.user) #and other parameters
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom user registration form at: somepath/register using hook form alter. I
I have a list within Sharepoint, using a custom new form I have added
I am using jquery validation plugin for form validation. I have added a custom
I have a few custom form validation rules I wish to apply. Things like
I'm using custom widget in my crud form like this: {{=form.custom.begin}} {{if condition:}} {{=form.custom.widget.field1}}
I have a custom data entry form which is bound to a ViewModel (VM).
I have created a Custom Edit Form for a custom list using SharePoint designer.
I have a custom form to which I would like to pass a parameter.
hii, I am using devexpress xtrascheduler.In this i have created one custom form which
I am using django-friends and django-messages. I have modified my custom compose form to

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.