How to provide a queryset field for a subclass of a one-to-many relation in Django?

Michael

How can I provide a queryset field for a subclass of a one-to-many relation in Django?

Example:

class Concept(models.Model):
    ...


class StudyResource(models.Model):
    concept = models.ForeignKey(Concept, on_delete=models.CASCADE)
    ...


class VideoStudyResource(StudyResource):
    ...

Django provides:

concept.studyresource_set.all()

how can I also provide:

concept.videostudyresource_set.all()

Appreciate any suggestions.

Siva Sankar
  • To handle One-To-Many relationships in Django you need to use ForeignKey.
  • From this: You can't follow the ForeignKey backwards from Concept to VideoStudyResource.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Forming Django queryset for one-to-many relation

Sort by a value in a many to one field with a django queryset?

Django one to one relation queryset

Django - How to create many to one relation

How to bulk update the many-to-many field of a Django queryset

How to filter a queryset with a many many to field object in django?

How to get queryset of objects in many to many field in Django

Django. Choosing a specific field - relation one-to-many

How to do a LEFT OUTER JOIN QuerySet in Django - Many to One

how to serialize two classes have one to many relation in django

In Django, how does one filter a QuerySet with dynamic field lookups?

Add a field in a many-to-one relation in NestJS

One-to-many relation with additional field

How to use one to many relation?

Getting related models from queryset of one-to-many relation with polymorphism

How to overwrite get_queryset method to only display the objects that are contained within a many-to-many field in django?

Retrieve one-to-many QuerySet in Django

Python + SQLAlchemy: how to update many-to-one relationship after one of relation's object field change?

Django how to filter queryset based on nested many to many relations in one query

Django, haystack, elastic search and one to many relation

Many to One Relation in Django With Existing Objects

One-To-Many relation with a specific order in Django

Django many-to-one relation with 3 tables

Django get queryset through Many To Many extra field

One to Many field in Model of Django

Updating a field to One-to-many relation field sum

Get extra field via annotate in Django many to many relation

Django Query, find most common value for field on a many to many relation

How to implement Many to many relation in django when the relation contain attributes?