{ "info": { "author": "Kevin Wetzels", "author_email": "kevin@roam.be", "bugtrack_url": null, "classifiers": [], "description": "================\ndjango-stdfields\n================\n\nFields I wish were standard in Django. At the moment this is limited to the\n``MinutesField``, ``EnumIntegerField`` and ``EnumCharField``.\n\nInstall::\n\n pip install django-stdfields\n\nContents\n========\n\n* ``stdfields.forms.MinutesField``: use an integer to represent a duration of \n minutes and hours\n* ``stdfields.fields.EnumIntegerField``: makes working with ``choices`` a bit \n easier\n* ``stdfields.fields.EnumCharField``: the same, but for ``choices`` with a char \n key\n\nMinutesField\n------------\nIs an extension of Django's standard ``django.forms.IntegerField``.\n\nThis field will accept values for a duration in minutes in the formats \n``hh:mm`` or ``h.fraction``, similar to the way BaseCamp allows you to specify \nyour time spent on a task as either ``8:30`` or ``8.5``. In the latter case only \n``8.25``, ``8.5``, ``8.50`` and ``8.75`` are considered valid inputs.\n\nExample\n^^^^^^^\nActions speak louder than words::\n\n # models.py\n class Task(models.Model):\n time_spent = models.IntegerField()\n\n # forms.py\n from stdfields.forms import MinutesField\n \n from models import Task\n \n class TaskForm(forms.ModelForm):\n time_spent = MinutesField(label='How long did it take?')\n \n class Meta:\n model = Task\n \nYou can use the ``minutes`` template filter from ``stdfieldstags`` to render\nsuch a field in the format ``8:30``::\n\n {% load stdfieldstags %}\n It took me {{ task.time_spent|minutes }} to complete this task.\n\n\nEnumeration\n-----------\nI always end up with ugly code when using Django's ``choices`` argument for \nfields. With the ``stdfields.models.Enumeration`` class, I've got a handy base \nclass that allows me to keep things tidy::\n\n # models.py\n class Color(Enumeration):\n RED = 'R'\n GREEN = 'G'\n BLUE = 'B'\n \n @classmethod\n def all(cls):\n return [\n (cls.RED, _(u'Red')),\n (cls.GREEN, _(u'Green')),\n (cls.BLUE, _(u'Blue'))\n ]\n \n class Pencil(models.Model):\n color = models.CharField(choices=Color.all(), max_length=Color.max_length())\n \n # views.py\n def red_pencils(request):\n pencils = Pencil.objects.filter(color=Color.RED)\n ...\n # Prints 'Showing the Red pencils'\n logging.info('Showing the %s pencils' % (Color.as_display(Color.RED)))\n\n\nThat could be shorter. Use ``Enum`` instead::\n\n # models.py\n class Color(Enum):\n RED = EnumValue('R', 'Red')\n GREEN = EnumValue('G', 'Green')\n BLUE = EnumValue('B', 'Blue')\n \n class Pencil(models.Model):\n color = models.CharField(choices=Color.all(), max_length=Color.max_length())\n \n # views.py\n def red_pencils(request):\n pencils = Pencil.objects.filter(color=Color.RED)\n ...\n # Prints 'Showing the Red pencils'\n logging.info('Showing the %s pencils' % (Color.RED_display))\n\n\nEnumCharField and EnumIntegerField\n----------------------------------\nAnd now we can make working with an ``Enum`` easier with the \n``EnumCharField`` and ``EnumIntegerField`` models fields::\n\n # models.py\n class Color(Enumeration):\n # same as above\n \n class Pencil(models.Model):\n color = models.EnumCharField(enum=Color, max_length=Color.max_length())\n \nThis example is basically the same as the above since ``EnumCharField`` is a \nsubclass of the regular Django ``CharField``. By using the ``enum`` keyword \nargument of the enum field, the choices will be automatically updated when you\nupdate the enumeration object. And since you're using the provided \n``max_length`` method of ``Enumeration``, the ``max_length`` will be updated\nwhen needed. Just like in the previous example. The enum fields simply offer \nsome more clarity when reading the code.\n\n``EnumIntegerField`` works exactly the same, but for enumerations with integer\nkeys. Both fields can be used with South.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/roam/django-stdfields", "keywords": null, "license": "BSD licence, see LICENCE", "maintainer": null, "maintainer_email": null, "name": "django-stdfields", "package_url": "https://pypi.org/project/django-stdfields/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-stdfields/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/roam/django-stdfields" }, "release_url": "https://pypi.org/project/django-stdfields/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "Extra model and form fields for Django: minutes and enumerations", "version": "1.0.2" }, "last_serial": 656145, "releases": { "0.0.10": [ { "comment_text": "", "digests": { "md5": "8760870619d9a1aadb5dabf8fd7369b7", "sha256": "96b68c8eee205482dcc5892b3f08f7addd78314fd051df83a9d28a862df30bdd" }, "downloads": -1, "filename": "django-stdfields-0.0.10.tar.gz", "has_sig": false, "md5_digest": "8760870619d9a1aadb5dabf8fd7369b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7396, "upload_time": "2011-11-10T20:08:56", "url": "https://files.pythonhosted.org/packages/86/3b/23ed1e44b7639bc7197730ecb1c5310394813fdfe897259ab1cb932751d0/django-stdfields-0.0.10.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "391a6fe06ef18d5c2f3a25c573078920", "sha256": "ea90036759760ac0d59dc27b75711513834fb86bfeae5f2a01aa465d934f6199" }, "downloads": -1, "filename": "django-stdfields-0.0.3.tar.gz", "has_sig": false, "md5_digest": "391a6fe06ef18d5c2f3a25c573078920", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6176, "upload_time": "2011-11-01T21:36:50", "url": "https://files.pythonhosted.org/packages/aa/f9/f90fb7f0771c2071f7b5e89fde6289750d466ef468b613fbb9ec11937e69/django-stdfields-0.0.3.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "1748174b14e0a8e64de5a56355fe5eca", "sha256": "bf2c824f0ee50133a6fc7b3b844a3cec1f4aa543f1b18f9acd0eac57924f6f51" }, "downloads": -1, "filename": "django-stdfields-1.0.0.tar.gz", "has_sig": false, "md5_digest": "1748174b14e0a8e64de5a56355fe5eca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7469, "upload_time": "2011-12-02T20:45:49", "url": "https://files.pythonhosted.org/packages/36/67/74f119a31d3eaf7d9f131bb18031e13b4c3f7fa895e3cfd9d3864487bfe8/django-stdfields-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "983e969d01201d3ec2f8f88b4bcd8177", "sha256": "ae09f65b11241d6d37414e40001ef146ff67e9e037ebcb72cb0278e5d8c45daa" }, "downloads": -1, "filename": "django-stdfields-1.0.1.tar.gz", "has_sig": false, "md5_digest": "983e969d01201d3ec2f8f88b4bcd8177", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7819, "upload_time": "2011-12-11T12:04:30", "url": "https://files.pythonhosted.org/packages/8f/e0/08121098e642a9d0240f6902883ccb81d2ab80f1bb82dfe30d139a62a962/django-stdfields-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "ef01ab6dc1b080cb5156e21a058c871a", "sha256": "59eac4c90646e972b23a44773fda1eb89f089b8de54290e2e1042706b07580b2" }, "downloads": -1, "filename": "django-stdfields-1.0.2.tar.gz", "has_sig": false, "md5_digest": "ef01ab6dc1b080cb5156e21a058c871a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7878, "upload_time": "2011-12-11T12:10:39", "url": "https://files.pythonhosted.org/packages/28/a2/0e29a15c6bbd4181e347e5708e75847b655889fec4d8fba872f81d3dc918/django-stdfields-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ef01ab6dc1b080cb5156e21a058c871a", "sha256": "59eac4c90646e972b23a44773fda1eb89f089b8de54290e2e1042706b07580b2" }, "downloads": -1, "filename": "django-stdfields-1.0.2.tar.gz", "has_sig": false, "md5_digest": "ef01ab6dc1b080cb5156e21a058c871a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7878, "upload_time": "2011-12-11T12:10:39", "url": "https://files.pythonhosted.org/packages/28/a2/0e29a15c6bbd4181e347e5708e75847b655889fec4d8fba872f81d3dc918/django-stdfields-1.0.2.tar.gz" } ] }