On 12/8/06, Rory Campbell-Lange <[EMAIL PROTECTED]> wrote: > > I'm not sure how to do a join against a related record:
What you are looking for is: g = SiteEnergy.objects.filter(siteyear=9, typer__isoffsite=False) To explain why, lets look at your errors: > g=SiteEnergy.objects.filter(siteyear=9, energy__isofsite=False) > raise TypeError, "Cannot resolve keyword '%s' into field" % name > TypeError: Cannot resolve keyword 'energy' into field Your SiteEnergy model doesn't have an 'energy' field. The relation with the Energy model is kept in a relation called "typer". Therefore, you need to use typer__isoffsite to reference the property on the related model. Related note: if you were to query the Energy object, you _would_ use the model name in your query: Energy.objects.filter(siteenergy__source='foo') In this case, Energy has an implied reverse relation on siteenergy, which assumes the name of the related model by default. You can override this default name using a 'related_name' kwarg. Check the model API docs for more details. > g=SiteEnergy.objects.filter(siteyear=9, typer.isoffsite=False) > SyntaxError: keyword can't be an expression Similarly - double underscore notation here, not dot notation. Keep in mind that Django has found a creative use for Python kwarg syntax - we haven't added any syntax to the Python interpreter. In this case, each query argument is a named argument to a function - and function arguments can't have dots in them (this would be an expression, not an argument - hence the error message). The 'double underscore' is the Django way of faking the '.' to provide relation traversal. Hope this helps, Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---