This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.base import TemplateView | |
from django.contrib.auth.decorators import login_required | |
from django.utils.decorators import method_decorator | |
class AccountSettings(TemplateView): | |
template_name = 'accountsettings/details.html' | |
@method_decorator(login_required) | |
def dispatch(self, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./manage.py migrate allauth.socialaccount | |
Running migrations for socialaccount: | |
- Migrating forwards to 0011_auto__chg_field_socialtoken_token. | |
> socialaccount:0001_initial | |
> socialaccount:0002_genericmodels | |
> socialaccount:0003_auto__add_unique_socialaccount_uid_provider | |
> socialaccount:0004_add_sites | |
> socialaccount:0005_set_sites | |
- Migration 'socialaccount:0005_set_sites' is marked for no-dry-run. | |
> socialaccount:0006_auto__del_field_socialapp_site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree -d | |
. | |
├── apps | |
│ ├── leads | |
│ │ ├── migrations | |
│ │ │ └── __pycache__ | |
│ │ ├── __pycache__ | |
│ │ └── templates | |
│ │ └── leads | |
│ └── __pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myproject/static | |
myproject/my_app | |
myproject/myproject | |
# after running collectstatic with no definition in settings.py | |
myproject/css | |
myproject/admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# old way: | |
<a href="{% url 'leads:detail' lead.pk %}">{{ lead.pk }}</a> | |
# new way: | |
<a href="{{ lead.get_absolute_url }}">{{ lead.pk }}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from django.core.urlresolvers import reverse | |
>>> from apps.leads.urls import * | |
>>> reverse('detail', args=('a79b098c-8512-11e3-87ea-08002754d6c5',)) | |
Traceback (most recent call last): | |
File "/usr/lib/python3.3/code.py", line 90, in runcode | |
exec(code, self.locals) | |
File "<console>", line 1, in <module> | |
File "/home/nick/.virtualenvs/foo/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 509, in reverse | |
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) | |
File "/home/nick/.virtualenvs/foo/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 429, in _reverse_with_prefix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts = Post.includes(:users) | |
# SELECT `posts`.* FROM `posts` | |
# SELECT `users`.* FROM `users` WHERE `users`.`id` IN (1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article Load (2ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" IN (5, 15, 6, 31, 26, 3, 2, 32, 7, 16, 4, 24, 30, 23, 21, 22, 10, 28, 8, 12, 18, 17, 25, 9, 1) | |
Category Load (0.3ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (5, 2, 6, 4, 1, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
includes(*args) public | |
Specify relationships to be included in the result set. For example: | |
users = User.includes(:address) | |
users.each do |user| | |
user.address.city | |
end | |
allows you to access the address attribute of the User model without firing an additional query. This will often result in a performance improvement over a simple join. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install zlib1g-dev libbz2-dev | |
# If you plan to use sqlite you will also need: | |
sudo apt-get install libsqlite3-dev sqlite3 bzip2 | |
# If you plan to use postgres you will also need: | |
sudo apt-get install libpq-dev python3-dev python-dev | |
wget http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2 | |
tar xf Python-3.3.2.tar.bz2 |
NewerOlder