djresttoolkit 0.6.0__py3-none-any.whl → 0.6.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: djresttoolkit
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: A collection of Django and DRF utilities to simplify API development.
5
5
  Project-URL: Homepage, https://github.com/shaileshpandit141/djresttoolkit
6
6
  Project-URL: Documentation, https://shaileshpandit141.github.io/djresttoolkit
@@ -6,16 +6,16 @@ src/djresttoolkit/admin.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  src/djresttoolkit/apps.py,sha256=nKb5GUIEhAB3IL3lTmEXNc5XuvvaZupH-1CCuYKFrEQ,158
7
7
  src/djresttoolkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  src/djresttoolkit/dbseed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- src/djresttoolkit/dbseed/models/__init__.py,sha256=SpAEE8mfd_cX8qgI-CeC4r1e17YLAwAlxeFgbK8gtE4,118
10
- src/djresttoolkit/dbseed/models/_base_seed_model.py,sha256=DlbmdafLicKd_ja1AIvKKzyBxdnxdq23zPJwlqxiTl8,2187
9
+ src/djresttoolkit/dbseed/models/__init__.py,sha256=B2WJqw2ncqf5nNhkM3XDFx13oNg2ccsULUQkFAjOyrY,105
11
10
  src/djresttoolkit/dbseed/models/_gen.py,sha256=qBPQaLvh1rcEam0YmE4JBJqpa-Vv5IFlIIagkEMHDVw,206
11
+ src/djresttoolkit/dbseed/models/_seed_model.py,sha256=0cmbi0VNKjmJbwhjeCFsvb3iKYjok6TJOk6Y2MF_3N4,2443
12
12
  src/djresttoolkit/mail/__init__.py,sha256=tB9SdMlhfWQ640q4aobZ0H1c7fTWalpDL2I-onkr2VI,268
13
13
  src/djresttoolkit/mail/_email_sender.py,sha256=bPMqgD5HibJcOZgO6xxHOhdK9HEhnGNC6BoMPpo-h7k,3096
14
14
  src/djresttoolkit/mail/_models.py,sha256=of5KsLGvsN2OWgDYgdtLEijulg817TXgsLKuUdsnDQc,1447
15
15
  src/djresttoolkit/mail/_types.py,sha256=zf6CcXR1ei_UmZ1nLAJa378OAJ6ftnBICqEOkzXPNw8,646
16
16
  src/djresttoolkit/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  src/djresttoolkit/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- src/djresttoolkit/management/commands/dbseed.py,sha256=tMpvvDx_es08GxYKgJ1umJddh_kmIB1Fy0J5Ich2hiE,4248
18
+ src/djresttoolkit/management/commands/dbseed.py,sha256=vS-s_B8No2rTl_T7HuIBg7f_Yp_6lztvK7FbcaxTZaA,4227
19
19
  src/djresttoolkit/middlewares/__init__.py,sha256=GZHU3Yy4xXoEi62tHn0UJNxN6XgGM2_HES8Bt5AS5Lk,100
20
20
  src/djresttoolkit/middlewares/_response_time_middleware.py,sha256=1wCwdkW5Ng6HJo8zx0F7ylms84OGP-1K0kbyG6Vacuk,908
21
21
  src/djresttoolkit/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -27,8 +27,8 @@ src/djresttoolkit/throttling/_throttle_inspector.py,sha256=Kss6ZxKy-EXq9UGaGprGD
27
27
  src/djresttoolkit/views/__init__.py,sha256=XrxBrs6sH4HmUzp41omcmy_y94pSaXAVn01ttQ022-4,76
28
28
  src/djresttoolkit/views/_exceptions/__init__.py,sha256=DrCUxuPNyBR4WhzNutn5HDxLa--q51ykIxSG7_bFsOI,83
29
29
  src/djresttoolkit/views/_exceptions/_exception_handler.py,sha256=_o7If47bzWLl57LeSXSWsIDsJGo2RIpwYAwNQ-hsHVY,2839
30
- djresttoolkit-0.6.0.dist-info/METADATA,sha256=KKviIBCDtQeoaRNcs8w5zZvlTNVyK1KJXwqNo7hcogM,8501
31
- djresttoolkit-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
- djresttoolkit-0.6.0.dist-info/entry_points.txt,sha256=YMhfTF-7mYppO8QqqWnvR_hyMWvoYxD6XI94_ViFu3k,60
33
- djresttoolkit-0.6.0.dist-info/licenses/LICENSE,sha256=8-oZM3yuuTRjySMbVKX9YXYA7Y4M_KhQNBYXPFjeWUo,1074
34
- djresttoolkit-0.6.0.dist-info/RECORD,,
30
+ djresttoolkit-0.6.1.dist-info/METADATA,sha256=doM3qba2_MGPAyrrfz3g79IjcNGaKyqiXYodOYFotso,8501
31
+ djresttoolkit-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
+ djresttoolkit-0.6.1.dist-info/entry_points.txt,sha256=YMhfTF-7mYppO8QqqWnvR_hyMWvoYxD6XI94_ViFu3k,60
33
+ djresttoolkit-0.6.1.dist-info/licenses/LICENSE,sha256=8-oZM3yuuTRjySMbVKX9YXYA7Y4M_KhQNBYXPFjeWUo,1074
34
+ djresttoolkit-0.6.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
- from ._base_seed_model import BaseSeedModel
2
1
  from ._gen import Field, Gen
2
+ from ._seed_model import SeedModel
3
3
 
4
- __all__ = ["BaseSeedModel", "Gen", "Field"]
4
+ __all__ = ["SeedModel", "Gen", "Field"]
@@ -1,31 +1,36 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Any
3
+ from typing import Any, ClassVar
4
4
 
5
5
  from django.db.models import ForeignKey, ManyToManyField, Model, OneToOneField
6
6
  from pydantic import BaseModel
7
7
 
8
8
 
9
- class BaseSeedModel(BaseModel):
9
+ class SeedModel(BaseModel):
10
10
  """
11
11
  Base class for all fake data models.
12
- Each subclass must define a `model` attribute.
12
+ Each subclass must define a `__model__` attribute (a Django model).
13
13
  """
14
14
 
15
- class Meta:
16
- model: type[Model]
15
+ __model__: ClassVar[type[Model] | None] = None
17
16
 
18
17
  def __init_subclass__(cls, **kwargs: Any) -> None:
19
18
  super().__init_subclass__(**kwargs)
20
- if not hasattr(cls, "Meta") or not hasattr(cls.Meta, "model"):
19
+ if not hasattr(cls, "__model__"):
21
20
  raise TypeError(
22
- f"{cls.__name__} must define a Meta class with a Django model"
21
+ f"{cls.__name__} must define a `__model__` attribute "
22
+ f"pointing to a Django model"
23
23
  )
24
24
 
25
25
  @classmethod
26
- def get_meta(cls) -> type[Meta]:
27
- """Class-level access."""
28
- return cls.Meta
26
+ def get_model(cls) -> type[Model]:
27
+ """Class-level access to the Django model."""
28
+ if cls.__model__ is None:
29
+ raise ValueError(
30
+ f"{cls.__name__} has no `__model__` defined. "
31
+ "Please set it to a Django model class."
32
+ )
33
+ return cls.__model__
29
34
 
30
35
  @classmethod
31
36
  def create_instance(cls) -> tuple[dict[str, Any], list[ManyToManyField[Any, Any]]]:
@@ -35,13 +40,13 @@ class BaseSeedModel(BaseModel):
35
40
  data = cls().model_dump()
36
41
 
37
42
  # Handle ForeignKey and OneToOneField
38
- for field in cls.get_meta().model._meta.get_fields():
43
+ for field in cls.get_model()._meta.get_fields():
39
44
  if isinstance(field, (ForeignKey, OneToOneField)):
40
45
  rel_model = field.remote_field.model
41
46
  if rel_model.objects.exists():
42
47
  # For OneToOne, must ensure unique (pick unused relation)
43
48
  if isinstance(field, OneToOneField):
44
- used_ids = cls.get_meta().model.objects.values_list(
49
+ used_ids = cls.get_model().objects.values_list(
45
50
  field.name, flat=True
46
51
  )
47
52
  available = rel_model.objects.exclude(pk__in=used_ids)
@@ -53,7 +58,8 @@ class BaseSeedModel(BaseModel):
53
58
  # Collect ManyToMany fields
54
59
  m2m_fields: list[ManyToManyField[Any, Any]] = [
55
60
  field
56
- for field in cls.get_meta().model._meta.get_fields()
61
+ for field in cls.get_model()._meta.get_fields()
57
62
  if isinstance(field, ManyToManyField)
58
63
  ]
59
64
  return data, m2m_fields
65
+
@@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand, CommandParser
8
8
  from django.db import transaction
9
9
  from django.db.models import Model, QuerySet
10
10
 
11
- from djresttoolkit.dbseed.models import BaseSeedModel
11
+ from djresttoolkit.dbseed.models import SeedModel
12
12
 
13
13
 
14
14
  class Command(BaseCommand):
@@ -48,7 +48,7 @@ class Command(BaseCommand):
48
48
  faker = Faker()
49
49
  faker.seed_instance(seed)
50
50
 
51
- seed_model_classes: list[type[BaseSeedModel]] = []
51
+ seed_model_classes: list[type[SeedModel]] = []
52
52
 
53
53
  # Discover all dbseed dirs in installed apps
54
54
  for app_config in apps.get_app_configs():
@@ -67,8 +67,8 @@ class Command(BaseCommand):
67
67
  attr = getattr(submodule, attr_name)
68
68
  if (
69
69
  isinstance(attr, type)
70
- and issubclass(attr, BaseSeedModel)
71
- and attr is not BaseSeedModel
70
+ and issubclass(attr, SeedModel)
71
+ and attr is not SeedModel
72
72
  ):
73
73
  # Filter by model name if provided
74
74
  if (
@@ -84,7 +84,7 @@ class Command(BaseCommand):
84
84
 
85
85
  # Generate fake data for each discovered dbseed model
86
86
  for dbseed_cls in seed_model_classes:
87
- django_model = dbseed_cls.get_meta().model
87
+ django_model = dbseed_cls.get_model()
88
88
  created_count: int = 0
89
89
 
90
90
  for _ in range(count):