Sequence Generation — Developer Index

Entry point for the Enezaframework sequence generation developer guides. Start here, then follow the links to the topic you need.

Table of Contents

  1. What Sequence Generation Is
  2. The Core Idea
  3. Documentation Map
  4. Suggested Reading Paths
  5. A Note on Testing

What Sequence Generation Is

The sequence generation system assigns unique document numbers to models automatically — invoice numbers (INV-0001), purchase orders (PO/001), customer codes (CUST-0001), and similar business identifiers. The format is driven by a SequenceConfig record, and the assignment happens in the model's save() through SequenceMixin.

Who this is for: Django developers and coding agents adding sequential business numbers to models built on Enezaframework.

Expected outcome: a model that inherits EnezaMaster or EnezaDocument, declares sequence_field_name and document_name, and gets a populated sequence field on first save.


The Core Idea

Three pieces cooperate:

  1. SequenceMixin (enezaframework/services/Mixin.py) — the save() hook and generate_sequence() logic.
  2. SequenceConfig (enezaframework/models/enezasequence.py) — per-document prefix, delimiter, number length, and next number.
  3. Pluggable choices — NumberSequencesDocument / Modules, optionally replaced by project-defined classes via settings.
flowchart LR
    SAVE["Model.save()"] --> MIXIN["SequenceMixin.save()"]
    MIXIN --> NEW{"new object and<br/>field empty?"}
    NEW -->|No| P["super().save()"]
    NEW -->|Yes| GEN["generate_sequence()"]
    GEN --> CFG["SequenceConfig.objects.filter(<br/>documents=..., active=True)"]
    CFG --> FMT["prefix + delimiter + padded nextnumber"]
    FMT --> SET["setattr(field, value)"]
    SET --> BUMP["config.nextnumber += 1; config.save()"]
    BUMP --> P

Documentation Map

Pos Guide What it covers
1 Sequence Generation — Developer Index This page — overview and navigation.
2 Sequence Generation Architecture SequenceMixin, SequenceConfig, the choice system, and save flow.
3 Sequence Generation Quick Start A minimal sequenced model, choices, settings, and config.
4 Sequence Configuration Model SequenceConfig fields, the unique constraint, and get_sequence_format().
5 Sequence Document & Module Choices Custom NumberSequencesDocument / Modules classes and fallback.
6 Using SequenceMixin in Models Base-model choice, required attributes, single-field limitation, overrides.
7 Sequence Admin Setup Creating and managing sequence configurations in admin.
8 Sequence Template Integration Format preview and admin template helpers.
9 Sequence Settings Configuration MY_PROJECT_NUMBER_SEQUENCE_DOCUMENT and MY_PROJECT_MODULES.
10 Sequence Generation Best Practices Prefixes, lengths, concurrency, backups, monitoring.
11 Sequence Generation Troubleshooting Common failures and debugging steps.

The original, unsplit reference remains available at sequence-generation-developer-guide.md.

For surrounding framework concepts, see the Enezaframework developer index:


Suggested Reading Paths

Adding sequence generation to a new model 1. Sequence Generation Architecture 2. Sequence Generation Quick Start 3. Using SequenceMixin in Models

Customizing formats and choices 1. Sequence Configuration Model 2. Sequence Document & Module Choices 3. Sequence Settings Configuration

Operating sequences in production 1. Sequence Admin Setup 2. Sequence Generation Best Practices 3. Sequence Generation Troubleshooting


A Note on Testing

Per project rules, the developer or agent does not run or claim test results. The user is solely responsible for all testing and validation of the output described in these guides.