On Apr 21, 7:08 am, Lachlan Musicman <data...@gmail.com> wrote:
> Hola,
>
> I'm having trouble getting a subclass to trigger an isinstance(). Code below:
>
> model.py excerpt:
> ------------
> from django.db import models
> from django.forms import ModelForm
>
> class Author(models.Model):
>   first = models.CharField(u'First Name', max_length=20)
>   other = models.CharField(u'Other Names', max_length=20, blank=True)
>   last = models.CharField(u'Last Name', max_length=20)
>
>   class Meta:
>     ordering = ['last']
>
>   def __unicode__(self):
>     return u'%s %s' % (self.first, self.last)
>
>   def get_absolute_url(self):
>     return "/author/%i" % self.str()
>
> class Translator(Author):
>   language = models.CharField(max_length=10, choices=LANGUAGES)
>
>   class Meta:
>     verbose_name = 'Translator'
>     verbose_name_plural = 'Translators'

<snip>

> And from the shell:
>
> >>> from booktrans.books.models import *
> >>> t = Translator.objects.all()
> >>> t
>
> [<Translator: qwerqwad asdasd>, <Translator: Yoko Miyagi>]>>> t = 
> Translator.objects.get(pk=2)
> >>> t
>
> <Translator: Yoko Miyagi>>>> isinstance(t, Translator)
> True
> >>> a = Author.objects.get(pk=1)
> >>> isinstance(a, Translator)
>
> False
>
> Any tips?

This is the expected behaviour. You've asked for an Author object, so
that's what you've got. There's no way to tell from the Author model
that this particular instance of it is also an instance of Translator.
--
DR.

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