Re: custom queryset with calculated field

2011-10-23 Thread dr.phil
Somehow I have itworking without any custom managers or querysets. The last issue was fixed by importing simplejson instead of json. Thanks for all the help On Oct 23, 5:05 pm, "dr.phil" wrote: > I narrowed down the error. Strang thing is this works in a shell but > not in my app. > > import dat

Re: custom queryset with calculated field

2011-10-23 Thread dr.phil
I narrowed down the error. Strang thing is this works in a shell but not in my app. import datetime from django.utils import simplejson as json from django.core.serializers.json import DjangoJSONEncoder queryset = {"sColums" : "time", "aaDAta" : "[(datetime.datetime(2011, 10, 19, 17, 18, 2))]"} j

Re: custom queryset with calculated field

2011-10-23 Thread Casey Greene
What is the error that that function gives you? It may be possible to just fix that function. Casey On 10/23/2011 07:42 AM, dr.phil wrote: The reason for this exercise is to produce suitable output for the jquery plugin datatables. I am trying to use the following code http://rus.hk/django-d

Re: custom queryset with calculated field

2011-10-23 Thread dr.phil
The reason for this exercise is to produce suitable output for the jquery plugin datatables. I am trying to use the following code http://rus.hk/django-data-parser-for-jquery-datatable/ There are no problems until I include a datetime field. Then 'datatabilize' fails because it cannot jsonify a d

Re: custom queryset with calculated field

2011-10-22 Thread Pedro Vasconcelos
If you post the relevant part of your code in http://dpaste.com/ will be more easy to help you! On Saturday, October 22, 2011, dr.phil wrote: > Thank you for the response. I added a function to the model to convert > a datetime field into the needed format (def convert_time). Then I set > new_tim

Re: custom queryset with calculated field

2011-10-22 Thread Casey Greene
The database isn't going to know about your property because that's all on the python side (thus the error). Why do you need the formatted time when looking in the database? I think Pedro is right, if this is only for display, it'd be better to do it with a template tag/filter. Casey On 10/

Re: custom queryset with calculated field

2011-10-22 Thread dr.phil
Thank you for the response. I added a function to the model to convert a datetime field into the needed format (def convert_time). Then I set new_time = property(convert_time). If I iterate over the queryset I can access each.new_time BUT I need the value in the queryset (Model.objects.filter().val

Re: custom queryset with calculated field

2011-10-22 Thread Pedro Vasconcelos
Hello, A possible solution is create a specific method in your model class to do this calculation. Take a look at: https://docs.djangoproject.com/en/1.3/topics/db/models/#model-methods If you only want to do this calculations to show it in templates you may consider creating a specific template c

custom queryset with calculated field

2011-10-22 Thread dr.phil
Is this possible? I have a model that includes a datetime field. When creating a queryset of this model, I want to include a calculated field of the time difference (in hours:minutes compared to datetime.now). Currently, when creating a queryset the datetime is included. I can iterate through the