In AnQi CMS, the content model is the core element for constructing the website content structure, providing strong flexibility that allows you to customize the fields and display methods of content according to different business needs (such as publishing articles, displaying products, managing activities, etc.).Understand and make good use of this feature, which will greatly enhance the management efficiency and display effect of your website content.
Understanding the content model of Aqii CMS
In the AnQi CMS, the content model can be regarded as the 'blueprint' or 'skeleton' of the content.It defines what information fields should be included in a certain type of content.For example, a regular article may only need a title, author, publication time, and content fields; while a product may require more detailed fields such as product name, price, stock, brand, and multiple images.The "article model" and "product model" are two basic models provided by Anqi CMS by default, but its strength lies in the fact that you can completely customize new content models according to your actual needs.
The content model is not the content itself, but the structural definition of the content.All content (referred to as 'documents' in AnQi CMS) needs to be assigned to a 'category', and each 'category' must be associated with a specific 'content model'.Here, when you publish documents under a certain category, the system will automatically provide the corresponding fields for you to fill in based on the content model associated with that category.
How to customize the content model
To start customizing the content model, you need to go to the "Content Management" section of the admin interface, and then find the "Content Model" option.Here, you can view, modify the built-in models of the system, and also add new custom models.
Create or modify the basic information of the model:
- Model name:This is the model name displayed in the background management interface for your reference, it should clearly reflect the content type managed by the model, such as "Real Estate Information
- Model Table Name:This is the table name stored in the database for the model data.For system compatibility and**practical considerations, it is recommended to use full English lowercase letters.Once set, it is generally not recommended to change it, as it directly affects the storage structure of the data.
- URL Alias:This field will be used in URL rewrite rules, such as in
/product/{id}.htmlin,productThis is the URL alias. It is also recommended to use English lowercase letters, which helps optimize the website's URL structure and improve SEO friendliness. - Title Name:This is the prompt text in the document title input box when publishing the model.For example, if the model is “product”, you can set it to “product name” so that content editors can see it at a glance.
Define custom fields—the core of content models:The real magic lies in custom fields.These fields determine what personalized information your content can include.Click the "Content Model Custom Field" area, where you can add various types of fields to meet the needs of different business scenarios.
- Single-line text:Suitable for short text inputs, such as “product brand”, “author name”, “article source”, and so on.
- Numbers:Used for inputting numbers, such as "product price
- Multi-line text:Suitable for longer text content, such as 'Product Introduction', 'Author Introduction', etc., which can accommodate more text.
- Single choice (radio button/dropdown selection):Allow users to select one from a preset list of options, for example “Product color”, “Article type (news/review/tutorial)”.When setting default values, just input each option on a separate line.
- Multiple choice (checkbox):Allow users to select multiple options from predefined options, such as “Product Features (Waterproof/Dustproof/Durable)”,”Article Tags (Technology/Marketing/Operation)”.Similarly, each option is on a separate line when setting the default value.
When adding each custom field, you can also set 'Required' to ensure the completeness of key information, and provide 'Default Value' for quick filling by content editors when publishing.For example, add the 'Price' field (type: number, required) to the 'Product Model', the 'Brand' field (type: single-line text, default value: AnQi Technology), and the 'Product Features' field (type: multiple selection, default values: efficient\nstable\nsafe).
Combination of content model and content release process
When you define a content model and add custom fields to it, these fields will not be displayed on the front-end page immediately.They need to be cleverly combined with 'Categories' and 'Documents' at the time of content publishing.
- Related categories:You need to create a new category (or edit an existing category) and associate it with your custom content model.For example, if you create a "Real Estate Information
- Published documents:When you publish a document under the 'New Listings' category, in addition to the usual fields such as title and content, you will also see custom fields defined in the 'Property Information' model, such as 'Layout', 'Area', 'Price', and 'Location' etc.The content editor can fill in these fields based on the actual property information.
Through this method, the custom fields of the content model will only appear after you have selected the corresponding category, greatly simplifying the content editing interface and avoiding unnecessary field interference.
Display custom fields in the front-end template
Customize the content model and fill in the data, the most critical step is to display this information on the front-end page of the website.The Anqi CMS uses Django template engine syntax and provides flexible tags to help you achieve this.
Display in the document detail page:In the document detail page template (usually)
{模型table}/detail.htmlfor examplearticle/detail.htmlorproduct/detail.html), you can directly call the document objectarchiveto call custom fields.- If you want to display a specific custom field, such as “Product Price”, and the calling field defined in the model is
Price,you can call it like this:{{archive.Price}}. - For fields of multiple choice, single choice, or dropdown choice types, if you need to cyclically display all selected items, you may need to use loop tags in conjunction.
- If you want to display a specific custom field, such as “Product Price”, and the calling field defined in the model is
Dynamic loop to display all custom parameters:If your content model includes multiple custom fields, and you want to display all these fields in a single area (such as the 'specification parameters' section on a product details page) without manually calling each one, then
archiveParamsTags are very convenient.{% archiveParams params %} <div> {% for item in params %} <div> <span>{{item.Name}}:</span> <span>{{item.Value}}</span> </div> {% endfor %} </div> {% endarchiveParams %}This code will iterate over the current document (
archiveThe custom parameters of the ) are displayed one by one in the form of "parameter name" and "parameter value".This is particularly useful for displaying product detailed specifications, house details, and other scenarios. Even if new custom fields are added in the future, there is no need to modify the template code; the system will automatically adapt.Filter and display in the document list page:Custom fields can not only be used for detail page display, but also combined
archiveFiltersTags, providing powerful filtering functions on list pages. For example, a real estate information list page