Hi Guys,

First post to the group I did do a search and came up dry.  I also own
the django book (Forcier,Bissex,Chun) and they don't explain how to do
this.  In short I can't figure out how to progmatically add a data via
a python shell script to the ManyToMay model..

--- models.py ---
from django.db import models
from django.contrib import admin

class Client(models.Model):
  client        = models.CharField(max_length=256, primary_key=True)
  access        = models.DateField()
  submitOptions = models.CharField(max_length=256)
  update        = models.DateField()
  def __unicode__(self):
    return str(self.client)
admin.site.register(Client)

class Change(models.Model):
  """This simply expands out 'p4 describe' """
  change        = models.IntegerField(primary_key=True)
  client        = models.ManyToManyField(Client)
  desc          = models.TextField()
  status        = models.CharField(max_length=128)
  def __unicode__(self):
    return str(self.change)
admin.site.register(Change)

Here is what I have which works but I don't know how to add the
ManyToMany.  I can't seem to figure out how to progmatically call it.
I know the row in SQL exists.

---  massImport.py ---

# Assume the client "clientspec" exists.  I know how to create that if
neeeded.

changes = [ { 'change': 123, 'desc': "foobar", status': "foobar",
client': "clientspec", }]

for item in changes:
  entry = Change(
            change    = item['change'],
            desc    = item['desc'],
            status    = item['status'],
            # client    = Client.objects.filter(client=item['client'])
            )
  entry.save()

---  massImport.py ---


Can anyone show me where the error of my ways is.  I would really
appreciate it.

Thanks!!


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to