|
6 | 6 | class BasicForm(forms.Form):
|
7 | 7 | # Render one of every Django field type
|
8 | 8 | # https://docs.djangoproject.com/en/stable/ref/forms/fields/#field-types
|
9 |
| - boolean_field = forms.BooleanField(label="boolean", initial=True) |
10 |
| - char_field = forms.CharField(label="chars", max_length=7, initial="Example") |
11 |
| - choice_field = forms.ChoiceField(label="choice", initial="2", choices=[("1", "One"), ("2", "Two")]) |
12 |
| - date_field = forms.DateField(label="date", initial="2000-01-01") |
13 |
| - date_time_field = forms.DateTimeField(label="date time", initial="2000-01-01 00:00:00") |
14 |
| - decimal_field = forms.DecimalField(label="decimal", initial=0.0) |
15 |
| - duration_field = forms.DurationField(label="duration", initial=0) |
16 |
| - email_field = forms. EmailField( label="email", initial="[email protected]") |
| 9 | + boolean_field = forms.BooleanField(label="boolean") |
| 10 | + char_field = forms.CharField(label="chars", max_length=7) |
| 11 | + choice_field = forms.ChoiceField(label="choice", choices=[("1", "One"), ("2", "Two")]) |
| 12 | + date_field = forms.DateField(label="date") |
| 13 | + date_time_field = forms.DateTimeField(label="date time") |
| 14 | + decimal_field = forms.DecimalField(label="decimal") |
| 15 | + duration_field = forms.DurationField(label="duration") |
| 16 | + email_field = forms.EmailField(label="email") |
17 | 17 | file_path_field = forms.FilePathField("./", label="file path")
|
18 |
| - float_field = forms.FloatField(label="float", initial=0.0) |
19 |
| - generic_ip_address_field = forms.GenericIPAddressField(label="Generic IP", initial="127.0.0.1") |
20 |
| - integer_field = forms.IntegerField(label="integer", initial=0) |
21 |
| - json_field = forms.JSONField(label="JSON", initial={"key": "value"}) |
| 18 | + float_field = forms.FloatField(label="float") |
| 19 | + generic_ip_address_field = forms.GenericIPAddressField(label="Generic IP") |
| 20 | + integer_field = forms.IntegerField(label="integer") |
| 21 | + json_field = forms.JSONField(label="JSON") |
22 | 22 | multiple_choice_field = forms.MultipleChoiceField(
|
23 |
| - label="multiple choice", initial=["1", "2"], choices=[("1", "One"), ("2", "Two"), ("3", "Three")] |
24 |
| - ) |
25 |
| - null_boolean_field = forms.NullBooleanField(label="null boolean", initial=True) |
26 |
| - regex_field = forms.RegexField(label="regex", regex=r"^\d{1,2}$", initial="12") |
27 |
| - slug_field = forms.SlugField(label="slug", initial="your-slug") |
28 |
| - time_field = forms.TimeField(label="time", initial="00:00:00") |
29 |
| - typed_choice_field = forms.TypedChoiceField( |
30 |
| - label="typed choice field", initial="1", choices=[("1", "One"), ("2", "Two")] |
| 23 | + label="multiple choice", choices=[("1", "One"), ("2", "Two"), ("3", "Three")] |
31 | 24 | )
|
| 25 | + null_boolean_field = forms.NullBooleanField(label="null boolean") |
| 26 | + regex_field = forms.RegexField(label="regex", regex=r"^\d{1,2}$") |
| 27 | + slug_field = forms.SlugField(label="slug") |
| 28 | + time_field = forms.TimeField(label="time") |
| 29 | + typed_choice_field = forms.TypedChoiceField(label="typed choice field", choices=[("1", "One"), ("2", "Two")]) |
32 | 30 | typed_multiple_choice_field = forms.TypedMultipleChoiceField(
|
33 |
| - label="typed multiple choice", initial="1", choices=[("1", "One"), ("2", "Two")] |
34 |
| - ) |
35 |
| - url_field = forms.URLField(label="URL", initial="https://example.com") |
36 |
| - uuid_field = forms.UUIDField(label="UUID", initial="550e8400-e29b-41d4-a716-446655440000") |
37 |
| - combo_field = forms.ComboField( |
38 |
| - label="combo", fields=[ forms. CharField(), forms. EmailField()], initial="[email protected]" |
| 31 | + label="typed multiple choice", choices=[("1", "One"), ("2", "Two")] |
39 | 32 | )
|
| 33 | + url_field = forms.URLField(label="URL") |
| 34 | + uuid_field = forms.UUIDField(label="UUID") |
| 35 | + combo_field = forms.ComboField(label="combo", fields=[forms.CharField(), forms.EmailField()]) |
40 | 36 | password_field = forms.CharField(label="password", widget=forms.PasswordInput)
|
41 |
| - model_choice_field = forms.ModelChoiceField( |
42 |
| - label="model choice field", initial="1", queryset=models.TodoItem.objects.all() |
43 |
| - ) |
| 37 | + model_choice_field = forms.ModelChoiceField(label="model choice field", queryset=models.TodoItem.objects.all()) |
44 | 38 | model_multiple_choice_field = forms.ModelMultipleChoiceField(
|
45 |
| - label="model multiple choice field", initial="1", queryset=models.TodoItem.objects.all() |
| 39 | + label="model multiple choice field", queryset=models.TodoItem.objects.all() |
46 | 40 | )
|
47 | 41 |
|
48 | 42 |
|
|
0 commit comments