Re: TypeError: unbound method save() must be called with NagiosLog instance as first argument (got nothing instead)

122 views
Skip to first unread message

Vijay Khemlani

unread,
Dec 6, 2014, 5:14:39 PM12/6/14
to django...@googlegroups.com
Call

k.save()

instad of 

NagiosLog.save()



On Sat, Dec 6, 2014 at 8:26 AM, Phil F <phil...@gmail.com> 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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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.
For more options, visit https://groups.google.com/d/optout.

monoBOT

unread,
Dec 6, 2014, 8:15:29 PM12/6/14
to django...@googlegroups.com
Short answer is Vijay's ... long answer is you have to save() the instanced object of the class not the class itself.


For more options, visit https://groups.google.com/d/optout.



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/
Reply all
Reply to author
Forward
0 new messages