Re: New CharField attribute to handle CharField(null=True, blank=True, unique=True) in model forms

2016-05-27 Thread Shai Berger
Hi,

On Thursday 19 May 2016 06:01:30 Jon Dufresne wrote:
> 
> Occasionally I'll need to define a CharField on a model that is unique but
> also allow blank values. At the database level, this is easily handled by
> storing NULL for the blank values. (Storing the empty string multiple times
> will result in a DB unique constraint violation.) This use case has
> surfaced several times as evident by the 9 year old ticket #4136 [1].
> 
> I have created a POC solution to the ticket at PR 6624 [2]. The change adds
> the attribute "empty_value" to forms.CharField. The value specified by
> empty_value is used as the Python empty value for the field. This value
> defaults to the empty string (current behavior) but could also be changed
> to None. The change also modifies model forms to set empty_value to None
> for CharField when null=True is set. The model forms change allows the use
> of the admin to save blank, unique char values without unique constraint
> violations.
> 

I've added some comments on the PR. The TL;DR is that this causes some 
problems for Oracle, where empty strings are always saved as nulls, but I 
think we can solve most of the issues and document around the others.

Shai.

> 
> [1] https://code.djangoproject.com/ticket/4136
> [2] https://github.com/django/django/pull/6624


Re: New CharField attribute to handle CharField(null=True, blank=True, unique=True) in model forms

2016-05-19 Thread Claude Paroz
The design and the patch look good to me. Thanks!

Claude

Le jeudi 19 mai 2016 05:01:37 UTC+2, Jon Dufresne a écrit :
>
> Hi,
>
> Occasionally I'll need to define a CharField on a model that is unique but 
> also allow blank values. At the database level, this is easily handled by 
> storing NULL for the blank values. (Storing the empty string multiple times 
> will result in a DB unique constraint violation.) This use case has 
> surfaced several times as evident by the 9 year old ticket #4136 [1].
>
> I have created a POC solution to the ticket at PR 6624 [2]. The change 
> adds the attribute "empty_value" to forms.CharField. The value specified by 
> empty_value is used as the Python empty value for the field. This value 
> defaults to the empty string (current behavior) but could also be changed 
> to None. The change also modifies model forms to set empty_value to None 
> for CharField when null=True is set. The model forms change allows the use 
> of the admin to save blank, unique char values without unique constraint 
> violations.
>
> This choice to create the empty_value attribute API was based on the prior 
> art of the empty_value attribute of TypedChoiceField [3].
>
> In the PR Tim Graham requested I raise the new API on the developers list. 
> I'm looking for concerns or feedback regarding the new attribute or any 
> other issue with the PR.
>
> Thanks!
>
> Cheers,
> Jon
>
>
> [1] https://code.djangoproject.com/ticket/4136
> [2] https://github.com/django/django/pull/6624
> [3] 
> https://github.com/django/django/blob/218175b/django/forms/fields.py#L832-L856
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ddebcca8-31f3-464e-a993-e4bdd288860d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New CharField attribute to handle CharField(null=True, blank=True, unique=True) in model forms

2016-05-18 Thread Jon Dufresne
Hi,

Occasionally I'll need to define a CharField on a model that is unique but
also allow blank values. At the database level, this is easily handled by
storing NULL for the blank values. (Storing the empty string multiple times
will result in a DB unique constraint violation.) This use case has
surfaced several times as evident by the 9 year old ticket #4136 [1].

I have created a POC solution to the ticket at PR 6624 [2]. The change adds
the attribute "empty_value" to forms.CharField. The value specified by
empty_value is used as the Python empty value for the field. This value
defaults to the empty string (current behavior) but could also be changed
to None. The change also modifies model forms to set empty_value to None
for CharField when null=True is set. The model forms change allows the use
of the admin to save blank, unique char values without unique constraint
violations.

This choice to create the empty_value attribute API was based on the prior
art of the empty_value attribute of TypedChoiceField [3].

In the PR Tim Graham requested I raise the new API on the developers list.
I'm looking for concerns or feedback regarding the new attribute or any
other issue with the PR.

Thanks!

Cheers,
Jon


[1] https://code.djangoproject.com/ticket/4136
[2] https://github.com/django/django/pull/6624
[3]
https://github.com/django/django/blob/218175b/django/forms/fields.py#L832-L856

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CADhq2b6dp46Z2MROPTanNt%2Bo3wAVfuq3A32jTGrRo87-W8Wo-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.