Z
Z
zh_erzh2015-10-24 23:41:55
Django
zh_erzh, 2015-10-24 23:41:55

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)

I go to the Jangi shell (python manage.py shell), enter:
>>> 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}]

I do not understand why the value of the ID of the zero element is the same as the second? It should be 1.
Or did I make a mistake somewhere? I ask for the help of people who understand this topic more than me.
>>> 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 question

Ask a Question

731 491 924 answers to any question