In Anqi CMS, the content model is the core element for building the website content structure, which provides strong flexibility, allowing you to customize the fields and display methods of content according to different business needs (such as publishing articles, displaying products, managing events, etc.).Understand and make good use of this feature, it will greatly enhance the management efficiency and display effect of your website content.

Understanding the content model of Anqi CMS

In 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, an ordinary article may only need the title, author, publication time, content, and other fields;And a product may need more detailed fields such as product name, price, stock, brand, and multiple images.The AnQi CMS provides the basic models of 'article model' and 'product model' 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) must belong to a "category", and each "category" must be associated with a specific "content model".This way, when you post a document 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 find the "Content Model" item.Here, you can view and modify the built-in models of the system, as well as add new custom models.

  1. Create or modify the basic information of the model:

    • Model name:This is the model name displayed in the background management interface for you to see, it should clearly reflect the content type managed by the model, such as 'Real Estate Information', 'Course List', etc.
    • Model table name:This is the table name stored in the database for model data. For system compatibility and practical considerations, it is recommended to use all lowercase English letters.Once set, it is usually not recommended to change it, as it directly affects the data storage structure.
    • URL alias:This field is used for URL static rules, such as in/product/{id}.html,productIt is the URL alias. It is recommended to use English lowercase letters, which helps to 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 document under this model.For example, if the model is "product", you can set it to "product name" to make it clear to the content editor.
  2. Define custom fields - the core of the content model:The true 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”, “source of article”, etc.
    • Number:Used for inputting numbers, such as "product price", "inventory quantity", "reading time", etc., the system will automatically perform numerical verification.
    • Multi-line text:Text suitable for long content, such as 'Product Introduction', 'Author Introduction', etc., which can accommodate more text.
    • Single choice (radio button/dropdown selection):Allow the user to select one from multiple preset options, such as 'Product color', 'Article type (news/review/tutorial).'When setting the default value, just enter each option on a separate line.
    • Multiple selection (checkbox):Allow users to select multiple options from predefined ones, such as 'Product features (waterproof/dustproof/durable)' and 'Article tags (technology/marketing/operations).'Similarly, each option is on a separate line when setting the default value.

    When adding each custom field, you can also set 'whether required' to ensure the integrity of key information, and provide a 'default value' for quick filling by content editors when publishing.For example, add a "price" field (type: number, required) to the "product model", a "brand" field (type: single-line text, default value: AnQi Technology), and a "product features" field (type: multiple selection, default value: efficient, stable, secure).

Combination of content model and content publishing process

After 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.

  1. Associated 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" model, you can create a category named "New Listing" and associate it with the "Real Estate Information" model.
  2. Publish documents:When you post a document under the "New Listing" category, in addition to the usual fields such as title and content, you will also see those custom fields defined in the "Real Estate Information" model, such as "type", "area", "price", "location", and so on.The content editor can fill in these fields based on the actual property information.

In this way, 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

After customizing the content model and filling in the data, the most critical step is to display this information on the website's frontend page.AnQi CMS uses Django template engine syntax, providing flexible tags to help you achieve this.

  1. Display on 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 the custom field.

    • If you want to display a specific custom field, such as "Product Price", and the field name defined in the model isPriceHow to call:{{archive.Price}}.
    • For fields of multiple choice, single choice, or dropdown types, if you need to display all selected items in a loop, you may need to use loop tags in conjunction.
  2. Dynamically loop to display all custom parameters:If your content model contains multiple custom fields and you want to display all these fields in a single area (such as the 'specifications parameters' column on the product details page) without manually calling them one by one, thenarchiveParamsTags 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 traverse the current document(archiveAll custom parameters, and display them one by one in the form of "parameter name" and "parameter value".This is especially useful for displaying product 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.

  3. Filter and display on the document list page:Custom fields can not only be used for detail page display, but can also be combined witharchiveFiltersTag, provides powerful filtering functionality on the list page. For example, a real estate information list page