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 = models.ForeignKey(Country)
isin = models.CharField(max_length=12, blank=True)
indices = models.ManyToManyField(Index, blank=True)
def the_indices(self):
ind = []
for index in self.indices.all():
ind.append(index.name)
return ', '.join(ind)
the_indices.short_description = u'Indices'
def __unicode__(self):
return self.name
This will work:
n = Company(name=my_name, country=my_country, isin=my_isin)
n.save()
This will not work:
n = Company(name=my_name, country=my_country, isin=my_isin,
indices=my_indices)
n.save()
Although I make sure that my_indices is a list of existing index
objects.
What do I have to do?
Jaroslav
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.