def foreign_key_factory(model_field, **kwargs): setdefaults_path( kwargs, choices=model_field.foreign_related_fields[0].model.objects.all(), model=model_field.foreign_related_fields[0].model, ) return Column.choice_queryset(model_field=model_field, **kwargs)
def foreign_key_factory(model_field, **kwargs): setdefaults( kwargs, dict(choices=model_field.foreign_related_fields[0].model. objects.all())) kwargs['model'] = model_field.foreign_related_fields[0].model return Column.choice_queryset(**kwargs)
class TestTable(Table): foo = Column.choice_queryset( model=Foo, choices=lambda table, column: Foo.objects.all(), query__gui__extra__endpoint_attr='b', query__show=True, bulk__show=True, query__gui__show=True)
class FooTable(Table): foo = Column.choice_queryset( query__show=True, query__gui__show=True, bulk__show=True, choices=lambda table, column: Foo.objects.filter(a=1)) class Meta: model = Foo
class TestTable(Table): foo__a = Column.number() foo__b = Column() foo = Column.choice_queryset( model=Foo, choices=lambda table, column: Foo.objects.all(), query__show=True, bulk__show=True, query__gui__show=True)
def inline_edit_select(**kwargs): def inline_edit_select_cell_format(table, column, row, value): options = '<option value=""></option>' + "\n".join( [ '<option value="%s"%s>%s</option>' % (choice.pk, ' selected="selected"' if choice == value else "", choice) for choice in evaluate(kwargs["choices"], table=table, column=column, row=row, value=value) ] ) return mark_safe( '<select class="inline_editable_select" edit_url="%sedit/%s/" id="%s">%s</select>' % (row.get_absolute_url(), column.name, row.pk, options) ) setdefaults(kwargs, dict(cell__format=inline_edit_select_cell_format, query__show=True)) return ColumnBase.choice_queryset(**kwargs)
class BarTable(Table): select = Column.select( ) # Shortcut for creating checkboxes to select rows b__a = Column.number( ) # Show "a" from "b". This works for plain old objects too. b = Column.choice_queryset( show=False, choices=Foo.objects.all(), model=Foo, bulk__show=True, query__show=True, query__gui__show=True, ) c = Column(bulk=True) # The form is created automatically d = Column( display_name='Display name', css_class={'css_class'}, url='url', title='title', sortable=False, group='Foo', auto_rowspan=True, cell__value=lambda table, column, row: row.b.a // 3, cell__format=lambda table, column, row, value: '- %s -' % value, cell__attrs__class__cj=True, cell__attrs__title='cell title', cell__url='url', cell__url_title='cell url title') e = Column(group='Foo', cell__value='explicit value', sortable=False) f = Column(show=False, sortable=False) g = Column(attr='c', sortable=False) django_templates_for_cells = Column( sortable=False, cell__value=None, cell__template='kitchen_sink_cell_template.html') class Meta: model = Bar
def inline_edit_select(**kwargs): def inline_edit_select_cell_format(table, column, row, value): options = '<option value=""></option>' + '\n'.join([ '<option value="%s"%s>%s</option>' % (choice.pk, ' selected="selected"' if choice == value else '', choice) for choice in evaluate(kwargs['choices'], table=table, column=column, row=row, value=value) ]) return mark_safe( '<select class="inline_editable_select" edit_url="%sedit/%s/" id="%s">%s</select>' % (row.get_absolute_url(), column.name, row.pk, options)) setdefaults( kwargs, dict( cell__format=inline_edit_select_cell_format, query__show=True, )) return ColumnBase.choice_queryset(**kwargs)
def foreign_key_factory(model_field, **kwargs): setdefaults(kwargs, dict( choices=model_field.foreign_related_fields[0].model.objects.all() )) kwargs['model'] = model_field.foreign_related_fields[0].model return Column.choice_queryset(**kwargs)