def create_unset_consents_on_term_create(sender, instance: Term, created: bool, **kwargs): if created: Consent.objects.bulk_create( Consent( person=person, term=instance, term_option=None, archived_at=instance.archived_at, ) for person in Person.objects.all())
def create_unset_consents_on_user_create(sender, instance: Person, created: bool, **kwargs): if created: Consent.objects.bulk_create( Consent( person=instance, term=term, term_option=None, archived_at=term.archived_at, ) for term in Term.objects.all())
def fake_consents(self): terms = Term.objects.active().prefetch_active_options() count = Person.objects.all().count() * len( terms) # all persons * number of consents generated self.stdout.write("Generating {} fake consents...".format(count)) consents: List[Consent] = [] people = Person.objects.all() for person in people: for term in terms: consents.append( Consent(person=person, term_option=choice(term.options), term=term)) # Archive unset old consents before adding new ones Consent.objects.filter( person__in=people, term__in=terms, ).active().update(archived_at=timezone.now()) Consent.objects.bulk_create(consents)