djresttoolkit 0.12.0__tar.gz → 0.13.0__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.
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/PKG-INFO +55 -1
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/README.md +54 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/pyproject.toml +1 -1
- djresttoolkit-0.13.0/src/djresttoolkit/views/mixins/__init__.py +6 -0
- djresttoolkit-0.13.0/src/djresttoolkit/views/mixins/_retrieve_object_mixin.py +41 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/.gitignore +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/LICENSE +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/demo/staticfiles/admin/img/LICENSE +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/admin.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/apps.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/_choice_field.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/_gen.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/_seed_model.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/envconfig/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/envconfig/_env_settings.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/mail/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/mail/_email_sender.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/mail/_models.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/mail/_types.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/dbflush.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/dbseed.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/middlewares/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/middlewares/_response_time_middleware.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/migrations/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/models/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/models/mixins/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/models/mixins/_model_choice_fields_mixin.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/py.typed +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/renderers/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/renderers/_throttle_info_json_renderer.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/serializers/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/serializers/mixins/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/serializers/mixins/_absolute_url_file_mixin.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/serializers/mixins/_bulk_create_mixin.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/throttling/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/throttling/_throttle_inspector.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_api_views/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_api_views/_choice_fields_apiview.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_exceptions/__init__.py +0 -0
- {djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_exceptions/_exception_handler.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: djresttoolkit
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.13.0
|
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
|
@@ -753,6 +753,60 @@ urlpatterns = [
|
|
753
753
|
- Useful for frontend forms or API consumers that need selectable options.
|
754
754
|
- Integrates seamlessly with `ModelChoiceFieldMixin` from `djresttoolkit`.
|
755
755
|
|
756
|
+
### 12. RetrieveObjectMixin — API Reference
|
757
|
+
|
758
|
+
```python
|
759
|
+
from djresttoolkit.views.mixins import RetrieveObjectMixin
|
760
|
+
```
|
761
|
+
|
762
|
+
#### `RetrieveObjectMixin[T: Model]`
|
763
|
+
|
764
|
+
A **generic mixin** to retrieve a single Django model instance by filters.
|
765
|
+
|
766
|
+
#### Class Attributes of Retrieve Object Mixin
|
767
|
+
|
768
|
+
- `queryset: QuerySet[T] | None` — The queryset used to retrieve objects. **Must be set.**
|
769
|
+
|
770
|
+
#### Raises of Retrieve Object Mixin
|
771
|
+
|
772
|
+
- `QuerysetNotDefinedError` — If `queryset` is not set in the class.
|
773
|
+
|
774
|
+
#### Retrieve Object Mixin Methods
|
775
|
+
|
776
|
+
- `get_object(**filters: Any) -> T | None`
|
777
|
+
|
778
|
+
Retrieve a single model object using the provided filter criteria.
|
779
|
+
|
780
|
+
- **Parameters:**
|
781
|
+
- `**filters` — Keyword arguments to filter the queryset (e.g., `id=1`, `slug="abc"`).
|
782
|
+
|
783
|
+
- **Returns:**
|
784
|
+
- Model instance matching the filters, or `None` if no match is found.
|
785
|
+
|
786
|
+
#### Example of Retrieve Object Mixin
|
787
|
+
|
788
|
+
```python
|
789
|
+
from rest_framework.views import APIView
|
790
|
+
from django.http import JsonResponse
|
791
|
+
from myapp.models import Book
|
792
|
+
from djresttoolkit.mixins import RetrieveObjectMixin
|
793
|
+
|
794
|
+
class BookDetailView(RetrieveObjectMixin[Book], APIView):
|
795
|
+
queryset = Book.objects.all()
|
796
|
+
|
797
|
+
def get(self, request, *args, **kwargs):
|
798
|
+
book = self.get_object(id=kwargs["id"])
|
799
|
+
if book:
|
800
|
+
return JsonResponse({"title": book.title, "author": book.author})
|
801
|
+
return JsonResponse({"detail": "Not found"}, status=404)
|
802
|
+
```
|
803
|
+
|
804
|
+
#### Features of Retrieve Object Mixin
|
805
|
+
|
806
|
+
- Simplifies object retrieval in class-based views or DRF views.
|
807
|
+
- Returns `None` instead of raising `DoesNotExist`, making error handling easier.
|
808
|
+
- Works with any Django model and queryset.
|
809
|
+
|
756
810
|
## 🛠️ Planned Features
|
757
811
|
|
758
812
|
- Add more utils
|
@@ -695,6 +695,60 @@ urlpatterns = [
|
|
695
695
|
- Useful for frontend forms or API consumers that need selectable options.
|
696
696
|
- Integrates seamlessly with `ModelChoiceFieldMixin` from `djresttoolkit`.
|
697
697
|
|
698
|
+
### 12. RetrieveObjectMixin — API Reference
|
699
|
+
|
700
|
+
```python
|
701
|
+
from djresttoolkit.views.mixins import RetrieveObjectMixin
|
702
|
+
```
|
703
|
+
|
704
|
+
#### `RetrieveObjectMixin[T: Model]`
|
705
|
+
|
706
|
+
A **generic mixin** to retrieve a single Django model instance by filters.
|
707
|
+
|
708
|
+
#### Class Attributes of Retrieve Object Mixin
|
709
|
+
|
710
|
+
- `queryset: QuerySet[T] | None` — The queryset used to retrieve objects. **Must be set.**
|
711
|
+
|
712
|
+
#### Raises of Retrieve Object Mixin
|
713
|
+
|
714
|
+
- `QuerysetNotDefinedError` — If `queryset` is not set in the class.
|
715
|
+
|
716
|
+
#### Retrieve Object Mixin Methods
|
717
|
+
|
718
|
+
- `get_object(**filters: Any) -> T | None`
|
719
|
+
|
720
|
+
Retrieve a single model object using the provided filter criteria.
|
721
|
+
|
722
|
+
- **Parameters:**
|
723
|
+
- `**filters` — Keyword arguments to filter the queryset (e.g., `id=1`, `slug="abc"`).
|
724
|
+
|
725
|
+
- **Returns:**
|
726
|
+
- Model instance matching the filters, or `None` if no match is found.
|
727
|
+
|
728
|
+
#### Example of Retrieve Object Mixin
|
729
|
+
|
730
|
+
```python
|
731
|
+
from rest_framework.views import APIView
|
732
|
+
from django.http import JsonResponse
|
733
|
+
from myapp.models import Book
|
734
|
+
from djresttoolkit.mixins import RetrieveObjectMixin
|
735
|
+
|
736
|
+
class BookDetailView(RetrieveObjectMixin[Book], APIView):
|
737
|
+
queryset = Book.objects.all()
|
738
|
+
|
739
|
+
def get(self, request, *args, **kwargs):
|
740
|
+
book = self.get_object(id=kwargs["id"])
|
741
|
+
if book:
|
742
|
+
return JsonResponse({"title": book.title, "author": book.author})
|
743
|
+
return JsonResponse({"detail": "Not found"}, status=404)
|
744
|
+
```
|
745
|
+
|
746
|
+
#### Features of Retrieve Object Mixin
|
747
|
+
|
748
|
+
- Simplifies object retrieval in class-based views or DRF views.
|
749
|
+
- Returns `None` instead of raising `DoesNotExist`, making error handling easier.
|
750
|
+
- Works with any Django model and queryset.
|
751
|
+
|
698
752
|
## 🛠️ Planned Features
|
699
753
|
|
700
754
|
- Add more utils
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "djresttoolkit"
|
7
|
-
version = "0.
|
7
|
+
version = "0.13.0"
|
8
8
|
description = "A collection of Django and DRF utilities to simplify API development."
|
9
9
|
readme = { file = "README.md", content-type = "text/markdown" }
|
10
10
|
license = { file = "LICENSE" }
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Any
|
2
|
+
from django.db.models import Model, QuerySet
|
3
|
+
|
4
|
+
|
5
|
+
class QuerysetNotDefinedError(Exception):
|
6
|
+
"""Exception raised when the `queryset` attribute is not set in the class."""
|
7
|
+
|
8
|
+
pass
|
9
|
+
|
10
|
+
|
11
|
+
class RetrieveObjectMixin[T: Model]:
|
12
|
+
"""
|
13
|
+
Mixin to provide a method for retrieving a single model object by filters.
|
14
|
+
|
15
|
+
Requires the `queryset` attribute to be set in the class that inherits this mixin.
|
16
|
+
|
17
|
+
Example:
|
18
|
+
```
|
19
|
+
class MyView(RetrieveModelMixin[Book], APIView):
|
20
|
+
queryset = Book.objects.all()
|
21
|
+
|
22
|
+
def get(self, request, *args, **kwargs):
|
23
|
+
obj = self.get_object(id=1)
|
24
|
+
return JsonResponse(obj.to_dict())
|
25
|
+
```
|
26
|
+
"""
|
27
|
+
|
28
|
+
queryset: QuerySet[T] | None = None
|
29
|
+
|
30
|
+
def get_object(self, **filters: Any) -> T | None:
|
31
|
+
"""Retrieve a model object based on provided filters."""
|
32
|
+
|
33
|
+
if self.queryset is None:
|
34
|
+
raise QuerysetNotDefinedError(
|
35
|
+
"Queryset attribute is not set in the class.",
|
36
|
+
)
|
37
|
+
|
38
|
+
try:
|
39
|
+
return self.queryset.get(**filters)
|
40
|
+
except self.queryset.model.DoesNotExist:
|
41
|
+
return None
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/_choice_field.py
RENAMED
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/dbseed/models/_seed_model.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/__init__.py
RENAMED
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/dbflush.py
RENAMED
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/management/commands/dbseed.py
RENAMED
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
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/serializers/mixins/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/throttling/_throttle_inspector.py
RENAMED
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_api_views/__init__.py
RENAMED
File without changes
|
File without changes
|
{djresttoolkit-0.12.0 → djresttoolkit-0.13.0}/src/djresttoolkit/views/_exceptions/__init__.py
RENAMED
File without changes
|
File without changes
|