Ich habe die anderen Lösungen auf Stackoverflow angeschaut, aber nichts scheint mir mit dem Problem zu helfen, das ich habe.Problem mit dem Speichern von Kontrollkästchen Wert aus Formular
Ich habe ein Formular zum Ausfüllen von Informationen, die gespeichert werden müssen. Ich gebe dem Benutzer drei Optionen, die er ankreuzen kann. Das Formular wird jedoch nicht gespeichert, da der Wert nicht gültig ist.
Hier ist mein Modell:
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
Hier ist meine Form ist:
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
Dieser Fehler wird angezeigt, auf der Webseite selbst, wenn Sie auf Speichern drücken:
Select a valid choice. [u'critical'] is not one of the available choices.
Dieser Fehler kommt wenn Sie das Kästchen "Critical" ankreuzen.