Search code examples
pythondjangosortingdjango-tables2

Django-tables2 Sorting TemplateColumn


Is it somehow possible, to add custom sort method to values generated using TemplateColumn? because on basic it tries to find column name in model and returns FieldError: Cannot resolve keyword u'coulmn_name' into field. Choices are: [all fields in model].


Solution

  • try with the same name as the column field name in the model

    model:

    class YourModel(models.Model):
        field_column = models.CharField()
    

    table

    class YourTable(tables.Table):
        field_column = tables.TemplateColumn(''' your custom ''', verbose_name='your desire name')
    
        class Meta:
            model = YourModel
    

    it's work for me