[Flask] Deleting Flask tables conditionally

Anonymous Coder anonymouscodar at gmail.com
Tue Mar 7 05:28:02 EST 2017


Thank you Spencer I was able to make it work with your help.

On Mon, Mar 6, 2017 at 8:45 PM, Young,Spencer P <spenceryoung at ufl.edu>
wrote:

> Suppose you add a record to your `Package` table…
>
>
>
>
>
>     student_id = 12345
>
>     new_package = Package()
>
>     new_package.student_id = student_id
>
>     db.session.add(new_package)
>
>     db.session.commit()
>
>
>
>
>
> Now suppose you want to remove that record from your table… You must query
> and retrieve the record you want to delete, then delete it.
>
>
>
>     package_to_delete = Package.query.filter_by(student_id=12345).first()
>
>     db.session.delete(package_to_delete)
>
>     db.session.commit()
>
>
>
>
>
> Does that make any sense?
>
>
>
> -Spencer
>
>
>
> *From: *Flask <flask-bounces+spenceryoung=ufl.edu at python.org> on behalf
> of Anonymous Coder <anonymouscodar at gmail.com>
> *Date: *Monday, March 6, 2017 at 1:54 AM
> *To: *Corey Boyle <coreybrett at gmail.com>
> *Cc: *flask <Flask at python.org>
> *Subject: *Re: [Flask] Deleting Flask tables conditionally
>
>
>
> I your solution but this isn't working at all to my surprise. I can create
> rows in tables but I can't delete. I tried a dozen solutions from google.
> But mine don't work at all. Please advise.
>
>
>
> On Sun, Mar 5, 2017 at 11:18 PM, Corey Boyle <coreybrett at gmail.com> wrote:
>
> Please clarify... by "table", do you mean "row" or "record"?
>
> Regarding deleteing, I think this line
> package = Package()
> Needs to be replaced with a query that returns the single object that
> you want to delete.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170307/c7e02efa/attachment.html>


More information about the Flask mailing list