Tuesday, March 30, 2021

Trying to understand duplicate results from related_set

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 <gmx@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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20210331070648.1c3915a6f0ccc8a0d69db31a%40ross.cx.

No comments:

Post a Comment