Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

lino.core.fields

Defines extended database field classes and utility functions related to fields.

Functions

choices_for_field(ar, holder, field)

Return the choices for the given field and the given HTTP request whose holder is either a Model, an Actor or an Action.

validate_incomplete_date(value)

Raise ValidationError if user enters e.g. a date 30.02.2009.

Classes

CharField(*args, **kw)

An extension of Django's models.CharField.

CustomField()

Mixin to create a custom field.

DatePickerField([verbose_name, name, ...])

A DateField that uses a DatePicker instead of a normal DateWidget.

DurationField(*args, **kw)

A field that stores Duration values as CHAR.

IncompleteDateField(*args, **kw)

A field that behaves like a DateField, but accepts incomplete dates represented using lino.utils.format_date.IncompleteDate.

MonthField([verbose_name, name, auto_now, ...])

A DateField that uses a MonthPicker instead of a normal DateWidget

PasswordField(*args[, db_collation])

Stored as plain text in database, but not displayed in user interface.

PercentageField(*args, **kwargs)

A field to express a percentage.

PreviewTextField(*args, **kw)

PriceField([verbose_name, max_digits])

A thin wrapper around Django's DecimalField with price-like default values for decimal_places, max_length and max_digits.

PriceRange(field_name[, verbose_name])

QuantityField(*args, **kw)

A field that accepts Quantity, Percentage and Duration values.

RecurrenceField(*args, **kw)

Deserves more documentation.

RichTextField(*args, **kw)

TimeField([verbose_name, name, auto_now, ...])

Like a TimeField, but allowed values are between calendar_start_hour and calendar_end_hour.

lino.core.fields.validate_incomplete_date(value)

Raise ValidationError if user enters e.g. a date 30.02.2009.

class lino.core.fields.PasswordField(*args, db_collation=None, **kwargs)

Bases: CharField

Stored as plain text in database, but not displayed in user interface.

class lino.core.fields.PercentageField(*args, **kwargs)

Bases: DecimalField

A field to express a percentage. The database stores this like a DecimalField. Plain HTML adds a “%”.

class lino.core.fields.TimeField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)

Bases: TimeField

Like a TimeField, but allowed values are between calendar_start_hour and calendar_end_hour.

class lino.core.fields.DatePickerField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)

Bases: DateField

A DateField that uses a DatePicker instead of a normal DateWidget. Doesn’t yet work.

class lino.core.fields.MonthField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)

Bases: DateField

A DateField that uses a MonthPicker instead of a normal DateWidget

class lino.core.fields.PriceField(verbose_name=None, max_digits=10, **kwargs)

Bases: DecimalField

A thin wrapper around Django’s DecimalField with price-like default values for decimal_places, max_length and max_digits.

class lino.core.fields.CharField(*args, **kw)

Bases: CharField

An extension of Django’s models.CharField.

Adds two keywords mask_re and strip_chars_re which, when using the ExtJS front end, will be rendered as the maskRe and stripCharsRe config options of TextField as described in the ExtJS documentation, converting naming conventions as follows:

regex

regex

A JavaScript RegExp object to be tested against the field value during validation (defaults to null). If the test fails, the field will be marked invalid using regexText.

mask_re

maskRe

An input mask regular expression that will be used to filter keystrokes that do not match (defaults to null). The maskRe will not operate on any paste events.

strip_chars_re

stripCharsRe

A JavaScript RegExp object used to strip unwanted content from the value before validation (defaults to null).

Example usage:

belgian_phone_no = dd.CharField(max_length=15, strip_chars_re='')
class lino.core.fields.QuantityField(*args, **kw)

Bases: CharField

A field that accepts Quantity, Percentage and Duration values.

Implemented as a CharField, which means that sorting or filter ranges may not work as expected, and you cannot use SUM or AVG agregators on quantity fields since the database does not know how to calculate sums from them.

When you set blank=True, then you should also set null=True.

to_python(value)

Excerpt from Django docs:

As a general rule, to_python() should deal gracefully with any of the following arguments:

  • An instance of the correct type (e.g., Hand in our ongoing example).

  • A string (e.g., from a deserializer).

  • None (if the field allows null=True)

I’d add “Any value allowed for this field when instantiating a model.”

class lino.core.fields.DurationField(*args, **kw)

Bases: QuantityField

A field that stores Duration values as CHAR.

class lino.core.fields.IncompleteDateField(*args, **kw)

Bases: CharField

A field that behaves like a DateField, but accepts incomplete dates represented using lino.utils.format_date.IncompleteDate.

class lino.core.fields.RecurrenceField(*args, **kw)

Bases: CharField

Deserves more documentation.

class lino.core.fields.CustomField

Bases: object

Mixin to create a custom field.

It defines a single method create_layout_elem().

create_layout_elem(base_class, layout_handle, field, **kw)

Return the widget to represent this field in the specified layout_handle.

The widget must be an instance of the given base_class.

self and field are identical unless self is a RemoteField or a VirtualField.

lino.core.fields.choices_for_field(ar, holder, field)

Return the choices for the given field and the given HTTP request whose holder is either a Model, an Actor or an Action.