title: (django) Showing posts according to interests of users
body: <p>I am pretty new to Django and still learning it, but I have to create something like medium.com. I want to show posts to users according to their interests. I added an interests field with a checkbox in a sign-up form. And of course, I added a category to the Post model. So, how can I show (to logged-in users only) publications that they interested in?
  Here is my models.py file in posts app</p>
  <pre><code>from django.db import models
  from django.utils import timezone
  from django.urls import reverse
  # Create your models here.
  class Post(models.Model):
      CATEGORY = (
          ('sport', 'Sport'),
          ('science', 'Science'),
          ('it', 'IT'),
          ('art', &quot;Art&quot;),
      )
  
      
      title = models.CharField(verbose_name=&quot;Title for publication&quot;, max_length=50)
      category = models.CharField(verbose_name=&quot;Category&quot;, choices=CATEGORY, max_length=50)
      author = models.ForeignKey(&quot;accounts.User&quot;, verbose_name=&quot;Author:&quot;, on_delete=models.CASCADE)
      body = models.TextField(verbose_name=&quot;Body for publication&quot;)
      pub_date = models.DateTimeField(verbose_name=&quot;Date:&quot;, auto_now_add=True)
      def was_published_recently(self):
          return self.pub_date &gt;= timezone.now() - datetime.timedelta(days=1)
  
  
      def get_absolute_url(self):
          return reverse(&quot;post_detail&quot;, kwargs={&quot;pk&quot;: self.pk})
      
  
      def __str__(self):
          return self.title
  </code></pre>
  <p>And here is my vies.py file in posts app</p>
  <pre><code>from django.views.generic import ListView, DetailView
  from django.views.generic.edit import CreateView, UpdateView, DeleteView
  from .models import Post
  from django.urls import reverse_lazy
  
  class PostListView(ListView):
      model = Post
      template_name = &quot;index.html&quot;    
      def get_queryset(self):
          return Post.objects.order_by('-pub_date')
  
  
  class PostDetailView(DetailView):
      model = Post
      template_name = &quot;./posts/post_detail.html&quot;
  
  class PostCreateView(CreateView):
      model = Post
      template_name = &quot;./posts/new_post.html&quot;
      fields = '__all__'
  
  class PostUpdateView(UpdateView):
      model = Post
      template_name = &quot;./posts/update_post.html&quot;
      fields = ['body', 'title', 'category']
  
  class PostDeleteView(DeleteView):
      model = Post
      template_name = &quot;./posts/delete_post.html&quot;
      success_url = reverse_lazy('index')
  
  
  class SportPostListView(ListView):
      model = Post
      template_name = &quot;./posts/sports.html&quot;
  
  class ITPostListView(ListView):
      model = Post
      template_name = &quot;./posts/it.html&quot;
  
  class SciencePostListView(ListView):
      model = Post
      template_name = &quot;./posts/ilm-fan.html&quot;
  
  class ArtPostListView(ListView):
      model = Post
      template_name = &quot;./posts/sanat.html&quot;
  </code></pre>
  <p>Here is my index.html file</p>
  <pre><code>{% extends 'base.html' %}
  {% block content %}
  {% if object_list %}
      {% for post in object_list %}
          &lt;h1&gt;{{ post.title }}&lt;/h1&gt;
          &lt;p&gt;{{ post.pub_date }}&lt;/p&gt;
          &lt;p&gt;{{ post.author }}&lt;/p&gt;
          &lt;p&gt;{{ post.body }}&lt;/p&gt;
          &lt;p&gt;{{ post.category }}&lt;/p&gt;
      {% endfor %}
  {% else %}
      &lt;p&gt;No posts are available.&lt;/p&gt;
  {% endif %}
  {% endblock content %}
  </code></pre>
  <p>This is my forms.py file in accounts app</p>
  <pre><code>from django.contrib.auth.forms import UserCreationForm
  from django.contrib.auth.models import User
  from django.db import models
  from django import forms
  class SignUpForm(UserCreationForm):
      INTERESTS = (
          ('sport', 'Sport'),
          ('science', 'Science'),
          ('it', 'IT'),
          ('art', &quot;Art&quot;),
          )
      username = forms.CharField(max_length=128, required=True)
      email = models.EmailField(verbose_name='emailingiz', unique=True, default='')
      first_name = forms.CharField(max_length=128, required=True)
      last_name = forms.CharField(max_length=128, required=True)
      interests = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple, choices=INTERESTS)
      USERNAME_FIELD = 'email'
  
      class Meta:
          model = User
          fields = ('first_name', 'last_name', 'username', 'email', 'interests', 'password1', 'password2')
      
  </code></pre>
  <p>And lastly this views.py file in accounts app</p>
  <pre><code>from django.urls import reverse_lazy
  from django.views.generic import CreateView
  from .forms import SignUpForm
  
  class SignUpView(CreateView):
      form_class = SignUpForm
      success_url = reverse_lazy('login')
      template_name = 'signup.html'
  
  </code></pre>
  <p>I have no idea how to do this, but I know that I have to do something in the views.py file in the posts app, however, I do not know what to do.
  Will be really grateful if you could help me.</p>