from __future__ import annotations

from typing import Any
from django.db import models
from django.forms import Field
from .widgets import RichTextWidget


class RichTextField(models.TextField):
    """Drop-in replacement for TextField that renders 101editor in forms and admin."""

    def formfield(self, **kwargs: Any) -> Field:
        # Force our widget — do not use setdefault, because Django admin injects
        # AdminTextareaWidget via kwargs before calling this method.
        kwargs["widget"] = RichTextWidget
        return super().formfield(**kwargs)
