Skip to content

Commit

Permalink
update documentation and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownPlatypus committed Dec 1, 2024
1 parent 75cbd78 commit cc4eeaf
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

* Added field class ``PositiveTinyIntegerField`` and ``TinyIntegerField`` that uses MySQL's ``TINYINT`` data type.

4.15.0 (2024-10-29)
-------------------

Expand Down
15 changes: 15 additions & 0 deletions docs/exposition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ field class allows you to interact with those fields:
:ref:`Read more <bit1booleanfields>`

TinyInteger Fields
------------------

MySQL’s ``TINYINT`` type efficiently stores small integers in just one byte.
These fields allow you to use it seamlessly in Django models:

.. code-block:: python
class TinyIntModel(Model):
tiny_value = TinyIntegerField() # Supports values from -128 to 127.
positive_tiny_value = PositiveTinyIntegerField() # Supports values from 0 to 255.
:ref:`Read more <tinyintegerfields>`


-------------
Field Lookups
-------------
Expand Down
54 changes: 54 additions & 0 deletions docs/model_fields/tiny_integer_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.. _tinyintegerfields:

----------------
TinyIntegerField
----------------

.. currentmodule:: django_mysql.models

When working with integers that fit within small ranges, the default integer
fields can lead to excessive storage usage. MySQL’s ``TINYINT`` type allows
efficient storage by limiting the size to one byte.
The `TinyIntegerField` and `PositiveTinyIntegerField` make it easy to use
the ``TINYINT`` and ``TINYINT UNSIGNED`` types in Django.

Docs:
`MySQL TINYINT <https://dev.mysql.com/doc/refman/en/numeric-types.html>`_ /
`MariaDB <https://mariadb.com/kb/en/tinyint/>`_.

.. class:: TinyIntegerField(**kwargs)

A subclass of Django’s :class:`~django.db.models.SmallIntegerField` that uses a MySQL
``TINYINT`` type for storage. It supports signed integer values ranging from -128 to 127.

Example:

.. code-block:: python
from django.db import models
from myapp.fields import TinyIntegerField
class ExampleModel(models.Model):
tiny_value = TinyIntegerField()
.. class:: PositiveTinyIntegerField(**kwargs)

A subclass of Django’s :class:`~django.db.models.PositiveSmallIntegerField` that uses a
MySQL ``TINYINT UNSIGNED`` type for storage. It supports unsigned integer values ranging
from 0 to 255.

Example:

.. code-block:: python
from django.db import models
from myapp.fields import PositiveTinyIntegerField
class ExampleModel(models.Model):
positive_tiny_value = PositiveTinyIntegerField()
.. note::
Ensure that existing data values fall within the specified ranges before migrating
to this field, as values outside these ranges will cause migration operations to fail.

0 comments on commit cc4eeaf

Please sign in to comment.