{"id":14972853,"url":"https://github.com/codermungan/djangoessentials","last_synced_at":"2025-10-26T20:32:08.961Z","repository":{"id":228397716,"uuid":"773890400","full_name":"CoderMungan/DjangoEssentials","owner":"CoderMungan","description":"DjangoEssentials is a Python library designed to streamline and enhance the development process of Django applications. It offers a collection of commonly used Django models and deployment settings, encapsulating repetitive patterns and configurations into a reusable package.","archived":false,"fork":false,"pushed_at":"2025-01-27T10:47:34.000Z","size":25,"stargazers_count":12,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T11:15:50.581Z","etag":null,"topics":["django","django-application","django-framework","django-library","django-rest-framework","library","python","python-library"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/DjangoEssentials/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoderMungan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-18T15:23:06.000Z","updated_at":"2025-01-27T10:47:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"01b087f6-7833-4d75-917c-c3a839cd67b1","html_url":"https://github.com/CoderMungan/DjangoEssentials","commit_stats":{"total_commits":13,"total_committers":3,"mean_commits":4.333333333333333,"dds":"0.46153846153846156","last_synced_commit":"0d4fbef15431a1821794c42686336d0571c185e9"},"previous_names":["codermungan/djangoessentials"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMungan%2FDjangoEssentials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMungan%2FDjangoEssentials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMungan%2FDjangoEssentials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMungan%2FDjangoEssentials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderMungan","download_url":"https://codeload.github.com/CoderMungan/DjangoEssentials/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238397214,"owners_count":19465135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-application","django-framework","django-library","django-rest-framework","library","python","python-library"],"created_at":"2024-09-24T13:47:38.567Z","updated_at":"2025-10-26T20:32:08.654Z","avatar_url":"https://github.com/CoderMungan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**DjangoEssentials**\n\n[Join Our Community - Kampus](https://discord.gg/kampus)\n\n**DjangoEssentials** is a Python library designed to streamline and simplify the development of Django applications. This library supports modern software development approaches, such as the **repository-service pattern**, and provides a more modular structure by preventing code repetition. Additionally, it includes essential features such as **model management, data access, and Amazon S3 storage integration**.\n\n**🚀 Features**\n\n**1️⃣ Repository-Service Pattern**\n\n•\t**BaseRepository:** A base repository class that manages CRUD operations for Django models.\n\n•\t**BaseService:** A service layer that utilizes repositories to manage business logic and reduce code duplication.\n\n**2️⃣ Model Utilities**\n\n•\t**TimeBasedStampModel:** An abstract model class that automatically tracks **creation, update, and deletion timestamps**.\n\n**3️⃣ Amazon S3 Storage Integration**\n\n•\t**MyS3Storage:** A custom storage class for **handling media files with Amazon S3** in Django applications.\n\n**📥 Installation**\n\nInstall the library using pip:\n\n```python\npip install DjangoEssentials\n```\n\n**📌 Usage**\n\n**1️⃣ Using the Repository-Service Pattern**\n\nThis pattern separates the **data access layer** from the **business logic layer**, making Django applications cleaner and more maintainable.\n\n**📌 Model Example**\n\nLet’s create a **simple Django model** using TimeBasedStampModel:\n\n```python\nfrom django.db import models\nfrom djangoessentials import TimeBasedStampModel\n\nclass Product(TimeBasedStampModel):\n    name = models.CharField(max_length=255)\n    description = models.TextField()\n    price = models.DecimalField(max_digits=10, decimal_places=2)\n    stock = models.PositiveIntegerField(default=0)\n```\n\n**📌 Repository Layer**\n\nThe repository interacts with Django models and manages database operations.\n\n```python\nfrom djangoessentials.repository import BaseRepository\nfrom myapp.models import Product\n\nclass ProductRepository(BaseRepository[Product]):\n    def __init__(self):\n        super().__init__(Product)\n```\n\n**📌 Service Layer**\n\nThe service layer uses the repository to manage business logic and reduce code duplication.\n\n```python\nfrom djangoessentials.service import BaseService\nfrom myapp.repositories import ProductRepository\n\nclass ProductService(BaseService[ProductRepository]):\n    def __init__(self):\n        super().__init__(ProductRepository())\n\n    def get_available_products(self):\n        return self._repository.filter(stock__gt=0)\n```\n\n**📌 Serializer for DRF**\n\nTo expose this model via an API, let’s create a serializer.\n\n```python\nfrom rest_framework import serializers\nfrom myapp.models import Product\n\nclass ProductSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Product\n        fields = '__all__'\n```\n\n**📌 ViewSet for Django REST Framework**\n\nTo expose the service through an API, we can use **ModelViewSet**.\n\n```python\nfrom rest_framework import viewsets\nfrom myapp.services import ProductService\nfrom myapp.serializers import ProductSerializer\n\nclass ProductViewSet(viewsets.ModelViewSet):\n    serializer_class = ProductSerializer\n    queryset = ProductService().get_all()\n    \n    def get_queryset(self):\n        \"\"\"\n        Optionally filter the queryset based on stock availability.\n        \"\"\"\n        service = ProductService()\n        available_only = self.request.query_params.get('available_only', None)\n        if available_only:\n            return service.get_available_products()\n        return service.get_all()\n```\n\n**📌 Register the ViewSet in Django’s Router**\n\nTo enable API endpoints, register the viewset in urls.py.\n\n```python\nfrom django.urls import path, include\nfrom rest_framework.routers import DefaultRouter\nfrom myapp.views import ProductViewSet\n\nrouter = DefaultRouter()\nrouter.register(r'products', ProductViewSet)\n\nurlpatterns = [\n    path('api/', include(router.urls)),\n]\n```\n\n**2️⃣ Using TimeBasedStampModel**\n\nTo add automatic **created_at, updated_at, and deleted_at** fields to your model:\n\n```python\nfrom django.db import models\nfrom djangoessentials import TimeBasedStampModel\n\nclass YourModel(TimeBasedStampModel):\n    name = models.CharField(max_length=255)\n    # Add your custom fields here\n```\n\nThis model **automatically tracks timestamps** for each record.\n\n**3️⃣ Amazon S3 Storage Integration**\n\nTo use **Amazon S3 as the media storage solution**, configure your Django project as follows.\n\n**📌 Add to settings.py**\n\n```python\nimport os\n\nUSE_S3 = True\n\nif USE_S3:\n    AWS_ACCESS_KEY_ID = os.getenv(\"AWS_ACCESS_KEY_ID\")\n    AWS_SECRET_ACCESS_KEY = os.getenv(\"AWS_SECRET_ACCESS_KEY\")\n    AWS_STORAGE_BUCKET_NAME = os.getenv(\"AWS_STORAGE_BUCKET_NAME\")\n    AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'\n    AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}\n\n    PUBLIC_MEDIA_LOCATION = 'media'\n    MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MEDIA_LOCATION}/'\nelse:\n    MEDIA_URL = '/media/'\n    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')\n\nSTATIC_URL = 'static/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')\nSTATICFILES_DIRS = [os.path.join(BASE_DIR, 'static/')]\n```\n\n**📌 Use in a Model**\n\n```python\nfrom django.db import models\nfrom djangoessentials import MyS3Storage\n\nclass MyModel(models.Model):\n    document = models.FileField(upload_to='documents/', storage=MyS3Storage)\n```\n\nThis setup ensures that files are **automatically uploaded to Amazon S3**.\n\n**🎯 Advanced Usage**\n\nDjangoEssentials is designed to grow with the community’s needs. Over time, more utilities and helpers will be added to **optimize Django development workflows**.\n\n**🤝 Contributing**\n\nWe welcome community contributions! If you’d like to add new features, improve documentation, or report bugs, follow these steps:\n\n1.\t**Fork the repository.**\n\n2.\t**Create a feature branch:**\n\n```python\ngit checkout -b feature/AmazingFeature\n```\n\n3.\t**Commit your changes:**\n\n```python\ngit commit -am \"Add some AmazingFeature\"\n```\n\n4.\t**Push to the branch:**\n\n```python\ngit push origin feature/AmazingFeature\n```\n\n5.\t**Open a Pull Request.**\n\n**📩 Contact**\n\nFor questions or further information, feel free to contact us:\n\n📧 [**codermungan@gmail.com**](mailto:codermungan@gmail.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodermungan%2Fdjangoessentials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodermungan%2Fdjangoessentials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodermungan%2Fdjangoessentials/lists"}