dj_ingredient_field

Module contents

class dj_ingredient_field.Ingredient(name)

Bases: object

format_string = '{name}'
class dj_ingredient_field.IngredientField(*args, **kwargs)

Bases: django.db.models.fields.CharField

An ingredient field for Django models which provides over 3500 cooking ingredients

Dataset from https://dominikschmidt.xyz/simplified-recipes-1M/

clean(value, model_instance)

Validates the string representation, since validate checks against the choice list, and generates clean python object

deconstruct()

Removes choices and max_length keywords as these are not to be user editable

description = 'A cooking ingredient'
from_db_value(value, expression, connection)
get_prep_value(value: dj_ingredient_field.Ingredient)

Perform preliminary non-db specific value checks and conversions.

to_python(value: Any) Any

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

class dj_ingredient_field.MeasurementUnit(name: str, symbol: str, conversion_rate: numbers.Number, unit_type: dj_ingredient_field.enums.UnitType, is_base_unit=False)

Bases: object

A class containing logic for cooking measurement units which have a ‘base’ unit.

base_mass_unit = None
base_volume_unit = None
convert_to(amount, o: dj_ingredient_field.MeasurementUnit, density=1.0) numbers.Number
get_base_unit_amount(amount) numbers.Number

Returns the equivalent base unit

class dj_ingredient_field.MeasurementUnitField(*args, **kwargs)

Bases: django.db.models.fields.CharField

A field for picking measurement options for an ingredient

clean(value, model_instance)

Validates the string representation, since validate checks against the choice list, and generates clean python object

deconstruct()

Removes choices and max_length keywords as these are not to be user editable

description = 'A cooking measurement unit'
from_db_value(value, expression, connection)
get_prep_value(value: dj_ingredient_field.MeasurementUnit)

Perform preliminary non-db specific value checks and conversions.

get_setting_for_unit_name_or_default(value)
to_python(value: Any) Any

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

units = [('Litre', 'Litre'), ('Millilitre', 'Millilitre'), ('Teaspoon', 'Teaspoon'), ('Tablespoon', 'Tablespoon'), ('Cup', 'Cup'), ('Pint', 'Pint'), ('Gallon', 'Gallon'), ('Gram', 'Gram'), ('Milligram', 'Milligram'), ('Unit', 'Unit'), ('Killogram', 'Killogram'), ('Cubic Metre', 'Cubic Metre')]