mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Handle multiple m2m args of same name
e.g. ?_m2m_ad_targets__target_id=ec3ac&_m2m_ad_targets__target_id=e128e
This commit is contained in:
parent
0cf91e3f88
commit
04c7fd6207
1 changed files with 11 additions and 10 deletions
|
|
@ -305,7 +305,7 @@ class TableView(RowTableShared):
|
||||||
where_clauses, params = filters.build_where_clauses()
|
where_clauses, params = filters.build_where_clauses()
|
||||||
|
|
||||||
# Hacky thing for ?_m2m_ad_targets__target_id=9a8c6
|
# Hacky thing for ?_m2m_ad_targets__target_id=9a8c6
|
||||||
for m2m_key in special_args:
|
for m2m_key in request.args:
|
||||||
if m2m_key.startswith("_m2m_"):
|
if m2m_key.startswith("_m2m_"):
|
||||||
rest = m2m_key.split("_m2m_", 1)[1]
|
rest = m2m_key.split("_m2m_", 1)[1]
|
||||||
m2m_table, other_column = rest.split("__", 1)
|
m2m_table, other_column = rest.split("__", 1)
|
||||||
|
|
@ -317,16 +317,17 @@ class TableView(RowTableShared):
|
||||||
# if fk["other_table"] != table
|
# if fk["other_table"] != table
|
||||||
# and fk["other_column"] == other_column
|
# and fk["other_column"] == other_column
|
||||||
# ][0]
|
# ][0]
|
||||||
value = special_args[m2m_key]
|
for value in request.args[m2m_key]:
|
||||||
# Figure out what the columns are in that m2m table
|
# Figure out what the columns are in that m2m table
|
||||||
where_clauses.append(
|
where_clauses.append(
|
||||||
'{our_pk} in (select {our_pk} from {m2m_table} where {other_column} = "{value}")'.format(
|
'{our_pk} in (select {our_column} from {m2m_table} where {other_column} = "{value}")'.format(
|
||||||
m2m_table=escape_sqlite(m2m_table),
|
m2m_table=escape_sqlite(m2m_table),
|
||||||
our_pk=fk_to_us["other_column"],
|
our_pk=fk_to_us["other_column"],
|
||||||
other_column=escape_sqlite(other_column),
|
our_column=fk_to_us["column"],
|
||||||
value=value,
|
other_column=escape_sqlite(other_column),
|
||||||
|
value=value,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# _search support:
|
# _search support:
|
||||||
fts_table = info[name]["tables"].get(table, {}).get("fts_table")
|
fts_table = info[name]["tables"].get(table, {}).get("fts_table")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue