Skip to content

Commit

Permalink
Added model field by default when using queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealVizard committed Aug 6, 2022
1 parent c407fe5 commit 2af4af1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions django_table_sort/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
column_css_clases: str = "text-center",
table_css_clases: str = "table",
table_id: Union[str, None] = None,
**kwargs,
):
self.request = request
self.object_list = object_list
Expand All @@ -25,6 +26,12 @@ def __init__(
self.column_names = column_names
self.table_css_clases = table_css_clases
self.table_id = table_id
if column_names is None and isinstance(object_list, QuerySet):
self.column_names = {
field.name: field.verbose_name.title()
for field in object_list.model._meta.fields
if not field.primary_key or kwargs.get("show_primary_key", False)
}

def __str__(self):
"""Returns the table in HTML format."""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-table-sort"
version = "0.2.0"
version = "0.2.1"
description = "Create tables with sorting on the headers in Django templates."
authors = ["TheRealVizard <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 2af4af1

Please sign in to comment.