1👍
✅
Django will handle cross-application and even cross-database joins for you. However, it will be up to the application developer / DevOps to make sure that the cross-database joins are actually doable (e.g., by housing the two databases within the same MySQL or PostGRES instance). However, the code that you have looks relatively funky. To get the server enclosure with rack=10, I would do the following:
from other.app.models import Enclosure
class Server(models.Model):
enclosure = models.ForeignKey(Enclosure, null=True, blank=True, db_index=True, related_name='server_enclosure')
@classmethod
def get_enclosure(cls):
return cls.objects.get(rack=10)
To get the enclosure related to a particular server, you can just use:
p = Server.objects.get(...)
enclosure = p.enclosure
👤2ps
Source:stackexchange.com