I'm new to using Flask and Jinja for creating websites. I have these lines of code:
<h1 align="center">Feed</h1>
<ul class="list-group list-group-flush" id="feeds">
{% for my_feed in user.feeds %}
<li class="list-group-item">
<div>
<b class="pull-center">{{user.first_name}}</b>
<p class="pull-right">{{my_feed.date}}</p>
<p>{{user.email}}</p>
</div>
<br>
{{ my_feed.data }}
This though only displays me data pulled from currently logged-in users. What I'd like is to see on this page every post from every logged-in user.
I don't know how to do this. Do I need to change my Class (Feed) to make it MANY:MANY. relationships? Or does it suffice to change my little code above?
I want for everyone to be able to post but also read what everyone else posted. I have the code function like this:
@views.route('/tweets', methods = ['GET', 'POST'])
@login_required
def tweet():
if request.method == 'GET':
my_feed = MyFeed.query.all()
elif request.method == 'POST':
my_feed = request.form.get('my_feed')
if len(my_feed) < 1:
flash('Tweet is too short!', category='error')
else:
new_tweet = MyFeed(data=my_feed, user_id=current_user.id)
db.session.add(new_tweet)
db.session.commit()
flash('Tweet added!', category='success')
return render_template("tweets.html" ,user=current_user)
useris most probably referring to a single entity of allusers. If you want to put it this way, it is only one row in a list ofusers. At some point you have to gather the data, probably using an ORM likeSQL Alchemyto send all data to the frontend, not just a singleuser.