Given the following block of code:
--- models.py ---
from django.db import models
from django.db.models.signals import post_save

class Animal(models.Model):
    category = models.CharField(max_length=20)

class Dog(Animal):
    color = models.CharField(max_length=10)

def echo_category(sender, **kwargs):
    print "category: '%s'" % sender.category

post_save.connect(echo_category, sender=Dog)


and the following fixture:
--- initial_data.json ---
[
{
    "pk": 1,
    "model": "animal.animal",
    "fields": {
        "category": "omnivore"
    }
},
{
    "pk": 1,
    "model": "animal.dog",
    "fields": {
        "color": "brown"
    }
}
]

Executing manage.py syncdb throws "AttributeError: type object 'Dog'
has no attribute 'category'" from inside of echo_category callback.
This is weird because I can access category from the Dog instance if
it is an instance from a query, say Dog.objects.get(pk=1).

How come the Dog instance received by echo_category is different
compared to the Dog instance from a query? Can't I do post_save on a
sub-model?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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