In Anqi CMS, the flexibility of the content model is one of its core strengths. It not only helps us manage traditional articles and product information, but also allows us to create highly personalized content types according to actual business needs.And customizing the article model fields is the key step to achieving 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 the movie title and synopsis, 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 hope to have information such as 'floor plan', 'area', 'orientation', 'price range', and more.The customized model field function of Anqi CMS is specifically designed to meet these diverse content needs.

Deep understanding of content model and custom fields

In Anqi CMS, the content model is like a "blueprint" or "structure definition" for the content of your website.The system provides the two basic models of 'article' and 'product' by default, but often this is far from meeting the unique business needs.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, 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 back end, just fill in the corresponding fields to reduce manual formatting and repetitive work.
  • Strong extensibility:Lay a solid foundation for future feature expansion (such as filtering, search, etc.)

Create and manage custom model fields

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

  1. Enter content model management:Log in to the Anqi CMS backend, navigate to the 'Content Management' menu, and click 'Content Model'.Here you will see a list of all content models created, including built-in and customized ones.

  2. Select or create a model:

    • Edit the existing model: If you want to add more fields to the 'Article' or 'Product' model, simply click the 'Edit' button on the right side of the corresponding model.
    • Create a custom model:If you need a completely different type of content (such as "events", "recruitment", etc.), you can click on "Add Content Model".When creating, you need to set the "model name", "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 field:After entering the model editing page, scroll down to find the "Custom field" area of the content model.This is the place for defining content-specific attributes. Click 'Add field' to define your personalized content attributes:

    • Parameter name:This is the Chinese name displayed in the background for editors, such as 'Film Director', 'Property Area'.
    • Call field: This is the most important part!It is the unique identifier that is called to retrieve the value of this field in the template, make sure to use lowercase English letters. For example, if you define "director", the field to be called can bedirectorIf defined, 'release date' can berelease_date.
    • Field type:Anqi CMS provides various field types to adapt to different data:
      • Single-line text:Suitable for brief text information, such as "brand", "model".
      • Number:Only numbers are allowed, such as "price", "stock".
      • Multi-line text:Suitable for longer descriptive text, such as 'Detailed introduction', 'Cautionary notes'.
      • Single choice/Multiple choice/Dropdown choice:Applicable to preset options, such as 'Red, Blue, Green', 'Apartment Type (One-bedroom, Two-bedroom, Three-bedroom)'. Enter each option on a separate line in the 'Default Value'.
    • Mandatory?:Set according to the importance of the content to ensure that key information is not missed.
    • Default:Set default values for fields, which can be used or modified directly during editing.

    After defining the field, remember to click save.

Enter 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:Make sure the "category" you choose is based on the content model you modify or create. Only then will the corresponding custom fields be displayed.
  3. Enter "other parameters":At the bottom of the document editing page, there is usually a collapsed 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 data according to the prompts.

Display personalized content in the template

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

  1. Invoke a single custom field:If you want to display a specific custom field in the content detail page (for examplearchive/detail.html) such as "Film Director", you can usedirector)archiveDetailTags:

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

    here,name="director"This corresponds to the "trigger field" you set up 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 further use:

    {% archiveDetail movieDirector with name="director" %}
    {% if movieDirector %}
        <p>导演:{{ movieDirector }}</p>
    {% endif %}
    
  2. Loop to display all custom fields:In some cases, you may want to display all non-empty custom fields in a single area or present them in a list. At this point,archiveParamsThe tag can be put to 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.NameIt will display the field