Hi.

You're using table inheritance which by default is like one way road.

In Question model there exists two reverse relations to your child models.
You just need to test which one is set.

If you truly want abstract base class (which changes model layouts as well)
you need to make Question model abstract in Meta.


to 19. syysk. 2019 klo 0.20 Courtney Bracefield <
courtneybracefiel...@gmail.com> kirjoitti:

> Hi there,
>
> I have some classes in my model.py file shown below. I would like my API
> to return a list of questions showing the slug, title and question_type of
> each question. Fetching the slug and title is trivial, but I cannot for the
> life of me access the question_type of a question because it isn't under
> the Question class, it is a field under each subclass (shown below).
>
> Anyone have any ideas? Thanks!
>
> class Question(TranslatableModel):
> """Base class for a question.
>
> Aims to be an abstract class as questions should be
> a particular subtype, though the class is not made
> completely abstract to allow retrieving all child
> objects through the InheritanceManager.
> """
>
> slug = models.SlugField(unique=True)
> title = models.CharField(max_length=SMALL)
> objects = InheritanceManager()
>
>
> class QuestionTypeProgram(Question):
> """A program based question."""
>
> QUESTION_TYPE = 'program'
>
>
> class QuestionTypeFunction(Question):
> """A function based question."""
>
> QUESTION_TYPE = 'function'
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/6da5f79c-5a51-4fe5-aa34-64a96b3571b6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/6da5f79c-5a51-4fe5-aa34-64a96b3571b6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAHn91odLS0A-1fdtkpe0HBEGzRsrwH-6wZ%3Dv7bbajSg96-XjGA%40mail.gmail.com.

Reply via email to