Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
Text fields¶
Overview¶
Django defines two types of database fields that contain text and the value of
which is represented in Python as a str
: charfields
and textfields.
- charfield¶
A field that contains a single line of text (no line breaks).
- textfield¶
A charfield that can contain more than one line of text.
A charfield requires a max_length while a textfield doesn’t.
A textfield has a flexible height in layouts, while a charfield hasn’t.
A charfield is defined using Django CharField while a textfield is a Django TextField.
Lino adds a dd.CharField
class, but this is not much used
and might get deprecated.
Two types of textfields¶
Lino knows two basic forms of textfields:
- plain textfield¶
A textfield meant to contain “raw” text without any formatting.
- rich textfield¶
A textfield that can contain HTML formatting like character style, links, tables, headers, enumerations, …
Both types of textfields are specified using the dd.RichTextField
class where format
is either either 'plain'
or
'html'
.
The content of a rich textfield can be limited* using Bleaching.
The content of a rich textfield can contain memo commands (see memo : The memo parser).
The textfield_format
site setting¶
There is a site attribute lino.core.site.Site.textfield_format
, which
defaults to 'plain'
.
You’ll probably better leave the site setting as ‘plain’, and specify explicitly the fields you want as html by declaring them:
foo = fields.RichTextField(..., format='html')
We recommend that you declare your plain text fields also using fields.RichTextField and not models.TextField:
foo = fields.RichTextField()
Because that gives subclasses of your application the possibility to make that specific field html-formatted:
resolve_field('Bar.foo').set_format('html')
Class reference¶
- class lino.core.fields.RichTextField¶
A thin wrapper around Django’s
TextField
class, but you can specify two additional keyword argumentsformat
andbleached
.- format¶
Contains either
'plain'
or'html'
.Default value is the
lino.core.site.Site.textfield_format
setting.
- class lino.core.fields.PreviewTextField¶
A text field that is previewable and editable at the same time.
I currently works only on the
lino.modlib.memo.mixins.Previewable.body