kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
2.06k stars 161 forks source link

Missing MyMedia as field #78

Open yannickfunk opened 3 years ago

yannickfunk commented 3 years ago
import genanki

my_model = genanki.Model(
  1091735104,
  'Simple Model with Media',
  fields=[
    {'name': 'Question'},
    {'name': 'Answer'},
  ],
  templates=[
    {
      'name': 'Card 1',
      'qfmt': '{{Question}}<br>{{MyMedia}}',
      'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
    },
  ])

my_note = genanki.Note(
  model=my_model,
  fields=['Capital of Argentina', 'Buenos Aires'])

my_deck = genanki.Deck(
  2059400110,
  'Country Capitals')

my_deck.add_note(my_note)
genanki.Package(my_deck).write_to_file('output.apkg')

Produces a file, where the question on the card can not be displayed, because it needs {{MyMedia}}, but I didn't define {{MyMedia}} as a field.

Should there maybe be a check if all fields are present, or should all template items which have no corresponding field be replaced with an empty string? As I'm currently working on a Rust port of genanki I am quite familiar with the codebase. I would like to solve this issue, if you can tell me, whether this is intended or not, and if yes, where to insert a check in the codebase.