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

  • Home
  • SEARCH
  • 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 8804361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:35:01+00:00 2026-06-14T01:35:01+00:00

Building a form to let users submit posts as well as an image. My

  • 0

Building a form to let users submit posts as well as an image. My model has a text field, image, publish date, and author field. Publish Date and Author auto save without any user input. It works on the admin side with admin.py. However, when displaying this through a view, it is not working. Why?

#models.py
    class Question(models.Model):
    text            = models.CharField(max_length = 500)
    image           = models.ImageField(upload_to = 'movie_poster')
    pub_date        = models.DateTimeField(auto_now_add = True)
    author          = models.ForeignKey(User)

    def __unicode__(self):
        return self.title

    class QuestionForm(ModelForm):
        class Meta:
             model = Question
             exclude = ('author', 'pub_date')
#views.py
def add_question(request):
     def save_model(self, request, obj, form, change):
        obj.author = request.user
        obj.save()
     if request.method == "POST":
        form = QuestionForm(request.POST, request.FILES)   
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/home/")
    else:
        form = QuestionForm
        return render_to_response("qanda/add_question.html", {'form': form}, context_instance = RequestContext(request))

#add_question.html
{% block content %}

<div class="loginform">
    <h1> Add Movie:</h1>
    <form enctype = "multipart/form-data" action = "" method = "post">{% csrf_token %}
        {{ form.as_p }}
        <input type = "submit" value = "Add" />
        <input type = "hidden" name = "next" value = "{{ next|escape }}" />
    </form>
{% endblock %}
  • 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-14T01:35:05+00:00Added an answer on June 14, 2026 at 1:35 am

    save_model is not magic that works everywhere just by being there. We’ll need to customize the form:

    class QuestionForm(ModelForm):
        def save(self, user=None, force_insert=False, force_update=False, commit=True):
            q = super(QuestionForm, self).save(commit=False)
            q.author = user
            if commit:
                q.save()
            return q
    
        class Meta:
            model = Question
            exclude = ('author', 'pub_date')
    
    def add_question(request):
        if request.method == "POST":
            form = QuestionForm(request.POST, request.FILES)
            if form.is_valid():
                form.save(user=request.user)
                return HttpResponseRedirect("/home/")
        else:
            form = QuestionForm()
            return render_to_response("qanda/add_question.html", {'form': form}, context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a form in Zend Framework 1.9 using subforms as well as
I am building a web application that will let users follow discussion threads, in
Scenario: I'm building an order-form. Like every other order-form on the planet, it has
I'm building a form in Drupal that needs to submit to a 3rd party
I am currently building a multiple pages form using $_SESSION , everything has been
So, I'm building a form that my users can customize based on their needs,
I am building a form, where required field validation must have been checked. I
Thank you for reading my question. I am building a form that will let
Let's say you're building something simple, like a data entry/CRUD form for working on
I'm building a form that let the user enter database connection parameters. Once the

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.