Ejemplo n.º 1
0
class HayBaleForm(forms.ModelForm):
    weight = QuantityFormField(base_units='gram',
                               unit_choices=['ounce', 'gram'])

    class Meta:
        model = HayBale
        exclude = []
Ejemplo n.º 2
0
class BoxModelForm(ModelForm):
    new_weight = QuantityFormField(base_units="gram",
                                   unit_choices=["gram", "ounce", "milligram"])

    class Meta:
        model = Box
        exclude = []
Ejemplo n.º 3
0
class MegalithForm(forms.ModelForm):

    weight = QuantityFormField(
        base_units='tonnes',
        unit_choices=['tonnes', 'ounces', 'grams', 'kilograms'])

    class Meta:
        model = Megalith
        fields = '__all__'
Ejemplo n.º 4
0
class SimpleForm(Form):
    hello = QuantityFormField(base_units="kilogram", required=False)
Ejemplo n.º 5
0
 def test_unit_choices_must_match_base_dimensionality(self):
     with self.assertRaises(DimensionalityError):
         field = QuantityFormField(base_units='gram',
                                   unit_choices=['meter', 'ounces'])
Ejemplo n.º 6
0
 def test_unit_choices_must_be_valid_units(self):
     with self.assertRaises(UndefinedUnitError):
         field = QuantityFormField(base_units="mile",
                                   unit_choices=['gunzu'])
Ejemplo n.º 7
0
 def test_base_units_is_included_by_default(self):
     field = QuantityFormField(base_units="mile",
                               unit_choices=['meters', 'feet'])
     self.assertIn('mile', field.units)
Ejemplo n.º 8
0
 def test_base_units_is_required_for_form_field(self):
     with self.assertRaises(ValueError):
         field = QuantityFormField()
Ejemplo n.º 9
0
class UnitChoicesForm(forms.Form):
    distance = QuantityFormField(
        base_units='kilometer',
        unit_choices=['mile', 'kilometer', 'yard', 'feet'])
Ejemplo n.º 10
0
class NullableWeightForm(forms.Form):
    weight = QuantityFormField(base_units='gram', required=False)
Ejemplo n.º 11
0
class TestForm(forms.Form):
    """docstring for TestForm"""

    amount = QuantityFormField(base_units="grams",
                               unit_choices=['ounce', 'gram'])