1

The problem: a group of several people can use instruments of different types, but the instruments of the same type are not distinguishable. For instance, a group could use 3 hammers and 4 axes, but we don't need to distinguish individual axes or hammers. UPD: One day we could use another instrument type we can't think of now.

How to design a Django model in this case?

My thoughts:

class Person(models.Model):
    name = models.CharField()

class Group(models.Model):
    title = models.CharField()
    members = models.ForeignKey(Person)
    equip = ???

I've found this question on StackExchange and a code snippet for a Django Dictionary model, but I am still not sure what approach to choose. Even more, there are django-jsonfield and django-picklefield suitable for dictionaries.

Also, do I really need a dictionary here?

Community
  • 1
  • 1
Jantar88
  • 137
  • 8
  • first of all you need to decide whether this is the right approach. normalizing your database is probably a better idea – e4c5 Jan 30 '17 at 14:26
  • I'm not sure I've understood your comment. If I do distinguish individual axes, I can normalize the DB. But I don't, and when I ask someone to fill in a report, he reports "we used 2 axes and 3 hammers", and this is exactly the info I want to store. // Another approach that I see is to make our set of available instrument types constant. But one day we could use another tool we can't think of now. – Jantar88 Jan 30 '17 at 14:39
  • 1
    So what you really need is a table that goes like `tool|job|number_used` – e4c5 Jan 30 '17 at 14:46
  • Thanks! I will ponder over that. – Jantar88 Jan 30 '17 at 15:14

1 Answers1

2

You have persons, that are related to groups. You assign group of persons to specific Job and track equipment by job, equipment type and its count.

class Group(models.Model):
    title = models.CharField()

class Person(models.Model):
    name = models.CharField()
    group = models.ForeignKey(Group)

class Job(models.Model)
    name = models.CharField()
    group = models.ForeignKey(Group)

class EquipmentUsage(models.Model)
    job = models.ForeignKey(Job)
    equip_name = models.CharField()
    count = models.IntegerField()
Dmitry Shilyaev
  • 713
  • 4
  • 10