Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin_ui/src/components/RowFormSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}"
class="add"
target="_blank"
v-if="!isFilter"
v-if="!isFilter && getKeySelectID(property.title)"
>
<font-awesome-icon icon="edit" />
</router-link>
Expand Down
4 changes: 2 additions & 2 deletions admin_ui/src/views/RowListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@
<span
class="link"
v-else-if="
isForeignKey(name) & (row[name] !== null)
isForeignKey(name) & (row[pkName] !== null)
"
>
<router-link
:to="{
name: 'editRow',
params: {
tableName: getTableName(name),
rowID: row[name]
rowID: row[pkName]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought so before, but the rowID: row[pkName] is the primary key of the Review table, not Review.movie.id.
I wrote in the comment the changes I think we need to make in Piccolo API to get correct results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - it took a while for me to realise this. My solution doesn't work.

}
}"
>{{ row[name + "_readable"] }}</router-link
Expand Down
31 changes: 27 additions & 4 deletions piccolo_admin/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
from pydantic import BaseModel, validator

from piccolo_admin.endpoints import FormConfig, TableConfig, create_admin
from piccolo_admin.example_data import DIRECTORS, MOVIE_WORDS, MOVIES, STUDIOS
from piccolo_admin.example_data import (
DIRECTORS,
MOVIE_WORDS,
MOVIES,
REVIEWS,
STUDIOS,
)


class Sessions(SessionsBase):
Expand Down Expand Up @@ -75,7 +81,7 @@ def get_readable(cls):

class Studio(Table, help_text="A movie studio."):
pk = UUID(primary_key=True)
name = Varchar()
name = Varchar(unique=True)
facilities = JSON()


Expand All @@ -90,7 +96,7 @@ class Genre(int, enum.Enum):
romance = 7
musical = 8

name = Varchar(length=300)
name = Varchar(length=300, unique=True)
rating = Real(help_text="The rating on IMDB.")
duration = Interval()
director = ForeignKey(references=Director)
Expand All @@ -104,6 +110,21 @@ class Genre(int, enum.Enum):
genre = SmallInt(choices=Genre, null=True)
studio = ForeignKey(Studio)

@classmethod
def get_readable(cls):
return Readable(template="%s", columns=[cls.name])


class Review(Table):
reviewer = Varchar()
content = Text()
rating = Integer()
movie = ForeignKey(Movie, target_column=Movie.name)

@classmethod
def get_readable(cls):
return Readable(template="%s %s", columns=[cls.reviewer, cls.rating])


class BusinessEmailModel(BaseModel):
email: str
Expand Down Expand Up @@ -176,6 +197,7 @@ async def booking_endpoint(request, data):
Director,
Movie,
Studio,
Review,
User,
Sessions,
)
Expand Down Expand Up @@ -208,7 +230,7 @@ async def booking_endpoint(request, data):
)

APP = create_admin(
[movie_config, director_config, Studio],
[movie_config, director_config, Studio, Review],
forms=[
FormConfig(
name="Business email form",
Expand Down Expand Up @@ -261,6 +283,7 @@ def populate_data(inflate: int = 0, engine: str = "sqlite"):
Director.insert(*[Director(**d) for d in DIRECTORS]).run_sync() # type: ignore # noqa: E501
Movie.insert(*[Movie(**m) for m in MOVIES]).run_sync() # type: ignore
Studio.insert(*[Studio(**s) for s in STUDIOS]).run_sync() # type: ignore
Review.insert(*[Review(**r) for r in REVIEWS]).run_sync() # type: ignore

if engine == "postgres":
# We need to update the sequence, as we explicitly set the IDs for the
Expand Down
21 changes: 21 additions & 0 deletions piccolo_admin/example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@
}
]

REVIEWS = [
{
"reviewer": "John McCloud",
"content": "Great film - loved the ending!",
"rating": 5,
"movie": MOVIES[0]['name']
},
{
"reviewer": "Penelope Jones",
"content": "The special effects blew me away.",
"rating": 4,
"movie": MOVIES[1]['name']
},
{
"reviewer": "Arnold Adams",
"content": "It was good. I enjoyed the plot.",
"rating": 3,
"movie": MOVIES[2]['name']
},
]


# Some random words used to generate fake movie names.
MOVIE_WORDS = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_tables(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json(),
["movie", "director", "studio"],
["movie", "director", "studio", "review"],
)

def test_get_user(self):
Expand Down