| 3861 | from django.db import models |
| 3862 | import datetime |
| 3863 | |
| 3864 | class Foo(models.Model): |
| 3865 | name = models.CharField(max_length=256, default='class wide default value') |
| 3866 | date = models.DateField(default = datetime.date(1980, 1, 1)) |
| 3867 | value = models.IntegerField(default=42) |
| 3868 | |
| 3869 | formfield_initial_from_default_tests = ur""" |
| 3870 | >>> from django import newforms as forms |
| 3871 | >>> FooForm = forms.form_for_model(Foo) |
| 3872 | >>> FooForm().fields['name'].initial |
| 3873 | 'class wide default value' |
| 3874 | >>> FooForm().fields['date'].initial |
| 3875 | datetime.date(1980, 1, 1) |
| 3876 | >>> FooForm().fields['value'].initial |
| 3877 | 42 |
| 3878 | >>> foo_instance = Foo(name='instance value', date = datetime.date(1969, 4, 4), value = 12) |
| 3879 | >>> InstanceForm = forms.form_for_instance(foo_instance) |
| 3880 | >>> InstanceForm().fields['name'].initial |
| 3881 | 'instance value' |
| 3882 | >>> InstanceForm().fields['date'].initial |
| 3883 | datetime.date(1969, 4, 4) |
| 3884 | >>> InstanceForm().fields['value'].initial |
| 3885 | 12 |
| 3886 | """ |
| 3887 | |