<div dir="ltr">Thanks for help but all I am trying to do here is create a udemy clone with some changes I would like my solution to have. Its not a job I am doing it for myself. I like python and that's why I chose Flask.<div><br></div><div>For your comment above, official documentation sucks that's why I have no other option as this is my very first project.</div><div>Thanks for help though, I will try it.</div><div><br></div><div>Cheers.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 7, 2017 at 4:21 PM, Ziirish <span dir="ltr"><<a href="mailto:ziirish@ziirish.info" target="_blank">ziirish@ziirish.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It would be better if you showed us some of your tries and/or error messages.<br>
Regarding the latest emails you sent it looks like you want us to do your job...<br>
<br>
Anyway, the "if" you are looking for is probably something like:<br>
<br>
<br>
    package = Package.query.filter_by(<br>
<span class="">        student_id=student_id, stripe_id = <a href="http://customer.id" rel="noreferrer" target="_blank">customer.id</a>,<br>
        student_email=request.form['<wbr>stripeEmail'], is_active=True,<br>
        package_type='yearlyrec', subscription_id=<a href="http://subscription.id" rel="noreferrer" target="_blank">subscription.<wbr>id</a><br>
</span>    ).first()<br>
<br>
    if not package:<br>
        package = Package(...)<br>
        dbase.session.add(package)<br>
        dbase.session.commit()<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
* On Tuesday, March 07, 2017 at 04:01 PM +0000, Anonymous Coder <<a href="mailto:anonymouscodar@gmail.com">anonymouscodar@gmail.com</a>> wrote:<br>
> I was trying to find a way to process/commit a model table for view only if<br>
> it doesn't exists already. But I couldn't find the way to do it. I tried<br>
> if/else but it doesn't create model at all if I try it that way. Following<br>
> is view and I need to create sqlalchymy table only if it doesn't exist<br>
> alrady.<br>
><br>
> @app.route('/yearlychargedrec'<wbr>, methods=['GET', 'POST'])<br>
> def yearly_charged_rec():<br>
>     if not user_authorized():<br>
>         return redirect('/')<br>
><br>
>     current_package = Package.query.all()<br>
><br>
>     if request.method == 'POST':<br>
>         data = get_profile_data(session['<wbr>auth_token'])<br>
>         profile_data = data['StudentProfile']<br>
>         student = get_profile_data(session['<wbr>auth_token'])['StudentProfile'<wbr>]<br>
><br>
>         stripe_token = request.form['stripeToken']<br>
>         email = request.form['stripeEmail']<br>
>         customer = stripe.Customer.create(<br>
>             email=email,<br>
>             source=request.form['<wbr>stripeToken']<br>
>         )<br>
>         try:<br>
>             subscription = stripe.Subscription.create(<br>
>                 customer=<a href="http://customer.id" rel="noreferrer" target="_blank">customer.id</a>,<br>
>                 plan="yearlyrec",<br>
>             )<br>
>             student_id = <a href="http://profile_data.id" rel="noreferrer" target="_blank">profile_data.id</a><br>
>             student.stripe_customer_id = <a href="http://customer.id" rel="noreferrer" target="_blank">customer.id</a><br>
>             student.stripe_subscription_id = <a href="http://subscription.id" rel="noreferrer" target="_blank">subscription.id</a><br>
><br>
>             package = Package(<br>
>                 student_id=student_id,<br>
>                 stripe_id = <a href="http://customer.id" rel="noreferrer" target="_blank">customer.id</a>,<br>
>                 student_email=request.form['<wbr>stripeEmail'],<br>
>                 is_active=True,<br>
>                 package_type='yearlyrec',<br>
>                 subscription_id=<a href="http://subscription.id" rel="noreferrer" target="_blank">subscription.<wbr>id</a><br>
>             )<br>
>             dbase.session.add(package)<br>
>             dbase.session.commit()<br>
><br>
>         except stripe.error.CardError as e:<br>
>             body = e.json_body<br>
>             err = body['error']<br>
><br>
>     return render_template('/profile/<wbr>charge/monthlycharge.html',<br>
> current_package=current_<wbr>package)<br>
><br>
> Please advise.<br>
</div></div></blockquote></div><br></div>