I write on Django for my site news section. Here I can not understand how it is more convenient to make users notify about new news. More precisely how to mark that the user read the news, or not.

As an option, I think to make a model containing the user_id, news_id fields, which will be responsible for what user_id has read news_id.

Perhaps there are easier solutions?

  • one
    It seems that there is no simpler, just do it through ManyToManyField - andreymal

1 answer 1

I propose such a solution for the USER model to create a read_news field in which the ID of the read news will be stored. it is important that the array is sorted. that is, to check in the worst case, you need log (n) -time. if you use binary search.

By luck for pythonists there is a bisect module

from bisect import bisect 

the worst check will take logn - time where n is the length of the array

  • Somehow it turned out difficult - andreymal
  • @andreymal may be, but the plus will be in performance. If you put a ManyToMany connection, then jango will create an additional link table, in which case there will be user_id, post_id fields. - Anuar Akhmetov