Today, with the increasing refinement of content operation, we often find that relying solely on traditional 'article' and 'product' categories is no longer sufficient to meet the diverse content display needs of websites.Every business scenario has its unique attributes and information structure, how to make the website's content management system (CMS) like a considerate tailor, tailor-made for each type of content, is our goal.The flexible content model feature provided by AnQiCMS (AnQiCMS) exactly helps us realize this vision.

Why do we need to customize the content model?

Imagine if your website not only publishes articles and products, but also needs to display real estate information, job vacancies, event schedules, and even team member introductions.Each content type has its own unique fields: real estate may require 'type', 'area', 'price', 'location';Hiring requires "Position Name", "Salary Range", "Location", and "Responsibilities";The event requires "start time", "end time", "location", "participation fee", etc.

If forced to stuff this rich information into a generic "article" template, it not only makes the back-end entry inefficient, but also makes the front-end display appear chaotic and unprofessional.Information cannot be structured, which means it is difficult to perform precise filtering and sorting, and cannot provide clear structured data to search engines, thereby affecting user experience and SEO effects.

The role of custom content models is like providing a brand new framework tailored to the content of your website.It allows us to define exclusive data fields for different types of content, ensuring that each piece of information is collected and displayed in the most reasonable and orderly way.

Create a custom content model in Anqi CMS

In AnQi CMS, creating and managing content models is an intuitive and powerful process.You can go to the "Content Management" section of the backend, find the "Content Model" option.Here, you will see the built-in 'article model' and 'product model' - they are preset general content structures.To meet individualized needs, we usually choose to "add a custom model".

After clicking the 'Add Model' button, you need to define some basic information for the new model:

  • Model name:This is the Chinese name used for identifying and managing models in the background, such as 'Real Estate Information', 'Recruitment Positions'.
  • Model table name:This is the English identifier used by the system when storing data in the database. It is recommended to use lowercase letters and numbers to ensure uniqueness. It determines how the data is organized on the backend.
  • URL alias:Used to generate static links, it is also recommended to use lowercase English letters, which will be part of your content URL and are very important for SEO.
  • Title Name:This is the prompt text for the main title of the content when publishing, such as "Product Name" or "Real Estate Title", making it clear for the content editor.

What follows is the essence of custom content model -Define model fields. Here, you can add custom fields according to your needs.AnQi CMS offers various field types, each like a tiny 'data container' that stores information in a specific format:

  • Single-line text:Suitable for brief text information, such as "property title", "contact phone number", "job position".
  • Number:Only numbers can be entered, suitable for fields such as 'area', 'price', 'salary range', 'inventory quantity' that require numerical calculations or range filtering.
  • Multi-line text:It is suitable for entering longer descriptive text, such as "Real estate details", "Job responsibilities", "Event introduction".
  • Single choice:Allow you to preset multiple options, but the content publisher can only choose one, for example, "House type (residential/commercial/villa)", "Article source (original/reprint)."}
  • Multiple selection:Similarly, multiple options are preset, but the content publisher can choose one or more, such as 'House features (elevator/parking space/school district)', 'Product functions (waterproof/shakeproof/touch screen).'
  • Dropdown selection:Similar to single selection, but presented in the form of a dropdown menu, suitable for situations with many options, such as 'Area (Haidian/Chaoyang/Fengtai)', 'Product Color (Red/Blue/Black)'.

When defining each field, you can also set 'whether it is required' to ensure that key information is not missed;And the "default value", provides convenient preset options for some common fields.These settings greatly enhance the efficiency and standardization of content entry.

Post and manage personalized content

After you create a custom content model and define all fields, it will seamlessly integrate into the content publishing process of AnQi CMS.Under "Content Management", when you select "Add Document" or "Add Product", you will find an important change: you first need to select a "category".

This category is closely related to the model you created. Once you select a category bound to a custom model, in the document editing interface, in addition to the original title, content, keywords, and other general fields, you will see a collapsible area for 'other parameters'.Expand this area, all the custom fields you defined will be listed clearly, waiting for you to fill in the corresponding data.

Such a design ensures that each type of content can be entered according to its unique structure, both standardized and efficient.

Display custom content in the front-end template.

The true magic of a custom content model lies in how it can be flexibly presented on the website front end.The AnQi CMS adopts the Django template engine syntax, allowing you to convert structured data stored in the background into a rich and varied page content through concise tags.

To call the custom model field in the template, several core tags are mainly used, and the most important one isarchiveDetailandarchiveListThey are used to obtain detailed information of a single content and the list of contents. As for the custom fields we define,archiveParamsthe tag is its exclusive "extractor".

For example, when you are on the content detail page (usually correspondingarchiveDetail), you can usearchiveParamsto iterate and display all custom fields:

{% archiveParams params %}
    {% for item in params %}
    <div>
        <strong>{{item.Name}}:</strong>{# 显示字段的中文名称,如“面积” #}
        <span>{{item.Value}}</span>{# 显示字段的值,如“120平米” #}
    </div>
    {% endfor %}
{% endarchiveParams %}

This code will intelligently traverse all the custom fields you have defined for the current content model and display them in the form of "Field name: Field value".This is very useful for pages that need to fully display content properties.

If you know the specific "call field" name of a custom field (for example, if you define a field namedarea), you can also access it directly througharchiveobject:

<div>
    <strong>房屋面积:</strong>
    <span>{{archive.area}} 平米</span>
</div>
<div>
    <strong>装修情况:</strong>
    <span>{{archive.decoration_status}}</span>
</div>

This direct access method allows you to be more flexible when designing specific layouts, and you can embed custom fields precisely into any position of the page element as needed.

Moreover, if you define filterable fields in a custom model (such as the 'type' of real estate), the Anqi CMS'sarchiveFiltersLabels can also help you build powerful filtering functions on the list page.Users can filter content based on these custom fields, greatly enhancing the discoverability and user experience.

The flexible content model of AnQi CMS opens up endless possibilities for website content design. Whether it is to build complex industry portals or create personalized corporate websites, it can provide strong