1👍
✅
You need to use the value of the clicked button, so:
data: {
newsid: $(this).val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
action: 'post'
},
Note: It is normally better to make use of the
settings.AUTH_USER_MODEL
[Django-doc] to refer to the user model, than to use theUser
model [Django-doc] directly. For more information you can see the referencing theUser
model section of the documentation.
Note: You do not have to store the number of items of a
ManyToManyField
in another field. You can use.annotate(…)
[Django-doc] when you need to determine this by the database. Storing this explicitly in a field is a form of data duplication, and it turns out that keeping these in sync is harder than what one might expect.
- [Answered ]-How to pass request object from one serializer class to other serializer class in Django
Source:stackexchange.com