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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:10:56+00:00 2026-06-02T18:10:56+00:00

I have the following form: from models import MyModel class MultProgresemosReferenciasForm(forms.Form): selected = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple,

  • 0

I have the following form:

from models import MyModel

class MultProgresemosReferenciasForm(forms.Form):
    selected = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                    queryset=MyModel.objects.filter(active=True))                   

Which I in turn use in the following template:

  <form action="" method="post">                                                                                             
      {% for field in form %}                                                                                                
        {{ field }}
      {% endfor %}                                                                                                           
      {% csrf_token %}                                                                                                       
      <input type="submit" value="Submit Selected" />
  </form>                                                                                                                    

Which renders the following html:

  <form action="" method="post">
    <ul>
<li><label for="id_selected_1"><input type="checkbox" name="selected" value="9" id="id_selected_8" /> prog 1420000930 - pp 0.0078125</label></li>
<li><label for="id_selected_2"><input type="checkbox" name="selected" value="10" id="id_selected_9" /> prog 1420001041 - pp 0.00390625</label></li>
    </ul>
      <div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='csrf_token_hash_string...' /></div>
      <input type="submit" value="Submit Selected" />
  </form>

As you can see, the template gets some label for each checkbox (from the model, which has two string fields with the values you can see there).

The question is, how can I get into this labels for the checkboxes and customize them? I’m trying to use those same model’s names but with some tweaks. Is there an easy way to achieve this in django?

I’ve tried to use field.label but all I get is the ‘Selected’ label for the entire ChoiceField. That’s not what I want, I need to get into the labels for each generated checkbox…

  • 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-02T18:10:59+00:00Added an answer on June 2, 2026 at 6:10 pm

    I think you want to override in your form label_from_instance

    The unicode method of the model will be called to generate string representations of the objects for use in the field’s choices; to provide customized representations, subclass ModelChoiceField and override label_from_instance. This method will receive a model object, and should return a string suitable for representing it. For example:

    def label_from_instance(self, obj):
        #custom logic here...
        return smart_unicode(obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I have the following code (inherited from someone): <div class=feedback>&nbsp;</div> <form onsubmit=return false autocomplete=off>
I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
I have the following form: class ModuleItemForm2(forms.ModelForm): class Meta: model = Module_item fields =
I am using django-registration app. and have following code in forms.py from django.contrib.auth.forms import
In every form we derive from FormBaseControl , we have the following code. I'm
I have the following form for photo_album which uses the nested forms feature of
I'm looking at some Java classes that have the following form: public abstract class

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.