Re: [Tutor] Error terminal

2019-08-07 Thread Mats Wichmann
On 8/7/19 5:27 PM, Richard Rizk wrote:
> Thank you Cameron for your message.
> 
> Please find below the error message i am receiving.
> 
> I think the command line i'm running is trying to connect with the
> python3.7 that i have on my computer which is a requirement for the command
> line to work but it keeps connecting to the default python2.7 that is on
> Macbook.
> 
> I'd love to jump on a 15min call if  it's possible for you.
> 
> Best regards,
> Richard
> 
> Error:
> -
> 
> DEPRECATION: Python 2.7 will reach the end of its life on January 1st,
> 2020. Please upgrade your Python as Python 2.7 won't be maintained after
> that date. A future version of pip will drop support for Python 2.7. More
> details about Python 2 support in pip, can be found at
> https://pip.pypa.io/en/latest/development/release-process/#python-2-support

Whichever way you get the Python you want to work for you, use the same
way to do installs.  Thus, if it works like this:

$ python3
Python 3.7.2 (default, Dec 27 2018, 07:35:45)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>


Then request your installations like this:

$ python3 -m pip install bunch-o-stuff


Your instructions probably said do "pip install bunch-o-stuff", don't do
it that way.


You can also check what you're getting this way (this is a snip from my
system, where the Python 3 came from homebrew, which is how I happen to
install it):

$ which python
/usr/bin/python# system version, you don't want this one
$ which python3
/usr/local/bin/python
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] flask_sqlalchemy query in relation to SQL relationships.

2019-08-07 Thread mhysnm1964
All,

 

Python 3.6 under windows 10 - I am using flask_sqlalchemy   and finding it
quite good with taking a lot of the heavy lifting of writing SQL statements.
I have a question in relation to SQL relationships and how would this be
done using SQL or flask_sqlalchemy or sqlalchemy.

 

I have three tables which are related to each other.

 

Table 1 has many records related to table 2.

Table 2 has many relationships to table 3.

 

Below is the model used by flask_sqlalchemy to make things clearer:

 

 

class Categories(db.Model):

# one to many relationships to SubCategories 

id = db.Column(db.Integer, primary_key=True)

category  = db.Column(db.String(64), index=True, unique=True)

subcategories  = db.relationship('SubCategories', backref='categories',
lazy='dynamic')



def __repr__(self):

return ''.format(self.category)

 

class SubCategories(db.Model):

# Many to one relationship to Categories.

# One to many relationship with Transactions.

id = db.Column(db.Integer, primary_key=True)

subcategory  = db.Column(db.String(80), index=True, unique=True)

category_id = db.Column(db.Integer, db.ForeignKey('categories.id'))

transactions   = db.relationship('Transactions',
backref='sub_categories', lazy='dynamic')

 

class Transactions (db.Model):

# Many to one relationship to Sub_categories 

# Many to one relationships with Accounts. 

id  = db.Column(db.Integer, primary_key=True)

transactiondate = db.Column(db.Date, index=True, nullable=False)

description  = db.Column(db.String(80), nullable=False)

amount = db.Column(db.Float, nullable=False) 

subcategory_id = db.Column(db.Integer,
db.ForeignKey('sub_categories.id'))

account_no  = db.Column(db.Integer,
db.ForeignKey('accounts.account_number'))

 

Thus, when I have a query from the view:

 

records = Transactions.query.order_by(Transactions.subcategory_id,
Transactions.transactiondate.desc())

 

page = request.args.get('page', 1, type=int)

records  = records.paginate(page, app.config['POSTS_PER_PAGE'], False)

next_url = url_for('index', page=records.next_num) if records.has_next
else None

prev_url = url_for('index', page=records.prev_num) if records.has_prev
else None

return render_template('index.html', title='Budget Program Main Page',
records = records.items, tables = tables, account  = 'all Transactions',
prev_url = prev_url, next_url = next_url, form = form, sort_form =
sort_form)

 

Template HTML code which displays the category and sub_category text values
based upon the above query. 

{% for row in records %}



{{row.accounts.account_name}}

{{row.account_no}}

{{row.transactiondate}}

{{row.description}}

{{row.amount}}

{{row.sub_categories.categories.category}}

{{row.sub_categories.subcategory }}



{% endfor %}

 

What I cannot do, is use sub_categories.categories.category or
sub_categories.subcategory in the query statements to sort the transaction
table by category or sub_category . For example the following does not work

 

sort_by = Transactions.sub_categories.categories.category

records = Transactions.query.order_by(sort_by.desc())

 

sqlalchemy  complains that it cannot find the object .categories. Thus I do
not know how to sort on the category table which is a child of
sub_categories which is a child of transactions. How would this be done in
SQL?

 

I hope this is the right place for this question.

 

Sean 

 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error terminal

2019-08-07 Thread Cameron Simpson

On 07Aug2019 13:08, Richard Rizk  wrote:
I wanted to send you this email to ask if you would have someone that 
can solve the problem I'm having with python.


I'm having issues with terminal on mac, is there someone that can help 
with this?


I probably can. Is this a Python problem, a Terminal problem, or some 
kind of mix?


Anyway, followup and describe your issue and we'll see.

Remember that this list drops attachments, so all your description 
should be text in the message, including and cut/paste of terminal 
output (which we usually want for context, and it is more precise than 
loose verbal descriptions alone).


Cheers,
Cameron Simpson 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Error terminal

2019-08-07 Thread Richard Rizk
Hello

I wanted to send you this email to ask if you would have someone that can solve 
the problem I'm having with python. 

I'm having issues with terminal on mac, is there someone that can help with 
this?

Best regards,
Richard
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor