On Wednesday, November 2, 2011 6:55:41 AM UTC-4, glimmung wrote:
>
> Hi,
>
> I've a seemingly workable solution for this, but it's hardly elegant.
>
> In my model, for the property_id field I have: -
>
> ,default=session.last_parent_id
>          ,writable=False
>          ,readable=True
>
> ...and in my controller: -
>
> @auth.requires_login()
> def property_detail_insert():
> form=crud.create(db.property_detail)
> session.last_parent_id=request.args(1)
> return dict(form=form)
>
> ...which works, but displays the parent ID in the form.
>
> Is there a more elegant solution using CRUD?
>
Does the parent_id have to persist across multiple requests? If so, then 
storing in session is probably the way to go. If you don't want to have the 
value appear in the form, you could either use an onvalidation function to 
populate the value after the form is validated, or you could make it a 
computed field if you know it will always be populated via a session and/or 
request variable.

Anthony

Reply via email to