V
V
vikholodov2018-03-16 20:14:21
Django
vikholodov, 2018-03-16 20:14:21

How to make a menu with GenericForeignKey?

Hello!
It is necessary to make editing the site menu convenient for the admin, like on wodpress, for example. I started to move towards GenericForeignKey, but manually choosing the object id can hardly be called convenient. I'm thinking of somehow implementing the selection of an instance of the select type within the framework of 4 models, i.e. replace object_id = models.PositiveIntegerField() with something more elegant

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2018-03-16
@vikholodov

do not make any Foreign keys and other objects.
Do a regular model with a url field. It is much simpler and clearer, and the structure in the database will be normal.
There are also ready-made menus https://djangopackages.org/grids/g/navigation/ , you can use any of them.
Well, if you really want a selection by objects, just add a custom modal window in the admin panel
with lists of objects. When you select an object, generate a url based on it and create a menu item with this url (You don't need to link anything)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question