У меня есть модель
class dog(models.Model):
name = models.CharField(max_length=30, blank=True)
type = models.CharField(max_length=30, blank=True)
sex = models.CharField(max_length=30, blank=True)
и просмотров
def dog_matching(request):
# Create the new dog, starting with data from the previous HTML page
name = request.session['name']
# Fill in the rest of the information on the current HTML page
if request.method == 'GET':
type = request.GET['type']
sex = request.GET['sex']
# Create an instance of the dog
dog_inst = dog(name=name, type=type, sex=sex)
# Save the instance to database
dog_inst.save()
# Perform matching and send email
Когда новая собака создается и сохраняется, я хочу найти каждую предыдущую собаку в базе данных, где «тип» совпадает, а «пол» отличается. Затем для каждого матча я хочу получать по электронной почте уведомление о том, что отправка на веб-сайте привела к совпадению (то есть к электронному письму, например, «Матч Scruffles and JayJay!».)
Как выполнить операцию сопоставления, чтобы каждое полученное письмо соответствовало каждому совпадению?
Я пытаюсь что-то вроде этого
if dog_inst.sex = 'male':
for dog.objects.get(sex__iexact="female"):
test = dog.objects.get(sex__iexact="female")
if test.type = dog_inst.type:
#Send email (I can find documentation for this)
if dog_inst.sex = 'female':
for dog.objects.get(sex__iexact="male"):
test = dog.objects.get(sex__iexact="male")
if test.type = dog_inst.type:
#Send email (I can find documentation for this)
Есть идеи?