#11381: select_related over nullable ForeignKey using GeoQuerySet and GeoManager gives blank object rather than None -----------------------------------------------------+---------------------- Reporter: bretthoerner | Owner: nobody Status: new | Milestone: 1.1 Component: GIS | Version: 1.1-beta-1 Keywords: geodjango geo select_related geomanager | Stage: Unreviewed Has_patch: 0 | -----------------------------------------------------+---------------------- Sorry for the bad title... I can only explain this with an example,
{{{ from django.contrib.gis.db import models class Author(models.Model): name = models.CharField(max_length=100) class BookManager(models.GeoManager): def get_query_set(self): return super(BookManager, self).get_query_set().select_related('author') class Book(models.Model): name = models.CharField(max_length=100) author = models.ForeignKey(Author, related_name="books", null=True, blank=True) objects = BookManager() }}} {{{ >>> Book.objects.create(name='Without Author') <Book: Book object> >>> b = Book.objects.get(name='Without Author') >>> b.author <Author: Author object> >>> b.author.name }}} As you can see, rather than b.author being None, is it an "empty" Author object. This isn't the case when using non-GeoDjango. What's even weirder is that this only happens when using the GeoManager. If you remove the manager and run the select_related yourself, the following happens, {{{ >>> Book.objects.select_related('author').get(name='Without Author').author }}} It's None, rather than the "empty" Author from above. -- Ticket URL: <http://code.djangoproject.com/ticket/11381> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---