Skip to content
Snippets Groups Projects
Commit 81320d71 authored by Arno Wunderlich's avatar Arno Wunderlich
Browse files

save image to db

parent f015cd55
No related branches found
No related tags found
1 merge request!21save image to db
Pipeline #14569 passed
......@@ -6,6 +6,7 @@ flask==2.2.2
python-dotenv
flask-mongoengine==1.0
Pillow
# Git hooks
pre-commit
......
......@@ -59,7 +59,7 @@ def create_app(config: Optional[Dict] = None) -> Flask:
init_db(flask_app)
# Register blueprints
from . import views # pylint: disable=import-outside-toplevel
from . import views
flask_app.register_blueprint(views.bp, url_prefix='')
# a simple page that says hello
......
......@@ -7,6 +7,7 @@ from mongoengine import (
ReferenceField,
DateTimeField,
EmailField,
FileField,
)
......@@ -38,3 +39,5 @@ class Item(db.Document):
created_at = DateTimeField(required=True, default=datetime.utcnow)
closes_at = DateTimeField()
image = FileField()
......@@ -10,7 +10,7 @@
</header>
<main>
<form class="container-fluid" action="{{ url_for('views.add_item') }}" method="POST">
<form class="container-fluid" action="{{ url_for('views.add_item') }}" method="POST" enctype="multipart/form-data">
<div class="container">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
......
......@@ -31,6 +31,7 @@
<div class="list-group container">
{%for item in items %}
<div class="d-flex w-100 justify-content-between mb-4">
<img class=" col-md-2 col-xs-2" src="Gaming_5000x3125.jpg"{{ item.image }} alt="Image" />
<a href="#" class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ item.title }}</h5>
......
......@@ -61,6 +61,7 @@ def add_item():
nItem = request.form.get('nItem')
description = request.form.get('description')
starting_price = int(request.form.get('sPrice'))
image = request.files['image']
error = None
if not nItem:
error = 'Item name is required.'
......@@ -81,12 +82,14 @@ def add_item():
description=description,
starting_bid=starting_price,
seller=user,
closes_at=datetime.utcnow() + timedelta(days=1)
closes_at=datetime.utcnow() + timedelta(days=1),
image=image
)
item.save()
except Exception as exc:
error = f"Error creating item: {exc!s}"
print('error')
else:
return redirect(url_for('views.adding_successful'))
......@@ -108,6 +111,8 @@ def list_bid():
"""
# for test reasons all items are shown and no selection on only on sale items
items = Item.objects.all()
for item in items:
print(type(item.image))
html = render_template("listBid.html", items=items)
return html
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment