开发者

Django database design help

I'm designing a project management site, The user needs to enter the hardware required for the project in addition to other details. For example,

project_name, project_location and hardware: A (5 units) B (10 units) C (1 unit)

The number of hardware types per p开发者_Go百科roject is not fixed. How do I design this model?


Could this do the job?

class Project(models.Model):
    name = models.CharField()
    location = models.CharField()

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

class HardwareUnits(models.Model):
    project = models.ForeignKey(Project)
    hardware = models.ForeignKey(Hardware)
    unit_count = models.IntegerField()

If you use the Admin interface, you could attach inlines of HardwareUnits in ProjectAdmin, and the user will be able to chose the hardwares and the number of units for each of them directly in the Project admin edit page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜