You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i try to achieve something that should be simple to do but i cant.
classObjectDataView(BaseView):
@expose('/')defindex(self):
returnself.render('path/to/index.html')
@expose('/<int:object_id>/')defobject_data(self, object_id):
object=Objects.query.get(object_id)
returnself.render('path/to/object_render_data.html', object=object')
# Get all objects and group them under 1 category# Each object then will get his own page where we render the data it containsobjects=Objects.query.all()
forobjectinobjects:
admin.add_view(ObjectDataView(name=object.name,
category='Objects',
endpoint=f'object_data/{object.id}',
url=f'object_data/{object.id}',)
With the code above, what I achieve is:
Category is created with all objects and when I select any I get routed to: http://127.0.0.1:5000/admin/object_data/99/ (or any other ID from the selected in the dropdown)/ which renders the index.html
if I manually edit the URL to include another ID: http://127.0.0.1:5000/admin/object_data/99/99/ - I get routed to object_render_data.html Which is what i want to achieve in the first place.
If i change the url url='object_data' i get redirected again to the index and if i add manually the object id object_data/99 i will go to the page i want.
I also tried creating them as menu links. Then I get to the specified route and receive the id, but then if i want to extend the flask admin template, I can't and i dont really want to do it that way.
It looks like you're creating an data view for each individual object - you don't need to do this. You create a single object data view, and it will work for any instance of your Object class.
It's possible you're intentionally doing what you're doing, in order to have a link for each specific object in the title bar, but I think this is probably not the right approach. Have you tried something more like what I've got above?
Hi, i try to achieve something that should be simple to do but i cant.
With the code above, what I achieve is:
Category is created with all objects and when I select any I get routed to:
http://127.0.0.1:5000/admin/object_data/99/ (or any other ID from the selected in the dropdown)/ which renders the
index.html
if I manually edit the URL to include another ID:
http://127.0.0.1:5000/admin/object_data/99/99/ - I get routed to
object_render_data.html
Which is what i want to achieve in the first place.If i change the url
url='object_data'
i get redirected again to the index and if i add manually the object idobject_data/99
i will go to the page i want.I also tried creating them as menu links. Then I get to the specified route and receive the id, but then if i want to extend the flask admin template, I can't and i dont really want to do it that way.
What I am missing or doing wrong?
Any help appreciated!
Thanks!
The text was updated successfully, but these errors were encountered: