Database Relation: ManyToMany with extra information?

17 views
Skip to first unread message

maxi....@googlemail.com

unread,
Jan 15, 2016, 4:27:48 AM1/15/16
to Django users
Hi all,

I need some advice regarding the database layout of the following problem:

I have a list P of PCs. I have a list S of Software. Both have different fields and are two models.Model subclasses.
Now, I want to store for each PC in P, which software from S is installed on it and with which version.

So, P has like a ManyToMany relation to S, however for each "link" the extra-field Version would be required.

In a table layout, this could look like this:

Table PC, with columns:
Name,   IP ...

Table Software with columns:  
Name, Description, ...

Table InstalledSoftware with Columns;
PC (links to PC.Name),   Software (links to Software.Name),   Version

With this layout, the problem could be layd out. The questions are:
- Is this the correct layout for this problem? Would you suggest something else?
- can Django support this? How would the code then look like, including relevant queries?

Thanks for your help!
Max

Balázs Oroszi

unread,
Jan 15, 2016, 6:16:52 AM1/15/16
to Django users
I would create a separate model, like VersionedSoftware, which links to Software with ForeignKey (ManyToOne) and includes the version, as I believe the version is related to the software, not the installation event (like a date of installation would for example).

The PC would then reference VersionedSoftware simply with a regular ManyToMany (if you don't need other link specific fields).

Greets,
Balázs
Reply all
Reply to author
Forward
0 new messages