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

lino.core.db.fields

class lino.core.db.fields.RichTextField

A wrapper around Django’s TextField class, but you can specify two additional keyword arguments format and bleached.

See Text fields.

format

Contains either 'plain' or 'html'. Default value is lino.core.site.Site.textfield_format.

bleached

See Bleaching.

class lino.core.db.fields.PreviewTextField

A text field that is previewable and editable at the same time.

I currently works only on lino.modlib.memo.mixins.Previewable.body

class lino.core.db.fields.PasswordField

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

Inherits from django.db.models.fields.CharField

class lino.core.db.fields.PercentageField

A field to express a percentage. The database stores this like a DecimalField. Rendered with a “%” suffix when using DISPLAY_MODE_HTML <lino.core.constants.DISPLAY_MODE_HTML>.

Inherits from django.db.models.fields.DecimalField

class lino.core.db.fields.TimeField

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

Inherits from django.db.models.fields.TimeField

class lino.core.db.fields.MonthField

A DateField that uses a MonthPicker instead of a normal DateWidget

Inherits from django.db.models.fields.DateField

class lino.core.db.fields.PriceField

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

Inherits from django.db.models.fields.DecimalField

class lino.core.db.fields.CharField

An extension of Django’s django.db.models.fields.CharField.

This probably isn’t used anymore in the real world. There is still a tutorial about it: Fields with an input mask.

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).

class lino.core.db.fields.QuantityField

A field that accepts Quantity, Percentage and Duration values.

Implemented as a django.db.models.fields.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.

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.db.fields.DurationField

A field that stores Duration values as CHAR.

Inherits from django.db.models.fields.CharField

class lino.core.db.fields.IncompleteDateField

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

Inherits from django.db.models.fields.CharField

CustomField:

Mixin to create a custom field.

It defines a single method create_layout_elem().

lino.core.db.fields.create_layout_elem(self, 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.