A set of Django filter requests by attribute subclass

I have a model Slugfor identifying objects Page. A is BlogPostinherited from Page. I want to find BlogPostwith a name Slug, but not with other objects Page.

EDIT: Added Models

class Slug(models.Model):
    name = models.CharField()
    page = models.ForeignKey('Page', null=True)

class Page(models.Model):
    slug = models.OneToOneField('Slug', related_name='primary_slug_set')
    content = models.TextField()

class BlogPost(Page):
    time = models.DateTimeField(auto_now_add=True, editable=False)

I think I'm behind something like this:

Slug.objects.get(name=slug_name).filter(page=subclass_of(BlogPost))

I know InheritanceManager and select_subclasses(BlogPost), but my request is for Slug, so I can’t help what if I don’t ask Pageand search BlogPostwith my slug (is this better?).

. , - , Slug - BlogPost. , .

?

+4
2

Slug :

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

:

content_type = ContentType.objects.get_for_model(BlogPost)
Slug.objects.filter(name=slug_name, content_type__pk=content_type.id)
0

, :

Slug.objects.filter(name=slug_name, blogpost__isnull=False)
0

All Articles