def generate_table(self):
        model_class = self.get_model_class()

        detail_url_name = '{}-{}-detail'.format(
            self.app, custom_postfix_url(self.crud(), self.model)
        )

        main_attrs = dict(
            id=tables.LinkColumn(detail_url_name, args=[A('pk')])
        )

        meta_attrs = dict(
            model=model_class,
            fields=('id',) + self.tables2_fields if self.tables2_fields else ('id',),
            attrs={
                "class": self.tables2_css_class,
                "empty_text": "No {} exist".format(plural(self.model))
            })

        main_attrs['Meta'] = type('Meta', (), meta_attrs)
        klass = type(
            model_class_form(self.model + 'Table'),
            (tables.Table,),
            main_attrs
        )
        return klass
Beispiel #2
0
    def generate_table(self):
        model_class = self.get_model_class()

        detail_url_name = '{}-{}-detail'.format(
            self.app, custom_postfix_url(self.crud(), self.model))

        main_attrs = dict(
            id=tables.LinkColumn(detail_url_name, args=[A('pk')])
            # uuid=tables.LinkColumn(detail_url_name, args=[A('uuid')]) #'uuid' replaced 'id'
        )

        meta_attrs = dict(
            model=model_class,
            fields=('id', ) + self.tables2_fields if self.tables2_fields else
            ('id', ),
            # fields=self.tables2_fields, #Exclude 'id' in table field
            attrs={
                "class": self.tables2_css_class,
                "empty_text": "No {} exist".format(plural(self.model))
            })

        main_attrs['Meta'] = type('Meta', (), meta_attrs)
        klass = type(model_class_form(self.model + 'Table'), (tables.Table, ),
                     main_attrs)
        return klass
Beispiel #3
0
 def postfix_url(self):
     return helpers.custom_postfix_url(self.crud(), self.model)
 def _model_key(self, model, crudbuilder):
     app_label = model._meta.app_label
     model_name = model.__name__.lower()
     postfix_url = helpers.custom_postfix_url(crudbuilder(), model_name)
     return '{}-{}-{}'.format(app_label, model_name, postfix_url)
 def postfix_url(self):
     return helpers.custom_postfix_url(self.crud(), self.model)