Skip to content

Creating a new PublishableEntity should automatically create a row in Draft and Published #362

@ormsbee

Description

@ormsbee

NOTE: This is not ready for work yet -- see the note at the bottom.

In a recent PR, there was a need for code like this:

current_draft: Optional[Draft] = getattr(entity, "draft", None)
current_published: Optional[Published] = getattr(entity, "published", None)

This is because creating a new PublishableEntity does not populate these other models:

def create_publishable_entity(
learning_package_id: int,
/,
key: str,
created: datetime,
# User ID who created this
created_by: int | None,
*,
can_stand_alone: bool = True,
) -> PublishableEntity:
"""
Create a PublishableEntity.
You'd typically want to call this right before creating your own content
model that points to it.
"""
return PublishableEntity.objects.create(
learning_package_id=learning_package_id,
key=key,
created=created,
created_by_id=created_by,
can_stand_alone=can_stand_alone,
)

I think I originally wanted to distinguish between never published and published-but-since-unpublished. But now we have a whole PublishLog to track that.

Problem: The Published model actually has a non-nullable reference to a PublishLogRecord that points to how this particular version became the published version. If we initialize a Published entry to null, we would have to make this field nullable as well. Is that tradeoff worth it, or should we just make helpers on PublishableEntity to return the draft and published versions instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions