Re: Case-insensitve unique = True

2020-01-24 Thread gaurav jain
Hi,
I think you can save a processed version of the text and apply a unique
constraint.
If you want save the original text then save the non processed test as well.
Kind regards
Gaurav Jain


On Fri, 24 Jan, 2020, 1:34 pm Mike Dewhirst,  wrote:

> On 24/01/2020 6:12 pm, maninder singh Kumar wrote:
> > I wonder at that.  When I develop a model does the CharField have to
> > be specified case insensitive at that level.
>
> That is what Simon advised and I think it is exactly what I want.
>
> >
> > For instance :  A search can be case insensitive and iexact is the
> > best way.
>
> Searching isn't the problem. I don't want duplicate names differing only
> in the case and I want that to be enforced at the model level at
> instance creation time and also later if the name is edited.
>
> I have been using iexact to "manually" enforce case insensitive-unique
> names.
>
> Cheers
>
> Mike
>
>
> > --
> >
> > Maninder Kumar
> > http://about.me/maninder.s.kumar
> >
> > 
> >
> >
> >
> > On Fri, Jan 24, 2020 at 8:06 AM Mike Dewhirst  > > wrote:
> >
> > What is the best way to ensure a charfield is case-insensitively
> > unique?
> >
> > Currently I'm using a query with __iexact=True but I wonder whether
> > there is a better way.
> >
> > Thanks
> >
> > Mike
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to django-users+unsubscr...@googlegroups.com
> > .
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/49ae5424-f079-d4eb-bc6d-aa5231efa773%40dewhirst.com.au
> .
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to django-users+unsubscr...@googlegroups.com
> > .
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/CABOHK3RTRmRwyMsgdryp50vVbBeopqBcu2CCQdrY9aJySjwkpg%40mail.gmail.com
> > <
> https://groups.google.com/d/msgid/django-users/CABOHK3RTRmRwyMsgdryp50vVbBeopqBcu2CCQdrY9aJySjwkpg%40mail.gmail.com?utm_medium=email&utm_source=footer
> >.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8c6f13f3-1e27-cd55-6ee8-51f0a1dcd039%40dewhirst.com.au
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMiDnWAZF3y_gb%3DyGF46jqLRXoYzBzjO0O1HaPUTK%2BGN-WNApg%40mail.gmail.com.


Re: Case-insensitve unique = True

2020-01-24 Thread Mike Dewhirst

On 24/01/2020 6:12 pm, maninder singh Kumar wrote:
I wonder at that.  When I develop a model does the CharField have to 
be specified case insensitive at that level.


That is what Simon advised and I think it is exactly what I want.



For instance :  A search can be case insensitive and iexact is the 
best way.


Searching isn't the problem. I don't want duplicate names differing only 
in the case and I want that to be enforced at the model level at 
instance creation time and also later if the name is edited.


I have been using iexact to "manually" enforce case insensitive-unique 
names.


Cheers

Mike



--

Maninder Kumar
http://about.me/maninder.s.kumar





On Fri, Jan 24, 2020 at 8:06 AM Mike Dewhirst > wrote:


What is the best way to ensure a charfield is case-insensitively
unique?

Currently I'm using a query with __iexact=True but I wonder whether
there is a better way.

Thanks

Mike


-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/49ae5424-f079-d4eb-bc6d-aa5231efa773%40dewhirst.com.au.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABOHK3RTRmRwyMsgdryp50vVbBeopqBcu2CCQdrY9aJySjwkpg%40mail.gmail.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8c6f13f3-1e27-cd55-6ee8-51f0a1dcd039%40dewhirst.com.au.


Re: Case-insensitve unique = True

2020-01-23 Thread Mike Dewhirst

On 24/01/2020 3:20 pm, Simon Charette wrote:
If you are using PostgreSQL I'd suggest using a CIText field[0] with a 
unique

constraint[1].


Surely everyone uses PostgreSQL, no?

That [0] is identical in Django 2.2 and it looks like I should migrate 
my models.CharField to django.contrib.postgresfield.CICharField


I'm already using [1] in Django 2.2

Thank you Simon you have made my day :-)

Cheers

Mike



If you are *not* using PostgreSQL your best choice is likely to 
emulate the
upcoming expression[3] support for UniqueConstraint(Lower('field')) by 
using

a RunSQL operation that performs the appropriate DDL assuming your backend
supports it.

Best,
Simon

[0] 
https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#citext-fields

[1] https://docs.djangoproject.com/en/3.0/ref/models/fields/#unique
[3] https://github.com/django/django/pull/11929

Le jeudi 23 janvier 2020 21:36:29 UTC-5, Mike Dewhirst a écrit :

What is the best way to ensure a charfield is case-insensitively
unique?

Currently I'm using a query with __iexact=True but I wonder whether
there is a better way.

Thanks

Mike


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/967c8a27-a8ec-42fc-abf5-bda76fbb5ef9%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afa46f25-214a-0de9-cc20-f58174de2bdf%40dewhirst.com.au.


Re: Case-insensitve unique = True

2020-01-23 Thread maninder singh Kumar
I wonder at that.  When I develop a model does the CharField have to be
specified case insensitive at that level.

For instance :  A search can be case insensitive and iexact is the best way.


[image: --]

Maninder Kumar
[image: http://]about.me/maninder.s.kumar





On Fri, Jan 24, 2020 at 8:06 AM Mike Dewhirst  wrote:

> What is the best way to ensure a charfield is case-insensitively unique?
>
> Currently I'm using a query with __iexact=True but I wonder whether
> there is a better way.
>
> Thanks
>
> Mike
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/49ae5424-f079-d4eb-bc6d-aa5231efa773%40dewhirst.com.au
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABOHK3RTRmRwyMsgdryp50vVbBeopqBcu2CCQdrY9aJySjwkpg%40mail.gmail.com.


Re: Case-insensitve unique = True

2020-01-23 Thread Simon Charette
If you are using PostgreSQL I'd suggest using a CIText field[0] with a 
unique
constraint[1].

If you are *not* using PostgreSQL your best choice is likely to emulate the
upcoming expression[3] support for UniqueConstraint(Lower('field')) by using
a RunSQL operation that performs the appropriate DDL assuming your backend
supports it.

Best,
Simon

[0] 
https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#citext-fields
[1] https://docs.djangoproject.com/en/3.0/ref/models/fields/#unique
[3] https://github.com/django/django/pull/11929

Le jeudi 23 janvier 2020 21:36:29 UTC-5, Mike Dewhirst a écrit :
>
> What is the best way to ensure a charfield is case-insensitively unique? 
>
> Currently I'm using a query with __iexact=True but I wonder whether 
> there is a better way. 
>
> Thanks 
>
> Mike 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/967c8a27-a8ec-42fc-abf5-bda76fbb5ef9%40googlegroups.com.


Case-insensitve unique = True

2020-01-23 Thread Mike Dewhirst

What is the best way to ensure a charfield is case-insensitively unique?

Currently I'm using a query with __iexact=True but I wonder whether 
there is a better way.


Thanks

Mike


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49ae5424-f079-d4eb-bc6d-aa5231efa773%40dewhirst.com.au.


Re: Make migration issue for a unique True filed.

2018-09-26 Thread luca bocchi
fields are not null by default, so you don't need:

*null=False*

that's why *makemigrations* doesn't detect changes in the *MyModel* model.

L

Il giorno mercoledì 26 settembre 2018 13:16:24 UTC+2, jisson varghese ha 
scritto:
>
>
> I have model MyModel in app app1
>
> class MyModel(models.Model):
>  ...
>  name = models.CharField(max_length=10, unique=True)
>
>
> I have made the following change,
>
> class MyModel(models.Model):
>  ...
>  name = models.CharField(max_length=10, unique=True, null=False)
>
>
> python manage.py makemigrations  - create migration in file different app, 
> and no there is no changes in that model.
> When I tried manage.py makemigrations  app1 - No changes detected in app 
> 'app1'
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/97554e80-b497-4fc6-be6d-e4fa84b1addd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Make migration issue for a unique True filed.

2018-09-26 Thread jisson varghese

I have model MyModel in app app1

class MyModel(models.Model):
 ...
 name = models.CharField(max_length=10, unique=True)


I have made the following change,

class MyModel(models.Model):
 ...
 name = models.CharField(max_length=10, unique=True, null=False)


python manage.py makemigrations  - create migration in file different app, 
and no there is no changes in that model.
When I tried manage.py makemigrations  app1 - No changes detected in app 
'app1'




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/27bb2c1b-9a3c-4c21-8fc9-cfb1bc7ff0c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2013-01-30 Thread mimino666
This snippet is what you need 
https://github.com/Mimino666/django-hash-field. Go ahead and give it a try, 
any feedback appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: unique=True doesn't work

2012-05-11 Thread .
Thanks for you comments.
I've recreated my repo and it worked.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: unique=True doesn't work

2012-05-11 Thread Nikolas Stevenson-Molnar
Take a look at your database schema and make sure that table actually
has a unique key for the `foo` column.

_Nik

On 5/11/2012 1:16 PM, . wrote:
> Hi there,
>
> Here is my class:
>
> MyClass(User):
>   foo = IPAddressField(unique=True)
>
> unique doesn't work:
>
> python manage.py shell
>
> from myproject.models import MyClass
> bar = MyClass(foo="12", username="first", password="secret")
> bar.save()
>
> baz = MyClass(foo="12", username="second", password="secret")
> baz.save()
>
> It should raise an exception, but there is no one.
> (username's unique=True works.)
>
> Do you have any ideas?
> Are there any other ways to make a unique field?
>
>
> Regards
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: unique=True doesn't work

2012-05-11 Thread Javier Guerra Giraldez
On Fri, May 11, 2012 at 3:16 PM, .  wrote:
> It should raise an exception, but there is no one.
> (username's unique=True works.)

my guess: the IPAddress field didn't have unique=True at first, but it
was added afterwards.

the syncdb command doesn't modify existing tables. if you want that, you can:

a) manually drop the table and let syncdb build it again, or

b) manually ALTER TABLE to make it conform the new models.py, or

c) use South


-- 
Javier

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



unique=True doesn't work

2012-05-11 Thread .
Hi there,

Here is my class:

MyClass(User):
  foo = IPAddressField(unique=True)

unique doesn't work:

python manage.py shell

from myproject.models import MyClass
bar = MyClass(foo="12", username="first", password="secret")
bar.save()

baz = MyClass(foo="12", username="second", password="secret")
baz.save()

It should raise an exception, but there is no one.
(username's unique=True works.)

Do you have any ideas?
Are there any other ways to make a unique field?


Regards

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django testing and unique=True

2011-12-13 Thread Karen Tracey
On Tue, Dec 13, 2011 at 8:33 AM, Acruax  wrote:

> Hi,
> I have a problem with model testing. My test fails with error:
>  IntegrityError: duplicate key value violates unique constraint
> "catalog_name_key"
>  DETAIL: Key (name)=(test_catalog1) already exists.
>
> I have unique=True on name field.
>
> class CatalogTestCase(unittest.TestCase):
>def setUp(self):
>self.catalog1 = Catalog.objects.create(name="test_catalog1",
> title_ru="Test Catalog1")
>

For tests that use the database, you need to extend from
django.test.TestCase, not unittest.TestCase. Django's custom TestCase will
ensure that the database is reset to its initial state between tests (see
https://docs.djangoproject.com/en/1.3/topics/testing/#testcase). The need
for using Django's custom TestCase is unfortunately not currently properly
noted in the docs, and there is a ticket open on that (
https://code.djangoproject.com/ticket/17312).

Karen
-- 
http://tracey.org/kmt/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django testing and unique=True

2011-12-13 Thread Acruax
Hi,
I have a problem with model testing. My test fails with error:
  IntegrityError: duplicate key value violates unique constraint
"catalog_name_key"
  DETAIL: Key (name)=(test_catalog1) already exists.

I have unique=True on name field.

class CatalogTestCase(unittest.TestCase):
def setUp(self):
self.catalog1 = Catalog.objects.create(name="test_catalog1",
title_ru="Test Catalog1")

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



index for fields with unique=True and db_index True

2010-11-05 Thread jordi
When I create the following model I get an index for field2 with syndb
or sqlindexes. Why doesn't it create an index for field3?

from django.db import models
class Entitat(models.Model):
field1 = models.CharField(max_length=4, unique=True)
field2 = models.CharField(max_length=4, db_index=True )
field3 = models.CharField(max_length=4, unique=True,
db_index=True )

To create an index for field3 I have to remove "unique=True", create
the index and after add again "unique=True", so django admin captures
non unique entries.

I am using sqlite (with spatialite).

I don't know if this is a bug, a feature or I understand something
wrong?

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



Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-10 Thread germ
for my needs i will patch django/db/backends/mysql/validation.py
producing my own locally used django rpm to allow more than 255. in my
configuration this works fine. thanks all for your time and guidance!

--

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




Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-09 Thread bruno desthuilliers
On 8 déc, 19:21, germ  wrote:
> > The point is that utf8 can use up to 3 bytes per character...
>
> i appreciate your reply. interesting distinction between bytes and
> chars.

Been here, done that :-/

> i think i still need some more guidance. still not sure how to
> resolve with your suggestion to consdier the character set.

Well, my suggestion wrt/ charset is to use utf-8 everywhere (os,
shells, source codes, templates and all text files, databases, default
encoding for Apache, etc) - but this won't obviously solve your
problem !-)

> just looking for a simple way to specify a url field in models.py that
> will allow creation with django 1.1.1 syncdb and mysql 5.0.67. want
> this url text/char field to be as large as permitted and unique.

IE won't accept urls longer than 2083 characters IIRC - and a 2083
characters urls is neither very practical nor something you meet
everyday. Also, as Karen said, a unique index on a 2000+ characters
field might not be such a good idea - at least depending on how you're
using it.

Anyway... There's at least one workaround I can think of that imply a
little denormalization: using a text field for the url - without
uniqueness constraint -, and storing the hash() value (or some md5 sum
or like) of the url in another field, this one with a unique
constraint. The hash or md5 would be computed in the model save()
method. This is not totally dry and not as robust as a real unique
constraint on the url field itself, but that's the better solution I
can come with.




> thanks all for your time and assistance!

--

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




Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-08 Thread Karen Tracey
On Tue, Dec 8, 2009 at 1:21 PM, germ  wrote:

> > The point is that utf8 can use up to 3 bytes per character...
>
> i appreciate your reply. interesting distinction between bytes and
> chars. i think i still need some more guidance. still not sure how to
> resolve with your suggestion to consdier the character set.
>
> i am able to create the django model class defining the table manually
> in mysql without any error. i was also able to create that same model
> with django 1.0.2 using syncdb. however, with django 1.1.1 i get the
> max_length error (as originally posted). it seems like the django
> syncdb code is detecting a size threshold, outputting the error, and
> exiting without ever really attempting the mysql table create.
>
>
Yes, I believe that change was made in response to this thread:

http://groups.google.com/group/django-developers/browse_thread/thread/edf3312c4fa1d2d4

reporting validation did not detect table creations that MySQL would reject.
The ticket to look at for details of the change is #9431 (
http://code.djangoproject.com/ticket/9431).  It appears to be rather
difficult to determine ahead of time what, exactly, is the limit MySQL will
apply. You show it reporting 767 bytes, that thread shows it reporting 999
bytes, the ticket notes it's a different limit for InnoDB compared to
MyISAM, the table charset is a factor, etc.

I think that a limit of 255 was put into Django due to difficulty
(impossibility?) of figuring out ahead of time what the limit really is for
the table about to be created, and since 255 would definitely not trigger an
error, and probably having a unique index on a field longer than that is
likely not a great idea.  But I'm not sure about all the reasons, I'm just
guessing based on what I read on the thread/ticket.

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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-08 Thread germ
> The point is that utf8 can use up to 3 bytes per character...

i appreciate your reply. interesting distinction between bytes and
chars. i think i still need some more guidance. still not sure how to
resolve with your suggestion to consdier the character set.

i am able to create the django model class defining the table manually
in mysql without any error. i was also able to create that same model
with django 1.0.2 using syncdb. however, with django 1.1.1 i get the
max_length error (as originally posted). it seems like the django
syncdb code is detecting a size threshold, outputting the error, and
exiting without ever really attempting the mysql table create.

here's the mysql table created by django 1.0.2 syncdb without any
errors (some portions redacted) as output with 'show create table t':

CREATE TABLE `t` (
  `id` int(11) NOT NULL auto_increment,
  `url` varchar(760) NOT NULL,
  ...
  PRIMARY KEY  (`id`),
  UNIQUE KEY `url` (`url`),
  ...
) ENGINE=InnoDB AUTO_INCREMENT=1374 DEFAULT CHARSET=latin1

and here it is as i manually created it in mysql:

REATE TABLE `mbg_t` (
  `id` int(11) NOT NULL auto_increment,
  `url` varchar(760) NOT NULL,
  ...
  PRIMARY KEY  (`id`),
  UNIQUE KEY `url` (`url`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

the corresponding model class in models.py has not changed from django
1.0.2 to 1.1.1:
  url = models.CharField('Full URL', max_length=760, unique=True)

when we first implemented this a year ago for django 1.0.2 we tried
using a TextField; however, we switched to CharField due to
http://code.djangoproject.com/ticket/2495 which still seems
unresolved.

just looking for a simple way to specify a url field in models.py that
will allow creation with django 1.1.1 syncdb and mysql 5.0.67. want
this url text/char field to be as large as permitted and unique.

thanks all for your time and assistance!

--

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




Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-08 Thread bruno desthuilliers
On 7 déc, 23:46, germ  wrote:
> my platform: django 1.1.1, mysql 5.0.67, python 2.6.2
>
> why does syncdb complain
>  CharField cannot have a "max_length" greater than 255 when using
> "unique=True"
>
> when mysql 5.0.67 does allow greater tan 255? is there a way to
> override or ignore this error?
>
> this works in mysql
> mysql> create table mbg_test_1 (id int(5), url varchar(760) not null,
> primary key (id), unique (url));
> Query OK, 0 rows affected (0.00 sec)
>
>
> not sure why django hits this error since the true max length is 767,
> not 255:
>
> mysql> create table mbg_test_1 (url varchar(999) not null, unique (url));
> ERROR 1071 (42000): Specified key was too long; max key length is 767
> bytes

Are you sure you're using the same encoding (charset) in both cases ?
Note that the above message says "767 *bytes*", not 767 *characters*

Here is what I have (mysql 5.0.75):

mysql> create table mbg_test_1 (url varchar(767) not null, unique
(url)) CHARACTER SET utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000
bytes

The point is that utf8 can use up to 3 bytes per character...

--

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




CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-07 Thread germ
my platform: django 1.1.1, mysql 5.0.67, python 2.6.2

why does syncdb complain
 CharField cannot have a "max_length" greater than 255 when using
"unique=True"

when mysql 5.0.67 does allow greater tan 255? is there a way to
override or ignore this error?

this works in mysql
mysql> create table mbg_test_1 (id int(5), url varchar(760) not null,
primary key (id), unique (url));
Query OK, 0 rows affected (0.00 sec)

mysql> desc mbg_test_1;
+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| id| int(5)   | NO   | PRI | 0   |   |
| url   | varchar(760) | NO   | UNI | NULL|   |
+---+--+--+-+-+---+
2 rows in set (0.00 sec)

mysql>

but a Model with
 url  = models.CharField('Full URL', max_length=760, unique=True)
yields an error from syncdb:
$ manage.py syncdb
Error: One or more models did not validate:
threats.threat: "url": CharField cannot have a "max_length" greater
than 255 when using "unique=True".
$

not sure why django hits this error since the true max length is 767,
not 255:

mysql> create table mbg_test_1 (url varchar(999) not null, unique
(url));
ERROR 1071 (42000): Specified key was too long; max key length is 767
bytes
mysql>

--

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




Re: unique=True and IntegrityError

2009-09-01 Thread aa56280

> The check for unique fields is done in the base ModelForm clean method.  By
> overriding clean without calling the superclass clean you are causing the
> checks to be bypassed.

I read up on it while you were posting your reply :)

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-clean-method

Thanks for all the help.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: unique=True and IntegrityError

2009-09-01 Thread Karen Tracey
On Tue, Sep 1, 2009 at 12:51 PM, aa56280  wrote:

>
> You're right, I did leave out something - the clean() method. Nothing
> unusual there. In fact, if I take out everything from the method and
> leave the shell:
>
> def clean(self):
>  return self.cleaned_data
>
> It still craps out. However, if I take away the entire method, then I
> do get the validation error.
>

The check for unique fields is done in the base ModelForm clean method.  By
overriding clean without calling the superclass clean you are causing the
checks to be bypassed.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: unique=True and IntegrityError

2009-09-01 Thread aa56280

You're right, I did leave out something - the clean() method. Nothing
unusual there. In fact, if I take out everything from the method and
leave the shell:

def clean(self):
  return self.cleaned_data

It still craps out. However, if I take away the entire method, then I
do get the validation error.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: unique=True and IntegrityError

2009-09-01 Thread Karen Tracey
On Tue, Sep 1, 2009 at 1:20 AM, aa56280  wrote:

>
> ### Model ###
> class School(models.Model):
>url = models.SlugField(max_length=50, unique=True)
>name = models.CharField(max_length=255)
>...
>
>
> ### Form ###
> class SchoolForm(ModelForm):
>
>class Meta:
>model = School
>fields = ('url', 'name')
>
> ### View ###
> def new_school(request):
>if request.method == 'POST':
>form = SchoolForm(request.POST)
>if form.is_valid():
>form.save()
>
> new_school craps out with an IntegrityError exception any time I have
> a duplicate value. Any additional thoughts?
>

I'd guess something from the snippet that is relevant has been removed.  I
cannot recreate the problem you are reporting.  If I change new_school (just
to simplify shell testing) to:

def new_school(d):
form = SchoolForm(d)
if form.is_valid():
form.save()
print 'Saved the new school'
else:
print 'Errors on form validation: %r' % form.errors

Then test in the shell:

>>> from ttt.models import new_school
>>> new_school({'url': 'abcde', 'name': 's1'})
Saved the new school
>>> new_school({'url': 'abcde', 'name': 's1'})
Errors on form validation: {'url': [u'School with this Url already
exists.']}
>>>

There is something different about what you are doing, but I don't know what
it is.  If I were you I'd start with this minimal example and verify it
works for you, then add back the things from your actual code that are
missing, so as to figure out what additional piece is coming into play here.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: unique=True and IntegrityError

2009-08-31 Thread aa56280

On Aug 31, 9:51 pm, Karen Tracey  wrote:

> However if you use a ModelForm to validate the data prior to attempting to
> save the model you get these problems reported as validation errors:

Karen,

Thanks for the thorough explanation. I really appreciate it. What I
took from it is that if I'm using a ModelForm, Django should return a
validation error for a duplicate value. However, for my scenario, I
*am* using a ModelForm. Here's a snippet:

### Model ###
class School(models.Model):
url = models.SlugField(max_length=50, unique=True)
name = models.CharField(max_length=255)
...


### Form ###
class SchoolForm(ModelForm):

class Meta:
model = School
fields = ('url', 'name')

### View ###
def new_school(request):
if request.method == 'POST':
form = SchoolForm(request.POST)
if form.is_valid():
form.save()

new_school craps out with an IntegrityError exception any time I have
a duplicate value. Any additional thoughts?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: unique=True and IntegrityError

2009-08-31 Thread Karen Tracey
On Mon, Aug 31, 2009 at 6:27 PM, aa56280  wrote:

>
> I can't find an answer to this, so I'm hoping folks here can help: why
> is it that Django catches IntegrityError for a field with unique=True
> in the Admin tool but requires you to catch it yourself in your app?
> That is, why isn't it handled like all other built-in validation
> checks that come bundled with other options like, say, max_length?
>

It is handled like other built-in validation checks.  Within admin both
max_length, unique, etc. are checked/validated through use of a ModelForm
for the model.  If your code uses ModelForms you will get the same
validation checks.  If you don't use forms you won't (as presently there is
no model validation).  Depending on the database you can get an exception
raised as easily for violating max_length as you can for violating
uniqueness.  For example, given this model:

class Foo(models.Model):
    name = models.CharField(max_length=2, unique=True)

and using a MySQL db with DEBUG on, attempting to create a model that
violates the max_length constraint will raise an exception:

>>> from ttt.models import Foo
>>> Foo.objects.all()
[]
>>> Foo.objects.create(name='Yeppers')
Traceback (most recent call last):
  File "", line 1, in 
[snip]
  File "/usr/lib/python2.5/warnings.py", line 102, in warn_explicit
raise message
Warning: Data truncated for column 'name' at row 1
>>>


MySQL considers that just a warning (though there may well be a
configuration option to tell it whether to treat this is a warning or error
situation, I haven't checked) so you need to have DEBUG True for that to
raise an exception, and MySQL has saved the model anyway with the truncated
data.  Sqlite won't enforce the max_length check at all, I don't believe.
Not sure off the top of my head how others behave.

If you then try to add another object that violates the unique constraint
again you get an exception if you do it directly by attempting to create the
model:

>>> Foo.objects.create(name='Ye')
Traceback (most recent call last):
  File "", line 1, in 
[snip]
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35,
in defaulterrorhandler
raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry 'Ye' for key 2")
>>>

However if you use a ModelForm to validate the data prior to attempting to
save the model you get these problems reported as validation errors:

>>> from django import forms
>>> class FooForm(forms.ModelForm):
...  class Meta:
... model = Foo
...
>>> ff = FooForm(data={'name': 'Yeppers'})
>>> ff.is_valid()
False
>>> ff.errors
{'name': [u'Ensure this value has at most 2 characters (it has 7).']}
>>> ff = FooForm(data={'name': 'Ye'})
>>> ff.is_valid()
False
>>> ff.errors
{'name': [u'Foo with this Name already exists.']}
>>>

Since admin uses ModelForms, you see form validation errors when using it
instead of exceptions.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



unique=True and IntegrityError

2009-08-31 Thread aa56280

I can't find an answer to this, so I'm hoping folks here can help: why
is it that Django catches IntegrityError for a field with unique=True
in the Admin tool but requires you to catch it yourself in your app?
That is, why isn't it handled like all other built-in validation
checks that come bundled with other options like, say, max_length?

Thanks in advance.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



blank = True and unique = True

2009-04-10 Thread CrabbyPete

I have a field for emails. I want it to be blank if nothing in there
and unique if something is. I get a duplicate field error if I have to
messages with blank fields. I can use null = True and it works, but
django's admin blows up. I seen some stuff, but no real solution. Does
anyone have a good solution for this?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
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

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
-~--~~~~--~~--~--~---



Re: unique=True doesn't seem to do its job

2008-04-02 Thread Julien

Oh! I'm using MYSQL and I just realised that there was an option to
set the field unique in there. I hadn't put "unique=True" when I first
ran syncdb... so it was not taken into account after I later added it
in the model definition.

Thanks!

On Apr 2, 5:42 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
> On 02-Apr-08, at 12:03 PM, Julien wrote:
>
> > get() returned more than one Project -- it returned 2! Lookup
> > parameters were {'slug__exact': u'hello'}
>
> > I have the same issue on the front end using ModelForm.
>
> > Shouldn't that raise an IntegrityError, and then reload the form page
> > with an error like: "This value is already taken, please give another
> > one"?
>
> > I'm using the latest trunk.
>
> mysql?
>
> --
>
> regards
> kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/code/
--~--~-~--~~~---~--~~
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: unique=True doesn't seem to do its job

2008-04-01 Thread Kenneth Gonsalves


On 02-Apr-08, at 12:03 PM, Julien wrote:

> get() returned more than one Project -- it returned 2! Lookup
> parameters were {'slug__exact': u'hello'}
>
> I have the same issue on the front end using ModelForm.
>
> Shouldn't that raise an IntegrityError, and then reload the form page
> with an error like: "This value is already taken, please give another
> one"?
>
> I'm using the latest trunk.

mysql?

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/




--~--~-~--~~~---~--~~
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: unique=True doesn't seem to do its job

2008-04-01 Thread Julien

Sorry, above I meant "I would NOT get an IntegrityError but the
following:..."

On Apr 2, 5:33 pm, Julien <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I have a slug field which I'd like to be unique, so I do like this:
>
> class Project(models.Model):
> slug = models.SlugField(_('bla'), max_length=50, blank=True,
> unique=True, help_text=_('blabla'))
>
> In admin, if I saved a project with the slug 'hello', and then saved
> another one with the same slug, I would get the IntegrityError but the
> following:
>
> get() returned more than one Project -- it returned 2! Lookup
> parameters were {'slug__exact': u'hello'}
>
> I have the same issue on the front end using ModelForm.
>
> Shouldn't that raise an IntegrityError, and then reload the form page
> with an error like: "This value is already taken, please give another
> one"?
>
> I'm using the latest trunk.
>
> Thanks!
>
> Julien
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



unique=True doesn't seem to do its job

2008-04-01 Thread Julien

Hi there,

I have a slug field which I'd like to be unique, so I do like this:

class Project(models.Model):
slug = models.SlugField(_('bla'), max_length=50, blank=True,
unique=True, help_text=_('blabla'))

In admin, if I saved a project with the slug 'hello', and then saved
another one with the same slug, I would get the IntegrityError but the
following:

get() returned more than one Project -- it returned 2! Lookup
parameters were {'slug__exact': u'hello'}

I have the same issue on the front end using ModelForm.

Shouldn't that raise an IntegrityError, and then reload the form page
with an error like: "This value is already taken, please give another
one"?

I'm using the latest trunk.

Thanks!

Julien
--~--~-~--~~~---~--~~
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: does is_valid handle unique=True

2007-11-09 Thread Malcolm Tredinnick

On Sat, 2007-11-10 at 11:41 +0530, Kenneth Gonsalves wrote:
> hi,
> 
> I was using form_for_model with one field which has unique=True. This  
> form passes the is_valid test, but postgres barfs on the duplicate  
> entry - am I doing something wrong, or does is_valid not handle  
> unique=True?

Checking uniqueness at the database level would require talking to the
database. Forms are completely divorced from the ORM, intentionally.

Checking uniqueness should be a property of model validation and once
model validation is completed, it will be integrated into form_for_model
and form_for_instance. At the moment, though, you have to do this check
by hand or be prepared to handle an IntegrityError. It's work in
progress.

Malcolm

-- 
Remember that you are unique. Just like everyone else. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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: does is_valid handle unique=True

2007-11-09 Thread Sean Perry

Kenneth Gonsalves wrote:
> hi,
> 
> I was using form_for_model with one field which has unique=True. This  
> form passes the is_valid test, but postgres barfs on the duplicate  
> entry - am I doing something wrong, or does is_valid not handle  
> unique=True?

is_valid simply validates that the form data is correct -- a string or 
int depending on what you specified, filled in and not empty, etc.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



does is_valid handle unique=True

2007-11-09 Thread Kenneth Gonsalves

hi,

I was using form_for_model with one field which has unique=True. This  
form passes the is_valid test, but postgres barfs on the duplicate  
entry - am I doing something wrong, or does is_valid not handle  
unique=True?
-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
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: SlugField missing an index when unique=True?

2007-08-25 Thread Shev

I'm still seeing this bug, so ticket-time it is.

On Aug 8, 11:11 pm, Shev <[EMAIL PROTECTED]> wrote:
> Hi Djangoers - I'm using Postgres 8.2 and I'm noticing that for all
> models where I have a SlugField, the database index seems to be
> missing where I also set unique=True in the SlugField definition.  By
> default, SlugField has db_index=True, according to the docs, and I do
> see an index for SlugFields without unique=True.  Is anyone else
> seeing this?  i.e.
>
> foo = models.SlugField()  > index is present in Postgres, as
> expected
>
> bar = models.SlugField(unique=True)   ---> index is not present in
> Postgres
>
> I also have other attributes on the SlugField, like maxlength,
> blank=True and null=True, but the only consistent difference between
> the SlugFields where an index is not present automatically vs those
> that are seems to be the attribute unique=True.  Manually creating the
> index works fine.  Any comments/suggests?  Is this a bug?
>
> Shev


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



SlugField missing an index when unique=True?

2007-08-08 Thread Shev

Hi Djangoers - I'm using Postgres 8.2 and I'm noticing that for all
models where I have a SlugField, the database index seems to be
missing where I also set unique=True in the SlugField definition.  By
default, SlugField has db_index=True, according to the docs, and I do
see an index for SlugFields without unique=True.  Is anyone else
seeing this?  i.e.

foo = models.SlugField()  > index is present in Postgres, as
expected

bar = models.SlugField(unique=True)   ---> index is not present in
Postgres

I also have other attributes on the SlugField, like maxlength,
blank=True and null=True, but the only consistent difference between
the SlugFields where an index is not present automatically vs those
that are seems to be the attribute unique=True.  Manually creating the
index works fine.  Any comments/suggests?  Is this a bug?

Shev


--~--~-~--~~~---~--~~
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: newforms and models unique=True validation

2007-07-19 Thread stereoit

+1 it works, perfect (I just change the self.cleaned_data into
self.clean_data). Now when you showed me the trick I was able to track
it in docs as well, unfortunately I'm using 0.96 and
http://www.djangoproject.com/documentation/0.96/newforms/ is much
different to http://www.djangoproject.com/documentation/newforms/

Is there anything coming into django that would provide validation of
unique=True out of the box?

Anyway thank you very much


On Jul 18, 8:42 pm, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
> You want to create a BaseForm to specify in your form_for_model call.
> You could do something like:
>
> from django import newforms as forms
>
> class MyBaseForm(forms.BaseForm):
>   def clean_myfield(self):
> if
> MyModel.objects.filter(myfield=self.cleaned_data['myfield']).count():
>   raise forms.ValidationError('some error message')
>
> MyForm = forms.form_for_model(MyModel, form=MyBaseForm)
>
> 
> Nathan Ostgard
>
> On Jul 18, 7:06 am, stereoit <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I have model with field that has attribute unique set to True. I know
> > newforms are not able to handle such a validation as this is DB
> > related. However I read at newforms doc page that it is possible to
> > provide method called clean_() that can do custom validation.
> > My problem is that method is supposed to access the data via
> > self.cleaned_date and I create form by using form_for_model hence I do
> > not know how to write such a method.
>
> > Can anyone point me to right direction or best practice? Handling this
> > at form.save() seem not right to me.
>
> > My idea was to create custom validation method that would try tu pull
> > object from DB with  set to same as in
> > cleaned_data['fieldname'] and if it exists it would raise
> > ValidationError. But I have no clue how to do that at the moment.


--~--~-~--~~~---~--~~
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: newforms and models unique=True validation

2007-07-18 Thread Nathan Ostgard

You can create a BaseForm class and specify it in your form_for_model
call:

from django import newforms as forms

class MyBaseForm(forms.BaseForm):
  def clean_myfield(self):
if
MyModel.objects.filter(myfield=self.cleaned_data['myfield']).count():
  raise forms.ValidationError('some error message')

MyForm = forms.form_for_model(MyModel, form=MyBaseForm)


Nathan Ostgard

On Jul 18, 7:06 am, stereoit <[EMAIL PROTECTED]> wrote:
> Hi,
> I have model with field that has attribute unique set to True. I know
> newforms are not able to handle such a validation as this is DB
> related. However I read at newforms doc page that it is possible to
> provide method called clean_() that can do custom validation.
> My problem is that method is supposed to access the data via
> self.cleaned_date and I create form by using form_for_model hence I do
> not know how to write such a method.
>
> Can anyone point me to right direction or best practice? Handling this
> at form.save() seem not right to me.
>
> My idea was to create custom validation method that would try tu pull
> object from DB with  set to same as in
> cleaned_data['fieldname'] and if it exists it would raise
> ValidationError. But I have no clue how to do that at the moment.


--~--~-~--~~~---~--~~
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: newforms and models unique=True validation

2007-07-18 Thread Nathan Ostgard

You want to create a BaseForm to specify in your form_for_model call.
You could do something like:

from django import newforms as forms

class MyBaseForm(forms.BaseForm):
  def clean_myfield(self):
if
MyModel.objects.filter(myfield=self.cleaned_data['myfield']).count():
  raise forms.ValidationError('some error message')

MyForm = forms.form_for_model(MyModel, form=MyBaseForm)


Nathan Ostgard

On Jul 18, 7:06 am, stereoit <[EMAIL PROTECTED]> wrote:
> Hi,
> I have model with field that has attribute unique set to True. I know
> newforms are not able to handle such a validation as this is DB
> related. However I read at newforms doc page that it is possible to
> provide method called clean_() that can do custom validation.
> My problem is that method is supposed to access the data via
> self.cleaned_date and I create form by using form_for_model hence I do
> not know how to write such a method.
>
> Can anyone point me to right direction or best practice? Handling this
> at form.save() seem not right to me.
>
> My idea was to create custom validation method that would try tu pull
> object from DB with  set to same as in
> cleaned_data['fieldname'] and if it exists it would raise
> ValidationError. But I have no clue how to do that at the moment.


--~--~-~--~~~---~--~~
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: Unique=true

2007-07-18 Thread Nis Jørgensen

Nis Jørgensen skrev:
> [EMAIL PROTECTED] skrev:
>   
>> OK, fixed the above problem -- figured out that it was related to my
>> setting unique=True on a field. But that raises the larger question...
>>
>> I have a bit of data that may or may not exist... a identifier on the
>> user that not all users will have, but if they DO have it, it needs to
>> be unique to that user. Apparently, unique=True isn't what I want,
>> because the second user without it throws the above duplicate entry
>> error, so how do I handle that?
>>   
>> 
> I believe the behavior depends on your database backend. Postgresql does
> what you want.
>
> Postgresql is, AFAICT, complying with at least one of the SQL standards
> (but I don't have a copy of those)
>   
It seems mysql 5 works the same way as postgres - and it seems the error
message you quoted was from postgres.

It seems to me you do not have  null=True set for the Field. Thus blank
values are stored as empty strings, which unlike NULLS are equal to each
other.

/Nis




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



newforms and models unique=True validation

2007-07-18 Thread stereoit

Hi,
I have model with field that has attribute unique set to True. I know
newforms are not able to handle such a validation as this is DB
related. However I read at newforms doc page that it is possible to
provide method called clean_() that can do custom validation.
My problem is that method is supposed to access the data via
self.cleaned_date and I create form by using form_for_model hence I do
not know how to write such a method.

Can anyone point me to right direction or best practice? Handling this
at form.save() seem not right to me.

My idea was to create custom validation method that would try tu pull
object from DB with  set to same as in
cleaned_data['fieldname'] and if it exists it would raise
ValidationError. But I have no clue how to do that at the moment.


--~--~-~--~~~---~--~~
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: Unique=true

2007-07-17 Thread Nis Jørgensen

[EMAIL PROTECTED] skrev:
> OK, fixed the above problem -- figured out that it was related to my
> setting unique=True on a field. But that raises the larger question...
>
> I have a bit of data that may or may not exist... a identifier on the
> user that not all users will have, but if they DO have it, it needs to
> be unique to that user. Apparently, unique=True isn't what I want,
> because the second user without it throws the above duplicate entry
> error, so how do I handle that?
>   
I believe the behavior depends on your database backend. Postgresql does
what you want.

Postgresql is, AFAICT, complying with at least one of the SQL standards
(but I don't have a copy of those)

Nis


--~--~-~--~~~---~--~~
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: Unique=true

2007-07-16 Thread Brian Morton

If you are using NewForms, you should implement this in the clean()
method for a field.  See the newforms docs and unit tests for more
details.

On Jul 16, 4:49 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> OK, fixed the above problem -- figured out that it was related to my
> setting unique=True on a field. But that raises the larger question...
>
> I have a bit of data that may or may not exist... a identifier on the
> user that not all users will have, but if they DO have it, it needs to
> be unique to that user. Apparently, unique=True isn't what I want,
> because the second user without it throws the above duplicate entry
> error, so how do I handle that?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Unique=true

2007-07-16 Thread [EMAIL PROTECTED]

OK, fixed the above problem -- figured out that it was related to my
setting unique=True on a field. But that raises the larger question...

I have a bit of data that may or may not exist... a identifier on the
user that not all users will have, but if they DO have it, it needs to
be unique to that user. Apparently, unique=True isn't what I want,
because the second user without it throws the above duplicate entry
error, so how do I handle that?


--~--~-~--~~~---~--~~
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_for_model, unique=True

2007-04-23 Thread Dmitry Mukhin

Hi,

Should form_for_model respect model's field 'unique=True' constraint?
It doesn't now (5061).

Or I should attach clean_xxx methods to the form myself?

Thank you.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



unique=True, one to one relationship

2006-06-30 Thread bernadet

1- if I combine related objects in the same page (by using the
edit_inline attribute), and add to one of the fields the unique
atrribute (unique=True), when trying to save the page, i got the
following exception:

Exception Type: TypeError
Exception Value: Cannot resolve keyword 'username' into field.

please note that the username is the name of the field that has the
unique attribute.

2- if I use the OneToOneField relationship between 2 classes and i
combined the 2 models in the same page i got an exception when doing
the following process:

Go to the page, fill the fields, save.
then return to the page in order to change some info fields, and try to
save, an exeption appears:

Exeption Type: Key Error
Exeption value:'person'

please note that am using person and user classes and user has the
field  OneToOneField.

3- if i separate user and person from the same page, but user always
has the OneToOneField. if i try to save a user without selecting a
person, an exeption appears:
OutOfRangevalue adjusted for column  person_id.
note that if i use ForeignKey relation, and i repeat the same process,
an error on the page appears not an exception.

hope that i was clear with my issues.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---