Skip to main content

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

AttributeTypeDescription
priorityfloat = NoneThe priority value assigned to the URLs in this sitemap, used by search engines to determine relative importance.
changefreqstring = NoneThe 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

NameTypeDescription
info_dictdictA dictionary containing the 'queryset' and optionally a 'date_field'.
priorityfloat = NoneThe priority of the URLs in the sitemap.
changefreqstring = NoneHow frequently the page is likely to change.
protocolstring = NoneThe protocol (http or https) to use for the URLs.

Signature

def GenericSitemap(
info_dict: dict,
priority: float,
changefreq: string,
protocol: string
)

Parameters

NameTypeDescription
info_dictdictA dictionary containing the 'queryset' of objects to include and an optional 'date_field' for modification timestamps
priorityfloatThe priority of these URLs relative to other URLs on your site, ranging from 0.0 to 1.0
changefreqstringHow frequently the page is likely to change (e.g., 'always', 'daily', 'yearly')
protocolstringThe 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

TypeDescription
[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

NameTypeDescription
itemobjectThe model instance for which to retrieve the modification timestamp

Returns

TypeDescription
datetimeThe 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

TypeDescription
datetimeThe latest timestamp found in the date field column, or None if the date field is not configured