I can't find out why my signal
does not work when the instance (of proxy model) is created implicitely by third app.
I use a third party app Django-Quiz
in my project. There is a model called Sitting
. Since I want to see the table in admin, I had to create a proxy
model QuizSittingProxy
, to be able to set __str__
and __unicode__
methods for Sitting
.
Each time when User
takes a quiz, the new Sitting
object is created. Respectively QuizSittingProxy
object is created too.
class QuizSittingProxy(Sitting):
"""
Holds information about taken Language Tests (in admin)
"""
class Meta:
proxy = True
def __str__(self):
return '{}: {}, score: {}'.format(self.user.username, self.quiz.title, self.current_score)
I want to assign result of the quiz to current User
so I've created a signal
.
The problem is, that this signal
works only if I create a QuizSittingProxy
object manually in admin.
Worth to say that it is created everytime User
takes a quiz.
@receiver(post_save,sender=QuizSittingProxy)
def assign_level(sender, instance, created, **kwargs):
print 'QUIZSITTING POST SAVE'
# user = instance.user
# quiz = instance.quiz
# score = len(instance.user_answers.keys()) / instance.current_score
Do you know where is the problem?