I have this table
db.define_table('materia',
Field('nome',
requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'materia.nome')]),
Field('docente','reference auth_user'),
auth.signature,singular="Materia",plural="Materie",migrate='materia.table',
format='%(nome)s')
db.materia.nome.requires=IS_NOT_IN_DB(db(db.materia.docente==request.vars.docente),db.materia.nome)
I have this function
def materie_docente():
# recupero l'id del docente
docente = request.args(0)
# query per recuperare il nome del docente
query_nome_docente = db.auth_user.id == docente
# recupero nome e cognome del docente
row =
db(query_nome_docente).select(db.auth_user.first_name,db.auth_user.last_name).first()
#materie del docente
query = (db.materia.docente == docente)
db.materia.docente.default = docente
db.materia.docente.readable = True
db.materia.docente.writable = False
# imposto la grid per far vedere le materie di quel docente
exportcls = dict(csv_with_hidden_cols=False, html=False, json=False,
tsv_with_hidden_cols=False, tsv=False)
form = SQLFORM.grid(query, args=[docente],
fields=[db.materia.nome],create=True, details=True, editable=True,
deletable=True, maxtextlength=60, exportclasses = exportcls)
return locals()
When I insert a new "materia" it can be inserted duplicated... it doesn't
control is the materia.nome is still in the database.
I know maybe the reason....because request.vars.docente is not managed in
the form. If I change db.materia.docente.writable from False to True is
working but I don't want that the user change the field "docente". How to
solve this problem?
Thank you
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.