コード例 #1
0
def seed(request):
    """Seeds the database with sample polls."""
    samples_path = path.join(path.dirname(__file__), 'samples.json')
    with open(samples_path, 'r') as samples_file:
        samples_polls = json.load(samples_file)

    for sample_poll in samples_polls:
        poll = Poll()
        poll.Geplanter_Status()
        poll.Status()
        poll.Kurzbeschreibung = sample_poll['Kurzbeschreibung']
        poll.text = sample_poll['text']
        poll.pub_date = true
        poll.save()

        for sample_choice in sample_poll['choices']:
            choice = Choice()
            choice.poll = poll
            choice.text = sample_choice
            choice.Status = 0
            choice.save()

    return HttpResponseRedirect(reverse('app:home'))