This is using Google App Engine. I am not sure if this is applicable to just normal Django development or if Google App Engine will play a part. If it does, would you let me know so I can update the description of this problem.
class MessageModel(db.Model): to_user_id = db.IntegerProperty() to_user = db.StringProperty(multiline=False) message = db.StringProperty(multiline=False) date_created = db.DateTimeProperty(auto_now_add=True)
Now when I do a query a get a list of ‘MessageModel’ and send it to the template.html to bind against, I would like to include a few more properties such as the ‘since_date_created’ to output how long ago since the last output, potentially play around with the message property and add other parameters that will help with the layout such as ‘highlight’ , ‘background-color’ etc…
The only way I thought of is to loop through the initial Query Object and create a new list where I would add the property values and then append it back to a list.
for msg in messagesSQL: msg.lalaland = 'test' msg.since_created_time = 321932 msglist.append(msg)
Then instead of passing the template.html messagesSQL, I will now pass it msglist.
You should still be able to send it messagesSQL to the template after you’ve added elements to it via the for loop. Python allows that sort of thing.
Something else that might make sense in some cases would be to give your MessageModel methods. For instance, if you have a
Then (assuming you have ‘messagesSQL’ in the template), you can use the function as
Basically, you can call any method in the model as long as you it needs no arguments passed to it.