M
M
Michael2014-05-22 13:14:47
MongoDB
Michael, 2014-05-22 13:14:47

How to implement dynamic menu items on a website using mongoengine and flask?

Hello, it is necessary to implement dynamic rendering of menu items from the database.
Well, that is, there are two sections on the site "One" and "Two" - you need to dynamically add them.
Each of these sections has its own menu with its own items.
It is necessary that both sections and menu items and submenus can be added dynamically.
And how to store all this in the database?
mongoDB base

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2014-05-22
@nextel

In my opinion, nested documents EmbeddedDocument
are well suited here . Example:

class MenuItem(EmbeddedDocument):
    name = StringField()
    url = StringField()
    sub = ListField(EmbeddedDocumentField('self'))

class Menu(Document):
    items = ListField(EmbeddedDocumentField(MenuItem))

Accordingly, this model should be enough for all menus with subsections. Instead of url, you can use slug and generate a url depending on the depth of occurrence of a menu sub-item.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question