Maybe it has something to do with the fact that once you start iterating 
through a query set it gets evaluated[1]. If you slice a query set before it 
gets evaluated that is different than slicing a query set after it gets 
evaluated. I'm not exactly sure why you're getting different results but 
perhaps it has something to do with the evaluated/not evaluated query set 
behavior.

[1] 
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#when-querysets-are-evaluated



On March 31, 2021 12:06:48 AM CDT, Michael Ross <g...@ross.cx> wrote:
>Hello,
>
>my first post here.
>I've been poking at this duplicate result thing
>and it's come down to maybe a fundamental what-does-django-do question:
>
>
>class Medium(models.Model):
>    artifact = models.ForeignKey('Artifact', on_delete=models.PROTECT) 
>
>
>class Artifact(models.Model):
>    def get_medium(self,idx):
>
>        try:
>            media = self.medium_set.all()
>            for m in media:  # <-- THIS
>                pass         # <-- THIS
>            return media[idx]
>        except:
>            return False
>        
>
>Why would iterating over media give me correct results,
>       get_medium(0), get_medium(1) == 9, 13
>
>but if I don't, I get a duplicate row?
>       get_medium(0), get_medium(1) == 9, 9
>
>
>-Michael
>
>
>
>-- 
>Michael Ross <g...@ross.cx>
>
>-- 
>You received this message because you are subscribed to the Google
>Groups "Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send
>an email to django-users+unsubscr...@googlegroups.com.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/20210331070648.1c3915a6f0ccc8a0d69db31a%40ross.cx.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/FF582BAC-42CF-4158-9312-5024DC1671FC%40fattuba.com.

Reply via email to