How to use the lino.api.dd.ForeignKey function in lino

To help you get started, we’ve selected a few lino examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lino-framework / lino / lino_noi / lib / tickets / ui.py View on Github external
order_by = ["-id"]
    column_names = 'id summary:50 reporter:10 topic faculty ' \
                   'workflow_buttons:30 project:10 *'
    detail_layout = TicketDetail()
    insert_layout = dd.InsertLayout("""
    # reporter #product
    summary
    description
    """, window_size=(70, 20))

    detail_html_template = "tickets/Ticket/detail.html"

    parameters = mixins.ObservedPeriod(
        observed_event=TicketEvents.field(blank=True),
        topic=dd.ForeignKey('topics.Topic', blank=True,),
        site=dd.ForeignKey('tickets.Site', blank=True,),
        reporter=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Reporter"),
            blank=True, null=True,
            help_text=_("Only rows reporter by this user.")),
        assigned_to=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Assigned to"),
            blank=True, null=True,
            help_text=_("Only tickets assigned to this user.")),
        feasable_by=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Feasable by"), blank=True, null=True),
        interesting_for=dd.ForeignKey(
            'contacts.Partner',
            verbose_name=_("Interesting for"),
github lino-framework / lino / lino / modlib / cv / models.py View on Github external
"""A **work experience** is when a given person has worked for a given
    period in a given company.

    """
    class Meta(object):
        app_label = 'cv'
        verbose_name = _("Job Experience")
        verbose_name_plural = _("Job Experiences")
        get_latest_by = 'start_date'

    company = models.CharField(max_length=200, verbose_name=_("company"))
    #~ type = models.ForeignKey(JobType,verbose_name=_("job type"))
    title = models.CharField(
        max_length=200, verbose_name=_("job title"), blank=True)
    status = dd.ForeignKey('cv.Status', blank=True, null=True)
    duration = dd.ForeignKey('cv.Duration', blank=True, null=True)
    regime = dd.ForeignKey('cv.Regime', blank=True, null=True)
    is_training = models.BooleanField(_("Training"), default=False)

    remarks = models.TextField(_("Remarks"), blank=True, null=True)

    termination_reason = models.CharField(
        max_length=200,
        blank=True,  # null=True,
        verbose_name=_("Termination reason"))

    def __str__(self):
        return str(self.title)


class Experiences(PeriodTable):
    """The default table showing all :class:`Experience` instances.
github lino-framework / lino / lino / modlib / notes / models.py View on Github external
manager_roles_required = dd.login_required(OfficeStaff)

    class Meta(object):
        app_label = 'notes'
        abstract = dd.is_abstract_model(__name__, 'Note')
        verbose_name = _("Note")
        verbose_name_plural = _("Notes")

    date = models.DateField(
        verbose_name=_('Date'), default=dd.today)
    time = models.TimeField(
        blank=True, null=True,
        verbose_name=_("Time"),
        default=timezone.now)
    type = dd.ForeignKey(
        'notes.NoteType',
        blank=True, null=True,
        verbose_name=_('Note Type (Content)'))
    event_type = dd.ForeignKey(
        'notes.EventType',
        blank=True, null=True,
        verbose_name=_('Event Type (Form)'))
    subject = models.CharField(_("Subject"), max_length=200, blank=True)
    body = dd.RichTextField(_("Body"), blank=True, format='html')

    language = dd.LanguageField()

    def __str__(self):
        return u'%s #%s' % (self._meta.verbose_name, self.pk)

    def summary_row(self, ar, **kw):
github lino-framework / lino / lino / modlib / events / models.py View on Github external
class Event(mixins.BabelNamed):
    date = models.DateField(_("Date"))
    place = dd.ForeignKey(Place, blank=True, null=True)
    type = dd.ForeignKey(Type)
    features = models.ManyToManyField(Feature)
    #~ cities = models.ManyToManyField('countries.Place')
    #~ description = dd.BabelTextField(format='plain',blank=True)
    url = models.URLField(blank=True)


@dd.python_2_unicode_compatible
class Stage(mixins.Sequenced):
    event = dd.ForeignKey('events.Event', related_name="stages")
    city = dd.ForeignKey('countries.Place', related_name="stages")

    def __str__(self):
        return str(self.city)

    def get_siblings(self):
        return self.event.stages.order_by('seqno')

dd.update_field(Event, 'name', blank=True)


class StagesByEvent(dd.Table):
    model = Stage  # Event.cities.through
    master_key = 'event'


class FeaturesByEvent(dd.Table):
github lino-framework / lino / lino / modlib / finan / models.py View on Github external
debit = DcAmountField(DEBIT, _("Debit"))
    credit = DcAmountField(CREDIT, _("Credit"))


class BankStatementItem(FinancialVoucherItem):
    """An item of a :class:`BankStatement`."""
    voucher = dd.ForeignKey('finan.BankStatement', related_name='items')
    date = models.DateField(blank=True, null=True)
    debit = DcAmountField(DEBIT, _("Income"))
    credit = DcAmountField(CREDIT, _("Expense"))


class PaymentOrderItem(FinancialVoucherItem):
    """An item of a :class:`PaymentOrder`."""
    voucher = dd.ForeignKey('finan.PaymentOrder', related_name='items')
    bank_account = dd.ForeignKey('sepa.Account', blank=True, null=True)

# dd.update_field(PaymentOrderItem, 'iban', blank=True)
# dd.update_field(PaymentOrderItem, 'bic', blank=True)


class JournalEntryDetail(dd.FormLayout):
    main = "general ledger"

    general = dd.Panel("""
    date user narration workflow_buttons
    finan.ItemsByJournalEntry
    """, label=_("General"))

    ledger = dd.Panel("""
    id journal year number
    ledger.MovementsByVoucher
github lino-framework / lino / lino / modlib / changes / models.py View on Github external
time = models.DateTimeField()
    type = ChangeTypes.field()
    if settings.SITE.user_model:
        user = dd.ForeignKey(settings.SITE.user_model)
    else:
        user = dd.DummyField()

    object_type = dd.ForeignKey(
        'contenttypes.ContentType', blank=True, null=True,
        verbose_name=_("Object type"),
        related_name='changes_by_object')
    object_id = GenericForeignKeyIdField(
        object_type, blank=True, null=True)
    object = GenericForeignKey('object_type', 'object_id', _("Object"))

    master_type = dd.ForeignKey(
        'contenttypes.ContentType', blank=True, null=True,
        verbose_name=_("Master type"), related_name='changes_by_master')
    master_id = GenericForeignKeyIdField(
        master_type, blank=True, null=True)
    master = GenericForeignKey('master_type', 'master_id', _("Master"))

    diff = dd.RichTextField(
        _("Changes"), format='plain', blank=True, editable=False)
    changed_fields = dd.CharField(
        _("Fields"), max_length=250, blank=True)

    def __str__(self):
        # ~ return "#%s - %s" % (self.id,self.time)
        return "#%s" % self.id
github lino-framework / lino / lino / modlib / ledger / mixins.py View on Github external
:class:`lino.modlib.contacts.models.Partner`.

    .. attribute:: payment_term

        The payment terms to be used in this document.  A pointer to
        :class:`PaymentTerm`.

    """
    class Meta:
        abstract = True

    partner = dd.ForeignKey(
        'contacts.Partner',
        related_name="%(app_label)s_%(class)s_set_by_partner",
        blank=True, null=True)
    payment_term = dd.ForeignKey(
        'ledger.PaymentTerm',
        related_name="%(app_label)s_%(class)s_set_by_payment_term",
        blank=True, null=True)

    @classmethod
    def get_registrable_fields(cls, site):
        for f in super(PartnerRelated, cls).get_registrable_fields(site):
            yield f
        yield 'partner'
        yield 'payment_term'

    def get_recipient(self):
        return self.partner
    recipient = property(get_recipient)

github lino-framework / lino / lino_noi / lib / tickets / ui.py View on Github external
parameters = mixins.ObservedPeriod(
        observed_event=TicketEvents.field(blank=True),
        topic=dd.ForeignKey('topics.Topic', blank=True,),
        site=dd.ForeignKey('tickets.Site', blank=True,),
        reporter=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Reporter"),
            blank=True, null=True,
            help_text=_("Only rows reporter by this user.")),
        assigned_to=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Assigned to"),
            blank=True, null=True,
            help_text=_("Only tickets assigned to this user.")),
        feasable_by=dd.ForeignKey(
            settings.SITE.user_model,
            verbose_name=_("Feasable by"), blank=True, null=True),
        interesting_for=dd.ForeignKey(
            'contacts.Partner',
            verbose_name=_("Interesting for"),
            blank=True, null=True,
            help_text=_("Only tickets interesting for this partner.")),
        project=dd.ForeignKey(
            'tickets.Project',
            blank=True, null=True),
        state=TicketStates.field(
            blank=True, help_text=_("Only rows having this state.")),
        show_assigned=dd.YesNo.field(_("Assigned"), blank=True),
        show_active=dd.YesNo.field(_("Active"), blank=True),
        has_project=dd.YesNo.field(_("Has project"), blank=True),
        show_private=dd.YesNo.field(_("Private"), blank=True))
github lino-framework / lino / lino / modlib / lists / models.py View on Github external
detail_layout = dd.FormLayout("""
    ref list_type id
    name
    remarks
    MembersByList
    """)


class Member(mixins.Sequenced):

    class Meta(object):
        verbose_name = _("List memberships")
        verbose_name_plural = _("List memberships")

    list = dd.ForeignKey('lists.List')
    partner = dd.ForeignKey(
        'contacts.Partner',
        related_name="list_memberships")
    remark = models.CharField(_("Remark"), max_length=200, blank=True)


class Members(dd.Table):
    required_roles = dd.required(dd.SiteStaff)
    model = 'lists.Member'


class MembersByList(Members):
    master_key = 'list'
    order_by = ['seqno']
    column_names = "seqno partner remark"
github lino-framework / lino / lino / modlib / ledger / models.py View on Github external
return "%s.%d" % (unicode(self.voucher), self.seqno)


class MatchRule(dd.Model):
    """A **match rule** specifies that a movement into given account can
be cleared using a given journal.

    """
    # allow_cascaded_delete = ['account', 'journal']

    class Meta:
        verbose_name = _("Match rule")
        verbose_name_plural = _("Match rules")
        unique_together = ['account', 'journal']

    account = dd.ForeignKey('accounts.Account')
    journal = JournalRef()


for tt in TradeTypes.objects():
    dd.inject_field(
        'accounts.Account',
        tt.name + '_allowed',
        models.BooleanField(verbose_name=tt.text, default=False))

dd.inject_field(
    'accounts.Account',
    'clearable', models.BooleanField(_("Clearable"), default=False))


def update_partner_satisfied(p):
    """This is called when a voucher has been (un)registered on each