Django中的多选字段

时间:2019-05-19 12:11:35

标签: python django django-forms

我创建了一个表单,该表单的字段具有.MultipleChoiceFields()

views.py

cat_choices = (
('Internships', 'Internships'),
('Scholarships', 'Scholarships'),
('Entrance exams', 'Entrance exams'),
)

class ProfileForm(forms.ModelForm):
    category = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                              choices=cat_choices)
    class Meta:
        model = Profile
        fields=('about','category')

我在profile.html

中使用了它
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
ul
{
    list-style-type: none;
}

* {
  box-sizing: border-box;
}
input{
  width: 100%;
  font-family: 'Lato', sans-serif;
  font-size: 15px;
  border: 1px solid gray;
  border-radius: 4px;
  margin: 5px 0;
  opacity: 0.85;
  display: inline-block;
  line-height: 40px;
  text-decoration: none; 
}
.container {
  position: relative;
  border-radius: 5px;
  background-color: white;
  padding: 20px 0 30px 0;
}

.col {

  width: 50%;
  left: 60px;
  margin: auto;
  padding: 0 50px;
  margin-top: 6px;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}


</style>
</head>
<body>

<div class="container">
  <form method="post">
    <div class="row">
      <div class="col">
        <div>
            <strong><p> About </p></strong>
            {% csrf_token %}
            {{ profile_form.about }}
        </div>

        <div>
            <strong><p> Select categories you are interested in </p></strong>
            {% csrf_token %}
            {{ profile_form.category }}
        </div>
        <input type="submit" value="Submit">
      </div>

    </div>
  </form>
</div>
</body>
</html>

我有两个输入(关于和类别)。类别是MultipleChoiceFields类型。 输入是profile.html中css中的样式。但是我要为我接受的两个输入提供两种不同的样式。我该怎么做?

0 个答案:

没有答案