(this is experimental package)
handling select_related and prefetch_reated, semi-automatically.
from django_aggressivequery import from_queryset
(
from_queryset(UserInfo.objects.filter(point__gt=0), ["user__teams__games"])
.prefetch_filter(
user__teams__games=lambda qs: qs.filter(name__contains="-a")
)
)
# almost same means
from django.db.models import Prefetch
(
UserInfo.objects.filter(point__gt=0)
.select_related("user")
.prefetch_related(
"user__teams",
Prefetch("user__teams__games", queryset=Game.objects.filter(name__contains="-a"))
)
)
SQL example
SELECT
"userinfo"."id", "userinfo"."point", "userinfo"."ctime", "userinfo"."user_id",
"user"."id", "user"."name", "user"."ctime"
FROM "userinfo"
INNER JOIN "user" ON ("userinfo"."user_id" = "user"."id")
WHERE "userinfo"."point" > 0;
SELECT
("team_users"."user_id") AS "_prefetch_related_val_user_id",
"team"."id", "team"."name", "team"."price", "team"."ctime"
FROM "team"
INNER JOIN "team_users" ON ("team"."id" = "team_users"."team_id")
WHERE "team_users"."user_id" IN (2);
SELECT
"game"."id", "game"."team_id", "game"."name", "game"."price", "game"."ctime"
FROM "game"
WHERE ("game"."name" LIKE '%-a%' ESCAPE '\' AND "game"."team_id" IN (1, 2));
model
# relation: UserInfo - User *-* Team -* Game
class User(models.Model):
name = models.CharField(max_length=255, default="", null=False)
ctime = models.DateTimeField()
class UserInfo(models.Model):
point = models.IntegerField(null=False, default=0)
user = models.OneToOneField(User, related_name="info")
ctime = models.DateTimeField()
class Team(models.Model):
users = models.ManyToManyField(User, related_name="teams")
name = models.CharField(max_length=255, default="", null=False)
price = models.IntegerField(null=False, default=0)
ctime = models.DateTimeField()
class Game(models.Model):
team = models.ForeignKey(Team, related_name="games")
name = models.CharField(max_length=255, default="", null=False)
price = models.IntegerField(null=False, default=0)
ctime = models.DateTimeField()
more specific option
Calling from_queryset() with more_specific option, then use Query.only().
from django_aggressivequery import from_queryset
(
from_queryset(UserInfo.objects.filter(point__gt=0), ["point", "user__name", "user__teams__name", "user__teams__games__name"], more_specific=True)
.prefetch_filter(
user__teams__games=lambda qs: qs.filter(name__contains="-a")
)
)
0.3.1:
fix bug when unexpected relations are found.
0.3.0: - fix bug that duplicated hints are occured - fix bug that get_accessor_name() method is not used - adding extension feature. - reimplementing skip_filter() as extension - implementing custom_prefetch() as extension - reimplementing prefetch_filter() as extension - (module separation)
0.2.0: - skipping function support (AggressiveQuery.skip_filter())
0.1.2: - gentle type check, in from_query()
0.1.1 - remove need less join (on prefetch releated)
0.1 - first release
Metadata
Release files for django-aggressivequery 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-aggressivequery-0.3.2.tar.gz | 9.7 kB | Without provenance | Details for django-aggressivequery-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_aggressivequery-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for django_aggressivequery-0.3.2-py3-none-any.whl |
Total release size: 22.9 kB
Release files / django-aggressivequery-0.3.2.tar.gz
| Download URL | django-aggressivequery-0.3.2.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c02bac3f2c6420eecdef36312b1d45366fb724c4e7033f3296bd51c22fa2fa00
|
|
BLAKE2b-256 checksum How to use checksums |
9d7b9b243369f422f974862a7734e45ab0a12582bfa7b4166d57e4a1d88b625a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_aggressivequery-0.3.2-py3-none-any.whl
| Download URL | django_aggressivequery-0.3.2-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7b281c2570cb20a0ed73ce856d7ca35aa4b917e1d7820c9a9c7e6c892bc98c6
|
|
BLAKE2b-256 checksum How to use checksums |
b3875fb6cda467ae90873f1fa6d84ea979ae468fb74ad1ec9ef0e76407b9da26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-aggressivequery 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.