statezero 0.1.0b12__py3-none-any.whl → 0.1.0b13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- statezero/adaptors/django/extensions/custom_field_serializers/money_field.py +8 -0
- statezero/adaptors/django/query_optimizer.py +40 -2
- {statezero-0.1.0b12.dist-info → statezero-0.1.0b13.dist-info}/METADATA +1 -1
- {statezero-0.1.0b12.dist-info → statezero-0.1.0b13.dist-info}/RECORD +7 -7
- {statezero-0.1.0b12.dist-info → statezero-0.1.0b13.dist-info}/WHEEL +0 -0
- {statezero-0.1.0b12.dist-info → statezero-0.1.0b13.dist-info}/licenses/license.md +0 -0
- {statezero-0.1.0b12.dist-info → statezero-0.1.0b13.dist-info}/top_level.txt +0 -0
|
@@ -15,6 +15,14 @@ class MoneyFieldSerializer(serializers.Field):
|
|
|
15
15
|
self.decimal_places = kwargs.pop("decimal_places", 2)
|
|
16
16
|
super().__init__(**kwargs)
|
|
17
17
|
|
|
18
|
+
@classmethod
|
|
19
|
+
def get_prefetch_db_fields(cls, field_name: str):
|
|
20
|
+
"""
|
|
21
|
+
Return all database fields required for this field to serialize.
|
|
22
|
+
MoneyField creates two database columns: field_name and field_name_currency.
|
|
23
|
+
"""
|
|
24
|
+
return [field_name, f"{field_name}_currency"]
|
|
25
|
+
|
|
18
26
|
def to_representation(self, value):
|
|
19
27
|
djmoney_field = MoneyField(
|
|
20
28
|
max_digits=self.max_digits, decimal_places=self.decimal_places
|
|
@@ -477,7 +477,34 @@ def optimize_query(queryset, fields=None, fields_map=None, depth=0, use_only=Tru
|
|
|
477
477
|
related_fields_to_fetch = set()
|
|
478
478
|
|
|
479
479
|
if fields_map and related_model_name in fields_map:
|
|
480
|
-
|
|
480
|
+
# Process each field, checking for custom serializers
|
|
481
|
+
from statezero.adaptors.django.serializers import get_custom_serializer
|
|
482
|
+
related_meta = _get_model_meta(related_model)
|
|
483
|
+
for field_name in fields_map[related_model_name]:
|
|
484
|
+
try:
|
|
485
|
+
field_obj = related_meta.get_field(field_name)
|
|
486
|
+
if not field_obj.is_relation:
|
|
487
|
+
# Check if this field has a custom serializer with explicit DB field requirements
|
|
488
|
+
custom_serializer = get_custom_serializer(field_obj.__class__)
|
|
489
|
+
if custom_serializer and hasattr(custom_serializer, 'get_prefetch_db_fields'):
|
|
490
|
+
# Use the explicit list from the custom serializer
|
|
491
|
+
db_fields = custom_serializer.get_prefetch_db_fields(field_name)
|
|
492
|
+
for db_field in db_fields:
|
|
493
|
+
related_fields_to_fetch.add(db_field)
|
|
494
|
+
logger.debug(f"Using custom DB fields {db_fields} for field '{field_name}' in {related_model_name}")
|
|
495
|
+
else:
|
|
496
|
+
# No custom serializer, just add the field itself
|
|
497
|
+
related_fields_to_fetch.add(field_name)
|
|
498
|
+
else:
|
|
499
|
+
# Relation field, add as-is
|
|
500
|
+
related_fields_to_fetch.add(field_name)
|
|
501
|
+
except FieldDoesNotExist:
|
|
502
|
+
# Field doesn't exist, add it anyway (might be computed)
|
|
503
|
+
related_fields_to_fetch.add(field_name)
|
|
504
|
+
except Exception as e:
|
|
505
|
+
logger.error(f"Error checking custom serializer for field '{field_name}' in {related_model_name}: {e}")
|
|
506
|
+
# On error, add the field anyway to be safe
|
|
507
|
+
related_fields_to_fetch.add(field_name)
|
|
481
508
|
else:
|
|
482
509
|
# If no field restrictions are provided, get all fields
|
|
483
510
|
all_fields = [f.name for f in related_model._meta.get_fields() if f.concrete]
|
|
@@ -531,7 +558,18 @@ def optimize_query(queryset, fields=None, fields_map=None, depth=0, use_only=Tru
|
|
|
531
558
|
try:
|
|
532
559
|
field_obj = root_meta.get_field(field_name)
|
|
533
560
|
if not field_obj.is_relation:
|
|
534
|
-
|
|
561
|
+
# Check if this field has a custom serializer with explicit DB field requirements
|
|
562
|
+
from statezero.adaptors.django.serializers import get_custom_serializer
|
|
563
|
+
custom_serializer = get_custom_serializer(field_obj.__class__)
|
|
564
|
+
if custom_serializer and hasattr(custom_serializer, 'get_prefetch_db_fields'):
|
|
565
|
+
# Use the explicit list from the custom serializer
|
|
566
|
+
db_fields = custom_serializer.get_prefetch_db_fields(field_name)
|
|
567
|
+
for db_field in db_fields:
|
|
568
|
+
root_fields_to_fetch.add(db_field)
|
|
569
|
+
logger.debug(f"Using custom DB fields {db_fields} for field '{field_name}'")
|
|
570
|
+
else:
|
|
571
|
+
# No custom serializer, just add the field itself
|
|
572
|
+
root_fields_to_fetch.add(field_name)
|
|
535
573
|
elif isinstance(field_obj, (ForeignKey, OneToOneField)):
|
|
536
574
|
# If FK/O2O itself is requested directly, include its id field
|
|
537
575
|
root_fields_to_fetch.add(field_obj.attname)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: statezero
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0b13
|
|
4
4
|
Summary: Connect your Python backend to a modern JavaScript SPA frontend with 90% less complexity.
|
|
5
5
|
Author-email: Robert <robert.herring@statezero.dev>
|
|
6
6
|
Project-URL: homepage, https://www.statezero.dev
|
|
@@ -12,7 +12,7 @@ statezero/adaptors/django/helpers.py,sha256=0Dyq5vboDuTUaH-KpS3oVDjastA9yv6xI6Xp
|
|
|
12
12
|
statezero/adaptors/django/middleware.py,sha256=YVr8fkqCk51xJQM-ovtrUiB9Kt9H81cLd9xv4cM9YlM,410
|
|
13
13
|
statezero/adaptors/django/orm.py,sha256=Z62XheCvuKIpKOoIIiLLOwrpJ5jPhv-BGxg-pqPgNaU,40757
|
|
14
14
|
statezero/adaptors/django/permissions.py,sha256=fU2c4bKK0zX2uuVB0UazZHTI-5OkiI5-BtPNcPEWmW0,9525
|
|
15
|
-
statezero/adaptors/django/query_optimizer.py,sha256=-
|
|
15
|
+
statezero/adaptors/django/query_optimizer.py,sha256=-iAh5kyE8WNZdjb_qBbNag_nxKzejroUYPBdwG_uVaQ,41462
|
|
16
16
|
statezero/adaptors/django/schemas.py,sha256=aIUbTvyEsQUWYN_g4oiorih_gOhT8ti-bLEK4TMk7Tw,13449
|
|
17
17
|
statezero/adaptors/django/serializers.py,sha256=YFFDu6bzoWkSEOVH5Wmc4yJ8SaOkUA6HbXXYt6djlfc,23296
|
|
18
18
|
statezero/adaptors/django/urls.py,sha256=OrGQ60vj_wrbiREAKmYDZTwohpKmgjH9n0fdOw1qPaY,924
|
|
@@ -20,7 +20,7 @@ statezero/adaptors/django/views.py,sha256=2bJDbXuRGoG2_7zyapWzmRzpSVUHkCpcI58wsr
|
|
|
20
20
|
statezero/adaptors/django/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
21
|
statezero/adaptors/django/extensions/custom_field_serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
statezero/adaptors/django/extensions/custom_field_serializers/file_fields.py,sha256=BaOaJPmyzCp-YFwpsTOvGHjHpk6s8UJuZ5JsF-PEGV4,4518
|
|
23
|
-
statezero/adaptors/django/extensions/custom_field_serializers/money_field.py,sha256=
|
|
23
|
+
statezero/adaptors/django/extensions/custom_field_serializers/money_field.py,sha256=Oms0_hOaxpeTDI7JhgwFud8kYIVxX-fEflO7C1QBi9I,3083
|
|
24
24
|
statezero/adaptors/django/migrations/0001_initial.py,sha256=F5kr819sPN5_xc82GpX6-e5CwVWDvywePWC0cv9zYKY,1318
|
|
25
25
|
statezero/adaptors/django/migrations/0002_delete_modelviewsubscription.py,sha256=7fJXl18gvMdEjKnQbO2h8mPAl4jNGVCAb60NRl5V6tI,317
|
|
26
26
|
statezero/adaptors/django/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -41,8 +41,8 @@ statezero/core/hook_checks.py,sha256=uqtvwRx1qGsF7Vc49elAWdOjMzhuv3RADKY1wiLvhK4
|
|
|
41
41
|
statezero/core/interfaces.py,sha256=kVkNWyh52tUlzD02CRheLJof3DyQoVcPuvX33fL6sn8,20544
|
|
42
42
|
statezero/core/process_request.py,sha256=dwIeBEVOE8zA-oE1h65XNOGiVqFbbXA7SzTAguLNgZk,8060
|
|
43
43
|
statezero/core/types.py,sha256=mMtqK3fGhEM6LtzUgQrxlyP-V0VgVqc-1eVKgRjTzp0,913
|
|
44
|
-
statezero-0.1.
|
|
45
|
-
statezero-0.1.
|
|
46
|
-
statezero-0.1.
|
|
47
|
-
statezero-0.1.
|
|
48
|
-
statezero-0.1.
|
|
44
|
+
statezero-0.1.0b13.dist-info/licenses/license.md,sha256=0uKjybTt9K_YbEmYgf25JN292qjjJ-BPofvIZ3wdtX4,7411
|
|
45
|
+
statezero-0.1.0b13.dist-info/METADATA,sha256=GANWIX-qVffIrC0f_usUkmxfsPPmunYXdVYJGVFoHiY,6704
|
|
46
|
+
statezero-0.1.0b13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
47
|
+
statezero-0.1.0b13.dist-info/top_level.txt,sha256=UAuZYPKczradU1kcMQxsGjUzEW0qdgsqzhXyscrcLpw,10
|
|
48
|
+
statezero-0.1.0b13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|