On Thursday 23 February 2006 13:53, [EMAIL PROTECTED] wrote:

> I would like to display a list of "statements" for a particular
> "account". The "account_id" is a foreign key on "statements" table.
> Is it possible, using generic views, to specify in the urlpatterns
> the <object_id> that will generate SQL query that will query on
> foreign key ("account_id") rather then primary key ("id")?
>
> In SQL terms I wish to achieve the following if possible while still
> using the generic view module:
> SELECT * FROM statements WHERE account_id=<account_fk_id-in-url>
> instead of using primary key as filter
> SELECT * FROM statements WHERE id=<statement_pk_id-in-url>
>
> If this is possible, what is the key requirement for getting this to
> work?

Think about it this way:  you want to get a specify account, and then 
view all the statements for that account, right?  So use an 
'object_detail' generic view to display a single 'account' object (the 
account_id being retrieved from the URL), and in the template do 
something like this:

{% for statement in object.get_statement_list %}
   whatever
{% endfor %}

The only down side is that you are getting the 'account' object perhaps 
unnecessarily.

Luke

-- 
OSBORN'S LAW
    Variables won't, constants aren't.

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to