[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

would like an example of Django ForeignKey.limit_choices_to with query

Asked by goknows in Web Frameworks, Python Scripting Language

Tags: django python, web frameworks

Hi -

a question from a django newbee ...

models.py looks something like this:

class Code_Type(models.Model):
    name= models.CharField(maxlength=20)
    description= models.CharField(maxlength=200)
    active_flag= models.BooleanField(default=True)

class Code_Value(models.Model):
    code_type = models.ForeignKey(Code_Type)
    name= models.CharField(maxlength=20)
    description= models.CharField(maxlength=200)
    active_flag= models.BooleanField(default=True)

When adding a Code_Value in the admin interface, I'd like the available choices for code_type be limited to those where active_flag = True ... this seems simple and straightforward, but I'm banging my head on the desk trying to get it to work.

An example would be a huge help - thanks!
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625