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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:38:59+00:00 2026-06-04T10:38:59+00:00

I am trying to change a form’s instance before I save it. I need

  • 0

I am trying to change a form’s instance before I save it. I need to set certain information within the view like this:

 class UploadedFile(models.Model):

     file = models.FileField(storage=s3store, upload_to=custom_upload_to)
     slug = models.SlugField(max_length=50, blank=True)
     bucket = models.ForeignKey(S3Bucket, blank=False)
     uploaded_by = models.ForeignKey(User, related_name='uploaded_by', blank=False)
     company = models.ForeignKey(Company, blank=False)

—

class UploadForm(ModelForm):

    class Meta:
        model = UploadedFile    

—

form = UploadForm(request.POST, request.FILES)
form.instance.company_id = r_user.company.id
form.instance.uploaded_by_id = r_user.id
form.instance.bucket_id = r_user.company.s3_bucket_id
if form.is_valid():
     form_object = form.save()

Now, I get that the form is not valid because company/uploaded/bucket are empty:

Errors Form:

  • company
  • This field is required.
  • bucket
  • This field is required.
  • uploaded_by
  • This field is required.
  • But I did set them! Do I need to make them blank=True, then do a save(commit=false), change them, and then resave? If yes, why is so? I did change the form ….

    • 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-06-04T10:39:01+00:00Added an answer on June 4, 2026 at 10:39 am

      The assignments are late. In the __init__() of ModelForm, or in your code: the form = UploadForm(request.POST, request.FILES) line, an instance has been created and populated to initial of the form. Later modification upon the instance will not affect the value of form.initial.

      Also, if you want to fill in some fields automatically in backend, don’t render them to user.

      Thus, yes, you could make them blank=True or exclude them from the form then follow the suggested way.

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

    Sidebar

    Related Questions

    I'm trying to use form's CheckboxSelectMultiple widget but I I'd like to change the
    I'm trying to change a panel to a specific form (as this is the
    Trying to change input type attribute from password to text . $('.form').find('input:password').attr({type:text}); Why this
    This should be a layup for someone... I'm trying to change a form field's
    I'm trying to change a Form's opacity automatically before loading. I am using built
    I'm trying to change the border style of my form using Windows Forms. The
    I'm trying to figure out how to change the standard rails scaffolding form so
    Trying to get a thread to change form controls in Windows Mobile. Throws an
    I am trying to set up a form using Formtastic which has a drop
    I am trying to change page on a form submit in Jquery, however, it

    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.