django-1.7

How to combine select_related() and value()? (2016)

百般思念 提交于 2019-12-01 02:44:43
I am asking this question again ( it was asked back in 2009 ), We know there is a values() method of QuerySet, when there is a foreignkey (author, for example), it result like: [{ 'author_id':3, ... }, ...] I want a result like: [{ 'author':{'name':'dave',...}, ... }, ...] Has something changed in the newer versions of Django? I want to convert the query set into a combination of lists and dictionnaries, is it possible? I will then take this object and place it into a bigger object to serialize it. It is the reason why I don't want to serialize it right away. You can access related fields via

Django-registration compatibility issue with django 1.7

半世苍凉 提交于 2019-11-30 13:22:52
问题 I've been using [django-registration] (https://bitbucket.org/ubernostrum/django-registration) and now I have started using django 1.7b1 and here is the error I am getting the error copied below. It is being raised from django-registration in models.py : try: from django.contrib.auth import get_user_model User = get_user_model() except ImportError: from django.contrib.auth.models import User and it seems it is being raised because get_user_model() is being called before the app registry is

How to JSON serialize __dict__ of a Django model?

…衆ロ難τιáo~ 提交于 2019-11-30 13:01:46
I want to serialize the values of a single model in Django. Because I want to use get() , values() is not available. However, I read on Google Groups that you can access the values with __dict__ . from django.http import HttpResponse, Http404 import json from customer.models import Customer def single(request, id): try: model = Customer.objects.get(id=id, user=1) except Customer.DoesNotExist: raise Http404 values = model.__dict__ print(values) string = json.dumps(values) return HttpResponse(string, content_type='application/json') The print statement outputs this. {'_state': <django.db.models

Django: passing JSON from view to template

空扰寡人 提交于 2019-11-30 09:22:23
In views.py , I have time series data stored in a dictionary as follows: time_series = {"timestamp1": occurrences, "timestamp2": occurrences} where each timestamp is in unix time and occurrences is an integer. Is there a way to pass the time series data as a json object in the context of the render function? Why do this: I am using Cal-heatmap on the front end which requires the data to be in json format. Ajax requests work just fine for now but I ideally would like to use the render approach if possible. If a frontend library needs a to parse JSON, you can use the json library to convert a

django 1.7 and connection pooling to PostgreSQL?

爷,独闯天下 提交于 2019-11-30 08:37:29
What are the differences between the django apps (Django-PostgresPool, djorm-ext-pool, django-db-pool) and PG Bouncer or PG Pool? Do the apps use one of the last two packages? In this article , the author says that there is a patch starting with django 1.6. Does that mean we do not have to use any of these solutions anymore, neither the apps, nor the PG Bouncer or PG Pool package? Postgres database connections are expensive (resources) compared to MySQL connections. Django pooling apps will open many connections and keep the open. PG Bouncer and PG Pool will open fewer connections to Postgres,

Runtime error:App registry isn't ready yet

会有一股神秘感。 提交于 2019-11-30 03:54:37
I am trying to create a script that populates a database with test users. I am new to Django and Python. I keep on getting: Runtime error: App registry isn't ready yet. Here is the output and error: starting population script Traceback (most recent call last): File "populate.py", line 32, in <module> populate() File "populate.py", line 22, in populate i.save() File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django\db\models\base.py", line 603, in save force_update=force_update, update_fields=update_fields) ... ... ... File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django

django.db.utils.IntegrityError: (1062, “Duplicate entry '' for key 'slug'”)

守給你的承諾、 提交于 2019-11-29 16:16:31
I'm trying to follow the tangowithdjango book and must add a slug to update the category table. However I'm getting an error after trying to migrate the databases. http://www.tangowithdjango.com/book17/chapters/models_templates.html#creating-a-details-page I didn't provide a default value for the slug, so Django asked me to provide one and as the book instructed I type in ''. It's worth noticing that instead of using sqlite as in the original book I'm using mysql. models.py from django.db import models from django.template.defaultfilters import slugify # Create your models here. class Category

django 1.7 and connection pooling to PostgreSQL?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 12:16:59
问题 What are the differences between the django apps (Django-PostgresPool, djorm-ext-pool, django-db-pool) and PG Bouncer or PG Pool? Do the apps use one of the last two packages? In this article, the author says that there is a patch starting with django 1.6. Does that mean we do not have to use any of these solutions anymore, neither the apps, nor the PG Bouncer or PG Pool package? 回答1: Postgres database connections are expensive (resources) compared to MySQL connections. Django pooling apps

Django Heroku Error “Your models have changes that are not yet reflected in a migration”

旧城冷巷雨未停 提交于 2019-11-29 12:06:21
问题 I recently added a model to my app (UserProfile) and when I pushed the changes to Heroku, I think I accidentally ran heroku run python manage.py makemigrations . Now when I try to run heroku run python manage.py migrate I get the error below (leaguemaster) benjamins-mbp-2:leaguemaster Ben$ heroku run python manage.py migrate Running `python manage.py migrate` attached to terminal... up, run.1357 Operations to perform: Synchronize unmigrated apps: allauth Apply all migrations: auth, admin,

Why does Django make migrations for help_text and verbose_name changes?

戏子无情 提交于 2019-11-29 02:49:27
When I change help_text or verbose_name for any of my model fields and run python manage.py makemigrations , it detects these changes and creates a new migration, say, 0002_xxxx.py . I am using PostgreSQL and I think these changes are irrelevant to my database (I wonder if a DBMS for which these changes are relevant exists at all). Why does Django generate migrations for such changes? Is there an option to ignore them? Can I apply the changes from 0002_xxxx.py to the previous migration ( 0001_initial.py ) manually and safely delete 0002_xxxx.py ? Is there a way to update previous migration