mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
d923d84754
commit
9bd39672de
1 changed files with 10 additions and 2 deletions
|
|
@ -647,8 +647,16 @@ class Datasette:
|
||||||
return explicit_label_column
|
return explicit_label_column
|
||||||
# If a table has two columns, one of which is ID, then label_column is the other one
|
# If a table has two columns, one of which is ID, then label_column is the other one
|
||||||
column_names = await self.table_columns(db_name, table)
|
column_names = await self.table_columns(db_name, table)
|
||||||
if column_names and len(column_names) == 2 and "id" in column_names:
|
# Is there a name or title column?
|
||||||
return [c for c in column_names if c != "id"][0]
|
name_or_title = [c for c in column_names if c in ("name", "title")]
|
||||||
|
if name_or_title:
|
||||||
|
return name_or_title[0]
|
||||||
|
if (
|
||||||
|
column_names
|
||||||
|
and len(column_names) == 2
|
||||||
|
and ("id" in column_names or "pk" in column_names)
|
||||||
|
):
|
||||||
|
return [c for c in column_names if c not in ("id", "pk")][0]
|
||||||
# Couldn't find a label:
|
# Couldn't find a label:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue