def your_contacts(request): user = request.user.person if request.method == 'POST': form = AddContactForm(request.POST) if form.is_valid(): print(form.cleaned_data) data = form.cleaned_data now = timezone.localtime(timezone.now()) res = int(data['update_day']) - now.weekday() if res <= 0: res += 7 dif = timedelta(days=res) new = now + dif new = new.replace(hour=data['update_time'].hour, minute=data['update_time'].minute, second=0, microsecond=0) contact = Contact(name=data['name'], phone=data['phone'], next_reminder=new, frequency=timedelta(weeks=1)) contact.save() user.contact_set.add(contact) form=AddContactForm() else: form = AddContactForm() contacts = user.contact_set.all() context = {'contacts': contacts, 'person': user, 'form':form} return render(request, 'reminders/contacts.html', context)
def populate_contacts(): now = timezone.now() diff = timedelta(hours=1) me = Person.objects.get(pk=1) for i in range(0, 100): contact = Contact(name="New" + str(i), phone="1231231221", next_reminder=now+diff, frequency=timedelta(weeks=1)) now = now + diff contact.save() me.contact_set.add(contact)