1

Im trying to specify a default value for my form field domainNm when the form is initially loaded.

I have: form

   class SubmitDomain(ModelForm):
        class Meta:
            model = Tld #Create form based off Model for Tld
            fields = ['domainNm',]

    def clean_domainNm(self):
        cleanedDomainName = self.cleaned_data.get('domainNm')
        if Tld.objects.filter(domainNm=cleanedDomainName).exists():
            errorMsg = u"Sorry that domain is not available."
            raise ValidationError(errorMsg)
        else:
            return cleanedDomainName

    ## This creates the form.
    form = SubmitDomain()

Model

class Tld(models.Model):
    domainNm = models.CharField( )   #add a call in here?

I tried searching google a lot before posting this, but cannot seem to find an example of something so basic.

Any help is much appreciated. Thanks.

CodeTalk
  • 3,571
  • 16
  • 57
  • 92

1 Answers1

1
class SubmitDomain(ModelForm):
    domainNm = forms.CharField(initial=u'Initial value')
    class Meta:
        model = Tld #Create form based off Model for Tld
        fields = ['domainNm',]
CJ4
  • 2,485
  • 3
  • 26
  • 29
  • I was trying this "initial" ,but it wasn't working, must have been doing something wrong here. Thanks! – CodeTalk Aug 02 '13 at 14:37