model-bakery 1.18.1__tar.gz → 1.18.3__tar.gz
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.
Potentially problematic release.
This version of model-bakery might be problematic. Click here for more details.
- {model_bakery-1.18.1 → model_bakery-1.18.3}/PKG-INFO +1 -1
- model_bakery-1.18.3/model_bakery/__about__.py +1 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/baker.py +22 -4
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/content_types.py +3 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/recipe.py +2 -1
- {model_bakery-1.18.1 → model_bakery-1.18.3}/pyproject.toml +5 -7
- model_bakery-1.18.1/model_bakery/__about__.py +0 -1
- {model_bakery-1.18.1 → model_bakery-1.18.3}/.gitignore +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/LICENSE +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/README.md +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/__init__.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/_types.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/exceptions.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/generators.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/gis.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/mock_file.txt +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/mock_img.jpeg +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/py.typed +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/random_gen.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/timezone.py +0 -0
- {model_bakery-1.18.1 → model_bakery-1.18.3}/model_bakery/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: model-bakery
|
|
3
|
-
Version: 1.18.
|
|
3
|
+
Version: 1.18.3
|
|
4
4
|
Summary: Smart object creation facility for Django.
|
|
5
5
|
Project-URL: Homepage, https://github.com/model-bakers/model_bakery
|
|
6
6
|
Author-email: berin <bernardoxhc@gmail.com>, amureki <amureki@hey.com>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.18.3"
|
|
@@ -51,7 +51,7 @@ from .utils import (
|
|
|
51
51
|
|
|
52
52
|
if BAKER_CONTENTTYPES:
|
|
53
53
|
from django.contrib.contenttypes import models as contenttypes_models
|
|
54
|
-
from django.contrib.contenttypes.fields import GenericRelation
|
|
54
|
+
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
|
55
55
|
else:
|
|
56
56
|
contenttypes_models = None
|
|
57
57
|
GenericRelation = None
|
|
@@ -501,6 +501,7 @@ class Baker(Generic[M]):
|
|
|
501
501
|
) -> M:
|
|
502
502
|
one_to_many_keys = {}
|
|
503
503
|
auto_now_keys = {}
|
|
504
|
+
generic_foreign_keys = {}
|
|
504
505
|
|
|
505
506
|
for k in tuple(attrs.keys()):
|
|
506
507
|
field = getattr(self.model, k, None)
|
|
@@ -517,12 +518,15 @@ class Baker(Generic[M]):
|
|
|
517
518
|
):
|
|
518
519
|
auto_now_keys[k] = attrs[k]
|
|
519
520
|
|
|
521
|
+
if BAKER_CONTENTTYPES and isinstance(field, GenericForeignKey):
|
|
522
|
+
generic_foreign_keys[k] = attrs.pop(k)
|
|
523
|
+
|
|
520
524
|
instance = self.model(**attrs)
|
|
521
|
-
# m2m only works for persisted instances
|
|
522
525
|
if _commit:
|
|
523
526
|
instance.save(**_save_kwargs)
|
|
524
527
|
self._handle_one_to_many(instance, one_to_many_keys)
|
|
525
528
|
self._handle_m2m(instance)
|
|
529
|
+
self._handle_generic_foreign_keys(instance, generic_foreign_keys)
|
|
526
530
|
self._handle_auto_now(instance, auto_now_keys)
|
|
527
531
|
|
|
528
532
|
if _from_manager:
|
|
@@ -622,7 +626,7 @@ class Baker(Generic[M]):
|
|
|
622
626
|
|
|
623
627
|
if field.name not in self.model_attrs: # noqa: SIM102
|
|
624
628
|
if field.name not in self.rel_fields and (
|
|
625
|
-
field.
|
|
629
|
+
not field.fill_optional and field.null
|
|
626
630
|
):
|
|
627
631
|
return True
|
|
628
632
|
|
|
@@ -638,6 +642,9 @@ class Baker(Generic[M]):
|
|
|
638
642
|
for key, values in attrs.items():
|
|
639
643
|
manager = getattr(instance, key)
|
|
640
644
|
|
|
645
|
+
if callable(values):
|
|
646
|
+
values = values()
|
|
647
|
+
|
|
641
648
|
for value in values:
|
|
642
649
|
# Django will handle any operation to persist nested non-persisted FK because
|
|
643
650
|
# save doesn't do so and, thus, raises constraint errors. That's why save()
|
|
@@ -659,6 +666,9 @@ class Baker(Generic[M]):
|
|
|
659
666
|
|
|
660
667
|
def _handle_m2m(self, instance: Model):
|
|
661
668
|
for key, values in self.m2m_dict.items():
|
|
669
|
+
if callable(values):
|
|
670
|
+
values = values()
|
|
671
|
+
|
|
662
672
|
for value in values:
|
|
663
673
|
if not value.pk:
|
|
664
674
|
value.save()
|
|
@@ -676,6 +686,10 @@ class Baker(Generic[M]):
|
|
|
676
686
|
}
|
|
677
687
|
make(through_model, _using=self._using, **base_kwargs)
|
|
678
688
|
|
|
689
|
+
def _handle_generic_foreign_keys(self, instance: Model, attrs: Dict[str, Any]):
|
|
690
|
+
for key, value in attrs.items():
|
|
691
|
+
setattr(instance, key, value)
|
|
692
|
+
|
|
679
693
|
def _remote_field(
|
|
680
694
|
self, field: Union[ForeignKey, OneToOneField]
|
|
681
695
|
) -> Union[OneToOneRel, ManyToOneRel]:
|
|
@@ -696,12 +710,16 @@ class Baker(Generic[M]):
|
|
|
696
710
|
model.
|
|
697
711
|
"""
|
|
698
712
|
is_content_type_fk = False
|
|
713
|
+
is_generic_fk = False
|
|
699
714
|
if BAKER_CONTENTTYPES:
|
|
700
715
|
is_content_type_fk = isinstance(field, ForeignKey) and issubclass(
|
|
701
716
|
self._remote_field(field).model, contenttypes_models.ContentType
|
|
702
717
|
)
|
|
718
|
+
is_generic_fk = isinstance(field, GenericForeignKey)
|
|
719
|
+
if is_generic_fk:
|
|
720
|
+
generator = self.type_mapping[GenericForeignKey]
|
|
703
721
|
# we only use default unless the field is overwritten in `self.rel_fields`
|
|
704
|
-
|
|
722
|
+
elif field.has_default() and field.name not in self.rel_fields:
|
|
705
723
|
if callable(field.default):
|
|
706
724
|
return field.default()
|
|
707
725
|
return field.default
|
|
@@ -7,8 +7,11 @@ default_contenttypes_mapping = {}
|
|
|
7
7
|
__all__ = ["BAKER_CONTENTTYPES", "default_contenttypes_mapping"]
|
|
8
8
|
|
|
9
9
|
if BAKER_CONTENTTYPES:
|
|
10
|
+
from django.contrib.contenttypes.fields import GenericForeignKey
|
|
10
11
|
from django.contrib.contenttypes.models import ContentType
|
|
11
12
|
|
|
12
13
|
from . import random_gen
|
|
13
14
|
|
|
14
15
|
default_contenttypes_mapping[ContentType] = random_gen.gen_content_type
|
|
16
|
+
# a small hack to generate random object for GenericForeignKey
|
|
17
|
+
default_contenttypes_mapping[GenericForeignKey] = random_gen.gen_content_type
|
|
@@ -78,7 +78,8 @@ class Recipe(Generic[M]):
|
|
|
78
78
|
else:
|
|
79
79
|
mapping[k] = v.recipe.prepare(_using=_using, **recipe_attrs)
|
|
80
80
|
elif isinstance(v, related):
|
|
81
|
-
mapping[k] = v.make
|
|
81
|
+
mapping[k] = v.make
|
|
82
|
+
|
|
82
83
|
mapping.update(new_attrs)
|
|
83
84
|
mapping.update(rel_fields_attrs)
|
|
84
85
|
return mapping
|
|
@@ -94,9 +94,7 @@ disallow_untyped_calls = true
|
|
|
94
94
|
[tool.pytest.ini_options]
|
|
95
95
|
addopts = "--tb=short -rxs --nomigrations"
|
|
96
96
|
|
|
97
|
-
[tool.ruff]
|
|
98
|
-
target-version = "py38"
|
|
99
|
-
|
|
97
|
+
[tool.ruff.lint]
|
|
100
98
|
select = [
|
|
101
99
|
"S", # flake8-bandit
|
|
102
100
|
"B", # flake8-bugbear
|
|
@@ -113,19 +111,19 @@ select = [
|
|
|
113
111
|
|
|
114
112
|
ignore = ["B904", "E501", "S101", "D1", "D212"]
|
|
115
113
|
|
|
116
|
-
[tool.ruff.per-file-ignores]
|
|
114
|
+
[tool.ruff.lint.per-file-ignores]
|
|
117
115
|
"tests/test_*.py" = [
|
|
118
116
|
"S",
|
|
119
117
|
]
|
|
120
118
|
|
|
121
|
-
[tool.ruff.isort]
|
|
119
|
+
[tool.ruff.lint.isort]
|
|
122
120
|
combine-as-imports=true
|
|
123
121
|
split-on-trailing-comma=true
|
|
124
122
|
section-order = ["future", "standard-library", "django", "third-party", "first-party", "local-folder"]
|
|
125
123
|
force-wrap-aliases=true
|
|
126
124
|
|
|
127
|
-
[tool.ruff.isort.sections]
|
|
125
|
+
[tool.ruff.lint.isort.sections]
|
|
128
126
|
django = ["django"]
|
|
129
127
|
|
|
130
|
-
[tool.ruff.pydocstyle]
|
|
128
|
+
[tool.ruff.lint.pydocstyle]
|
|
131
129
|
convention = "google"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.18.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|