From e266dce5db1c650e141c72d5b08a10d40756e805 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 16 May 2017 22:00:20 +0200 Subject: [PATCH] Fixbug HTML and Fixbug new contact --- app.py | 12 ++++++------ models.py | 6 ------ templates/layouts/master.html | 4 ++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 58901c6..e4f4a73 100644 --- a/app.py +++ b/app.py @@ -27,11 +27,11 @@ def new_contact(): Create new contact ''' form = ContactForm() - if form.validate_on_submit(): + if form.validate_on_submit(): + my_contact = Contact() + form.populate_obj(my_contact) + db.session.add(my_contact) try: - my_contact = Contact() - form.populate_obj(my_contact) - db.session.add(my_contact) db.session.commit() # User info flash('Contact created correctly', 'success') @@ -51,11 +51,11 @@ def edit_contact(id): :param id: Id from contact ''' my_contact = Contact.query.filter_by(id=id).first() - form = ContactForm(obj=my_contact) + form = ContactForm(obj=my_contact) if form.validate_on_submit(): try: # Update contact - form.populate_obj(my_contact) + form.populate_obj(my_contact) db.session.add(my_contact) db.session.commit() # User info diff --git a/models.py b/models.py index 0e98aa3..51d3b0a 100644 --- a/models.py +++ b/models.py @@ -18,11 +18,5 @@ class Contact(db.Model): email = db.Column(db.String(200), nullable=True, unique=True) phone = db.Column(db.String(20), nullable=True, unique=False) - def __init__(self, name, surname, email, phone): - self.name = name - self.surname = surname - self.email = email - self.phone = phone - def __repr__(self): return '' % self.name diff --git a/templates/layouts/master.html b/templates/layouts/master.html index dd97ee8..b5abfe3 100644 --- a/templates/layouts/master.html +++ b/templates/layouts/master.html @@ -1,5 +1,5 @@ - + @@ -18,7 +18,7 @@ - Contactos + Contact Manager