Categories: , ,
Posted by: bjb

Not surprisingly, the blog spam commenters found my blog. Now I am investigating ways to ensure that only people comment on my blog.

With a little searching, I found that recaptcha is the recommended method these days. However, since Google has bought the recaptcha organization, you have to agree to a large legal agreement between yourself and Google to use it.

I’m not really up for that. It’s too bad as I might have liked to contribute to the “digitize old books” effort. So now I’m looking into regular captchas.

Categories: ,
Posted by: bjb

Another error made at the same time as the previous one was to call the model constructors with positional args:

mm = MyModel ('name', 'description')

This resulted in creating a MyModel instance like this: = 'name' = 'description'
mm.description = None

I should have called them with keyword args so the passed values would be assigned to the right attributes:

mm = MyModel (name = 'name', description = 'description')
Categories: , ,
Posted by: bjb

I made a new django app. First I made a few models, then some unit tests for the models. I could not save newly created model instances in the database, the error was something about there not being an attribute id.

It turned out that although I inherited the models.Model class into each of my models, I was overriding the __init__ function. I should have called super from the derived class’s __init__ method … This is what the model class should have looked like:

from django.db import models

class MyModel (models.Model):

    name = CharField (max_length = 64)
    description = CharField (max_length = 512)

    def __unicode__ (self):

and if i was going to declare an __init__ method, it should have looked like this:

    def __init__(self, *args, **kwargs):
        super(MyClass, self).__init__(self, *args, **kwargs)
        # my own customization code goes here