# -*- coding: utf-8 -*- """ Tencent is pleased to support the open source community by making 藍鯨智雲(BlueKing) available. Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://opensource.org/licenses/MIT Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from django.db import models class ops(models.Model): name = models.CharField(max_length=30) class shift(models.Model): shift_class = models.CharField(max_length=30) class ops_shift(models.Model): """ 多個字段對應同一個外鍵的情況下會報錯 原因是指向同一模型的三個外鍵反向關聯名稱產生了沖突,shift模型對Day1字段的反向關聯名稱為ops_shift_set(), 對Day2的反向關聯名稱也是ops_shift_set(),對Day3的反向關聯名稱還是ops_shift_set()。 解決方法:給models.ForeignKey()加入related_name參數,定義不同的關聯名稱。 db_column屬性是用來定義在數據庫中此字段的名稱 """ ops_name = models.ForeignKey(ops,db_column='ops_name') Day1 = models.ForeignKey(shift,related_name='ops_shift_Day1',default='',db_column='Day1') Day2 = models.ForeignKey(shift,related_name='ops_shift_Day2',default='',db_column='Day2') Day3 = models.ForeignKey(shift,related_name='ops_shift_Day3',default='',db_column='Day3') Day4 = models.ForeignKey(shift,related_name='ops_shift_Day4',default='',db_column='Day4') Day5 = models.ForeignKey(shift,related_name='ops_shift_Day5',default='',db_column='Day5') Day6 = models.ForeignKey(shift,related_name='ops_shift_Day6',default='',db_column='Day6') Day7 = models.ForeignKey(shift,related_name='ops_shift_Day7',default='',db_column='Day7') Day8 = models.ForeignKey(shift,related_name='ops_shift_Day8',default='',db_column='Day8') Day9 = models.ForeignKey(shift,related_name='ops_shift_Day9',default='',db_column='Day9') Day10 = models.ForeignKey(shift,related_name='ops_shift_Day10',default='',db_column='Day10') Day11 = models.ForeignKey(shift,related_name='ops_shift_Day11',default='',db_column='Day11') Day12 = models.ForeignKey(shift,related_name='ops_shift_Day12',default='',db_column='Day12') Day13 = models.ForeignKey(shift,related_name='ops_shift_Day13',default='',db_column='Day13') Day14 = models.ForeignKey(shift,related_name='ops_shift_Day14',default='',db_column='Day14') Day15 = models.ForeignKey(shift,related_name='ops_shift_Day15',default='',db_column='Day15') Day16 = models.ForeignKey(shift,related_name='ops_shift_Day16',default='',db_column='Day16') Day17 = models.ForeignKey(shift,related_name='ops_shift_Day17',default='',db_column='Day17') Day18 = models.ForeignKey(shift,related_name='ops_shift_Day18',default='',db_column='Day18') Day19 = models.ForeignKey(shift,related_name='ops_shift_Day19',default='',db_column='Day19') Day20 = models.ForeignKey(shift,related_name='ops_shift_Day20',default='',db_column='Day20') Day21 = models.ForeignKey(shift,related_name='ops_shift_Day21',default='',db_column='Day21') Day22 = models.ForeignKey(shift,related_name='ops_shift_Day22',default='',db_column='Day22') Day23 = models.ForeignKey(shift,related_name='ops_shift_Day23',default='',db_column='Day23') Day24 = models.ForeignKey(shift,related_name='ops_shift_Day24',default='',db_column='Day24') Day25 = models.ForeignKey(shift,related_name='ops_shift_Day25',default='',db_column='Day25') Day26 = models.ForeignKey(shift,related_name='ops_shift_Day26',default='',db_column='Day26') Day27 = models.ForeignKey(shift,related_name='ops_shift_Day27',default='',db_column='Day27') Day28 = models.ForeignKey(shift,related_name='ops_shift_Day28',default='',db_column='Day28') Day29 = models.ForeignKey(shift,related_name='ops_shift_Day29',default='',db_column='Day29') Day30 = models.ForeignKey(shift,related_name='ops_shift_Day30',default='',db_column='Day30') Day31 = models.ForeignKey(shift,related_name='ops_shift_Day31',default='',db_column='Day31') class Meta: """ 在Django的后台可以顯示此處定義的中文名稱 """ verbose_name=u'排班表' verbose_name_plural = u"排班表"