On Sun, May 31, 2009 at 10:13 AM, Eric Abrahamsen <gir...@gmail.com> wrote:

>
> Hi,
>
> I've got two models, Author and Entry, with a foreignkey from Entry to
> Author. There are many Authors with no related entries, and until
> recently I've been able to put this manager on the Author model to
> only select Authors with Entries:
>
> def contributors():
>  return self.exclude(entry__isnull=True)
>
> Recently this started returning a FieldError, saying it could not
> resolve "entry" into a field.


What changed?  Did you update Django?  Change your code?  Something must
have changed, and if you could identify it, that would be a clue.


> I'm running the most recent version of
> django. Before I go tearing up my app trying to figure out what I
> changed, I'd like to make sure – is this the recommended way to check
> for Authors with no Entries? I just found a couple of hints online
> saying to expect errors from this kind of code, though it has worked
> to date (and appears to still be working on some production code).
> Should this work?


Where are these hints to expect errors from this sort of code?  In the
Django docs would be a reliable source (but I'd hope it would be a lot
clearer than a hint of possible errors), random blogs or old mailing list
threads not so much.

FWIW, I cannot recreate any problem like this using this manager & models:

class AManager(models.Manager):
    def contributors(self):
        return self.exclude(entry__isnull=True)

class Author(models.Model):
    name = models.CharField(max_length=44)
    def __unicode__(self):
        return self.name
    objects = AManager()

class Entry(models.Model):
    value = models.CharField(max_length=23)
    author = models.ForeignKey(Author)
    def __unicode__(self):
        return u'%s (author: %s)' % (self.value, unicode(self.author))

in a Python shell using Django SVN r10865:

Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from ttt.models import Author, Entry
>>> Author.objects.all()
[]
>>> Entry.objects.all()
[]
>>> Author.objects.contributors()
[]
>>> Author.objects.create(name="Jacinta")
<Author: Jacinta>
>>> Author.objects.create(name="Eamon")
<Author: Eamon>
>>> Author.objects.contributors()
[]
>>> Entry.objects.create(value="Icterus",author=Author.objects.all()[1])
<Entry: Icterus (author: Eamon)>
>>> Author.objects.contributors()
[<Author: Eamon>]
>>> quit()

I think the models/manager I created match what you describe, so how is you
setup different?

Karen

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to