I meant like this:

views.py:

form = PersonActionsForm()

actions = form.fields['actions']

# set checked_choice to None
checked_choice = None

for choice in actions.choices:

    # if choice.selected (confirm this against request.POST)
        checked_choice = choice


return render_to_response('template.html', {'choice': checked_choice})


in your template.html:

# the data you want shown

# this should contain the selected choice
{{ choice }}


If you run into problems, try simulating this in ipython.
Or you can send dir(checked_choice) into the render_to_response function, instead
just checked_choice, this way you can see what data are you getting.

Also it is a good idea to have some print's in the view for debugging purposes, so you can see
exactly what is going on.


On 07/17/2013 12:29 PM, Sivaram R wrote:
Can you provide me a sample or related url for reference purpose.I don't know how to right custom templatetag for this.

Thanks

On Tuesday, July 16, 2013 11:54:17 AM UTC+5:30, Lukáš Němec wrote:

    You should do something like this (I havent tried it but it should
    work):

    1. you are missing this in forms.py

    class Meta:

        model = Actions

    2. then you can do this in your views:

    form = PersonActionsForm()

    actions = form.fields['actions']

    for choice in actions.choices:

        # do something - check if this was the selected choice from
    db, or from POST data


    And then you return this to your template and create custom html
    tags for this...

    Enjoy


    Dne pondělí, 15. července 2013 16:16:43 UTC+2 Sivaram R napsal(a):

        forms.py

        |PERSON_ACTIONS=  (
             ('1',  '01.Allowed to rest and returned to class'),
             ('2',  '02.Contacted parents /guardians'),
             ('3',  '02a.- Unable to Contact'),
             ('4',  '02b.Unavailable - left message'),)

        class  PersonActionsForm(forms.ModelForm):
            action=  forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),  
choices=PERSON_ACTIONS,  required=False,  label=  u"Actions")|


        models.py

        |class  Actions(models.Model):
             reportperson=  models.ForeignKey(ReportPerson)
             action=   models.IntegerField('Action type')

        template.html

        ||{{  actionform.as_p}}|

        The PersonActionsForm contains the items with multichoice
        checkbox. In report registration page,the user can select any
        one or more item.The checked items are saved in models as
        integer values.

        Since i am rendering the whole form it is showing the entire
        form with checked and unchecked item.

        In print page,i want to show only the checked item alone
        without checkbox.

        How to do this in django.

        Thanks



--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to