私の Django Web サイトの 1 つには、次のデータベース モデルがあります。
class Collection(models.Model):
name = models.CharField(max_length = 255, unique = True)
_short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
class Particle(models.Model):
content = models.TextField(blank=False)
owner = models.ForeignKey(Collection)
order = models.IntegerField(null=True, blank=True)
Django アプリの「シットコム」では:
class Media(models.Model):
name = models.CharField(max_length = 248)
_short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
capital = models.CharField(max_length = 1)
description = models.TextField(blank=True)
progress = models.CharField(max_length = 32, blank=True, null=True)
class Relation(models.Model):
name = models.CharField(max_length = 128)
_short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
description = models.TextField(blank=True)
parent = models.ForeignKey('self', blank=True, null=True)
order = models.IntegerField(blank=True, null=True)
particle = models.ForeignKey(Particle, blank=True, null=True)
media = models.ForeignKey(Media, blank=True, null=True)
つまり、モデル クラス Relation には、他のテーブルへの 3 つの外部キーがあります。問題は、Django Admin を使用して単一のリレーションを変更すると、ページ (change_form) の読み込みがかなり遅くなることです。その後、モデル クラス Relation を次のように変更しました。
class Relation(models.Model):
name = models.CharField(max_length = 128)
_short_name = models.CharField(db_column="short_name", max_length = 32, blank=True)
description = models.TextField(blank=True)
order = models.IntegerField(blank=True, null=True)
parent_id = models.IntegerField(blank=True, null=True)
particle_id = models.IntegerField(blank=True, null=True)
media_id = models.IntegerField(blank=True, null=True)
この変更により、外部キーが IntegerField に変更されたため、Django ORM システム内のいくつかの魔法が無効になり、変更フォーム ページの読み込みが非常に高速になりました。私の質問は、「django orm 内の無効化された魔法」とは何ですか? 問題を引き起こす可能性のあるものは何ですか?