Jeden z moich witryn Django ma następujące modele baz danych: W Django App „wspólny”:Django Admin zmiana obciążenia forma dość powolna
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)
W Django App „sitcomie”:
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)
W short, model class Relation ma 3 klucze obce dla innych tabel. Problem polega na tym, że gdy używam Administratora Django do zmiany pojedynczej relacji, strona (change_form) ładuje się dość wolno. Później zmieniłem modelu klasy Relacja następująco:
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)
Modyfikacja zmieniła klucze obce do IntegerFields, więc wyłączył niektóre magii wewnątrz systemu Django ORM, a teraz formie zmiana strona ładuje się bardzo szybko. Moje pytanie brzmi, jaka jest "wyłączona magia wewnątrz django orm"? co może spowodować problem?
dziękuję bardzo! to działa, a teraz mogę ponownie użyć ForeignKey, to znacznie więcej wygody. – Brent81