Answer the question
In order to leave comments, you need to log in
How to compare 2 ForeignKeys?
There are such models:
class Client(models.Model):
full_name = models.CharField('Full name', max_length=45)
class Document(models.Model):
description = models.CharField('Description', max_length=45)
client = models.ForeignKey('Client')
class Ticket(models.Model):
description = models.CharField('Description', max_length=255)
client = models.ForeignKey('Client')
document = models.ForeignKey('Document')
Answer the question
In order to leave comments, you need to log in
I support iegor . Of course, I'm not familiar with your task. But I assume that the document refers to a specific client, and the ticket, in turn, refers to a specific document.
It should be something like this:
class Client(models.Model):
full_name = models.CharField('Full name', max_length=45)
class Document(models.Model):
description = models.CharField('Description', max_length=45)
client = models.ForeignKey('Client')
class Ticket(models.Model):
description = models.CharField('Description', max_length=255)
document = models.ForeignKey('Document')
Your base composition is incorrect, think about relationships, read about normal forms.
I assumed that you can fill it like this.
doc = Document.objects.get(pk=request.data['document'])
Ticket.objects.create(description=u"Бла Бла", client=doc.client, document=doc)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question