Reputation: 19
I want to insert into the notifications list, one notification of each type. and I have this:
Result from the initial query (I guess is a list with queryset), named notifications
:
[<Notification: Should be first>, <Notification: New link>]
And the restriction that I have is:
for(note in notification):
if len(note.region.all()) == 0 and (note.notificationType.priority not in notifications):
notifications.append(note)
My question is, how do I get inside the notifications list to get the attribute notificationType.priority to see is that number isn't inside notifications
list.
Upvotes: 0
Views: 63
Reputation: 1433
If I get your question, you can try this :
notificationsPiorities = set([note.notificationType.priority for note in notifications ])
for(note in notification):
if len(note.region.all()) == 0 and (note.notificationType.priority not in notificationsPiorities ):
notifications.append(note)
notificationsPiorities.add(note.notificationType.priority)
Also, you may need to rename your variables. I can't tell for sure what are notification
and notifications
. One is the list you will display, and one is the list you retrieve with your query ?
Upvotes: 1