Hi All,
Now I'm at ForeignKey funkiness. So I have the Services model which
has a ForeignKey field to the Sermon model. The funny thing is that
if I choose a sermon object when I first create a new service object,
all is well. If, on the other hand, I don't choose one, then it turns
out that I can never choose one. That is to say, I can choose one,
and hit save and when I come back in it's unchosen. Happens every
single time. I've attached the services/models.py and
sermons/models.py if that helps.
Thanks!
Seemant
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
from django.db import models
from django.contrib.auth.models import User
from people.models import Person, Role
from sermons.models import Sermon
import constants
class Service( models.Model ):
day = models.CharField (maxlength = 200)
date = models.DateField ('date')
time = models.TimeField ('time')
slug = models.SlugField (prepopulate_from = ('time',), blank = True)
priest = models.ForeignKey (
Person,
related_name = 'priest',
limit_choices_to = { 'role__name': 'Priest' },
)
celebrant = models.ForeignKey (
Person,
related_name = 'celebrant',
limit_choices_to = { 'role__name': 'Priest' },
)
sermon = models.ForeignKey (
Sermon,
null = True,
blank = True,
)
crucifer = models.ManyToManyField (
Person,
related_name = 'crucifer',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Acolyte' },
)
left_torch = models.ManyToManyField (
Person,
related_name = 'left_torch',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Acolyte' },
)
right_torch = models.ManyToManyField (
Person,
related_name = 'right_torch',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Acolyte' },
)
banner_bearer = models.ManyToManyField (
Person,
related_name = 'banner_bearer',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Acolyte' },
)
LEM = models.ManyToManyField (
Person,
related_name = 'LEM',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'LEM' },
)
lector = models.ManyToManyField (
Person,
related_name = 'lector',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Lector' },
)
usher = models.ManyToManyField (
Person,
related_name = 'usher',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Usher' },
)
greeter = models.ManyToManyField (
Person,
related_name = 'greeter',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Greeter' },
)
childrens_chapel = models.ManyToManyField (
Person,
related_name = 'childrens_chapel',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Childrens Chapel' },
blank = True, null = True,
)
altar_flowers = models.ManyToManyField (
Person,
related_name = 'altar_flowers',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Flower Guild' },
)
flower_delivery = models.ManyToManyField (
Person,
related_name = 'flower_delivery',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Flower Deliverer' },
)
altar_guild = models.ManyToManyField (
Person,
related_name = 'altar_guild',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Altar Guild' },
)
food_delivery = models.ManyToManyField (
Person,
related_name = 'food_delivery',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Food Deliverer' },
blank = True, null = True,
)
summer_punch = models.ManyToManyField (
Person,
related_name = 'summer_punch',
filter_interface = models.HORIZONTAL,
limit_choices_to = { 'role__name': 'Punch Server' },
blank = True, null = True,
)
def __str__( self ):
return self.date.__str__() + self.time.__str__()
def save( self ):
if self.slug == '':
self.slug = '%s%s' % (self.time.hour, self.time.minute)
super(Service, self).save()
def get_absolute_url( self ):
return "/services/%s/%s/" % (self.date.strftime("%Y/%b/%d").lower(), self.slug)
class Meta:
get_latest_by = 'date'
ordering = ['-date']
class Admin:
list_display = ('date', 'time', 'priest',)
search_fields = ('priest', 'celebrant')
list_filter = ('date',)
fields = (
('Date Information', {'fields': ('day', 'date', 'time', 'slug')}),
('Officials', {'fields': ('priest', 'celebrant',)}),
('Sermon', {'fields': ('sermon',)}),
('Acolytes', {'fields': ('crucifer', 'left_torch', 'right_torch', 'banner_bearer',), 'classes': 'collapse'}),
('Required', {'fields': ('LEM', 'lector', 'usher', 'greeter'), 'classes': 'collapse'}),
('Altar Guild', {'fields': ('altar_guild',), 'classes': 'collapse'}),
('Childrens Chapel', {'fields': ('childrens_chapel',), 'classes': 'collapse'}),
('Flowers', {'fields': ('altar_flowers', 'flower_delivery',), 'classes': 'collapse'}),
('Refreshments', {'fields': ('food_delivery', 'summer_punch',), 'classes': 'collapse'}),
)
from django.db import models
from people.models import Person, Role
import constants
class Sermon( models.Model ):
title = models.CharField (maxlength = 200)
day = models.CharField (maxlength = 200)
date = models.DateField ()
slug = models.SlugField (prepopulate_from = ('title',), blank = True)
book = models.IntegerField (choices = constants.BIBLE_BOOKS)
chapter = models.IntegerField ()
from_verse = models.CharField (maxlength = 3)
to_verse = models.CharField (maxlength = 3, blank = True, null = True)
body = models.TextField ()
priest = models.ForeignKey (
Person,
limit_choices_to = { 'role__name': 'Priest' },
)
def __str__( self ):
return self.date.__str__()
def save( self ):
if self.slug == '':
self.slug = title
super (Sermon, self).save()
def get_absolute_url( self ):
return "/sermons/%s/%s/" % (self.date.strftime("%Y/%b/%d").lower(), self.slug)
class Meta:
get_latest_by = 'date'
ordering = ['-date']
class Admin:
list_display = ('title', 'day', 'date',)
search_fields = ('title', 'day', 'body', 'priest',)
list_filter = ('date', 'day',)
fields = (
('Title', {'fields': ('title', )}),
('Date Information', {'fields': ('date', 'day',)}),
('Priest', {'fields': ('priest',)}),
('Passage', {'fields': ('book', 'chapter', 'from_verse', 'to_verse',)}),
('Sermon', {'fields': ('body',)}),
)