Esempio n. 1
0
 def register_class_attribute(cls, k, v):
     if isinstance(v, fields.Constant):
         cls.add_constant(k, v)
     elif isinstance(v, fields.VirtualField):  # 20120903b
         cls.add_virtual_field(k, v)
     elif isinstance(v, models.Field):  # 20130910
         #~ print "20130910 add virtual field " ,k, cls
         vf = fields.VirtualField(v, field_getter(k))
         cls.add_virtual_field(k, vf)
Esempio n. 2
0
def inject_quick_add_buttons(model, name, target):
    """
    Injects a virtual display field `name` into the specified `model`.
    This field will show up to three buttons
    `[New]` `[Show last]` `[Show all]`.
    `target` is the table that will run these actions.
    It must be a slave of `model`.
    """

    def fn(self, ar):
        if ar is None:
            return ''
        return ar.renderer.quick_add_buttons(
            ar.spawn(target, master_instance=self))
    tm = resolve_model(target.model)
    inject_field(model, name,
                 fields.VirtualField(fields.DisplayField(
                     tm._meta.verbose_name_plural), fn))