Re: create object instance with ManyToManyField

2011-10-28 Thread Leonardo Giordani
The add() method of a ManyToMany field adds the indexes of the given objects to the field. If you add a list, each index in the list is added to the field. In the admin interface, when you edit a Company object, you see a convenient automagically-created menu which lists all Index object in your

Re: create object instance with ManyToManyField

2011-10-28 Thread Jaroslav Dobrek
Hello Leonardo, thanks your your answer. > n = Company(name=my_name, country=my_country, isin=my_isin) > n.save() > n.indices.add(my_indices) This causes that the company object has all indices in my_indices (such as Dow Jones S 100, Dax, ...) as *choices*. I.e. someone who manipulates these

Re: create object instance with ManyToManyField

2011-10-27 Thread Leonardo Giordani
Hi Jaroslav, you have to do the following n = Company(name=my_name, country=my_country, isin=my_isin) n.save() n.indices.add(my_indices) See here https://docs.djangoproject.com/en/dev/topics/db/queries/#saving-foreignkey-and-manytomanyfield-fields Bye 2011/10/27 Jaroslav Dobrek

create object instance with ManyToManyField

2011-10-27 Thread Jaroslav Dobrek
Hello, how can I create an object instance with a ManyToManyField. Everything works fine via the admin interface. But I don't understand how to do it in Python. Example: I have this model: class Company(models.Model): name = models.CharField(max_length=200, unique=True) country =