On Sun, 2006-05-21 at 05:05 -0700, Robert wrote:
> Hello,
> 
> I'm writing a small app. for wifi network management.
> 
> In a "computer" model there is an "ext_ip" field which is a ForeignKey
> to "Ext_ip" model.
> 
> When adding/modifying a computer, I can use a select one from ext_ips
> list.
> 
> The problem is that I need to select only from ext_ips not used by
> another computer.
> 
> What is the best way to accomplish this ?
> Do I need to play with raw sql or I missed anything when played with an
> API ?

Is the limit_choices_to option on ForeignKey fields of use to you
(scroll down to the options in
http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships 
)?

If you can extract your choice list via simple filtering on a queryset,
then this should do what you want.

Regards,
Malcolm


X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.54.63.18 with SMTP id l18mr167539wra;
        Sun, 21 May 2006 05:32:33 -0700 (PDT)
Return-Path: <[EMAIL PROTECTED]>
Received: from tallyho.bytemark.co.uk (tallyho.bytemark.co.uk [80.68.81.166])
        by mx.googlegroups.com with ESMTP id v11si653160cwb.2006.05.21.05.32.32;
        Sun, 21 May 2006 05:32:33 -0700 (PDT)
Received-SPF: neutral (googlegroups.com: 80.68.81.166 is neither permitted nor 
denied by best guess record for domain of [EMAIL PROTECTED])
Received: from sharp.pointy-stick.com ([80.68.90.23])
        by tallyho.bytemark.co.uk with esmtp (Exim 4.52)
        id 1Fhn6l-0006qs-Pn
        for django-users@googlegroups.com; Sun, 21 May 2006 12:32:31 +0000
Received: from counterweight.tredinnick.org (cust7071.nsw01.dataco.com.au 
[203.171.88.159])
        by sharp.pointy-stick.com (Postfix) with ESMTP id 20E72C38C
        for <django-users@googlegroups.com>; Sun, 21 May 2006 22:32:25 +1000 
(EST)
Subject: Re: foreign_key limiting choices
From: Malcolm Tredinnick <[EMAIL PROTECTED]>
To: django-users@googlegroups.com
In-Reply-To: <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
Mime-Version: 1.0
Content-Type: text/plain
Date: Sun, 21 May 2006 22:32:19 +1000
Message-Id: <[EMAIL PROTECTED]>
X-Mailer: Evolution 2.6.1 (2.6.1-1.fc5.2) 

On Sun, 2006-05-21 at 05:05 -0700, Robert wrote:
> Hello,
> 
> I'm writing a small app. for wifi network management.
> 
> In a "computer" model there is an "ext_ip" field which is a ForeignKey
> to "Ext_ip" model.
> 
> When adding/modifying a computer, I can use a select one from ext_ips
> list.
> 
> The problem is that I need to select only from ext_ips not used by
> another computer.
> 
> What is the best way to accomplish this ?
> Do I need to play with raw sql or I missed anything when played with an
> API ?

Is the limit_choices_to option on ForeignKey fields of use to you
(scroll down to the options in
http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships 
)?

If you can extract your choice list via simple filtering on a queryset,
then this should do what you want.

Regards,
Malcolm



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