i creating app allows users answer form.
so have :
class form(models.model): owner = models.foreignkey(user, on_delete=models.cascade) topic = models.charfield(max_length=40) class question(models.model): form = models.foreignkey(form, on_delete=models.cascade) text = models.charfield(max_length=200) question_type = models.charfield(max_length=10) class participation(models.model): user = models.foreignkey(user, on_delete=models.cascade) form = models.foreignkey(form, on_delete=models.cascade) created_at = models.datetimefield(auto_now_add=true) class answer(models.model): participation = models.foreignkey(participation) question = models.foreignkey(question) value = models.charfield(max_length=255)
where user
model django.contrib.auth.models
how can query users have answered specific form ?
how can query users have answered specific form ?
if have specific form
instance, can answers, user has participated , answered , users:
users = answer.objects.filter(participation__form=form).values('participation__user')
if want cautious, check if form in question same form in participation:
users = answer.objects.filter(participation__form=form, question__form=form).values('participation__user')
Comments
Post a Comment