0
나는 Stackoverflow의 다른 솔루션을 살펴 봤지만 아무 문제가없는 것 같습니다.양식에서 체크 박스 값을 저장하는 문제
저장해야하는 정보를 입력하는 양식이 있습니다. 사용자에게 세 가지 옵션을 제공하여 틱 할 수 있습니다. 그러나 값이 유효하지 않기 때문에 양식을 저장하지 않습니다. 당신이 키를 누르면 웹 페이지 자체에
from django import forms
from server_status.models import Event
FLAG_CHECKBOX = [('active', 'Active'), ('inactive', 'Inactive'), ]
STATUS_CHOICES=[('critical', 'Critical'), ('medium', 'Medium'), ('low','Low'),]
class Add_Event_Form(forms.ModelForm):
event_title = forms.CharField(max_length=50, help_text="Please enter an informative title.")
event_status = forms.MultipleChoiceField(choices=STATUS_CHOICES, widget=forms.CheckboxSelectMultiple,
help_text="Please select the status of the event")
event_description = forms.CharField(max_length=500, initial="",
help_text="Enter a short description of the event here")
event_flag = forms.MultipleChoiceField(choices=FLAG_CHECKBOX, required=True, widget=forms.CheckboxSelectMultiple,
help_text="Please select the status of this event.")
date_active = forms.DateField(required=True, widget=forms.DateInput(attrs={'class': 'datepicker'}),
help_text="Please select a date for this event.")
time_active = forms.TimeField(required=True, widget=forms.TimeInput(format='%HH:%MM'),
help_text="Please select a time for this event in HH:MM format.")
class Meta:
model = Event
fields = '__all__' # I want all fields to be editable
이 오류가 표시 저장 : 여기
from django.db import models
from django.utils import timezone
FLAG_CHOICES = (('Active', 'Active'), ('Inactive', 'Inactive'),)
STATUS_CHOICES=(('Critical', 'Critical'), ('Medium', 'Medium'), ('Low','Low'))
class Event(models.Model):
event_status=models.CharField(max_length=10, choices=STATUS_CHOICES)
event_title=models.CharField(max_length=50)
event_description=models.CharField(max_length=500)
event_flag=models.CharField(max_length=10, choices=FLAG_CHOICES)
date_active=models.DateField(default=timezone.now())
time_active=models.TimeField(default=timezone.now())
def __str__(self):
return self.event_title
내 형태 :
이
Select a valid choice. [u'critical'] is not one of the available choices.
이 오류는 여기 온다
내 모델입니다 'Critical'이라는 상자를 체크하면 귀하의 모델에서