lundi 16 novembre 2015

Django: how to use the checkbox in the admin

I try to display the values of checkbox in my view but It's not working..

forms.py

class JoursForm(forms.ModelForm):

class Meta:
    model = Event

JOURS = ( 
(1, 'L'),
(2, 'M'),
(3, 'M'),
(4, 'J'),
(5, 'V'),)

jours = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                                     choices=JOURS, label= u"répéter les :")

def clean_my_field(self):
    return self.cleaned_data['jours']

admin.py

class EventAdmin(admin.ModelAdmin):

form = JoursForm
save_on_top = True
save_as = True
list_per_page = 25
list_display = ('title', 'start', 'end',  'user', 'fin', 'frequency')


fieldsets = (
    (None, {
        'fields': ('title','start', 'end', 'is_cancelled', 'calendar', 'user', 'description', ('frequency', 'fin' ), 'activated', 'jours',)
    }),

)

views.py

if request.method == 'POST':
    form = JoursForm(request.POST)
    if form.is_valid():
        jours = form.cleaned_data.get('jours')
        print 'jours', jours

else:
    form = JoursForm

I would like to use the values of checkbox but when I save in admin after having tick the boxes, they remain unchecked

what to do ?




Aucun commentaire:

Enregistrer un commentaire