Notification という抽象クラスがあります。NearNotification と FarNotification という 2 つの具体的な実装があります。
それぞれに異なるエンティティが関連付けられています。1 つは部門で、もう 1 つはグループです。
NearNotification の部門または FarNotifications のグループに関連付けられた電子メールに電子メールを送信したいと考えています。
現在、私の抽象 Notification クラスは次のようになっています。
class Notification(models.Model):
name = models.CharField(max_length=256)
class Meta:
abstract = True
def send(self):
group_email = self.group.email
department_email = self.department.email
作成されたクラス、部門またはグループに応じて、部門またはグループ フィールドが入力されます。
このサブクラスを条件付きで並べ替えて、使用する電子メールを決定するにはどうすればよいですか?
何かのようなもの
def send(self):
if concrete class = FarNotification:
group_email = self.group.email
elif if concrete class = NearNotification:
department_email = self.department.email