Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How to initialize Django ModelForms on an entire queryset?

I am building an ad manager software, and I want to use django's ModelForm system to load an entire queryset of Ad objects so that users can alter fields in an already running/existing ad.

I want to do this preferably in an alternative way to the modelformset_factory method.

For example, if a user has a single Ad model you could simply call that instance and load the instance into a modelForm instance called AdForm so that they can edit the ad's properties:

ad_instance = Ad.objects.get(pk=1)
ad_form = AdForm(instance=ad_instance)

So what about if the user has 20 active ads running? How can a queryset of 20 ad instances be loaded into their respective AdForms?

Thanks

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can Change the queryset

AdFormSet = modelformset_factory(Ad, fields=('name', 'title'))
formset = AdFormSet(queryset=request.user.ad_set.all())
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!