title: How can I detect if a user tries to upvote once again?
body: <p>I'm currently in the process of implementing an upvoting system ( no down voting system will be used in the app). I managed to create an upvote property to the Post model in my app. The default for that property is 0 as shown here:</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class User(UserMixin, Model):
      username = CharField(unique= True)
      email = CharField(unique= True)
      password = CharField(max_length = 100)
      joined_at = DateTimeField(default = datetime.datetime.now)
      is_admin = BooleanField(default = False)
      confirmed = BooleanField(default = False)
      confirmed_on = DateTimeField(null=True)
  
      class Meta:
          database = DATABASE
          order_by = ('-joined_at',)
  
      def get_posts(self):
          return Post.select().where(Post.user == self)
  
      def get_stream(self):
          return Post.select().where(
              (Post.user == self)
          )
  
      @classmethod
      def create_user(cls, username, email, password, is_admin= False, confirmed = False, confirmed_on = None):
          try:
              with DATABASE.transaction():
                  cls.create(
                  username = username,
                  email = email,
                  password = generate_password_hash(password),
                  is_admin = is_admin,
                  confirmed = confirmed,
                  confirmed_on = confirmed_on)
          except IntegrityError:
              raise ValueError("User already exists")
  
  class Post(Model):
      timestamp = DateTimeField(default=datetime.datetime.now)
      user = ForeignKeyField(
          rel_model = User,
          related_name = 'posts'
      )
      name = TextField()
      content = TextField()
      upvotes = IntegerField(default=0)
      url = TextField()
      category = TextField()
  
      class Meta:
          database = DATABASE
          order_by = ('-timestamp',)
  </code></pre>
  
  <p>I managed to increment the value by making the user follow a link:</p>
  
  <p><strong>stream.html</strong></p>
  
  <pre><code> &lt;div class="voting_bar"&gt;
          &lt;a href="/vote/{{post.id}}"&gt;&lt;img src="/static/img/upvote.png"&gt;&lt;/a&gt;
          &lt;p&gt;{{post.upvotes}}&lt;/p&gt;
        &lt;/div&gt;
  </code></pre>
  
  <p>This will activate a function with the associated route:</p>
  
  <p><strong>app.py</strong></p>
  
  <pre><code>@app.route('/vote/&lt;int:post_id&gt;')
  def upvote(post_id):
      posts = models.Post.select().where(models.Post.id == post_id)
      if posts.count() == 0:
          abort(404)
      post = models.Post.select().where(models.Post.id == post_id).get()
      query = models.Post.update(upvotes = (post.upvotes+1)).where(models.Post.id == post_id)
      query.execute()
      return redirect(url_for('index'))
  </code></pre>
  
  <p>My question is, how can I detect if the user had already voted? I'm not sure what I should do to accomplish this. My plan was that if I identify if the user tried to upvote again, what I would do is simply decrement their previous vote. </p>