Thanks Alan, I will give that a try.

--
Regards,
Bruce

On Sat, Jan 7, 2012 at 2:32 AM, Alan Etkin <spame...@gmail.com> wrote:

> I think that requires=IS_EMPTY_OR(IS_IN_DB(...)) should give the user
> the options plus an empty option to leave the field blank, but i am
> not sure if the value stored is null if empty is selected.
>
> On Jan 7, 12:51 am, Bruce Wade <bruce.w...@gmail.com> wrote:
> > Ok thanks I was trying that except I couldn't figure out how to do the
> last
> > part 'ads.url' to point to that field, kept getting ads does not exist
> > error because I wasn't using the ' ' with ads.url.
> >
> > What about the second problem? Is it possible to allow null but also have
> > the IS_IN_DB to provide a select combo?
> >
> > In other words if some ones location does not exist currently in the
> > database I want to give them a checkbox that if checked
> > country, province and city can be NULL, behind the scene the checkbox
> will
> > email customer service to contact that member about the location to add
> > etc..
> >
> > Thanks,
> > Bruce
> >
> >
> >
> > On Fri, Jan 6, 2012 at 5:18 PM, Anthony <abasta...@gmail.com> wrote:
> > > unique=True is enforced at the level of the database, not the form. If
> you
> > > want to validate form input, you have to provide a validator in the
> field's
> > > "requires" attribute:
> >
> > > Field('url', unique=True, requires=[IS_NOT_IN_DB(db, 'ads.url'),
> IS_URL()])
> >
> > > Seehttp://
> web2py.com/books/default/chapter/29/6#Record-representationand
> > >http://web2py.com/books/default/chapter/29/7#Database-validators.
> >
> > > Anthony
> >
> > > On Friday, January 6, 2012 7:34:10 PM UTC-5, Detectedstealth wrote:
> >
> > >> When using unique=True on my database model the validation is
> allowing duplicates to pass through the form validation. Also notnull=False
> does NOT allow me to store Null entries for country, province, city.
> >
> > >> db.define_table('ads',
> > >>     Field('member_id', db. user_account,
> default=auth.user.account_id),
> > >>     Field('points', 'integer', default=0),
> > >>     Field('url', unique=True, requires=IS_URL()),
> > >>     Field('language', db.languages, requires=IS_IN_DB(db,
> db.languages.id, '%(language)s')),
> > >>     Field('country', db.countries, requires=IS_IN_DB(db,
> db.countries.id, '%(name)s'), notnull=False, default=None),
> > >>     Field('province', db.provinces, requires=IS_IN_DB(db,
> db.provinces.id, '%(name)s'), notnull=False, default=None),
> > >>     Field('city', db.cities, requires=IS_IN_DB(db, db.cities.id,
> '%(name)s'), notnull=False, default=None),
> > >>     Field('accepted', 'boolean', default=False),
> > >>     Field('viewable', 'boolean', default=True),
> > >>     Field('updated_at', 'datetime', default=request.now,
> writable=False),
> > >>     Field('added_at', 'datetime', default=request.now, writable=False)
> > >> )
> >
> > >> def createad():
> > >>     table = ads_api.getDatabaseTable()
> > >>     table.member_id.readable = table.member_id.writable = False
> > >>     table.accepted.readable = table.accepted.writable = False
> > >>     form = SQLFORM(table)
> > >>     if form.accepts(request,session, keepvalues=True):
> > >>         response.flash = 'form accepted'
> > >>     elif form.errors:
> > >>         response.flash = 'form has errors'
> > >>     else:
> > >>         response.flash = 'please fill the form'
> > >>     return dict(form=form)
> >
> > >> IntegrityError: duplicate key value violates unique constraint
> "ads_url_key"
> > >> DETAIL:  Key (url)=(http://wadecybertech.co**m) already exists.
> >
> > >> Am I doing something incorrect? I basically want a form that allows
> country, province, city to be NULL OR a valid item already in the database,
> finally I want the url column to be unique. However when a value already
> exists and I submit the form I get the IntegrityError.
> >
> > >> --
> > >> --
> > >> Regards,
> > >> Bruce Wade
> > >>http://ca.linkedin.com/in/**brucelwade<
> http://ca.linkedin.com/in/brucelwade>
> > >>http://www.wadecybertech.com
> > >>http://www.warplydesigned.com
> > >>http://www.**fitnessfriendsfinder.com<
> http://www.fitnessfriendsfinder.com>
> >
> > --
> > --
> > Regards,
> > Bruce Wadehttp://
> ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
>



-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com

Reply via email to