Yuvraj
I think it would be foreignkey for most cases. Again, it depends on some factors. Go with foreignkey.
(i am not an expert).
Anonymous
Hey !! Anyone knows how to integrate Paytm in Django
Anonymous
Anyone who ever done that
Anonymous
?
Anonymous
from PayTm import Checksum
Anonymous
But I'm getting error : No module named found PayTm
Yuvraj
are you working in a venv ?
Anonymous
No
Yuvraj
did you pip install ?
Anonymous
what ?
pip install paytn
Anonymous
What is exact command
Anonymous
?
Yuvraj
pip install django-paytm
i haven't worked with this one yet but i found it on pypi
Anonymous
Ohhh it's django-paytm
Yuvraj
https://pypi.org/project/django-paytm/
Anonymous
I used only paytm
Anonymous
Ok I'll try
Yuvraj
That happens sometimes
Yuvraj
also, in INSTALLED_APPS, add 'paytm'
Anonymous
Thank you 😊
Anonymous
Yuvraj
Thank you 😊
Welcome and you will also need to run python manage.py makemigrations and python manage.py migrate once and add it to the urls as well
url('paytm/', include('paytm.urls')),
Anonymous
Ohh okay 👍
Yuvraj
Okay 👍🏻
Abdulakhad
Hello everyone,
i was using this method for the first time.
what error of writing is there? the result is not as expected
class OrderListAPIView(generics.ListAPIView):
serializer_class = OrderListSerializers
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
return Order.objects.filter(billing_profile__user=user).exclude(status='created')
def get_context_data(self, **kwargs):
context = super(OrderListAPIView, self).get_context_data(**kwargs)
print('TEST')
context['test'] = 'Test'
return context
Mirco
Mirco
Put the dictionary or list into request.session
Mirco
Yuvraj
I am working on a blogging website in which each post has two components. The user who is reading the blog can like only one component. I have created the Post Model like this:
class Post(models.Model):
title = models.CharField(max_length=250)
idea1_title = models.CharField(max_length=140)
idea2_title = models.CharField(max_length=140)
idea1_description = models.TextField()
idea2_description = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
post_date = models.DateField(auto_now_add=True)
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
def __str__(self):
return self.title + ' | ' + str(self.author)
def get_absolute_url(self):
return reverse('home')
Views.py:
def LikeIdea1View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea1'))
post.idea1_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
def LikeIdea2View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea2'))
post.idea2_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
The last two in the models :
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/article/3/like1/?likeidea1=
Raised by: mainapp.views.LikeIdea1View
No Post matches the given query.
Mirco
I am working on a blogging website in which each post has two components. The user who is reading the blog can like only one component. I have created the Post Model like this:
class Post(models.Model):
title = models.CharField(max_length=250)
idea1_title = models.CharField(max_length=140)
idea2_title = models.CharField(max_length=140)
idea1_description = models.TextField()
idea2_description = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
post_date = models.DateField(auto_now_add=True)
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
def __str__(self):
return self.title + ' | ' + str(self.author)
def get_absolute_url(self):
return reverse('home')
Views.py:
def LikeIdea1View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea1'))
post.idea1_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
def LikeIdea2View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea2'))
post.idea2_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
The last two in the models :
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/article/3/like1/?likeidea1=
Raised by: mainapp.views.LikeIdea1View
No Post matches the given query.
share urls
Mirco
with code sharing tool is better
Yuvraj
path('article/<int:pk>', ArticleView.as_view(), name='article'),
path('article/<int:pk>/like1/', LikeIdea1View, name='likeidea1'),
path('article/<int:pk>/like2/', LikeIdea2View, name='likeidea2'),
ArticleView one is a generic view from views. py
Yuvraj
Yuvraj
pls help
Mirco
I am working on a blogging website in which each post has two components. The user who is reading the blog can like only one component. I have created the Post Model like this:
class Post(models.Model):
title = models.CharField(max_length=250)
idea1_title = models.CharField(max_length=140)
idea2_title = models.CharField(max_length=140)
idea1_description = models.TextField()
idea2_description = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
post_date = models.DateField(auto_now_add=True)
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
def __str__(self):
return self.title + ' | ' + str(self.author)
def get_absolute_url(self):
return reverse('home')
Views.py:
def LikeIdea1View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea1'))
post.idea1_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
def LikeIdea2View(request, pk):
post = get_object_or_404(Post, id=request.POST.get('likeidea2'))
post.idea2_likes.add(request.user)
return HttpResponseRedirect(reverse('article', args=[str(pk)]))
The last two in the models :
idea1_likes = models.ManyToManyField(User, related_name='idea1')
idea2_likes = models.ManyToManyField(User, related_name='idea2')
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/article/3/like1/?likeidea1=
Raised by: mainapp.views.LikeIdea1View
No Post matches the given query.
why you are stringify pk if your urls expect an int ? first of all
Mirco
and why from frontend you append likeidea1 to the url ?
Yuvraj
Yuvraj
Mirco
that likeidea1 query param is useless too
Yuvraj
its the button's name
Yuvraj
<form action="{% url 'likeidea1' post.pk %}"> <button class="btn btn-primary" name="likeidea1" type="submit" style="width: 100%;"><i class="fa fa-heart"></i></button>
</form>
same for likeidea2 as well
Mirco
so you are using GET method inside the form ?
Yuvraj
why GET ? i think i forgot to put method = 'POST'
Mirco
Mirco
the main problem is that you are not creating any Post object
Yuvraj
ValueError at /article/3/like1/
Field 'id' expected a number but got ''.
Request Method: POST
Request URL: http://127.0.0.1:8000/article/3/like1/
Django Version: 3.1.2
Exception Type: ValueError
Exception Value:
Field 'id' expected a number but got ''.
Exception Location: C:\whyseeadminname\virt\lib\site-packages\django\db\models\fields\__init__.py, line 1776, in get_prep_value
Yuvraj
New Error after specifying POST method for form
Mirco
could u use a code sharing tool please ? and you can paste your code and the traceback
Yuvraj
@pyflare https://dpaste.org/meVw/slim
Here's the code
Mirco
Study what a CreateView is and how to use it
Mirco
Yuvraj
i have used it in the adding post functionality, i did not paste the whole views.py file in https://dpaste.org/meVw/slim
and i have also used django forms to use ModelForms
i have tested it many times, it works fine
Yuvraj
?
Mirco
I'm reading again carefully your code
Why are you trying to get the Post ID by likeidea1 into request.POST
It's normal it's empty
Yuvraj
Mirco
You views, first line
Yuvraj
ok ok
Mirco
You just need to use the pk argument passed through the function
Mirco
To get the Post object
Mirco
Into the get object or 404 just use id=pk
Mirco
Instead of trying to get the id through the request.POST as it doesn't exist inside it
Mirco
Mirco
To get the Post object, you need to use the pk argument of the view
post = get_object_or_404(Post, id=pk)
Then you can add the like inside the M2M
Yuvraj
could there be something wrong with the naming of things? cuz the names are quite similar.... probably😅
Mirco
Mirco
Try it and you will see
Yuvraj
Yuvraj
Mirco
Yuvraj
if i am not wrong