0

I want to access the actual ID of the sender, right now I can only access the email of the sender.

This is the Javascript

    fetch(`/emails/${id}`)
.then(response => response.json())
.then(email => {
  subject = email.subject
  sender = email.sender
  recipients = email.recipients
  timestamp = email.timestamp
  body = email.body
}

This is the model in Django

class Email(models.Model):
user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="emails")
sender = models.ForeignKey("User", on_delete=models.PROTECT, related_name="emails_sent")
recipients = models.ManyToManyField("User", related_name="emails_received")
subject = models.CharField(max_length=255)
body = models.TextField(blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
archived = models.BooleanField(default=False)
read = models.BooleanField(default=False)
0

Fixed it, added this to the def return "senderid": self.sender_id,

1
  • Have you edited the views.py file? – Vsjain Mar 26 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .