question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I create with many Fields?

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kerrickstaleycommented, Sep 25, 2020

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?

3reactions
remiberthozcommented, Sep 23, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create an object for a Django model with a many to ...
You can do this without specifying a "through" model on the field. For completeness, the example below creates a blank Users model to...
Read more >
Many-to-many relationships - Django documentation
To define a many-to-many relationship, use ManyToManyField . In this example, an Article can be published in multiple Publication objects, and a Publication ......
Read more >
The right way to use a ManyToManyField in Django
To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references...
Read more >
Create Many-to-Many Relationships - Intermediate Django
Link Users With Many-to-Many Fields · Step 1: Update the Models · Step 2: Creating Many-to-Many Relationships in a Form · Step 3:...
Read more >
Tips for Using Django's ManyToManyField - REVSYS
The invisible "through" model that Django uses to make many-to-many relationships work requires the primary keys for the source model and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found