Re: ForeignKey field with null = True and blank = True

2006-10-05 Thread Andy Dustman

On 10/4/06, Seemant Kulleen <[EMAIL PROTECTED]> wrote:
> 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.

I've got a similar model arrangement:

instructor = ForeignKey(
Person,
limit_choices_to = dict(user__groups__name__in=['Instructors']),
null = True,
blank = True,
)

and I can change instructor from chosen to unchosen and vice versa
without any problem. I'm using a recent SVN trunk version of Django
with a MySQL backend. Have you altered your model since creating the
table? You may want to compare the output of manage.py sqlall with our
actual table schema.  Maybe your table schema has that column set NOT
NULL or something, but I would expect an error in that case.

-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



ForeignKey field with null = True and blank = True

2006-10-04 Thread Seemant Kulleen
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 django-users@googlegroups.com
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':