Created
November 30, 2012 22:16
-
-
Save mki/4179098 to your computer and use it in GitHub Desktop.
Gists for article
This file contains hidden or 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.contrib.auth.models import User | |
user = User.objects.get(pk=5) | |
user.set_password('super-sekrit') | |
user.save() |
This file contains hidden or 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.contrib.auth.hashers import make_password | |
class User(models.Model): | |
# fields go here.. | |
def set_password(self, raw_password): | |
self.password = make_password(raw_password) |
This file contains hidden or 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.db import models | |
PRIORITY_CHOICES = [(1, 'High'), (2, 'Low')] | |
class Todo(models.Model): | |
content = models.CharField(max_length=100) | |
is_done = models.BooleanField(default=False) | |
owner = models.ForeignKey('auth.User') | |
priority = models.IntegerField(choices=PRIORITY_CHOICES, | |
default=1) |
This file contains hidden or 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
def dashboard(request): | |
todos = Todo.objects.filter( | |
owner=request.user | |
).filter( | |
is_done=False | |
).filter( | |
priority=1 | |
) | |
return render(request, 'todos/list.html', { | |
'todos': todos, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment