Looks like ForeignKeys? respect model's custom default manager and OneToOneField? don't. Here's an example.
There are 3 models: Author, Article and Contact. Article refers to Author with ForeignKey? and Contact refers to Author with OneToOneField?. Author has a custom default manager that gives out only authors with their 'available' field set to True:
class AvailableAuthorManager(models.Manager):
def get_query_set(self):
return super(AvailableAuthorManager, self).get_query_set().filter(available__exact=True)
class Author(models.Model):
name = models.CharField(maxlength=50)
available = models.BooleanField(default=True)
objects = AvailableAuthorManager()
class Article(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(maxlength=50)
class Contact(models.Model):
author = models.OneToOneField(Author)
address = models.CharField(maxlength=50)
Then if you have an author with available=False and an article and a contact reefering to it you get:
- article.author -- raises an exception DoesNotExist?
- contact.author -- returns the author
Looks like this should behave the same way in both cases. However I'm not sure how exactly but I tend to think that it should raise an exception because managers are supposed to be the ultimate mechanism to access model objects.