[Answer]-Django insert into list if doesn't contain it

1👍

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 ?

Leave a comment