Re: [web2py] Re: unique entry or null validation

2014-04-13 Thread Claudio Cocciarelli




 If you want the items in field1 to be uinique then you cannot allow update 
 to put a duplicate value in there.

 If you get that message, find the duplicate value in the database and do 
 something about that.

 Regards
 Johann

  
As I mentioned, it's difficult to explain :)

I don't want to create a duplicate using update(), what I meant is that 
message comes even though that field1 is still unique, I'm updating field2 
after all.
For now I managed to workaround the issue by a simple check in the 
controller:

if request.method ==update:
  field1.requires = None
else:
  field1.requires = IS_EMPTY_OR(IS_NOT_IN_DB(db, 'table.field1'))

I just hope it doesn't cause some nasty side effects.

Claudio

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: unique entry or null validation

2014-04-10 Thread Johann Spies
On 9 April 2014 17:45, Claudio Cocciarelli claudiococciare...@gmail.comwrote:


 So I have a db.table.field1.requires=IS_EMPTY_OR(IS_NOT_IN_DB(db,
 'table.field1')) but I have a problem with this:
 when inserting a new record it works flawlessly,
 instead when updating another record field2 in the same table, the
 validators are called again on field1 and I cannot update the record
 because I get the error Value already in database or empty
 of course it's already in the database, I'm updating the same table!!

 It's quite difficult to explain but I hope you got my point. Basically I
 don't want the validator to be called on update() but only on insert()

 Any advice on how to deal with this situation?


If you want the items in field1 to be uinique then you cannot allow update
to put a duplicate value in there.

If you get that message, find the duplicate value in the database and do
something about that.

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.