mirror of
https://github.com/jeffknupp/sandman2.git
synced 2026-04-26 00:55:53 +03:00
[GH-ISSUE #55] Documentation for defining foreign key strings in the admin site is soooo close... #35
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
pull-request
question
refactoring
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/sandman2-jeffknupp#35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abegong on GitHub (Dec 31, 2016).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/55
In the admin interface, I need the foreign keys to show something more informative than
<flask_sqlalchemy.users object at 0x7fdec43e6c90>.Chapter 4 of the latest docs describes a fix for this problem. Unfortunately, the docs are incomplete.
I've tried to implement the fix, but haven't been able to get it to work. Editing models.py is not enough, and I'm not deeply familiar with the abstractions for SQLAlchemy and Flask-SQLAlchemy. Even after a couple hours of probing, I haven't been able to make sense of where to inject my edits.
Thanks!
@DanielJoyce commented on GitHub (Feb 15, 2017):
Still doesn't tell us where to put models.py, or how to get sandman2ctl to load and use it. This bug is still valid.
@time-less-ness commented on GitHub (Mar 23, 2017):
I modified the
models.pythat was included with thepippackage and put the classes at the bottom. But when I do, the top-level table disappears from the list of tables.All the existing data looks nice, and the foreign key references do what they should, at the expense of no longer being able to query the table itself anymore.
I tried putting the Class extensions into
/usr/local/bin/sandman2ctlas well, which worked precisely the same way.@time-less-ness commented on GitHub (Mar 23, 2017):
It occurs to me that FK-referenced tables are meant to be static within the view of Sandman2's admin interface. So in order to fix my problem above, I run two instances of Sandman2, one with my FK-referenced tables without any Class extension, so that I can edit those tables, and another with them, so that I can edit the relationships sensibly.
It seems weird, but it does work.
@PieterVeldman commented on GitHub (Jun 23, 2017):
Hi,
@abegong, I had a similar problem because I used to get "<sandman2.models.Employee object at ...>" in foreign keys in the admin view. Found out that I had to overwrite the str method instead of unicode method in models.py. I don't know why it is so, I just made a lucky guess that turned out to be correct.
As in your case, it didn't solve the issue right away. I had to modify run.py in order to list the tables.
run.py
app = get_app('sqlite+pysqlite:///tests/data/db.sqlite3', user_models=[ Artist, Album,Customer, Employee, Genre, Invoice, InvoiceLine, MediaType, Playlist, Track])instead of
#app = get_app('sqlite+pysqlite:///tests/data/db.sqlite3')In models.py , I addedd the str_ method.
models.py
...
...
Maybe this will work for you, @philovivero.
Thanks @jeffknupp for this great tool.