W
W
windf1n2019-07-19 11:33:04
Django
windf1n, 2019-07-19 11:33:04

How to create likes system without django registration?

Greetings. Submit on ajax click:

$('.plus{{ server.id }}').on('click', function() {
                    var data_plus = {
                      id: {{server.id}},
                      move: '+'
                    }
                    $.ajax({
                      url: '/add_voice/',
                      dataType: 'json',
                      data: data_plus,
                      success: function(response) {
                        $('.voices{{ server.id }} b').html(response['voices_count'])
                      }
                    });
                  })
                  $('.minus{{ server.id }}').on('click', function() {
                    var data_minus = {
                      id: {{server.id}},
                      move: '-'
                    }
                    $.ajax({
                      url: '/add_voice/',
                      dataType: 'json',
                      data: data_minus,
                      success: function(response) {
                        $('.voices{{ server.id }} b').html(response['voices_count'])
                      }
                    });
                  })

On views I process:
def add_voice(request):
    id = request.GET.get('id')
    move = request.GET.get('move')
    server = Server.objects.get(id=id)
    ip = get_client_ip(request)

    if move == '+':
        server.voices += 1
        server.save()
    if move == '-':
        server.voices -= 1
        server.save()

    voices_count = server.voices
    response_data = {
        'voices_count': voices_count
    }

    return JsonResponse(response_data)

The problem is that one user can add 10000 likes to one model. I could restrict all this, but only through mandatory authorization. It is necessary to make such a restriction: an unauthorized user can add a like once every 24 hours. How to do it? bind to ip? Or how? Maybe something with sessions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2019-07-19
@windf1n

The options are:
The last 2 points are more convenient to do using JS. As you understand, they are not reliable at all, because cookies and localStorage are stored in the user's browser and nothing prevents them from being deleted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question