Skip to content

Decks from an article

POST /api/v1/articles/{article_id}/ai-cards

Requires permission to start a deck — moderator or admin — and requires the article to have a category, because a deck takes its category from its article. An uncategorised article cannot have a deck made from it.

It queues the Celery task generate_article_cards. Model task name: flashcard.

What it writes

  • How many: roughly one card per 150 words of the article, clamped to between 12 and 30.
  • Where: an existing deck already marked as sourced from this article, if there is one — found by the source link, never by title, which used to produce duplicates. Otherwise a new deck titled Cards: {article title}, filed under the article's category.
  • Shared: no. is_shared = 0. A generated deck is private until an educator has read it and shared it.

A deck can come from more than one article

A deck links to every article its cards came from, through a many-to-many link table, and exactly one of those links is flagged as the source — the article the cards were generated from.

This matters for where the deck appears. A deck is shown on an article's page if it is linked to that article, or if it is filed in that article's category. Before the many-to-many link existed, a deck built from two articles appeared under one of them and, unless they happened to share a category, nowhere near the other.

The service also tracks staleness: it compares the deck against the updated_at of every article linked to it, so a deck whose reading has moved on since the cards were written can say so.

Who may do what afterwards

Action Who
Start a new deck moderator
Edit a deck and write cards into it moderator, the deck's owner, or a deck-grant holder
Delete, restore or share a deck the same three — everything through can_edit_deck
Force-unshare any deck admin
See the deck bin moderator

See Managing decks and cards for the consequences of those last two rows, and Grants, including the known gap in the card-linking endpoints.