Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Nathaniel Griswold

Thanks, created Ticket #9039

> I don't think the ModelForm validation should prohibit something the
> databases generally allow. I'd open a ticket (search first though to see if
> it's already been reported/decided on...I could be missing something).
>
> Karen
>

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



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Karen Tracey
On Thu, Sep 11, 2008 at 8:14 AM, krylatij <[EMAIL PROTECTED]> wrote:

>
> You can create only one model with empty 'other' field.
> If you could  create one more, field 'other'  will not be unique more.
> That's why validation fails.
>

This is not generally true at the database level, as Nathaniel showed by the
fact that he could indeed create multiple objects with null values, just not
via a ModelForm.  From the PostgreSQL doc (
http://www.postgresql.org/docs/8.3/interactive/indexes-unique.html):

"When an index is declared unique, multiple table rows with equal indexed
values will not be allowed. Null values are not considered equal."

and MySQL (http://dev.mysql.com/doc/refman/5.0/en/create-index.html):

"A UNIQUE index creates a constraint such that all values in the index must
be distinct. An error occurs if you try to add a new row with a key value
that matches an existing row. This constraint does not apply to NULL values
except for the BDB storage engine. For other engines, a UNIQUE index allows
multiple NULL values for columns that can contain NULL."

I don't think the ModelForm validation should prohibit something the
databases generally allow. I'd open a ticket (search first though to see if
it's already been reported/decided on...I could be missing something).

Karen

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



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread krylatij

You can create only one model with empty 'other' field.
If you could  create one more, field 'other'  will not be unique more.
That's why validation fails.




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



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Nathaniel Griswold

My django version is 1.0-final-SVN-9013

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



Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Nathaniel Griswold

Hi,

I'm having problems validating a form for the below models. Multiple
null values in the below "Thing" model's "other" column seem to
prevent the basic ModelForm from validating. This also happens for
OneToOneFields of the same nature. Normal django db api functions and
the database do not seem to have any problem. I also tried this in an
older revision of django (using form_for_model) and had no problems
there.

Is this a known issue? It seems really basic.

---
class OtherThing(models.Model):
pass

class Thing(models.Model):
other = models.ForeignKey('OtherThing', null=True, blank=True, unique=True)

>>> import django
>>> django.get_version()
>>> from django.forms import ModelForm
>>> from test.models import *
>>>
>>> class ThingForm(ModelForm):
...   class Meta:
... model = Thing
...
>>> Thing.objects.all()
[]
>>> ThingForm({}).save()

>>> ThingForm({}).save()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/home/griswold/lib/python/django/forms/models.py", line 302, in save
return save_instance(self, self.instance, self._meta.fields,
fail_message, commit)
  File "/home/griswold/lib/python/django/forms/models.py", line 36, in
save_instance
raise ValueError("The %s could not be %s because the data didn't"
ValueError: The Thing could not be created because the data didn't validate.
>>>
>>> Thing.objects.create()

>>> Thing.objects.create()

>>> Thing.objects.all()
[, , ]

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