forms.py: used get_user_model() inside __init__ instead of User, to facilitate late binding, models.py: used settings.AUTH_USER_MODEL instead of user
This commit is contained in:
parent
6a78c3f8b0
commit
9bbc09dba8
2 changed files with 8 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
from django import forms
|
||||
from django.forms import ModelForm
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.contrib.auth.models import Group
|
||||
from todo.models import Item, List
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ class AddItemForm(ModelForm):
|
|||
super(AddItemForm, self).__init__(*args, **kwargs)
|
||||
# print dir(self.fields['list'])
|
||||
# print self.fields['list'].initial
|
||||
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[task_list.group])
|
||||
self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[task_list.group])
|
||||
self.fields['assigned_to'].label_from_instance = \
|
||||
lambda obj: "%s (%s)" % (obj.get_full_name(), obj.username)
|
||||
|
||||
|
@ -49,7 +49,7 @@ class EditItemForm(ModelForm):
|
|||
# must find other members of the groups the current list belongs to.
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(EditItemForm, self).__init__(*args, **kwargs)
|
||||
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[self.instance.list.group])
|
||||
self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[self.instance.list.group])
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
|
|
|
@ -2,10 +2,11 @@ from __future__ import unicode_literals
|
|||
import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.contrib.auth.models import Group
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
|
@ -43,8 +44,8 @@ class Item(models.Model):
|
|||
due_date = models.DateField(blank=True, null=True, )
|
||||
completed = models.BooleanField(default=None)
|
||||
completed_date = models.DateField(blank=True, null=True)
|
||||
created_by = models.ForeignKey(User, related_name='todo_created_by')
|
||||
assigned_to = models.ForeignKey(User, blank=True, null=True, related_name='todo_assigned_to')
|
||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='todo_created_by')
|
||||
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='todo_assigned_to')
|
||||
note = models.TextField(blank=True, null=True)
|
||||
priority = models.PositiveIntegerField()
|
||||
|
||||
|
@ -77,7 +78,7 @@ class Comment(models.Model):
|
|||
Not using Django's built-in comments because we want to be able to save
|
||||
a comment and change task details at the same time. Rolling our own since it's easy.
|
||||
"""
|
||||
author = models.ForeignKey(User)
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
task = models.ForeignKey(Item)
|
||||
date = models.DateTimeField(default=datetime.datetime.now)
|
||||
body = models.TextField(blank=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue