[Fixed]-How to use custom made django template tags inside django-tables2?

1👍

If you want additional field in your table – try this

class YourModel(models.Model):
    # here your fields

    @property
    def total_date(self):
        fmt = '%Y-%m-%d %H:%M:%S'
        if self.date_start is not None and self.date_end is not None:
            ds = str(self.date_start)
            new_ds = ds[:19]
            de = str(self.date_end)
            new_de = de[:19]
            date_start = datetime.strptime(new_ds, fmt)
            date_end = datetime.strptime(new_de, fmt)

            return date_end - date_start
        else:
            return None

Then add it to your table class fields

class YourTableClass(tables.Table):
    total_date = tables.Column(verbose_name='Total date')

    class Meta:
        model = YourModel

Leave a comment