Hello guys, good afternoon! Maybe I'm missing something absurd, I'm not
seeing, but this is my first app to study web2py.
I have some tables with relationships, but I can not enter data in Table
Movies, which has fields related to other tables.
Under the codes and the results. Thanks a lot for the help!
db.py
# -------------------------------------------------------------------------
# Table Movie - *Category, *Actor, *Diretor
# -------------------------------------------------------------------------
Movie = db.define_table('movies',
Field('title','string', label = 'Title'),
Field('date_release','integer', label = 'Date Release'),
Field('duraction','integer', label = 'Duraction'),
Field('category','string','list:reference categories', label =
'Category'),
Field('actor','list:reference actors', label = 'Actor'),
Field('director','list:reference directors', label = 'Diretor'),
)
# -------------------------------------------------------------------------
# Table Category -
# -------------------------------------------------------------------------
Category = db.define_table('categories',
Field('title','string', label = 'Title'),
)
alidators.py
# -------------------------------------------------------------------------
# Validator of Movies
# -------------------------------------------------------------------------
Movie.title.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'movies.title')]
Movie.category.requires = IS_IN_DB(db, 'categories.title')
Movie.director.requires = IS_IN_DB(db, 'directors.name')
Movie.actor.requires = IS_IN_DB(db, 'actors.name') #Protagonist
Movie.duraction.requires = IS_INT_IN_RANGE(0, 1000)
# -------------------------------------------------------------------------
# Validator of Category
# -------------------------------------------------------------------------
Category.title.requires = IS_NOT_EMPTY()
controllers/movie.py
def add():
form = SQLFORM(Movie)
if form.process().accepted:
response.flash = "Successful! New movie added!"
redirect(URL('add'))
elif form.errors:
response.flash = 'Form Error'
else:
response.flash = 'Form, insert data'
return dict(form = form)
#view
{{extend 'layout.html'}}
{{for movie in movies:}}
<div style="background: #f0f0f0; margin-bottom: 5px; padding: 8px;">
<h3>{{=MARKMIN(movie.title)}}</h3>
<p>Category: {{=MARKMIN(movie.category)}}</p>
<p>Actor: {{=MARKMIN(movie.actor)}}</p>
<p>director: {{=MARKMIN(movie.director)}}</p>
<p>Duraction:{{=MARKMIN(movie.duraction)}}</p>
</div>
{{pass}}
The list is loaded, but it is not registered in Movies registration.
<https://lh3.googleusercontent.com/-7Nmj5dMyTgA/VyI50kQOX3I/AAAAAAAAd-k/QOHUzj0xIRolb2PTCKUrku15FLC4vYxtwCLcB/s1600/data.png>
<https://lh3.googleusercontent.com/-lMaIl6JR-dA/VyI54rx46vI/AAAAAAAAd-o/0y-504wftkkkoGLpMrb4T4kKd2aT01izgCLcB/s1600/List.png>
--
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.