kerrickstaley / genanki

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

How can I create with many Fields? #50

Closed gelodefaultbrain closed 4 years ago

gelodefaultbrain commented 4 years ago

Hello first of all thank you with this python library. It is so cool! really helps me a lot in creating anki decks!

I have a question thoooo can you please help me and I think my question is just very very simple so here it is

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

On this code is you create a card right with the question "Capital of Argentina" and as the answer "Buenos Aires"... and it looks like this image image

I was thinking of can you provide an example on how can I make a field like this? image

Thank you so much!

remiberthoz commented 4 years ago

Hey! I'm not the author or genanki but I can help on this one. When creating a note, you can pass as many fields as you wish:

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

but this only makes sense if the model (my_model) you create defines the correct amount of fields:

my_model = genanki.Model(
  1607392319,
  'Capital Model',
  fields=[
    {'name': 'Question'},
    {'name': 'City'},
    {'name': 'IconicMonument'},
  ],
  templates=[
    {
      'name': 'Card 1',
      'qfmt': '{{Question}}',
      'afmt': '{{FrontSide}}<hr id="answer">{{City}}<br>{{IconicMonument}}',
    },
  ])

So in you case you would have to define quite a lot of such fields when creating the model, and pass the list of values when creating notes.

gelodefaultbrain commented 4 years ago

Woooow Thank you so much! :D Got it! Also I'll be opening up a new issue... I think I got another one I don't know if this is intentional but I'll open it up in a bit... Thanks!

kerrickstaley commented 4 years ago

Thanks for the help on this, @remiberthoz !

I think one thing to help make this issue clearer is we could throw an exception when the number of fields in a Note doesn't match the number of fields in the Model. @gelodefaultbrain would that have helped you understand this problem and fix it on your own?

gelodefaultbrain commented 4 years ago

Yeeep! Thank you so much!

Can I close the issue? since it solved my problem cause I have the button here... anyways THANKS A LOT!

kerrickstaley commented 4 years ago

I pushed https://github.com/kerrickstaley/genanki/commit/d3a5ac5d5a06ee29565a1173a1f63bbba252d265 which should help clarify this issue in the future.

kerrickstaley commented 4 years ago

Released in 0.8.1.