Search code examples
djangodjango-modelsdjango-appsdjango-quiz

How to add fields to third party app model?


I'm working on a web page which uses Django-quiz app. When you install the django-quiz, you can create quizes, questions etc. in Admin.

Unfortunately, there is no way, how to assign Quiz to my model Language so I'm looking for a way, how to add field Language into the model Quiz.

I've tried this but it does not work. I've tried already to create a proxy model with additional field but I realised that it is not possible in proxy models.

from quiz.models import Sitting,Quiz

class QuizAddLanguage(models.Model):
    quiz = models.OneToOneField(Quiz)
    language = models.ForeignKey(Language)

Do you know what to do to add field to third party app model?


Solution

  • For this time, OneToOne should be enough - for each language there will be one quiz

    Since its one to one then you can just define the relationship on your own language class, django by default, will provide you the reverse lookup meaning

    language_obj.quiz
    quiz_obj.language
    

    will both be valid.