Guest User

Untitled

a guest
Feb 17th, 2013
152
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #models.py
  2. class Post(db.Model):
  3. __searchable__ = ['artist', 'title']
  4.  
  5. id = db.Column(db.Integer, primary_key = True)
  6. artist = db.Column(db.String(40))
  7. title = db.Column(db.String(40))
  8. link = db.Column(db.String(140))
  9. timestamp = db.Column(db.DateTime)
  10. user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
  11. previous_nick = db.Column(db.String)
  12.  
  13. def __repr__(self):
  14. return '<Post %r>' % (self.body)
  15.  
  16. #views.py
  17. @app.route('/delete/<id>')
  18. @login_required
  19. def delete(id):
  20. post = Post.query.filter_by(id = id).first()
  21. if post == None:
  22. flash('Post ' + id + ' not found.')
  23. return redirect(url_for('index'))
  24. if g.user.id != post.user_id:
  25. flash('You cannot delete others\' posts!')
  26. return redirect(url_for('index'))
  27. db.session.delete(u)
  28. db.session.commit()
  29. flash('Post ' + id + ' has been deleted.')
  30. return redirect(url_for('user', nickname = g.user.nickname))
RAW Paste Data