开发者

Django database design help

开发者 https://www.devze.com 2023-03-09 04:14 出处:网络
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,

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

精彩评论

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