Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #models.py
- class Post(db.Model):
- __searchable__ = ['artist', 'title']
- id = db.Column(db.Integer, primary_key = True)
- artist = db.Column(db.String(40))
- title = db.Column(db.String(40))
- link = db.Column(db.String(140))
- timestamp = db.Column(db.DateTime)
- user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
- previous_nick = db.Column(db.String)
- def __repr__(self):
- return '<Post %r>' % (self.body)
- #views.py
- @app.route('/delete/<id>')
- @login_required
- def delete(id):
- post = Post.query.filter_by(id = id).first()
- if post == None:
- flash('Post ' + id + ' not found.')
- return redirect(url_for('index'))
- if g.user.id != post.user_id:
- flash('You cannot delete others\' posts!')
- return redirect(url_for('index'))
- db.session.delete(u)
- db.session.commit()
- flash('Post ' + id + ' has been deleted.')
- return redirect(url_for('user', nickname = g.user.nickname))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement