Skip to main content
added 1 character in body
Source Link
Zulu
  • 9.1k
  • 9
  • 50
  • 57

The usual way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dangodjango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

The usual way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

The usual way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from django import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

deleted 5 characters in body
Source Link
Jarret Hardie
  • 97k
  • 10
  • 133
  • 127

The proscribedusual way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

The proscribed way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

The usual way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

added 483 characters in body
Source Link
Jarret Hardie
  • 97k
  • 10
  • 133
  • 127

The proscribed way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

The proscribed way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

The proscribed way to do this is to override the default field types in your ModelForm definition.

The example below would work if you had a DateField in your model (I note you have a DateTimeField... I'll come back to that in a sec). You're going to be specifying the exact same field type as would normally be specified, but you'll pass a different widget to the form field constructor.

from django.db import models
from dango import forms
from django.forms.extras import SelectDateWidget

class MyModel(models.Model):
    a_date_field = models.DateField()

class MyModelForm(forms.ModelForm):
    a_date_field = forms.DateField(widget=SelectDateWidget())

    class Meta:
        model = MyModel

There isn't, to my knowledge, an equivalent widget provided for the DateTimeField in Django 1.0.x. In this case, you'll want to make a custom widget, perhaps subclassing SelectDateWidget. I note from a quick google on SelectDateTimeWidget that there have been several others who've been making what appear to be the widget you're seeking. I've not used them, so caveat emptor, but something like this SelectDateTimeWidget patch might be a good place to start.


Edit: When using a ModelFormset or InlineModelFormset, you can still achieve this by passing form=MyModelForm to the inlineformet_factory function:

MyModelFormset = inlineformset_factory(MyParentModel, MyModel, form=MyModelForm)

This works because the two model formset factories actually call the regular formset_factory constructor in their own implementations. It's a little hard to figure out because it's not explicitly stated in the docs... rather the Django docs allude to this ability by mentioning in passing that the model formset factories extend the normal formset_factory. Whenever I'm in doubt, I open django/forms/models.py to check out the full signature of the formset factory functions.

added 257 characters in body
Source Link
Jarret Hardie
  • 97k
  • 10
  • 133
  • 127
Loading
Source Link
Jarret Hardie
  • 97k
  • 10
  • 133
  • 127
Loading