0

Is there any pre-done widget to incorporate into my django code which create an very special widget?

Let's say that I have a database with

# this is simplified code to keep only problematic stuff
#model.py 

class Company(models.Model):
    name     = CharField( max_length = 50)

class Person(models.Model):
    name     = CharField( max_length = 26 , blank = True)
    company  = ForeignKey ( Company , related_name = 'Persons' )

class Meeting(models.Model):
    person   = ForeignKey ( Person , related_name = 'Meetings' )
    # So, there is a company in the meeting through myItem.person.company.name

So each Person have its own Company and requiring a Company in the Meeting class create a diamond of the death, since the met company is determined by the met Person. But, in real life, before meeting someone I have to go to his/her Company.

I would like to csreate a javascript widget for the 'person' field in the Meeting class that enable to select the contact in two waves.

<select Company>  <Select Person in the company in the "Select Company" field>
  • First, select the company. OnClick, the second Select fields is updated removing all the contact which are not related to the selected company.
  • Then the user can choose between the few remaining contacts in the selected company.

Well, after if the user click again on the first select to choose an other company, I am sure that complicated thinks should happen but let us make it simple at first approach...

I have looked several times on the Internet to find a snippet that can do, but I have to mention that I am experiencing some difficulties to grasp the exact way to find that kind code...

Do you know about such a project, widget? Is there any incorporated and easy way to do that?

jpic
  • 32,891
  • 5
  • 112
  • 113
MUY Belgium
  • 2,330
  • 4
  • 30
  • 46

1 Answers1

1

You could use django-selectable or django-autocomplete-light for this purpose.

jpic
  • 32,891
  • 5
  • 112
  • 113
  • I have a problem : since I am working on Ubuntu 10.04 LTS, version of django is 1.1.1. Required version are 1.2 and 1.4. – MUY Belgium Aug 27 '12 at 17:37
  • Easy: just use [virtualenv](http://virtualenv.org), here an [article that can help](http://blog.yourlabs.org/post/19725807220/django-pinax-virtualenv-setuptools-pip) too. Virtualenv will let you create a python environment that is isolated from the system and just for your project. Using this environment, and pip instead of apt-get, you will be able to use the latest versions of django and apps. Any Python user who tries virtualenv never looks back !! – jpic Aug 27 '12 at 17:43