I wonder if you'd better do this using a method on your model:
class MyModel(models.Model): name = models.CharField(max_length=50) fullname = models.CharField(max_length=100) def display_name(self): if self.fullname: return self.fullname return self.name
Perhaps instead of display_name this should be your __unicode__ method.
If you really want to do what you requested, then you cannot do it with default - use the clean method in your form (or your model, if you use the new -fangled model check (available with Django 1.2).
Something like this (for model validation):
class MyModel(models.Model): name = models.CharField(max_length=50) fullname = models.CharField(max_length=100,default=name) def clean(self): self.fullname=name
Or like this (for form validation):
class MyModelForm(ModelForm): class Meta: model = MyModel def clean(self): cleaned_data = self.cleaned_data cleaned_data['fullname'] = cleaned_data['name'] return cleaned_data
Dominic Rodger
source share