Django model naming convention

前端 未结 4 828
轻奢々
轻奢々 2021-02-02 09:45

What is the preferred naming convention for Django model classes?

4条回答
  •  -上瘾入骨i
    2021-02-02 10:34

    In adition, when you need related objects for a Model of more than one word, you can use the _set attribute. Example:

    class ProcessRoom(models.Model):
    ...
        plant = models.ForeignKey("Plant", verbose_name='planta', on_delete=models.CASCADE)
    

    Then, related objects will be:

    plant = Plant.object.get(id=1)
    process_rooms = plant.processroom_set.all
    

提交回复
热议问题