[Answer]-Is it possible/sensible to customize Django's auto-through tables to include other fields…through-factory?

1👍

IMO, adding fields to a “through” table is a great pattern for many possible uses. I’m not sure that Django needs new syntax to handle this case, but if you think you’re creating lots of these tables and mixing/matching different tables, perhaps some abstract mixins will simplify things. For Example:

class CharacterLink(models.Model):
    character =  models.ForeignKey('NWODCharacter')
    class Meta:
        abstract = True

class SkillLink(models.Model):
    skill = models.ForeignKey('Skill', choices = SKILL_CHOICES)
    class Meta:
        abstract = True

class AttributeLink(models.Model):
    attribute = models.ForeignKey('Attribute', choices = ATTRIBUTE_CHOICES)
    class Meta:
        abstract = True

class CharacterSkillLink(CharacterLink, SkillLink):
    value = models.IntegerRangeField(min_value=1, max_value=5)
    speciality = models.CharField(max_length=200)

class CharacterAttributeLink(CharacterLink, AttributeLink):
    value = model.IntegerRangeField(min_value=1, max_value=5)
👤dylrei

Leave a comment