Why don't you:
{% if form.myText.text %}
     <label for="id_myText">My text:</label> {{form.myText }}
{% else %}
     No text yet.<input name="myText" id="id_myText" value=""  
type="hidden">
{% endif %}

That will get a myText field passed in the post/get parameter.

Corey

On Aug 21, 2006, at 5:39 PM, cyberco wrote:

>
> Given the model:
> ===========================================
> myText = models.TextField(blank=True)
> ===========================================
>
> In case this TextField has no text I want to hide it from my form.
> Template code:
>
> ===========================================
> {% if form.myText.text %}
>     <label for="id_myText">My text:</label> {{form.myText }}
> {% else %}
>     No text yet.
> {% endif %}
> ===========================================
>
> But then saving the form gives an error saying it wants to save a NULL
> value in a field that cannot be NULL. A solution could be adding
> 'null=True' to the field:
>
> ===========================================
> myText = models.TextField(blank=True, null=True)
> ===========================================
>
> But this is discouraged by Django:
>
> http://www.djangoproject.com/documentation/model_api/#null
> "Avoid using null on string-based fields such as CharField and
> TextField unless you have an excellent reason. If a string-based field
> has null=True, that means it has two possible values for "no data":
> NULL, and the empty string. In most cases, it's redundant to have two
> possible values for "no data;" Django convention is to use the empty
> string, not NULL."
>
> What would be the proper way to do this?
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to