
Security News
PyPI Expands Trusted Publishing to GitLab Self-Managed as Adoption Passes 25 Percent
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads
django-model-utils
Advanced tools
.. image:: https://jazzband.co/static/img/badge.svg :target: https://jazzband.co/ :alt: Jazzband .. image:: https://github.com/jazzband/django-model-utils/workflows/Test/badge.svg :target: https://github.com/jazzband/django-model-utils/actions .. image:: https://codecov.io/gh/jazzband/django-model-utils/branch/master/graph/badge.svg :target: https://codecov.io/gh/jazzband/django-model-utils .. image:: https://img.shields.io/pypi/v/django-model-utils.svg :target: https://pypi.python.org/pypi/django-model-utils .. image:: https://img.shields.io/pypi/pyversions/django-model-utils.svg :target: https://pypi.python.org/pypi/django-model-utils :alt: Supported Python versions .. image:: https://img.shields.io/pypi/djversions/django-model-utils.svg :target: https://pypi.org/project/django-model-utils/ :alt: Supported Django versions
Django model mixins and utilities.
django-model-utils supports Django_ 3.2+.
.. _Django: https://www.djangoproject.com/
This app is available on PyPI_.
.. _PyPI: https://pypi.python.org/pypi/django-model-utils/
Documentation for django-model-utils is available https://django-model-utils.readthedocs.io/
Please file bugs and send pull requests to the GitHub repository_ and issue tracker. See CONTRIBUTING.rst for details.
.. _GitHub repository: https://github.com/jazzband/django-model-utils/ .. _issue tracker: https://github.com/jazzband/django-model-utils/issues .. _CONTRIBUTING.rst: https://github.com/jazzband/django-model-utils/blob/master/CONTRIBUTING.rst
Django 5.1None - instead of
django.utils.timezone.now will be used when nullable and no default provided (GH-#599)None
instead of django.utils.timezone.now - when nullable and without a default.post_init signal for initialize trackercontribute_to_class() in StatusField, MonitorField and SplitField
forward additional arguments to DjangoSplitField no longer accepts no_excerpt_field as a keyword argumentsoft argument to SoftDeletableModel.delete() keyword-onlyJoinManager and JoinManagerMixin have been deprecated;
please use JoinQueryset.as_manager() insteadSoftDeletableQuerySetMixin.delete to replicate Django's API.JoinQueryset.get_quoted_query() by @mthuurne (GH-#618)post_init signal for initialize tracker by @meanmail in - (GH-#556)Language Support - Add translations for Brazilian Portuguese by @gmcrocetti in - (GH-#578)init_deferred_fields method by @joecox in - (GH-#580)ConnectionDoesNotExist is imported from by @mthuurne in - (GH-#566)InheritanceQuerySetMixin._clone() by @mthuurne in - (GH-#567)MonitorField - Change default to None when the field is nullable by @gmcrocetti in - (GH-#577)__init__ module by @mthuurne in - (GH-#591)JoinManager from tests by @mthuurne in - (GH-#594)@skip decorator by @mthuurne in - (GH-#595)tests.signals module by @mthuurne in - (GH-#597)Python 3.11 (GH-#545)Python 3.12 (GH-#545)Python 3.7 (GH-#545)Django 4.2Django 5.0SaveSignalHandlingModel. This model used a modified copy of the internal Django method Model.save_base()
and had not been updated for upstream bug fixes changes since its addition.Django 4.0select_subclasses()Django < 3.2Python 3.6Django 4.1Django 3.2Django 3.0Python 3.10isort to codebase (Refs GH-#402)TypeError in save when model inherits from both TimeStampModel
and StatusModel. (Fixes GH-465)Breaking changes:
FieldTracker now marks fields as not changed after refresh_from_db
respecting fields argument (GH-#404)FieldTracker now respects update_fields changed in overridden save()
method (GH-#404)FieldTracker now resets states after pre_save() and not anymore save()
signals, possibly altering the behaviour of overridden save()
methods (GH-#404)Other changes:
Django 2.1Python 3.9Django 3.1Choices.subset.sixDjango 1.11Python 3.8Django 3.0AttributeError for deferred abstract fields, fixes GH-331.timeframed model manager, fixes GH-118OneToOneField.parent_link=False.FieldTracker.has_changed() and FieldTracker.previous() to return
correct responses for deferred fields.reversed for all kinds of Choices objects, fixes GH-309save in FieldTrackerUpdate InheritanceIterable to inherit from ModelIterable instead of BaseIterable, fixes GH-277.
Add all_objects Manager for 'SoftDeletableModel' to include soft deleted objects on queries as per issue GH-255
Fix infinite recursion with multiple MonitorField and defer() or only()
on Django 1.10+. Thanks Romain Garrigues. Merge of GH-242, fixes GH-241.
Fix InheritanceManager and SoftDeletableManager to respect
self._queryset_class instead of hardcoding the queryset class. Merge of
GH-250, fixes GH-249.
Add mixins for SoftDeletableQuerySet and SoftDeletableManager, as stated
in the the documentation.
Fix SoftDeletableModel.delete() to use the correct database connection.
Merge of GH-239.
Added boolean keyword argument soft to SoftDeletableModel.delete() that
revert to default behavior when set to False. Merge of GH-240.
Enforced default manager in StatusModel to avoid manager order issues when
using abstract models that redefine objects manager. Merge of GH-253, fixes
GH-251.
Added SoftDeletableModel abstract class, its manageer
SoftDeletableManager and queryset SoftDeletableQuerySet.
Fix issue with field tracker and deferred FileField for Django 1.10.
runtests.py in sdist.Fix InheritanceQuerySet raising an AttributeError exception
under Django 1.9.
Django 1.10 support regressed with changes between pre-alpha and final release; 1.10 currently not supported.
Drop support for Python 3.2.
Add support for Django 1.10 pre-alpha.
Track foreign keys on parent models properly when a tracker is defined on a child model. Fixes GH-214.
Remove PassThroughManager. Use Django's built-in QuerySet.as_manager()
and/or Manager.from_queryset() utilities instead.
Add support for Django 1.9.
setup.py. Fixes GH-178 and
GH-179. Thanks Joe Weiss, Matt Molyneaux, and others for the reports.Keep track of deferred fields on model instance instead of on FieldInstanceTracker instance. Fixes accessing deferred fields for multiple instances of a model from the same queryset. Thanks Bram Boogaard. Merge of GH-151.
Fix Django 1.7 migrations compatibility for SplitField. Thanks ad-m. Merge of GH-157; fixes GH-156.
Add German translations.
Django 1.8 compatibility.
FieldTracker changes in
overridden save methods or post_save handlers. This reopens GH-83
(inability to pickle models with FieldTracker) until a solution can be
found that doesn't break behavior otherwise. Thanks Brian May for the
report. Fixes GH-143.Add support for Django's built-in migrations to MonitorField and
StatusField.
PassThroughManager now has support for seeing exposed methods via
dir, allowing IPython_ tab completion to be useful. Merge of GH-104,
fixes GH-55.
Add pickle support for models using FieldTracker. Thanks Ondrej Slintak
for the report. Thanks Matthew Schinckel for the fix. Merge of GH-130,
fixes GH-83.
.. _IPython: https://ipython.org/
Fix get_query_set vs get_queryset in PassThroughManager for
Django <1.6. Fixes issues with related managers not filtering by relation
properly. Thanks whop, Bojan Mihelac, Daniel Shapiro, and Matthew Schinckel
for the report; Matthew for the fix. Merge of GH-121.
Fix FieldTracker with deferred model attributes. Thanks Michael van
Tellingen. Merge of GH-115.
Fix InheritanceManager with self-referential FK; avoid infinite
recursion. Thanks rsenkbeil. Merge of GH-114.
Fix dependency to be on "Django" rather than "django", which plays better with static PyPI mirrors. Thanks Travis Swicegood.
Fix issue with attempt to access __slots__ when copying
PassThroughManager. Thanks Patryk Zawadzki. Merge of GH-105.
Improve InheritanceManager so any attributes added by using extra(select)
will be propagated onto children. Thanks Curtis Maloney. Merge of GH-101,
fixes GH-34.
Added InheritanceManagerMixin, InheritanceQuerySetMixin,
PassThroughManagerMixin, and QueryManagerMixin to allow composing
their functionality with other custom manager/queryset subclasses (e.g. those
in GeoDjango). Thanks Douglas Meehan!
BACKWARDS-INCOMPATIBLE: Indexing into a Choices instance now translates
database representations to human-readable choice names, rather than simply
indexing into an array of choice tuples. (Indexing into Choices was
previously not documented.) If you have code that is relying on indexing or
slicing Choices, the simplest workaround is to change e.g. STATUS[1:]
to list(STATUS)[1:].
Fixed bug with checking for field name conflicts for added query managers on
StatusModel.
Can pass choices_name to StatusField to use a different name for
choices class attribute. STATUS is used by default.
Can pass model subclasses, rather than strings, into
select_subclasses(). Thanks Keryn Knight. Merge of GH-79.
Deepcopying a Choices instance no longer fails with infinite recursion in
getattr. Thanks Leden. Merge of GH-75.
get_subclass() method is now available on both managers and
querysets. Thanks Travis Swicegood. Merge of GH-82.
Fix bug in InheritanceManager with grandchild classes on Django 1.6+;
select_subclasses('child', 'child__grandchild') would only ever get to the
child class. Thanks Keryn Knight for report and proposed fix.
MonitorField now accepts a 'when' parameter. It will update only when the field changes to one of the values specified.
Choices now accepts option-groupings. Fixes GH-14.
Choices can now be added to other Choices or to any iterable, and can be
compared for equality with itself. Thanks Tony Aldridge. (Merge of GH-76.)
Choices now __contains__ its Python identifier values. Thanks Keryn
Knight. (Merge of GH-69).
Fixed a bug causing KeyError when saving with the parameter
update_fields in which there are untracked fields. Thanks Mikhail
Silonov. (Merge of GH-70, fixes GH-71).
Fixed FieldTracker usage on inherited models. Fixes GH-57.
Added mutable field support to FieldTracker (Merge of GH-73, fixes GH-74)
Introduced FieldTracker as replacement for ModelTracker, which is now
deprecated.
PassThroughManager.for_queryset_class() no longer ignores superclass
get_query_set. Thanks Andy Freeland.
Fixed InheritanceManager bug with grandchildren in Django 1.6. Thanks
CrazyCasta.
Fixed lack of get_FOO_display method for StatusField. Fixes GH-41.
Added explicit default to BooleanField in tests, for Django trunk
compatibility.
Fixed intermittent StatusField bug. Fixes GH-29.
Added Python 3 support.
Dropped support for Django 1.2 and 1.3. Django 1.4.2+ required.
Allow specifying default value for a StatusField. Thanks Felipe
Prenholato.
Fix calling create() on a RelatedManager that subclasses a dynamic
PassThroughManager. Thanks SeiryuZ for the report. Fixes GH-24.
Add workaround for https://code.djangoproject.com/ticket/16855 in
InheritanceQuerySet to avoid overriding prior calls to
select_related(). Thanks ivirabyan.
Added support for arbitrary levels of model inheritance in InheritanceManager. Thanks ivirabyan. (This feature only works in Django 1.6+ due to https://code.djangoproject.com/ticket/16572).
Added ModelTracker for tracking field changes between model saves. Thanks
Trey Hunner.
Bitbucket_ to GitHub_. Bitbucket mirror
will continue to receive updates; Bitbucket issue tracker will be closed once
all issues tracked in it are resolved... _BitBucket: https://bitbucket.org/carljm/django-model-utils/overview .. _GitHub: https://github.com/carljm/django-model-utils/
Removed deprecated ChoiceEnum, InheritanceCastModel,
InheritanceCastManager, and manager_from.
Fixed pickling of PassThroughManager. Thanks Rinat Shigapov.
Set use_for_related_fields = True on QueryManager.
Added __len__ method to Choices. Thanks Ryan Kaskel and James Oakley.
Fixed InheritanceQuerySet on Django 1.5. Thanks Javier Garcia Sogo.
Updated AutoCreatedField, AutoLastModifiedField, MonitorField, and
TimeFramedModel to use django.utils.timezone.now on Django 1.4.
Thanks Donald Stufft.
Fixed annotation of InheritanceQuerysets. Thanks Jeff Elmore and Facundo Gaich.
Dropped support for Python 2.5 and Django 1.1. Both are no longer supported even for security fixes, and should not be used.
Added PassThroughManager.for_queryset_class(), which fixes use of
PassThroughManager with related fields. Thanks Ryan Kaskel for report and
fix.
Added InheritanceManager.get_subclass(). Thanks smacker.
Fixed using SplitField on an abstract base model.
Fixed issue #8, adding use_for_related_fields = True to
InheritanceManager.
Added PassThroughManager. Thanks Paul McLanahan.
Added pending-deprecation warnings for InheritanceCastModel,
manager_from, and Django 1.1 support. Removed documentation for the
deprecated utilities. Bumped ChoiceEnum from pending-deprecation to
deprecation.
Fixed issue #6, bug with InheritanceManager and descriptor fields (e.g. FileField). Thanks zyegfryed for the fix and sayane for tests.
updated SplitField to define get_prep_value rather than get_db_prep_value. This avoids deprecation warnings on Django trunk/1.3, but makes SplitField incompatible with Django versions prior to 1.2.
added InheritanceManager, a better approach to selecting subclass instances for Django 1.2+. Thanks Jeff Elmore.
added InheritanceCastManager and InheritanceCastQuerySet, to allow bulk casting of a queryset to child types. Thanks Gregor Muellegger.
QueryManagerFAQs
Django model mixins and utilities
We found that django-model-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.