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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:39:01+00:00 2026-05-10T21:39:01+00:00

I’m working on my first Django application. In short, what it needs to do

  • 0

I’m working on my first Django application. In short, what it needs to do is to display a list of film titles, and allow users to give a rating (out of 10) to each film. I’ve been able to use the {{ form }} and {{ formset }} syntax in a template to produce a form which lets you rate one film at a time, which corresponds to one row in a MySQL table, but how do I produce a form that iterates over all the movie titles in the database and produces a form that lets you rate lots of them at once?

At first, I thought this was what formsets were for, but I can’t see any way to automatically iterate over the contents of a database table to produce items to go in the form, if you see what I mean.

Currently, my views.py has this code:

def survey(request):         ScoreFormSet = formset_factory(ScoreForm)         if request.method == 'POST':                 formset = ScoreFormSet(request.POST, request.FILES)                 if formset.is_valid():                         return HttpResponseRedirect('/')         else:                 formset = ScoreFormSet()         return render_to_response('cf/survey.html', {                 'formset':formset,         }) 

And my survey.html has this:

<form action='/survey/' method='POST'> <table> {{ formset }} </table>   <input type = 'submit' value = 'Submit'> </form> 

Oh, and the definition of ScoreForm and Score from models.py are:

class Score(models.Model):         movie = models.ForeignKey(Movie)         score = models.IntegerField()         user = models.ForeignKey(User)  class ScoreForm(ModelForm):         class Meta:                 model = Score 

So, in case the above is not clear, what I’m aiming to produce is a form which has one row per movie, and each row shows a title, and has a box to allow the user to enter their score.

If anyone can point me at the right sort of approach to this, I’d be most grateful.

  • 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. 2026-05-10T21:39:02+00:00Added an answer on May 10, 2026 at 9:39 pm

    ‘At first, I thought this was what formsets were for, but I can’t see any way to automatically iterate over the contents of a database table to produce items to go in the form, if you see what I mean.’

    You need to get a queryset. And you need to provide that queryset to your form as initial data. See using initial data with a formset for the code.

    initial = [ list of { dictionaries }, one per form ]  

    Interestingly, this is a direct feature of the model API through the values method of a queryset.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
i want to parse a xhtml file and display in UITableView. what is the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker

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.