Login

Tag "month"

Snippet List

Month / Year SelectDateWidget based on django SelectDateWidget

A more simple version of [https://djangosnippets.org/snippets/1688/](https://djangosnippets.org/snippets/1688/), inheriting from `SelectDateWidget`, overriding only the necessarily. **Usage example:** **In models.py:** from django.db import models from django.utils.translation import gettext_lazy as _ class MyModel(models.Model): start = models.DateField( _("Start date"), ) end = models.DateField( _("End date"), ) class Meta: verbose_name = _("My model") **In forms.py:** from django import forms from .models import MyModel from .widgets import MonthYearWidget class MyModelForm(forms.ModelForm): class Meta: model = MyModel exclude = [] widgets = { "start": MonthYearWidget(), "end": MonthYearWidget(last_day=True), } **kwargs:** - *last_day :* if set to `True`, returns the last day of the month in the generated date.

  • widgets
  • select
  • year
  • month
  • SelectDateWidget
Read More

SelectDateWidget with format: day, month, year

This is the same as [django.forms.extras.widgets.SelectDateWidget](http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py#L16) but changing the order of the rendered select boxes to: day, month, year.

  • date
  • widgets
  • widget
  • year
  • month
  • selectdatewidget
  • dates
  • day
Read More

Month / Year dropdown widget

This is an adaption of [django.forms.extras.widgets.SelectDateWidget](http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py#L16) which has no day dropdown - it still produces a date but with the day set to 1. Example use class myForm(forms.Form): # ... date = forms.DateField( required=False, widget=MonthYearWidget(years=xrange(2004,2010)) )

  • date
  • year
  • credit-card
  • month
Read More

4 snippets posted so far.