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

131
Views
ADD multiple objects with form

I'm trying to do something which I would think is quite common, but I'm just really unsure how to realise it.

I have modal 'Requirement'. Every requirement has there own name and unique code. I want to show form with REQUIREMENTS_CHOICES list with checkboxs. User can select checkboxes which requirements they need. How to make it in Django?

enter image description here

models.py:

class Requirement(models.Model):
     code = models.UUIDField(_('Code'), primary_key=True, default=uuid.uuid4, editable=False)
     symbol = models.CharField(_('Symbol'), max_length=250)
     name = models.CharField(_('Name'), max_length=250)

forms.py:

class RequirementAddForm(forms.ModelForm):
    name = forms.MultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, choices=REQUIREMENTS_CHOICES,)

    class Meta:
        model = Requirement
        fields = ('symbol',)

 REQUIREMENTS_CHOICES = (
     ('A', 'Name A'),
     ('B', 'Name B'),
     ('C', 'Name C'),
 )

views.py:

def requirement_add(request, project_code):
data = dict()
if request.method == 'POST':
    form = RequirementAddForm(request.POST)
    if form.is_valid():
        symbols = form.cleaned_data.get('symbol') # List of symbols which user selected ['A', 'C']
        for symbol in symbols:
            requirement = form.save(commit=False)
            requirement.symbol = symbol
            requirement.name = symbol.get_symbol_display() #???
            requirement.save()
        data['form_is_valid'] = True
        requirements = Requirement.objects.filter()
        context = {'requirement': requirement, 'requirements': requirements}
        data['html_requirement'] = render_to_string('project/requirement_list.html', context)
    else:
        data['form_is_valid'] = False
else:
    form = GroupRequirementAddForm()
context = {'form': form}
data['html_requirement_form'] = render_to_string('project/requirement_add.html', context, request=request)
return JsonResponse(data)
over 4 years ago · Santiago Trujillo
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!