Skip to main content

Additional fields for(ever) Django.

PyPI Version Supported Python versions Build Status Documentation Status GPL-2.0-only OR LGPL-2.1-or-later Coverage

Prerequisites

  • Django 1.11, 2.0, 2.1, 2.2 and 3.0.

  • Python 2.7, 3.6, 3.7 and 3.8.

Documentation

Documentation is available on Read the Docs.

Main features and highlights

  • MD5Field.

Installation

  1. Install latest stable version from PyPI:

    pip install django-strawberry

    or latest stable version from GitHub:

    pip install https://github.com/barseghyanartur/django-strawberry/archive/stable.tar.gz

    or latest stable version from BitBucket:

    pip install https://bitbucket.org/barseghyanartur/django-strawberry/get/stable.tar.gz

Usage

MD5 field

In case you want to have an MD5 field populated from another field of the same model.

Example 1

myapp/models.py

from django.db import models
from strawberry.fields import MD5Field

class MyModel(models.Model):

    title = models.CharField(max_length=255)
    title_hash = MD5Field(
        populate_from='title',
        null=True,
        blank=True
    )

    def __str__(self):
        return self.title

myapp/example.py

from myapp.models import MyModel

mymodel = MyModel.objects.create(title="Lorem7")
print(mymodel.title_hash)
'd48a712e77902d0558a3721d9a4740c9'

Example 2

The populate_from argument can also be a callable, that would expect the model instance as an argument. Thus, example identical to the first one would be:

myapp/models.py

from django.db import models
from strawberry.fields import MD5Field


def strip_title(instance):
    return instance.title.strip()


class MyModel(models.Model):

    title = models.CharField(max_length=255)
    title_hash = MD5Field(
        populate_from=strip_title,
        null=True,
        blank=True,
    )

    def __str__(self):
        return self.title

myapp/example.py

from myapp.models import MyModel

mymodel = MyModel.objects.create(title=" Lorem7 ")
print(mymodel.title_hash)
'd48a712e77902d0558a3721d9a4740c9'

Testing

Project is covered with tests.

To test with all supported Python/Django versions type:

tox

To test against specific environment, type:

tox -e py38-django30

To test just your working environment type:

./runtests.py

To run a single test in your working environment type:

./runtests.py src/strawberry/tests/test_fields.py

Or:

./manage.py test strawberry.tests.test_fields

It’s assumed that you have all the requirements installed. If not, first install the test requirements:

pip install -r examples/requirements/test.txt

Writing documentation

Keep the following hierarchy.

=====
title
=====

header
======

sub-header
----------

sub-sub-header
~~~~~~~~~~~~~~

sub-sub-sub-header
^^^^^^^^^^^^^^^^^^

sub-sub-sub-sub-header
++++++++++++++++++++++

sub-sub-sub-sub-sub-header
**************************

License

GPL-2.0-only OR LGPL-2.1-or-later

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

Release files for django-strawberry 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-strawberry 0.1.2
File Size Uploaded
django-strawberry-0.1.2.tar.gz 33.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-strawberry 0.1.2
File Interpreter ABI Platform
django_strawberry-0.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 60.2 kB

Release files / django-strawberry-0.1.2.tar.gz

Download URL django-strawberry-0.1.2.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b481a375ef0f6830d73a17e715b7f03bded344553e471acb12bfebf3f5689d29
BLAKE2b-256 checksum
How to use checksums
c1222f531692e625bdd5bc41b33a5d6e64ae671e92537e06128fe0c341bd318b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release files / django_strawberry-0.1.2-py2.py3-none-any.whl

Download URL django_strawberry-0.1.2-py2.py3-none-any.whl
Size 26.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9c60d81e5a63cb8bae85bf7c447de8b0fc158ed78f9d852d9ba743041aff61aa
BLAKE2b-256 checksum
How to use checksums
c585d0213c9c07c673cb38494e46fa06810d25a8ef5d6e416f4787e62e78073c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page