Call k.save()
instad of NagiosLog.save() On Sat, Dec 6, 2014 at 8:26 AM, Phil F <[email protected]> wrote: > Hi, > > I am attempting to write a python script that will populate the Django db > from data stored in a dictionary. > > I'm currently getting the error :"TypeError: unbound method save() must be > called with NagiosLog instance as first argument (got nothing instead)" > > from incidents.models import NagiosLog > import django > xcount = 0 > > for k,v in myDic.items(): > iincidentnumber = k > itime =v[0] > idevice =v[2] > iservice =v[3] > iseverity =v[4] > imessage =v[5] > print "%r %r %r %r %r" % (itime,idevice,iservice,iseverity,imessage,) > ## prints successfully, code working until here > xcount= xcount+1 > if xcount == 1: # count to run django setup a single time > django.setup() > k = NagiosLog( > incident = iincidentnumber, > time = itime, > device = idevice, > service = iservice, > severity = iseverity, > message = imessage,) > NagiosLog.save() > else: > k = NagiosLog( > incident = iincidentnumber, > time = itime, > device = idevice, > service = iservice, > severity = iseverity, > message = imessage,) > NagiosLog.save() > > This is my models file: > > from django.db import models > > from django.utils import timezone > import datetime > > class NagiosLog(models.Model): > incident = models.CharField(primary_key=True, max_length=80) > time = models.CharField(max_length=80, blank=True, > null=True) > device = models.CharField(max_length=80, blank=True, > null=True) > service = models.CharField(max_length=80, blank=True, > null=True) > severity = models.CharField(max_length=20, blank=True, > null=True) > message = models.CharField(max_length=250, blank=True, > null=True) > > Any help appreciated ! > > Thanks, Phil. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/1cc3eda3-d180-430e-8e41-866dceb0bca2%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/1cc3eda3-d180-430e-8e41-866dceb0bca2%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei1x51MjhDZCXJPT59kRJLpSGoq6B2Du5xxBggDq1uvRuA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

