A
A
Alexander Vinogradov2017-02-11 09:58:18
Django
Alexander Vinogradov, 2017-02-11 09:58:18

How to assign menu content type?

Good evening or afternoon.
I am writing a site, the menu items of which will be created by the admin at any time, as well as changed / deleted, etc.
Having created the "catalog" menu item, for example, you will need to specify the content type of the page of this directory. The type of page content will be something like this: catalog - the page displays a gallery of product pictures with a description; article - plain formatted text; etc.
When you select a content type, select boxes will appear according to the content type. For example, there is a model catalog - containing a list of goods with pictures and descriptions. There is an articles model containing articles - text.
For the menu, a MenuCategory model has been created, which is currently associated with the ContentType table - the content type. The ContentType model contains the fields: name, template, model, model_fields.

  • template - a field containing the name of the template files for the page
  • model - a field containing the name of the model (eg catalogue)
  • model_fields - a list of fields from model to model that should appear in the admin area to select a directory or become or otherwise.

How now to connect the MenuCategory model with models from the model field of the ContentType table? Or how to do it right, because. I feel like I'm doing something wrong.
Push on the right path theoretically.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2017-02-11
@sim3x

Model names in the singular
Article
Catalog
No need to dynamically link models
Usecase

By creating a menu item "catalog", for example, you will need to specify the content type of the page of this directory
no one will use it - dzhanga is not jumla
model_fields - a list of fields from model to model that should appear in the admin area to select a directory or become or otherwise.
read how fields for editing are managed in the junga admin panel
Strictly speaking, you need to add a field to the Article, Catalog models
is_show_in_menu = BooleanField(...and transfer a list of those records to the template from the view that you want to show in the menu

P
Pan Propan, 2017-02-11
@mgis

Isn't it better to use something ready- made .

A
Alexander Vinogradov, 2017-02-14
@ruchej

Thank you for your help.
So far I have decided to go the following way.
Because the layout of the site and its content must be initially developed, then the menu sections must be initially defined. For example, we have the main menus: main, catalog, interesting, about the company.
For the "catalog" menu, I did this.
The Catalog model has been created. It contains product catalogs with subdirectories. Here I used mptt. As a result, I can get a Kitchen catalog with subdirectories: plastic, veneer, etc.
When creating a page layout, I connect tree lists from the Catalog model to the Catalog menu using mptt. Links to each section of the directory is an id in the database. Further, through the view, I process these links, as in the lesson of the official documentation.
It’s still easier, besides, the admin panel is not a website builder, like Joomla.
I looked at the proposed version of the finished menu module, though briefly, there was no menu creation through the admin panel in the example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question