What am I doing wrong?
Is there any other way to do what I want?
I'm basically trying to implement the GOF's strategy design pattern
(the real code is more complicated than this example).

## my models
class Donkey(models.Model):
        name = models.CharField(max_length=11)

class Barn( models.Model):
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        animal = generic.GenericForeignKey('content_type', 'object_id')


##my test
def test_barn(self):
                donkey = Donkey( name = "Stewart")
                donkey.save()
                barn = Barn(animal = donkey)
                barn.save()
                self.assertEqual( barn.animal.name, "Stewart")
                donkey.name = "Bob"
                donkey.save()
                self.assertEqual( len(Donkey.objects.all()),1)
                self.assertEqual( Donkey.objects.all()[0].name, "Bob")
                self.assertEqual( barn.animal.name, "Bob")
                #this fails saying: AssertionError: u'Stewart' != 'Bob'

--~--~---------~--~----~------------~-------~--~----~
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