Re: How do I output a variable from Models.py to Detail.html?
On Monday, 9 September 2013 10:24:54 UTC+1, Pepsodent Cola wrote:
-- This is my Models code and I want to output the contents of variable blackbox to my screen.1.) Do I need to write some code in Views.py to transfer my variable "blackbox" from Models to Views to Detail.html?2.) Or can I access my variable "blackbox" directly from Detail.html?#___________________________________________________________ ____________________ class AltwordManager(models.Manager): def dictfetchall2(self, p):"Returns all rows from a cursor as a dict."desc = p.descriptionself.dark = descreturn [dict(zip([col[0] for col in desc], row))for row in p.fetchall()]def vote_order(self):"Returns a 1:M list ordered by votes."cursor = connection.cursor()cursor.execute("""SELECT navi_polls_word.rosword, navi_polls_altword.alt_ros_word, navi_polls_altword.votes FROM navi_polls_altword INNER JOIN navi_polls_wordON (navi_polls_altword.rosword_id=navi_polls_word.id) ORDER BY votes DESC""")#row = cursor.fetchall()#row = dictfetchall(cursor)row = AltwordManager.dictfetchall2(self, cursor) blackbox = self.darkreturn blackbox#___________________________________________________________ ____________________
This, like most of your questions, is *really basic stuff* that is well covered by the tutorial.
You should stop trying to write this complex manager (which BTW does not do what a manager is supposed to do) and go back and do the tutorial, which introduces the concepts simply. Then, read the documentation on managers and understand what they are actually for - and stop writing SQL unless you really need it.
--
DR.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home