GenericSitemap
This class provides a generic implementation for generating sitemaps from a provided queryset. It allows for the dynamic retrieval of items and supports optional configuration for priority, change frequency, and last modification dates based on a specified model field.
Attributes
| Attribute | Type | Description |
|---|---|---|
| priority | float = None | The priority value assigned to the URLs in this sitemap, used by search engines to determine relative importance. |
| changefreq | string = None | The expected frequency of changes for the URLs, providing a hint to search engine crawlers. |
Constructor
Signature
def GenericSitemap(
info_dict: dict,
priority: float = None,
changefreq: string = None,
protocol: string = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| info_dict | dict | A dictionary containing the 'queryset' and optionally a 'date_field'. |
| priority | float = None | The priority of the URLs in the sitemap. |
| changefreq | string = None | How frequently the page is likely to change. |
| protocol | string = None | The protocol (http or https) to use for the URLs. |
Signature
def GenericSitemap(
info_dict: dict,
priority: float,
changefreq: string,
protocol: string
)
Parameters
| Name | Type | Description |
|---|---|---|
| info_dict | dict | A dictionary containing the 'queryset' of objects to include and an optional 'date_field' for modification timestamps |
| priority | float | The priority of these URLs relative to other URLs on your site, ranging from 0.0 to 1.0 |
| changefreq | string | How frequently the page is likely to change (e.g., 'always', 'daily', 'yearly') |
| protocol | string | The protocol to use for URLs in the sitemap ('http' or 'https') |
Methods
items()
@classmethod
def items() - > [QuerySet](../../db/models/query/queryset.md?sid=django_db_models_query_queryset)
Returns a clone of the configured queryset to provide the list of objects for the sitemap without premature evaluation.
Returns
| Type | Description |
|---|---|
[QuerySet](../../db/models/query/queryset.md?sid=django_db_models_query_queryset) | A Django QuerySet containing the objects to be indexed in the sitemap |
lastmod()
@classmethod
def lastmod(
item: object
) - > datetime
Retrieves the modification date for a specific item based on the configured date field.
Parameters
| Name | Type | Description |
|---|---|---|
| item | object | The model instance for which to retrieve the modification timestamp |
Returns
| Type | Description |
|---|---|
datetime | The value of the item's date field, or None if no date field is defined |
get_latest_lastmod()
@classmethod
def get_latest_lastmod() - > datetime
Fetches the most recent modification date across all items in the queryset for use in sitemap index headers.
Returns
| Type | Description |
|---|---|
datetime | The latest timestamp found in the date field column, or None if the date field is not configured |