What I'm doing is allowing the user to enter their exercise routine(s) for the day. I could just do a crud.create() if they were just going to enter once a day, but I am making it to where they can log in multiple times to add more exercise routines if they so choose. It is tied in the the calendar.js. I just do not want crud.create() producing an error if they decide to log on multiple times a day.
On Jan 21, 4:24 pm, Massimo Di Pierro <[email protected]> wrote: > Something like this? > > form=SQLFORM(db.schedule) > if form.accepts(request,dbio=False): > if db.schedule(todays_date==form.vars.todays_date): > form.errors['todays_date']="sorry busy that day" > else: db.schedule.insert(todays_date=form.vars.todays_date) > > It really depends on details. > > On Jan 21, 3:45 pm, dominatus <[email protected]> wrote: > > > > > > > > > If a db.schedule table exists with db.schedule.todays_date set to > > today's date. For example, if I, as a user, wake up today to enter my > > daily tasks for the current day, it gives a crud.create() form to > > insert a new db.schedule record. If I log in at lunch to add/modify > > activities further, it gives a crud.update() form to the same > > db.schedule record for today's date. > > > On Jan 20, 9:37 pm, Massimo Di Pierro <[email protected]> > > wrote: > > > > what is the condition to decide whether is exists or not? > > > > On Jan 20, 7:24 pm, dominatus <[email protected]> wrote: > > > > > I have a table in one of my models that I am trying to either create > > > > or update based on the current date when the user logs in. I noticed > > > > there is no explainable way to check if a current record exists in a > > > > model from within a controller function. Do we have to use: > > > > > crud.create(db.schedule) or crud.update(db.schedule, > > > > db.schedule((auth.user.id == db.schedule.user)) & > > > > (db.schedule.todays_date == datetime.date.time())).select(id) > > > > > In Django there is simply a get_or_create() function to perform this > > > > task. Just wondering if this is the right way of going about it. > > > > Thanks.

