Skip to content
Advertisement

Tag: django

‘unicode’ object has no attribute ‘utcoffset’

In my admin, I am getting errors for only one class, ‘unicode’ object has no attribute ‘utcoffset’. I have looked at a few other similar questions and have been unable to solve it. Any ideas on how to fix it? The traceback is below the class. Traceback: Answer The default value for your pub_date field is a string. It should

A query with 3 tables in django

I have 3 classes like this: My question is: How can I make a query to get the devices used by the person “name”? Which needs to pass through the uses class. Answer Life will be easier if you use ManyToManyField, i.e. add this field to the Person model: Then, to get the list, you just need to get the

Django: Adding “NULLS LAST” to query

I would like to sort a model by using Postgresql’s “NULLS LAST” option. How could it be done? I tried something like MyModel.objects.all().extra(order_by=(‘-price’, ‘NULLS LAST’)) But I get “Cannot resolve keyword ‘NULLS LAST’ into field” Answer This functionality has been added to Django 1.11. https://docs.djangoproject.com/en/dev/releases/1.11/ Added the nulls_first and nulls_last parameters to Expression.asc() and desc() to control the ordering of

django: datediff sql queries?

I’m trying to do the equivalent of the following SQL in Django: SELECT * FROM applicant WHERE date_out – date_in >= 1 AND date_out – date_in <= 6 I can do this as a RAW sql query, but this is ...

Aggregating save()s in Django?

I’m using Django with an sqlite backend, and write performance is a problem. I may graduate to a “proper” db at some stage, but for the moment I’m stuck with sqlite. I think that my write performance problems are probably related to the fact that I’m creating a large number of rows, and presumably each time I save() one it’s

Advertisement