On Sat, 2008-08-30 at 06:56 -0700, eniac wrote: > Hello, > > I'm using django 0.96.1 on ubuntu. > I'm going to describe the steps I went through until I encountered > something odd. > > I create a model: > > class shoutbox(models.Model): > name = models.CharField(maxlength=15) > shout = models.CharField(maxlength=256) > pub_date = models.DateTimeField() > > Next I sync with my database which is mysql using manage.py syncdb. > > > Then I enter the manage.py shell to test it out > > In [1]: from thisSite.shoutbox.models import shoutbox > In [4]: s = shoutbox('jonas', 'bla enzo', datetime.now()) > > untill here everhting works fine > then I want to check on the id of s and here is what it returns > In [5]: s.id > Out[5]: 'jonas' > > so I add an other param, like 1 and it works fine, seems like none > doesn't get accepted. > What should I do ? Is this a bug ? Did I do something wrong ? I don't > want to hardcode every id when I enter some new data to my tables.
It's not a bug. You are assuming that you can pass position arguments to your model (which would be true if the only arguments taken by __init__ were the fields you declared). This isn't true, since are some implicit fields created by Django: for example, the automatic primary key field "id". That's why none of the examples in the documentation use positional arguments. So you should always use keyword arguments when initialising a model: shoutbox(name='jonas', shout='...', pub_date='...') or data = {'name': 'jonas', 'shout': '...', 'pub_date': '...'} s = shoutbox(**data) Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---