Note that there are some explanatory texts on larger screens.

plurals
  1. POmodels.py with ManyToMany and progmatically adding data via a shell script
    text
    copied!<p>First post to stackoverflow 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.. </p> <pre><code>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() description = models.TextField() host = models.CharField(max_length=256) lineEnd = models.CharField(max_length=256) options = models.TextField() owner = models.CharField(max_length=100) root = models.CharField(max_length=256) 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) </code></pre> <p>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. </p> <p>--- massImport.py --- </p> <pre><code># 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() </code></pre> <p>Can anyone show me where the error of my ways is. I would really appreciate it. Thanks!! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload