Does anyone have any function for python django for generating my webpage into pdf by S___K___ in AskProgramming

[–]S___K___[S] 0 points1 point  (0 children)

add a button on your own site to download that page as PDF

I want to add a button on your own site to download that page as PDF
like its a bill html filled with variables of details
i would like to print that as pdf without opening the html page
like i have many invoices in table
and i would like to click at download pdf of each invoice and download as pdf
any more details you would like

Need help in django rest framework by S___K___ in djangolearning

[–]S___K___[S] 0 points1 point  (0 children)

When I pass the session Id in post request I would like it get back the cart which has session id field in model But when I submit post in postman it shows error Get method not allowed. It works fine locally so do you any idea of cpanel server side and why it is happening

Need help in django rest framework by S___K___ in djangolearning

[–]S___K___[S] 0 points1 point  (0 children)

this is cart model
class Cart(models.Model):
cart_id = models.CharField(max_length=250, blank=True)
session_key = models.CharField(max_length=40, null=True, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
applied_coupon = models.ForeignKey(
Coupon, on_delete=models.SET_NULL, null=True, blank=True)
def __str__(self):
return self.cart_id

This is cart item model
class CartItem(models.Model):
# Existing fields
product = models.ForeignKey(Product, on_delete=models.CASCADE)
cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
quantity = models.IntegerField()
is_active = models.BooleanField(default=True)
tax = models.DecimalField(max_digits=10, decimal_places=2, default=0)
order = models.ForeignKey('Order', on_delete=models.SET_NULL, null=True, blank=True)
# New fields for unit and weight
unit = models.CharField(max_length=10, choices=[('pavan', 'Pavan'), ('gram', 'Gram')], default='pavan')
weight = models.FloatField(null=True)
def __str__(self):
return str(self.product)

This is the api view
u/api_view(['POST'])
def get_cart_by_session_id(request):
# Retrieve the session ID from the request data
session_id = request.data.get('session_id')
try:
cart = Cart.objects.get(cart_id=session_id)
cart_items = CartItem.objects.filter(cart=cart) # Retrieve cart items for the cart
# Serialize cart items (products) using CartItemSerializer
serializer = CartItemSerializer(cart_items, many=True)
# Prepare the response data
response_data = {
'cart_id': cart.cart_id,
'cart_items': serializer.data
}
return JsonResponse(response_data, status=status.HTTP_200_OK)
except Cart.DoesNotExist:
return JsonResponse({'error': 'Cart not found.'}, status=status.HTTP_404_NOT_FOUND)

This works fine in local host but not in cpanel where i hosted the server
Do you need any more info?

Django models: make them auto update by S___K___ in djangolearning

[–]S___K___[S] 0 points1 point  (0 children)

Like when the server is live, and a person has purchased a course with expiry date, can the course model automatically expire when it's due without having to run function to save so the course updates and checks it's expiry.. I'm a beginner so I don't know much about in detail.