Models
PublishedQuerySet
- class headless_cms.models.PublishedQuerySet(model=None, query=None, using=None, hints=None)
Bases:
QuerySetCustom QuerySet for handling published models.
- property prefetch_relation_list
- published(auto_prefetch=False)
Filter the QuerySet to only include published items.
- Parameters:
auto_prefetch (bool) – Whether to automatically prefetch related objects.
- Returns:
A filtered QuerySet with only published items.
- Return type:
QuerySet
PublishedManager
- class headless_cms.models.PublishedManager(*args, **kwargs)
Bases:
ManagerCustom Manager for handling published models.
- get_queryset()
Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.
- published(auto_prefetch=False)
Filter the QuerySet to only include published items.
- Parameters:
auto_prefetch (bool) – Whether to automatically prefetch related objects.
- Returns:
A filtered QuerySet with only published items.
- Return type:
QuerySet
LocalizedPublicationModel
- class headless_cms.models.LocalizedPublicationModel(*args, **kwargs)
Bases:
LocalizedModelAbstract model for localized publication.
This model extends the LocalizedModel to include versioning and publication functionality. It keeps track of the published version and allows for recursive actions on related objects.
- published_version
Reference to the published version.
- Type:
ForeignKey
- versions
Relation to the versions of the model.
- Type:
GenericRelation
- class AdminPublishedStateHtml
Bases:
objectHTML representations of the publication state.
This nested class contains constants representing the HTML used to indicate the publication state of an object in the Django admin interface. It provides visual feedback on whether an object is unpublished, published but outdated, or published and up-to-date, using different colors for each state.
- UNPUBLISHED
HTML for the unpublished state (red).
- Type:
str
- PUBLISHED_OUTDATED
HTML for the published but outdated state (orange).
- Type:
str
- PUBLISHED_LATEST
HTML for the published and up-to-date state (blue).
- Type:
str
- PUBLISHED_LATEST = '<div style="color:blue;">published (latest)<div>'
- PUBLISHED_OUTDATED = '<div style="color:orange;">published (outdated)<div>'
- UNPUBLISHED = '<div style="color:red;">unpublished<div>'
- class Meta
Bases:
Meta- abstract = False
- objects
- publish(user=None)
Publish the current version of the object.
- Parameters:
user (User, optional) – The user performing the publish action.
- property published_data
Get the data of the published version.
- Returns:
The field data of the published version, or None if not published.
- Return type:
dict
- published_objects
- published_state()
Get the published state of the object as HTML for the Django admin interface.
This method provides a visual indicator of the publication state of an object in the Django admin interface. It returns an HTML representation indicating whether the object is unpublished, published (outdated), or published (latest).
- Returns:
The HTML representation of the published state.
- Return type:
str
- published_version
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- published_version_id
- recursive_action(action, *args, tracker=None, **kwargs)
Perform an action recursively on the object and its related objects.
- Parameters:
action (callable) – The action to be performed.
tracker – the list to track the object processed, not to do it again when being reference multiple times
- recursively_publish(user=None)
Recursively publish the object and its related objects.
- Parameters:
user (User, optional) – The user performing the publish action.
- recursively_translate(user=None, force=False)
Recursively translate the object and its related objects.
- Parameters:
user (User, optional) – The user performing the translation.
force (bool, optional) – Whether to force the translation.
- translate(user=None, force=False)
Translate the object.
- Parameters:
user (User, optional) – The user performing the translation.
force (bool, optional) – Whether to force the translation.
- unpublish(user=None)
Unpublish the current version of the object.
- Parameters:
user (User, optional) – The user performing the unpublish action.
- versions
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
post.commentsis a ReverseGenericManyToOneDescriptor instance.
LocalizedSingletonModel
- class headless_cms.models.LocalizedSingletonModel(*args, **kwargs)
Bases:
LocalizedPublicationModel,SingletonModelAbstract model for localized singleton.
This model extends SingletonModel to include versioning and publication functionality for singleton instances.
- class Meta
Bases:
object- abstract = False
- classmethod get_solo()
- published_version
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- published_version_id
- versions
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
post.commentsis a ReverseGenericManyToOneDescriptor instance.
LocalizedTitleSlugModel
- class headless_cms.models.LocalizedTitleSlugModel(*args, **kwargs)
Bases:
LocalizedPublicationModelAbstract model for localized title and slug.
This model extends LocalizedPublicationModel to include title and slug fields that are automatically populated and unique per language.
- title
The title of the object.
- Type:
LocalizedTextField
- slug
The slug of the object.
- Type:
LocalizedUniqueNormalizedSlugField
- class Meta
Bases:
object- abstract = False
- published_version
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- published_version_id
- slug
The descriptor for the localized value attribute on the model instance. Returns a :see:LocalizedValue when accessed so you can do stuff like:
>>> from myapp.models import MyModel >>> instance = MyModel() >>> instance.value.en = 'English value'
Assigns a strings to active language key in :see:LocalizedValue on assignment so you can do:
>>> from django.utils import translation >>> from myapp.models import MyModel >>> translation.activate('nl') >>> instance = MyModel() >>> instance.title = 'dutch title' >>> print(instance.title.nl) # prints 'dutch title'
- title
The descriptor for the localized value attribute on the model instance. Returns a :see:LocalizedValue when accessed so you can do stuff like:
>>> from myapp.models import MyModel >>> instance = MyModel() >>> instance.value.en = 'English value'
Assigns a strings to active language key in :see:LocalizedValue on assignment so you can do:
>>> from django.utils import translation >>> from myapp.models import MyModel >>> translation.activate('nl') >>> instance = MyModel() >>> instance.title = 'dutch title' >>> print(instance.title.nl) # prints 'dutch title'
- versions
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
post.commentsis a ReverseGenericManyToOneDescriptor instance.
LocalizedDynamicFileModel
- class headless_cms.models.LocalizedDynamicFileModel(*args, **kwargs)
Bases:
LocalizedPublicationModelAbstract model for localized dynamic file.
This model extends LocalizedPublicationModel to include fields for either uploading files or specifying URLs, along with alternative text. When both a file and a URL are provided, the file takes precedence.
- src_file
The source file.
- Type:
LocalizedFileField
- src_url
The source URL.
- Type:
LocalizedCharField
- alt
The alternative text for the file.
- Type:
LocalizedTextField
- class Meta
Bases:
object- abstract = False
- alt
The descriptor for the localized value attribute on the model instance. Returns a :see:LocalizedValue when accessed so you can do stuff like:
>>> from myapp.models import MyModel >>> instance = MyModel() >>> instance.value.en = 'English value'
Assigns a strings to active language key in :see:LocalizedValue on assignment so you can do:
>>> from django.utils import translation >>> from myapp.models import MyModel >>> translation.activate('nl') >>> instance = MyModel() >>> instance.title = 'dutch title' >>> print(instance.title.nl) # prints 'dutch title'
- published_version
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- published_version_id
- src_file
- property src_link
Get the source link.
This property returns the absolute URL of the source file if it exists. If the source file does not exist, it returns the translated URL.
- Returns:
The absolute URL of the source file or the translated URL.
- Return type:
str
- src_url
The descriptor for the localized value attribute on the model instance. Returns a :see:LocalizedValue when accessed so you can do stuff like:
>>> from myapp.models import MyModel >>> instance = MyModel() >>> instance.value.en = 'English value'
Assigns a strings to active language key in :see:LocalizedValue on assignment so you can do:
>>> from django.utils import translation >>> from myapp.models import MyModel >>> translation.activate('nl') >>> instance = MyModel() >>> instance.title = 'dutch title' >>> print(instance.title.nl) # prints 'dutch title'
- versions
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
post.commentsis a ReverseGenericManyToOneDescriptor instance.
M2MSortedOrderThrough
- class headless_cms.models.M2MSortedOrderThrough(*args, **kwargs)
Bases:
ModelAbstract model for many-to-many relationships with a position field for sorting.
This model is designed to be used as a through table for many-to-many relationships where the order of the related objects is important. It includes a position field that is used by the sortableadmin library to specify the order of the related objects.
- fk_name
The name of the foreign key field that points to the parent model. This is used to detect the parent model in self-referencing many-to-many relationships. For normal many-to-many relationships, this attribute is not needed.
- Type:
str
- position
The position field for sorting the related objects.
- Type:
PositiveIntegerField
- Usage:
The fk_name attribute is specifically used in self-referencing many-to-many relationships to detect the parent object. This allows the detection of child objects and the ability to get the status of the child objects for visualization in the Django admin interface.
Example
In a self-referencing many-to-many relationship, set fk_name to the name of the foreign key field that points to the parent model.
class MyModel(LocalizedPublicationModel): related_objects = models.ManyToManyField( 'self', through='MyModelThrough' ) class MyModelThrough(M2MSortedOrderThrough): fk_name = 'parent_model' parent_model = models.ForeignKey(MyModel, on_delete=models.CASCADE) child_model = models.ForeignKey(MyModel, related_name='child_set', on_delete=models.CASCADE)
- class Meta
Bases:
object- abstract = False
- ordering = ['position']
- fk_name = None
- position
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
SortableGenericBaseModel
- class headless_cms.models.SortableGenericBaseModel(*args, **kwargs)
Bases:
LocalizedPublicationModelAbstract model for sortable generic base.
This model extends LocalizedPublicationModel to include fields for generic relations and sorting.
- content_type
The content type of the related object.
- Type:
ForeignKey
- object
The related object.
- Type:
GenericForeignKey
- object_id
The ID of the related object.
- Type:
PositiveIntegerField
- position
The position for sorting.
- Type:
PositiveIntegerField
- class Meta
Bases:
object- abstract = False
- ordering = ['position']
- content_type
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- content_type_id
- object
Provide a generic many-to-one relation through the
content_typeandobject_idfields.This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.
- object_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- position
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- published_version
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- published_version_id
- versions
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
post.commentsis a ReverseGenericManyToOneDescriptor instance.