Code Monkey home page Code Monkey logo

django-monthfield's Introduction

django-monthfield

Introduction

This module provides a custom field for storing month (YYYY-MM) as a django field.

This can be useful when dealing with data that relates to a whole month, for example, the total expenditure for a given month.

This module also adds some arithmetic and other functionality for dealing with months.

Usage

Adding a month field to a django model:

from django.db import models
from month.models import MonthField


# Create your models here.

class ExampleModel(models.Model):
    name = models.CharField(max_length=20, blank=True)
    month = MonthField("Month Value", help_text="some help...")

    def __unicode__(self):
        return unicode(self.month)

The module defines a "Month" class which is used to represent the MonthField attribute on the model. The "Month" class can also be used standalone without any django model.

Some examples of funcionality provided by the Month class:

import month

m = month.Month(2017, 3)

print(m)
>"2017-03"

print(m + 2)
>"2017-05"

print(m.last_day())
>"2017-03-31"

m2 = month.Month(2017, 7)

print(m > m2)
>"False"

print(m.range(m2))
>"[2017-03, 2017-04, 2017-05, 2017-06, 2017-07]"

Example project

An example website using this module is included in the repository.

username: test password: test

django-monthfield's People

Contributors

alexsilva avatar beigna avatar hephhay avatar matthysk avatar natlee avatar paramono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-monthfield's Issues

ugettext_lazy deprecated

from django.utils.translation import ugettext_lazy as _

just needs to become

from django.utils.translation import gettext_lazy as _

Hope you're doing well!

Integration

Nice concept. But please, How do i integrate into project? Thanks

Widget (?) breaks django's autocomplete fields

Hi,

In a project's admin.py, specify a MonthField field.
In the same file, specify some autocomplete fields, as in:

autocomplete_fields = [
    'field1',
    'field2',
]

The result of the autocomplete fields (django 3.2.13) is this:

image

Is there a workaround to this?

Many thanks!

PS: removing the MonthField from the fieldset restores the autocomplete fields to full functionality.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.