In the Anqi CMS, the flexibility of the content model is one of its core advantages. It not only helps us manage traditional articles and product information, but also allows us to create highly personalized content types based on actual business needs.Customizing article model fields is the key step to achieve this personalized display.

The essence of content operation is to provide users with the information they truly need and present it in the most intuitive and attractive way.Imagine if your website needs to display movie reviews, in addition to movie names and summaries, you may also need special fields such as 'director', 'starring', 'release date', 'rating', and so on.If it is a real estate website, in addition to the basic introduction, you would expect to have information such as 'layout', 'area', 'orientation', and 'price range'.The custom model field function of AnQi CMS is designed to meet these diverse content needs.

Deep understanding of content model and custom fields

In the AnQi CMS, the content model is like a "blueprint" or "structure definition" for the content of your website.The system defaults to providing "article" and "product" two basic models, but this often cannot meet the unique needs of business.Custom fields allow us to add exclusive 'details' to these blueprints, making the content more structured and expressive.

Why do we need it?

  • Structured data:Let every piece of content have a unified and standardized data structure, making it convenient for management and retrieval.
  • Personalized display:Display the unique properties of different types of content to enhance user experience.
  • Efficient operation:When editing content on the backend, just fill in the corresponding fields, reducing manual layout and repetitive work.
  • Strong expandability:Lay a solid foundation for future functional expansion (such as filtering, search, etc).

Create and manage custom model fields

In the AnQi CMS, the process of managing custom fields is intuitive and efficient.

  1. Enter the content model management:Log in to the CMS backend, navigate to the "Content ManagementHere you will see a list of all content models created, including built-in and customized ones.

  2. Select or create a model:

    • Edit existing model:If you want to add more fields to the "Article" or "Product" model, simply click the "Edit" button on the right of the corresponding model.
    • Create a custom model:If you need a completely different content type (such as "eventAt creation, you need to set the 'Model Name', 'Model Table Name' (recommended in lowercase English), 'URL Alias', and the 'Title Name' displayed when publishing content.These are the metadata of the model.
  3. Add custom fields:Enter the model editing page and scroll down to find the "Content Model Custom Fields" area.This is the place for defining exclusive properties.

    • Parameter name:This is the Chinese name displayed on the back-end for editors, such as 'Film Director', 'Real Estate Area'.
    • Field call: This is the most important part!It is the unique identifier for calling the field value in the template, make sure to use lowercase English letters. For example, if you define "director", the field name can bedirectorIf the 'Release Date' is defined, it can berelease_date.
    • Field Type:Anqi CMS provides various field types to adapt to different data:
      • Single-line text:Applicable to short text information, such as “brand”, “model”.
      • Numbers:Only input numbers, such as “price”, “stock”.
      • Multi-line text:Suits for longer descriptive text, such as "Detailed Introduction
      • Single choice/multiple choice/dropdown selection:Applicable to preset options, such as “Color (red, blue, green)”,”Type (one bedroom, two bedrooms, three bedrooms)”.”Enter each option on a new line under “Default value”.
    • Mandatory:According to content importance, ensure that key information is not missed.
    • Default value:Set preset values for the field, which can be directly used or modified during editing.

    After defining the field, remember to click save.

Fill in personalized content data

After you add custom fields in the content model, these fields will automatically appear in the content publishing and editing interface.

  1. Publish or edit documents:Enter "Content Management" under "Publish Document", or edit an existing document.
  2. Select the corresponding category:Ensure that the "Category" you select is based on the content model you modify or create. Only then will the corresponding custom fields be displayed.
  3. Enter the "Other Parameters":At the bottom of the document editing page, there is usually a collapsible area called "Other Parameters.Expand it, and you will find that all the custom fields you just created are neatly arranged here, just fill in the corresponding data according to the prompts.

Display personalized content in the template

The value of the custom field is ultimately reflected in the personalized display on the front-end page.The template system of Anqi CMS supports Django template engine syntax, utilizing its powerful tags and filters, you can easily present these custom data to the users.

  1. Invoke a single custom field:If you want to display a specific custom field on the content detail page (for example)archive/detail.html) such as "Movie Director" ()director), you can usearchiveDetailTags:

    <p>导演:{% archiveDetail with name="director" %}</p>
    

    Here,name="director"It corresponds to the 'call field' you set in the background. The system will automatically retrieve the current document'sdirectorfield value and display it. You can also assign it to a variable for use:

    {% archiveDetail movieDirector with name="director" %}
    {% if movieDirector %}
        <p>导演:{{ movieDirector }}</p>
    {% endif %}
    
  2. Loop to display all custom fields:In some cases, you may wish to display all non-empty custom fields in an area or present them as a list. At this time,archiveParamsThe tag can be put into use, it can get the collection of all custom fields in the current document, and output them through a loop:

    <h3>电影参数</h3>
    <ul>
    {% archiveParams params with sorted=true %} {# sorted=true 保持后台定义顺序 #}
        {% for item in params %}
            {# 假设有些字段您不希望显示,可以这样排除 #}
            {% if item.Name != '内部备注' %}
                <li>{{ item.Name }}:{{ item.Value }}</li>
            {% endif %}
        {% endfor %}
    {% endarchiveParams %}
    </ul>
    

    Hereitem.NameFields will be displayed.