appを2つ作り、Aのmodelで登録した内容を継承したmodelを3つ作りたいと考えています。
1つ目のappは製品を登録する台帳機能を持ったAのmodel。 ※作成済み
2つ目のappはAの台帳で登録した内容を引用(継承)した点検チェックシートを作成するためのBとCのmodel。
詳細と困り事は以下。
詳細:
A、台帳登録用:品に対しての情報が登録されて、多数の品が無限に登録されていく。
B、line毎に振り分ける:台帳登録用のmodel class.InsLedgerで登録したカラムの内容を継承してline登録が同じもの同士に分ける。
困り事1⇒line毎にclassを作成する?継承元が際限なく無数に増えていく場合の分け方がわかりません。
C、Bで分けたline毎の情報を読み取り専用(更新不可)で項目にして点検チェックシート用のmodelを作成する。
困り事2⇒ここも複数のclassを作成する必要がありますか?
具体的なソースコード、何を使っていくか、
また、参考になるURL等いただけても大変助かります。
よろしくお願いいたします。
Aの台帳model↓
python
1 2class InsLedger(models.Model): 3 measuring_ins_group = models.IntegerField(choices=MEASURING_INS_GROUP_CHOICES,default=1) 4 measuring_tool = models.ForeignKey(Device, on_delete=models.CASCADE) 5 ins_num = models.CharField(max_length=10) 6 calibration_type = models.IntegerField(choices=CALIBRATION_CHOICES) 7 calibration_date = models.DateField(default=now)#datetime.datetime.now()) 8 next_calibration_date = models.DateField() 9 serial_num = models.CharField(max_length=20, null=True, blank=True, default='') 10 product_num = models.ForeignKey(Product_num, on_delete=models.CASCADE) 11 # team = models.ForeignKey(TeamModel, on_delete=models.CASCADE, related_name='teams1') 12 line = models.ForeignKey(LineModel, on_delete=models.CASCADE, related_name='lines1') 13 useapp = models.ForeignKey(Useapp, on_delete=models.CASCADE) 14 spec1 = models.ForeignKey(Spec1, on_delete=models.CASCADE) 15 spec2 = models.ForeignKey(Spec2, on_delete=models.CASCADE) 16 spec3 = models.IntegerField(choices=SPEC3_CHOICES) 17 check_items = models.ForeignKey(Check_Items, on_delete=models.CASCADE) 18 ins_result = models.CharField(max_length=10,) 19 20 def save(self, *args, **kwargs): 21 auto_now = kwargs.pop('next_calibration_date_auto_now', True) 22 if auto_now: 23 if self.calibration_type == CALIBRATION_CHOICES[0][0]: 24 calibration_span = 1 25 elif self.calibration_type == CALIBRATION_CHOICES[1][0]: 26 calibration_span = 2 27 elif self.calibration_type == CALIBRATION_CHOICES[2][0]: 28 calibration_span = 5 29 elif self.calibration_type == CALIBRATION_CHOICES[3][0]: 30 calibration_span = 10 31 32 self.next_calibration_date = self.calibration_date + relativedelta(years=calibration_span) 33 self.passorfail() 34 super().save(*args, **kwargs) 35 36 37 def passorfail(self): 38 today = datetime.today() 39 if self.next_calibration_date.strftime('%Y-%m-%d') == today.strftime('%Y-%m-%d'): 40 pass_result = ('対象') 41 elif self.next_calibration_date.strftime('%Y-%m-%d') > today.strftime('%Y-%m-%d'): 42 pass_result = ('合格') 43 else: 44 pass_result = ('不合格') 45 46 self.ins_result = pass_result 47 48 49 def __str__(self): 50 return str(self.measuring_tool) 51 52 class Meta: 53 verbose_name = "台帳"

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/09/06 04:26 編集
2021/09/06 04:54
2021/09/06 05:12
2021/09/06 06:47 編集