simplified form syuff
This commit is contained in:
parent
7978bfcdb3
commit
4c186b690a
27
app.py
27
app.py
@ -28,14 +28,9 @@ def new_contact():
|
|||||||
'''
|
'''
|
||||||
form = ContactForm()
|
form = ContactForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
# Get form
|
|
||||||
name = form.name.data
|
|
||||||
surname = form.surname.data
|
|
||||||
email = form.email.data
|
|
||||||
phone = form.phone.data
|
|
||||||
# Save in database
|
|
||||||
try:
|
try:
|
||||||
my_contact = Contact(name, surname, email, phone)
|
my_contact = Contact()
|
||||||
|
form.populate_obj(my_contact)
|
||||||
db.session.add(my_contact)
|
db.session.add(my_contact)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# User info
|
# User info
|
||||||
@ -56,25 +51,11 @@ def edit_contact(id):
|
|||||||
:param id: Id from contact
|
:param id: Id from contact
|
||||||
'''
|
'''
|
||||||
my_contact = Contact.query.filter_by(id=id).first()
|
my_contact = Contact.query.filter_by(id=id).first()
|
||||||
form = ContactForm(
|
form = ContactForm(obj=my_contact)
|
||||||
name=my_contact.name,
|
|
||||||
surname=my_contact.surname,
|
|
||||||
email=my_contact.email,
|
|
||||||
phone=my_contact.phone
|
|
||||||
)
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
# Get form
|
|
||||||
name = form.name.data
|
|
||||||
surname = form.surname.data
|
|
||||||
email = form.email.data
|
|
||||||
phone = form.phone.data
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Update contact
|
# Update contact
|
||||||
my_contact.name = name
|
form.populate_obj(my_contact)
|
||||||
my_contact.surname = surname
|
|
||||||
my_contact.email = email
|
|
||||||
my_contact.phone = phone
|
|
||||||
db.session.add(my_contact)
|
db.session.add(my_contact)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# User info
|
# User info
|
||||||
|
Loading…
Reference in New Issue
Block a user