0👍
If your Slug model defines the association with Pages in the following way:
class Slug(models.Model):
...
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
page = generic.GenericForeignKey('content_type', 'object_id')
Then, your query should look something like this:
content_type = ContentType.objects.get_for_model(BlogPost)
Slug.objects.filter(name=slug_name, content_type__pk=content_type.id)
0👍
Haven’t tested this but give it a try:
Slug.objects.filter(name=slug_name, blogpost__isnull=False)
Source:stackexchange.com