DryORM
Code
Result
no cache
SQLite
PostgreSQL 17.4
MariaDB 11.4.5
Select a template
dryorm features
basic
bulk create
bulk fake
csv import
basic fk
self fk
user profile
dryorm tabular output
from django.db import models from django.db.models import Prefetch, Q class Network(models.Model): code = models.CharField(max_length=8) def __str__(self) -> str: return self.code class Station(models.Model): code = models.CharField(max_length=8) network = models.ForeignKey(Network, on_delete=models.PROTECT) class Meta: constraints = [ models.UniqueConstraint( fields=["code", "network"], name="station_code_network_id_unique" ) ] def __str__(self) -> str: return self.code def run(): net1 = Network.objects.create(code="net1") net2 = Network.objects.create(code="net2") stat1 = Station.objects.create( network=net1, code="stat1", ) stat25 = Station.objects.create( network=net2, code="stat25", ) networks = list( Network.objects.filter(code="net1").prefetch_related( Prefetch( "station_set", queryset=Station.objects.filter(code="stat1") ) ).union( Network.objects.filter(code="net2").prefetch_related( Prefetch( "station_set", queryset=Station.objects.filter(code="stat25") ) ) ) ) print("with custom prefetch") print(networks[0].station_set.all()) print(networks[1].station_set.all()) networks = list( Network.objects.filter(code="net1").prefetch_related("station_set").union( Network.objects.filter(code="net2").prefetch_related("station_set") )) print("with regular prefetch") print(networks[0].station_set.all()) print(networks[1].station_set.all())
Output
Show Template
No output.
Queries
TCL
TCL
DDL
DDL
SELECT
S
INSERT
I
UPDATE
U
DELETE
D
REVERSE
R
Queries
Q
(
0
)
No queries.
✖ Close
Save & Share
✖
private?
Save
Save & Copy