|
List Info
Thread: limiting foreign key choices in a selection field
|
|
| limiting foreign key choices in a
selection field |

|
2006-02-28 16:41:55 |
sam wrote:
> I have a model such as:
>
> class Part:
> maker = ForeignKey(Maker)
> ......
>
> When I make a form to enter the "part"
information, if I user standard
> AddManipulator, maker will become a selection list of
all possible
> makers. What if I only want to show a sub-list of
makers that belong to
> a specific "category". I suppose I should
use custom manipulators, but
> don't know exactly how to do. Pls help!
How about:
maker = meta.ForeignKey(Maker,
limit_choices_to={'category__exact': 'foo'})
--
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
a>
http://djnesh.blogspot.co
m/ | http://djnesh-djan
go.blogspot.com/ | http://djangou
tils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| limiting foreign key choices in a
selection field |

|
2006-02-28 17:47:16 |
My problem is the "category" is determined at
run-time, not at module
definition time. How to do that? Thanks.
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| limiting foreign key choices in a
selection field |

|
2006-02-28 19:26:49 |
sam wrote:
> My problem is the "category" is determined
at run-time, not at module
> definition time. How to do that? Thanks.
I'm missed 'When I make a form to enter the
"part" information' part
From: htt
p://www.djangoproject.com/documentation/forms/
something like this (untested):
class ContactManipulator(formfields.Manipulator):
def __init__(self, category):
<import model module>
maker_choices = []
for dct in makers.get_values(fields=['id', 'name'],
category__exact=category):
maker_choices.append((dct['id'], dct['name']))
self.fields = (
formfields.SelectField(field_name="maker",
choices=maker_choices),
....
)
So you can decide which category to show when creating a
form in your view function, and use this instead of
AddManipulator.
Hope that helps.
--
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
a>
http://djnesh.blogspot.co
m/ | http://djnesh-djan
go.blogspot.com/ | http://djangou
tils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| limiting foreign key choices in a
selection field |

|
2006-03-01 21:22:50 |
Nesh:
Your method works. Thanks very much!
Now a tougher situation:
I want to have the same form to enter "part"
information, except the
maker field I want to split into two fields:
"category" and "maker". I
want to show different selections in the "maker"
field based on what
was selected in the category. The objective is to reduce the
number of
options user has to deal with when making a selection. How
can this be
done? (Do I have to use javascripts?) Thanks.
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| limiting foreign key choices in a
selection field |

|
2006-03-02 09:59:23 |
sam wrote:
> Nesh:
>
> Your method works. Thanks very much!
>
> Now a tougher situation:
>
> I want to have the same form to enter
"part" information, except the
> maker field I want to split into two fields:
"category" and "maker". I
> want to show different selections in the
"maker" field based on what
> was selected in the category. The objective is to
reduce the number of
> options user has to deal with when making a selection.
How can this be
> done? (Do I have to use javascripts?) Thanks.
Well, if you don't want to use two stage form (select
category and reload), you definitely must use some JS to
generate
content of select box for maker (AJAX alike) but my
knowledge of JS is very limited to be of much help here.
Maybe
(IIRC) some of django-Dojo integration stuff discussed on
django-devel can be of some help for you. And if you find
solution please post here because I will soon need to use
something like this in my current project.
--
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
a>
http://djnesh.blogspot.co
m/ | http://djnesh-djan
go.blogspot.com/ | http://djangou
tils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
[1-5]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|