lino.core.dbtables

This defines the Table class.

(This module's source code is available here.)

Functions

add_gridfilters(qs, gridfilters)

Converts a filter request in the format used by Ext.ux.grid.GridFilters into a Django field lookup on a django.db.models.query.QuerySet.

base_attrs(cl)

column_choices(rptname)

has_fk(rr, name)

model2actor(m)

rc_name(rptclass)

table_factory(model)

Automatically define a Table class for the specified model.

Classes

Table(*args, **kw)

An AbstractTable that works on a Django Model using a QuerySet.

lino.core.dbtables.add_gridfilters(qs, gridfilters)

Converts a filter request in the format used by Ext.ux.grid.GridFilters into a Django field lookup on a django.db.models.query.QuerySet.

Parameters
  • qs -- the queryset to be modified.

  • gridfilters -- a list of dictionaries, each having 3 keys field, type and value.

class lino.core.dbtables.Table(*args, **kw)

Bases: lino.core.tables.AbstractTable

An AbstractTable that works on a Django Model using a QuerySet.

A Table inherits from AbstractTable and adds attributes like model and master and master_key who are important because Lino handles relations automagically.

Another class of attributes are filter, exclude and sort_order which are thin wrappers to Django's query lookup parameters of same name.

See dd.Table.

model = None

See lino.core.actors.Actor.model

screenshot_profiles = ['admin']

The user user_type(s) for which we want a screenshot of this table.

use_as_default_table = True

Set this to False if this Table should not become the Model's default table.

expand_memos = False

(No longer used; see docs/tickets/44). Whether multi-line text fields in Grid views should be expanded in by default or not.

use_detail_params_value = False

If when in a detail view will override default param values with the detail's pv values.

classmethod add_quick_search_filter(qs, search_text)

Add a filter to the given queryset qs in order to apply a quick search for the given search_text.

classmethod get_detail_sets()

Yield a list of (app_label,name) tuples for which the kernel should try to create a Detail Set.

classmethod get_row_by_pk(ar, pk)

Implements get_row_by_pk for a database table.

Note: ar may not be None.

classmethod get_row_permission(obj, ar, state, ba)

Returns True if the given action is allowed for the given instance obj and the given user.

classmethod disable_delete(obj, ar)

Return either None if the given obj is allowed to be deleted by action request ar, or a string with a message explaining why, if not.

classmethod get_request_queryset(ar, **filter)

Return the iterable of Django database objects for the specified action request.

The default implementation calls get_user_queryset() and then applies request parameters.

classmethod get_queryset(ar, **filter)

Return the Django Queryset processed by this table.

The default implementation forwards the call to the model's get_request_queryset.

Override this to use e.g. select_related() or to return a list.

Example:

def get_queryset(self, **ar):
    return self.model.objects.select_related('country', 'city')
classmethod create_instance(ar, **kw)

Create a model instance using the specified keyword args, calling also lino.core.model.Model.on_create().

classmethod after_create_instance(obj, ar)

A hook for code to be executed when a new instance has been created in this table.

This is for actor-specific behaviour. You can do the equivalent for every table on a model by defining an after_ui_create method on the model.

Usage example: lino_xl.lib.cal.GuestsByPartner.

lino.core.dbtables.table_factory(model)

Automatically define a Table class for the specified model. This is used during kernel setup to create default tables for models who have no Table.