fabricatio_anki.models.deck

Module for defining data models and constants related to Anki decks.

Classes

Constants

Constants used across the module to represent various keys and directories.

Model

Represents a model in Anki which contains fields and templates.

Deck

Represents an Anki deck which contains multiple models.

ModelMetaData

Patch class for updating metadata of a deck model.

Module Contents

class fabricatio_anki.models.deck.Constants

Bases: enum.StrEnum

Constants used across the module to represent various keys and directories.

MEDIA = 'media'
DATA = 'data'
TEMPLATES = 'templates'
MODELS = 'models'
FIELDS = 'fields'
DECK = 'deck'
MODEL_ID = 'model_id'
DECK_ID = 'deck_id'
class fabricatio_anki.models.deck.Model(/, **data: Any)

Bases: fabricatio_core.models.generic.SketchedAble, fabricatio_core.models.generic.Named

Represents a model in Anki which contains fields and templates.

fields: List[str]

List of field names that define the data structure for this model.

Each field represents a piece of information that can be filled in when creating cards, such as ‘Front’, ‘Back’, ‘Extra’, etc. These fields are used as placeholders in the template HTML and determine what data can be stored for each note.

templates: List[fabricatio_anki.models.template.Template]

List of card templates associated with this model.

Each template defines how the fields should be displayed on the front and back of a card, including the HTML structure and CSS styling. A model can have multiple templates to create different card variations from the same field data.

save_to(parent_dir: pathlib.Path | str) Self

Saves the model’s metadata and its templates to the specified directory.

Parameters:

parent_dir (Path | str) – Directory where the model should be saved.

Returns:

The instance of the model after saving.

Return type:

Self

class fabricatio_anki.models.deck.Deck(/, **data: Any)

Bases: fabricatio_core.models.generic.SketchedAble, fabricatio_core.models.generic.WithBriefing

Represents an Anki deck which contains multiple models.

author: str = 'Anonymous'

The author or creator of this Anki deck.

This field identifies who created the deck and is displayed in the deck metadata. Defaults to ‘Anonymous’ if no author is specified.

models: List[Model]

List of card models that define the structure and appearance of cards in this deck.

Each model contains fields and templates that determine how information is organized and displayed. A deck can contain multiple models to support different types of cards or study materials within the same deck.

save_to(path: pathlib.Path | str) Self

Saves all models in the deck to the specified path and writes deck metadata.

Parameters:

path (Path | str) – Directory where the deck should be saved.

Returns:

The instance of the deck after saving.

Return type:

Self

class fabricatio_anki.models.deck.ModelMetaData(/, **data: Any)

Bases: fabricatio_core.models.generic.WithBriefing, fabricatio_capabilities.models.generic.Patch[Deck]

Patch class for updating metadata of a deck model.

This class is used to apply metadata updates to a Deck instance, while excluding specific fields from the update process.

static excluded_fields() Set[str]

Returns a set of fields that should be excluded from updates.

These fields are intentionally not modified when applying metadata patches.

Returns:

A set containing the names of excluded fields.

Return type:

Set[str]

static ref_cls() Type[pydantic.BaseModel] | None

Returns the reference class for this patch.

Determines which class this patch can be applied to.

Returns:

The Deck class.

Return type:

Optional[Type[BaseModel]]