I am creating a powerlifting database, or trying too. I have a users Squat, deadlift and Bench Press amounts. Lets say i want to add just there deadlift and benchpress amounts, for example, but not store it, in mysql shell i do this:
mysql> SELECT sq, dl, bp, sq+dl AS sq_+_dlweight FROM mysite_weightsprofile
Ok, i get that.
In views i can do this as so:
conn = mdb.connect('localhost', 'bobby', '#########', 'website');
cursor = conn.cursor()
cursor.execute("SELECT sq, dl, bp, sq+dl AS sq_+_dlweight FROM mysite_weightsprofile")
rows = cursor.fetchall()
However, this method seems quite convaluted, difficult to appropriate into templates and not very adjustable. Is there a way i can do the above using the short code
query_results = UserProfile.objects.all("?")
without having to create a cursor object.
Just add a method to your model. For instance:
Then in your template: