0

I'm currently creating an equipment management database and need to allow equipment to be associated with other equipment.

Thanks to this stackoverflow question I currently have something akin to the following (vastly simplified):

class Equipment(models.Model):
    equipment_title = models.CharField()
    relates_to = models.ForeignKey('self')

However, to relate a dynamic number of equipment to other equipment I think I need something like a one-to-many field that doesn't exist natively within Django, e.g. a filter housing may be associated with many filter units, and several filter housings may be associated with a machine tool.

How can I get around this? I'm not sure that it's the right place for a many-to-many field...

Community
  • 1
  • 1
TimJ
  • 399
  • 4
  • 18

1 Answers1

1

A ForeignKey is a one-to-many relationship, defined on the "many" side. Since your relationship is pointing to self anyway, it already does what you want.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895