Nirupam
Can you please elaborate a bit.
Two model.one emp no , emp name and manager name. And other model is manager .what would be the relation
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
?
Yuvraj
Hey !! Anyone knows how to integrate Paytm in Django
https://medium.com/@dhavalsavalia/how-to-integrate-paytm-with-django-d8df17932026 Try This
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 😊
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
Put the dictionary or list into request.session
Abdulakhad
Remove the get context data
I don't understand. Can you give me more details? i want to add a dict to data
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
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
why you are stringify pk if your urls expect an int ? first of all
It showed the same error when i tried earlier, so i tried str
Mirco
It showed the same error when i tried earlier, so i tried str
try to understand instead of putting useless stuff u've used int into your url so no need of stringify pk
Mirco
that likeidea1 query param is useless too
Yuvraj
that likeidea1 query param is useless too
that is from a form on the frontend that has only one button
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
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
@pyflare https://dpaste.org/meVw/slim Here's the code
The traceback needed is what you see on the console And again you are not creating any Post with that code
Mirco
Study what a CreateView is and how to use it
Yuvraj
Study what a CreateView is and how to use it
Nothing's going wrong with the create view
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
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
Yuvraj
Into the get object or 404 just use id=pk
then how do i get the notion that the user pressed the like button from the frontend ? i used request.POST for that purpose only
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
Try it and you will see
Mirco
i understand that, but frontend ?? should i just use if request.method == POST:
Frontend is correct, why you wanna change it ? It's a simple button and a POST request
Yuvraj
Frontend is correct, why you wanna change it ? It's a simple button and a POST request
yeah, so.. when there is a post request to that particular url (view), there is a like added to the particular component of the post and the user gets redirected
Yuvraj
if i am not wrong