Skip to content

Commit 9b20001

Browse files
committed
refactor link_column
1 parent 1ed7062 commit 9b20001

File tree

3 files changed

+21
-48
lines changed

3 files changed

+21
-48
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Experimenting with using a dockerized Piccolo Admin with an existing (legacy) database.
1+
Dockerized Piccolo Admin to use existing (legacy) database.
22

33
### Usage
44

@@ -41,12 +41,12 @@ tables:
4141
# An example of additional Piccolo Admin configuration
4242
Actor:
4343
visible_columns:
44-
- actor_id
4544
- first_name
4645
visible_filters:
4746
- actor_id
4847
- first_name
4948
menu_group: Movies
49+
link_column: first_name
5050
Address:
5151
visible_columns:
5252
- address_id
@@ -57,6 +57,7 @@ tables:
5757
- address
5858
- city_id
5959
menu_group: Location
60+
rich_text_columns: address
6061
City:
6162
visible_columns:
6263
- city_id
@@ -73,6 +74,10 @@ tables:
7374
- country_id
7475
- country
7576
menu_group: Location
77+
78+
sidebar_links:
79+
Piccolo Admin: https://piccolo-admin.readthedocs.io/en/latest/index.html
80+
Piccolo ORM: https://piccolo-orm.readthedocs.io/en/latest/index.html
7681
```
7782
7883
For these changes to take effect, you must stop the container and rebuild it with.

app/main.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,17 @@ async def main():
119119
except TypeError:
120120
rich_text_columns = None
121121
# link column
122-
link_column = [
123-
column
124-
for column in table._meta.columns
125-
if column._meta.name
126-
== BASE_CONFIG[capitalize_table_name].get("link_column", None)
127-
]
122+
try:
123+
link_column = [
124+
column
125+
for column in table._meta.columns
126+
if column._meta.name
127+
== BASE_CONFIG[capitalize_table_name].get(
128+
"link_column", None
129+
)
130+
][0]
131+
except IndexError:
132+
link_column = None
128133
# menu_group
129134
menu_group = BASE_CONFIG[capitalize_table_name].get(
130135
"menu_group", None
@@ -136,7 +141,7 @@ async def main():
136141
visible_columns=visible_columns,
137142
visible_filters=visible_filters,
138143
rich_text_columns=rich_text_columns,
139-
link_column=None if link_column == [] else link_column[0],
144+
link_column=link_column,
140145
menu_group=menu_group,
141146
)
142147
)

config.yaml

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,4 @@
11
tables:
2-
# An example of additional Piccolo Admin configuration
3-
# Actor:
4-
# visible_columns:
5-
# - actor_id
6-
# - first_name
7-
# visible_filters:
8-
# - actor_id
9-
# - first_name
10-
# menu_group: Movies
11-
# link_column: first_name
12-
# Address:
13-
# visible_columns:
14-
# - address_id
15-
# - address
16-
# - city_id
17-
# visible_filters:
18-
# - address_id
19-
# - address
20-
# - city_id
21-
# menu_group: Location
22-
# rich_text_columns: address # it only works in the Text type column
23-
# City:
24-
# visible_columns:
25-
# - city_id
26-
# - city
27-
# visible_filters:
28-
# - city_id
29-
# - city
30-
# menu_group: Location
31-
# Country:
32-
# visible_columns:
33-
# - country_id
34-
# - country
35-
# visible_filters:
36-
# - country_id
37-
# - country
38-
2+
# Additional tables configurations go here
393
sidebar_links:
40-
# Piccolo Admin: https://piccolo-admin.readthedocs.io/en/latest/index.html
41-
# Piccolo ORM: https://piccolo-orm.readthedocs.io/en/latest/index.html
4+
# External links go here

0 commit comments

Comments
 (0)