Skip to main content

A Mixins and Models with Django utilities.

Project description

django-extended-models

GitHub license

django-extended-models is a Django utility package that provides mixins and models with extended functionalities.

Installation

Install the package using Poetry:

poetry add django-extended-models

Features

utils.py

__set_default_values

The function sets default values for fields in a model if they are not provided.

from django_extended_models.utils import __set_default_values

# Example usage:
model = ...
fields = ...

dictionary, fields = __set_default_values(model, fields)

model_to_dict

Converts a Django model object into a dictionary, recursively including related model objects up to a specified depth.

from django_extended_models.utils import model_to_dict

# Example usage:
object = ...
fields = ...

dictionary = model_to_dict(object, fields=fields)

mixins.py

ToDictMixin

Provides a method to_dict that converts a model instance to a dictionary.

from django_extended_models.mixins import ToDictMixin

# Example usage:
class MyModel(ToDictMixin):
    pass

instance = MyModel()
dictionary = instance.to_dict()

models.py

BaseModel

A base model that includes the ToDictMixin.

from django_extended_models.models import BaseModel

# Example usage:
class MyModel(BaseModel):
    pass

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_extended_models-0.1.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

django_extended_models-0.1.0-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page