class QuestionSet(models.Model):
     title = models.CharField(max_length=100)
     description = models.TextField()
     order = models.IntegerField()

     def __init__(self, *args, **kwargs):
         self.title = kwargs.get('title','Default Title')
         self.description = kwargs.get('description', 'DefDescription')
         self.order = kwargs.get('order', 0)

One thing that looks suspect to me here is that you're not calling __init__ on models.Model.

def __init__(self, *args, **kwargs):
    models.Model.__init__(self, ...)

Which will prevent the base class from initializing.

For example:

>>> class A(object):
...     def __init__(self):
...             print 'A init'
...
>>> class B(A):
...     def __init__(self):
...             A.__init__(self)
...             print 'B init'
...
>>> class C(A):
...     def __init__(self):
...             print 'C init'
...
>>> C()
C init
<__main__.C object at 0x7fd811c23bd0>
>>> B()
A init
B init
<__main__.B object at 0x7fd811c23c50>

Constructor calls don't bubble up on their own, you have to explicitly call them.

I would assume that something in the model's base class is what adds the _state attribute. By short circuiting the constructor, you're preventing this from ever happening.

--
Demian Brecht
@demianbrecht
http://demianbrecht.github.com

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to