How to persist default class configurations in the database?

Let's say I've a ToDo model and Point model with foreign key relation in database.

class Todo(ManuallyTimestampedModel):
    title = models.CharField(max_length=255)
    description = models.TextField()


class Point(Model):
    title = models.CharField(max_length=255)
    description = models.TextField()

    todo = models.ForeignKey(
        Todo,
        on_delete=models.CASCADE,
        related_name="points",
        help_text=_("ToDo to which point belongs."),
    )

I also have a function for creating a few todos and points assigned to then based on chosen option:

class PlanType(enum.Enum):
    RUNNING = "Running"
    SWIMMING = "Swimming"

def plan(option: PlanType) -> None:
    todos = []
    if option == PlanType.RUNNING:
        options = ...
    elif option == PlanType.SWIMMING:
        options = ...
    
    return todos

What is a good approach to load default todos and points based on chosen option?

I plan to store them in database with possibility to edit via admin UI.

Вернуться на верх