Answer the question
In order to leave comments, you need to log in
Question about Django shell?
Good evening Toaster.
The situation is this. There are 2 models.
class Notice(models.Model):
notice_title = models.CharField(max_length=255)
notice_text = models.TextField()
notice_date = models.DateTimeField(auto_now_add=True)
notice_author = models.ForeignKey(User)
def __str__(self):
return self.notice_title
class Destination(models.Model):
notice = models.ForeignKey(Notice)
destination = models.ForeignKey(User)
accepted = models.BooleanField(default=False)
>>> from notice.models import *
>>> notice = Notice.objects.get(pk=2)
>>> notice.destination_set.all().values()
[{'accepted': False, 'destination_id': 10, 'id': 1, 'notice_id': 2},
{'accepted': False, 'destination_id': 12, 'id': 2, 'notice_id': 2},
{'accepted': False, 'destination_id': 1, 'id': 3, 'notice_id': 2}]
>>> notice.destination_set.all()[0].id
3
>>> notice.destination_set.all()[1].id
2
>>> notice.destination_set.all()[2].id
3
>>>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question