Skip to content

Instantly share code, notes, and snippets.

@nacady
Created May 29, 2014 08:38
Show Gist options
  • Save nacady/8dd5cab2f749d1589f1e to your computer and use it in GitHub Desktop.
Save nacady/8dd5cab2f749d1589f1e to your computer and use it in GitHub Desktop.
SplitDateTimeField in modelform django
class DateTimeField(models.DateTimeField):
def formfield(self, **kwargs):
defaults = {'form_class': forms.SplitDateTimeField,
'input_date_formats': ['%y/%m/%d']}
defaults.update(kwargs)
return super(DateTimeField, self).formfield(**defaults)
class Model(models.Model):
date = DateTimeField()
class Form(forms.ModelForm):
class Meta:
model = Model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment