Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140259 Juliana Kofi
9,532 Pointsformset
Creating products one at a time is getting tedious. I want to be able to make multiple at a time. In forms.py, create a model formset factory for the Digital model. Include the same fields as the DigitalProductForm. Name the factory DigitalFormset.
from django import forms
from . import models
class DigitalProductForm(forms.ModelForm):
class Meta:
model = models.Digital
fields = ['name', 'description', 'url']
DigitalFormset = Forms.modelformset_factory(
models.Digital,
form=DigitalForms,
)
fields = ['name', 'description', 'url']
5 Answers
Innocent Ngwaru
7,554 PointsAfter a long struggle I then figured this out:
- your fields should be inside those parentheses;
- remove form = DigitalForm;
you should ahve something like this
DigitalFormset = forms.modelformset_factory( models.Digital, fields = ['name', 'description', 'url'] )
tc11
19,518 PointsHumphrey,
All you have to do is set the variables extra and max_num = 5.
You can do it likes this:
DigitalFormset = forms.modelformset_factory( models.Digital, extra = 5, max_num = 5, fields = ['name', 'description', 'url'] )
MUZ140259 Juliana Kofi
9,532 Pointsthank you Innocent it worked
Humphrey Tinotenda
9,045 Pointsguys am stuck on task 2 of that challlenge
Humphrey Tinotenda
9,045 Pointsplease help
Leroy Saldanha
8,006 PointsDigitalFormset = forms.modelformset_factory( models.Digital, fields = ['name', 'description', 'url'],extra =5,max_num=5 )