Coverage for lino/modlib/gfks/fields.py : 68%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2008-2015 Luc Saffre # License: BSD (see file COPYING for details) """
as DjangoGenericForeignKey
"""Add verbose_name and help_text to Django's GFK.
Used by :class:`lino.modlib.gfks.mixins.Controllable`.
"""
verbose_name=None, help_text=None, dont_merge=False):
"""Automatically setup chooser and display field for ID field of generic foreign key.
"""
# Chooser object_type = kwargs[self.ct_field] if object_type: return object_type.model_class().objects.all() return []
# Display fk_field=self.fk_field) ct = getattr(obj, self.ct_field) if ct: try: return str(ct.get_object_for_this_type(pk=value)) except ct.model_class().DoesNotExist: return "%s with pk %r does not exist" % ( full_model_name(ct.model_class()), value)
"""Use this instead of `models.PositiveIntegerField` for fields that are part of a :term:`GFK` and you want Lino to render them using a Combobox.
Used by :class:`lino.modlib.gfks.mixins.Controllable`.
Note: `type_field` is a mandatory argument, but you can specify anything because it is being ignored.
"""
# needed for Django 1.7 # https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#custom-field-deconstruct-method
name, path, args, kwargs = super( GenericForeignKeyIdField, self).deconstruct() args = [self.type_field] return name, path, args, kwargs
|