mirror of https://github.com/django/django.git
Fixed #24302 -- Added DurationField.formfield()
This commit is contained in:
parent
32ed4c202f
commit
2d7c27d387
|
@ -1689,6 +1689,13 @@ class DurationField(Field):
|
||||||
val = self._get_val_from_obj(obj)
|
val = self._get_val_from_obj(obj)
|
||||||
return '' if val is None else duration_string(val)
|
return '' if val is None else duration_string(val)
|
||||||
|
|
||||||
|
def formfield(self, **kwargs):
|
||||||
|
defaults = {
|
||||||
|
'form_class': forms.DurationField,
|
||||||
|
}
|
||||||
|
defaults.update(kwargs)
|
||||||
|
return super(DurationField, self).formfield(**defaults)
|
||||||
|
|
||||||
|
|
||||||
class EmailField(CharField):
|
class EmailField(CharField):
|
||||||
default_validators = [validators.validate_email]
|
default_validators = [validators.validate_email]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from django import forms
|
||||||
from django.core import exceptions, serializers
|
from django.core import exceptions, serializers
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -70,3 +71,11 @@ class TestValidation(TestCase):
|
||||||
"'not a datetime' value has an invalid format. "
|
"'not a datetime' value has an invalid format. "
|
||||||
"It must be in [DD] [HH:[MM:]]ss[.uuuuuu] format."
|
"It must be in [DD] [HH:[MM:]]ss[.uuuuuu] format."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestFormField(TestCase):
|
||||||
|
# Tests for forms.DurationField are in the forms_tests app.
|
||||||
|
|
||||||
|
def test_formfield(self):
|
||||||
|
field = models.DurationField()
|
||||||
|
self.assertIsInstance(field.formfield(), forms.DurationField)
|
||||||
|
|
Loading…
Reference in New Issue