I am using django and a model definition such as
class Question(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)
Attempting to call save() on an object of the question class, causes the shell to respond with
/django/db/utils.py", line 133, in _route_db
return hints['instance']._state.db or DEFAULT_DB_ALIAS
AttributeError: 'Question' object has no attribute '_state'
However, removing the _____init_____ function, makes everything ok again. Any idea on what causes this and how to resolve it?
many thanks
You need to call the superclass' __init__
method at some point in your subclass' __init__
method:
def __init__(self, *args, **kwargs):
super(Question, self).__init__(*args, **kwargs)
# your code here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With