anki.models#
Attributes#
Classes#
Module Contents#
- anki.models.NotetypeNameId#
- anki.models.NotetypeNameIdUseCount#
- anki.models.NotetypeNames#
- anki.models.ChangeNotetypeInfo#
- anki.models.ChangeNotetypeRequest#
- anki.models.StockNotetype#
- anki.models.NotetypeDict#
- anki.models.NoteType#
- anki.models.FieldDict#
- anki.models.TemplateDict#
- anki.models.NotetypeId#
- class anki.models.ModelsDictProxy(col: anki.collection.Collection)#
- keys() Any#
- values() Any#
- items() Any#
- class anki.models.ModelManager(col: anki.collection.Collection)#
Bases:
anki._legacy.DeprecatedNamesMixin- col#
- models#
- all_names_and_ids() collections.abc.Sequence[NotetypeNameId]#
- all_use_counts() collections.abc.Sequence[NotetypeNameIdUseCount]#
- have(id: NotetypeId) bool#
- current(for_deck: bool = True) NotetypeDict#
Get current model. In new code, prefer col.defaults_for_adding()
- id_for_name(name: str) NotetypeId | None#
- get(id: NotetypeId) NotetypeDict | None#
Get model with ID, or None.
This returns a reference to a cached dict. Copy the returned model before modifying it if you’re not calling .update_dict() afterward.
- all() list[NotetypeDict]#
Get all models.
- by_name(name: str) NotetypeDict | None#
Get model with NAME.
- new(name: str) NotetypeDict#
Create a new model, and return it.
- remove_all_notetypes() None#
- remove(id: NotetypeId) anki.collection.OpChanges#
Modifies schema.
- add(notetype: NotetypeDict) anki.collection.OpChangesWithId#
Replaced with add_dict()
- add_dict(notetype: NotetypeDict) anki.collection.OpChangesWithId#
Notetype needs to be fetched from DB after adding.
- ensure_name_unique(notetype: NotetypeDict) None#
- update_dict(notetype: NotetypeDict, skip_checks: bool = False) anki.collection.OpChanges#
Update a NotetypeDict. Caller will need to re-load notetype if new fields/cards added.
- nids(ntid: NotetypeId) list[anki.notes.NoteId]#
Note ids for M.
- use_count(notetype: NotetypeDict) int#
Number of note using M.
- copy(notetype: NotetypeDict, add: bool = True) NotetypeDict#
Copy, save and return.
- field_map(notetype: NotetypeDict) dict[str, tuple[int, FieldDict]]#
Mapping of field name -> (ord, field).
- field_names(notetype: NotetypeDict) list[str]#
- sort_idx(notetype: NotetypeDict) int#
- cloze_fields(mid: NotetypeId) collections.abc.Sequence[int]#
The list of index of fields that are used by cloze deletion in the note type with id mid.
- new_field(name: str) FieldDict#
- add_field(notetype: NotetypeDict, field: FieldDict) None#
Modifies schema.
- remove_field(notetype: NotetypeDict, field: FieldDict) None#
Modifies schema.
- reposition_field(notetype: NotetypeDict, field: FieldDict, idx: int) None#
Modifies schema.
- rename_field(notetype: NotetypeDict, field: FieldDict, new_name: str) None#
- set_sort_index(notetype: NotetypeDict, idx: int) None#
Modifies schema.
- new_template(name: str) TemplateDict#
- add_template(notetype: NotetypeDict, template: TemplateDict) None#
Modifies schema.
- remove_template(notetype: NotetypeDict, template: TemplateDict) None#
Modifies schema.
- reposition_template(notetype: NotetypeDict, template: TemplateDict, idx: int) None#
Modifies schema.
- template_use_count(ntid: NotetypeId, ord: int) int#
- get_single_notetype_of_notes(note_ids: collections.abc.Sequence[anki.notes.NoteId]) NotetypeId#
- change_notetype_info(*, old_notetype_id: NotetypeId, new_notetype_id: NotetypeId) ChangeNotetypeInfo#
- change_notetype_of_notes(input: ChangeNotetypeRequest) anki.collection.OpChanges#
Assign a new notetype, optionally altering field/template order.
To get defaults, use
info = col.models.change_notetype_info(…) input = info.input input.note_ids.extend([…])
The new_fields and new_templates lists are relative to the new notetype’s field/template count. Each value represents the index in the previous notetype. -1 indicates the original value will be discarded.
- restore_notetype_to_stock(notetype_id: NotetypeId, force_kind: anki.stdmodels.StockNotetypeKind.V | None) anki.collection.OpChanges#
- change(notetype: NotetypeDict, nids: list[anki.notes.NoteId], newModel: NotetypeDict, fmap: dict[int, int | None], cmap: dict[int, int | None] | None) None#
- scmhash(notetype: NotetypeDict) str#
Return a hash of the schema, to see if models are compatible.
- addTemplate(notetype: NotetypeDict, template: TemplateDict) None#
- remTemplate(notetype: NotetypeDict, template: TemplateDict) None#
- move_template(notetype: NotetypeDict, template: TemplateDict, idx: int) None#
- addField(notetype: NotetypeDict, field: FieldDict) None#
- remField(notetype: NotetypeDict, field: FieldDict) None#
- moveField(notetype: NotetypeDict, field: FieldDict, idx: int) None#
- renameField(notetype: NotetypeDict, field: FieldDict, new_name: str) None#
- rem(m: NotetypeDict) None#
Delete model, and all its cards/notes.
- set_current(m: NotetypeDict) None#
- all_names() list[str]#
- ids() list[NotetypeId]#
- flush() None#
- update(notetype: NotetypeDict, preserve_usn: bool = True, skip_checks: bool = False) None#
Add or update an existing model. Use .update_dict() instead.
- save(notetype: NotetypeDict | None = None, **legacy_kwargs: bool) None#
Save changes made to provided note type.