Example #1
0
def show_add_pet_form():
    """ render form to add pet """
    form = AddPetForm()
    if form.validate_on_submit():
        pet = Pet()
        pet.name = form.name.data
        pet.species = (form.species.data).lower()
        pet.photo_url = form.photo_url.data
        pet.age = form.age.data
        pet.notes = form.notes.data
        pet.available = form.available.data
        flash(f"Added {pet.name} to adoptable pets!")
        db.session.add(pet)
        db.session.commit()
        return redirect("/")
    else:
        return render_template('add_pet_form.html', form=form)
Example #2
0
def add_pet():

    form = AddPetForm()

    if form.validate_on_submit():
        pet = Pet()
        pet.name = form.name.data
        pet.species = form.species.data
        pet.photo_url = form.photo_url.data
        pet.age = form.age.data
        pet.notes = form.notes.data
        db.session.add(pet)
        db.session.commit()
        flash(f'Added {pet.name}!')
        return redirect('/')
    else:
        return render_template('add_pet.html', form=form)
Example #3
0
def add_pet():
    """ Add a pet for adoption """
    form = AddPetForm()

    if form.validate_on_submit():
        pet = Pet()
        pet.name = form.name.data
        pet.species = form.species.data
        pet.photo_url = form.photo_url.data
        pet.age = form.age.data
        pet.notes = form.notes.data

        db.session.add(pet)
        db.session.commit()

        return redirect("/")

    else:
        return render_template("add_new_pet.html", form=form)