The AnQi CMS, with its powerful content model and flexible custom field features, provides great convenience for website operators.These custom fields are the key to personalizing website content and structuring data.How can you accurately query all the custom field information contained in a specific model (such as an article model)?This is very useful when conducting secondary development, data connection, or just to understand the system structure.

In AnQi CMS, the most direct and effective way to query all custom field information contained in a model is throughthe interface to get model details (/api/module/detail)to query.

Learn about custom fields by accessing the model detail interface

When you need to understand the custom field definition of a specific model (such as an article model or product model), you can use this interface. You just need to provide the model's ID or its alias (filename), you can obtain all the detailed information of the model, including the custom fields we are concerned about.

The calling method of this interface isGET, one of the following parameters needs to be passed in:

  • id: The unique identifier of the model, an integer value.
  • filename: The URL alias of the model, a string.

For example, if you know the ID of the article model is 1, you can construct the request like this:{域名地址}/api/module/detail?id=1.

In the data structure returned by the interface, there is adataarray under the object.fieldsThis array.fieldsThe array is the complete definition of all custom fields under the model. Each array item represents a custom field and includes the following key information:

  • name(Field Chinese name)This is the intuitive name you see when setting up in the Anqin CMS backend, convenient for content editors to understand.
  • field_name(Field Name)This is the unique identifier called in the program, usually used for template tags, front-end rendering, or specifying fields through API data interaction.
  • type(Field type)It indicates the data type of the field, for exampletext(Text),number(Number),textarea(Multi-line text),radio(Single selection),checkbox(Multiple choice),select(Dropdown selection) etc. Understanding field types helps you properly handle and display data.
  • required(Mandatory): This is a boolean value (trueorfalse), indicating whether the field is required when publishing content.
  • is_system(Is it a system built-in field): It is also a boolean value,trueThis indicates that it is a core field of the system,falseIt means that it is a field added by the user.
  • is_filter(Filter parameter): This attribute is very useful, if it istrueThis field can be used as a filter condition in the front-end content list, and users can filter content through the value of this field.
  • follow_level(Whether to follow the document reading level): If it istrueThis means that the visibility of this custom field will be restricted by the document reading level.
  • content(Default Value)If the field is configured with a default value when the model is set, then this property will display the corresponding default content.For dropdown selections, radio buttons, multiple choices, etc., an options list may be included here.

By parsing thisfieldsAn array, you can clearly understand the names, types, whether mandatory, and other important properties of all custom fields under a certain model.

Query all models and their custom fields

If you want to get a comprehensive overview of all models and their custom fields at once, or if you are unsure of a specific model's ID or aliasThe interface to get the list of models (/api/module/list)will be a good helper for you.

The calling method of this interface isGETAnd without any parameters, it can return a detailed list of all content models in the system. In the returneddataarray, each element is a model object, which also containsfieldsAn array with a structure获取模型详情接口The field definitions returned are consistent. This allows you to iterate through all models and view their custom field definitions one by one.

Understand the custom field values in the document.

After understanding the definition of custom fields, we might want to know how to view the actual content filled in for these custom fields in a specific article or product. This can be done byInterface to get document details(/api/archive/detail)orInterface to get document list(/api/archive/list)to achieve.

In the return data of these two interfaces, you will see a namedextrathe object.extraobject withfield_name => itemThe form shows the actual values of all custom fields.itemObjects usually contain:

  • name: The Chinese name of the custom field.
  • value: The actual content filled in for this custom field in the document.
  • defaultThe default value of this field (if it exists).

By combining the use of the aforementioned several API interfaces, whether it is to obtain the field definitions of the model or to query the field values of specific content, Anqi CMS provides a clear and convenient way for you to flexibly manage and utilize the structured content of the website.


Frequently Asked Questions (FAQ)

  1. Q:is_filterWhat is the actual use of the field?A:is_filterThe field indicates whether a custom field can be used as a filter condition on the website frontend. For example, if your article model has a custom field named "city", and itsis_filterWithtrueThen on the article list page, you can filter articles based on the value of the "city" field, making it convenient for users to quickly find articles related to specific cities.
  2. Q: Why am I获取文档详情interface'sextraCan't see a custom field inside the object?A:extraThe object only contains thoseThe content has been filled inOrThere is a default valueThe custom field. If a custom field is defined in the background model but no content is filled in the specific document and no default value is set, it will not appear in the document.extraIn the object.
  3. Q:field_nameandnameWhat is the difference? Which one should be used in development?A:nameIs the custom field's Chinese display name, mainly used for the background management interface and to provide content editors with intuitive identification.field_nameIs the unique identifier of the field, used internally in the program, in API request parameters, and in template tags. You should always use it, especially when interacting with data through APIs.field_nameAccurately refer to and operate custom fields.