Got attribute error when trying creating model
I got this error message
Is there any option to get “to-many” relation objects while saving “parent” object?
I have three models
Nested Serializer with Foreign Key and to_field
Stock model has a OneToMany relationship with Data model. I am using the to_field to link them via model_number field.
Django Rest Framework – testing serializers vs testing views
I’m writing a new Django app with Django Rest Framework and trying to use TDD as much as I can but I’m a bit unsure as to where to draw the line between testing the serializer and testing the view.
nesting a serializer by year then month
class Transactions(models.Model): id = models.CharField(max_length=100, primary_key=True) owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True) date = models.DateField() watch = models.CharField(max_length=100) purchase_price = models.IntegerField() sale_price = models.IntegerField() My Transactions model has a date field, purchase price, and sale_price. @api_view([‘GET’]) @permission_classes([IsAuthenticatedOrReadOnly]) def profit_chart(request): current_year = datetime.now().year queryset = Transactions.objects.filter(date__year=current_year).values(month=ExtractMonth(‘date’), year=ExtractYear(‘date’)).annotate( profit=Sum(F(‘sale_price’)) – Sum(F(‘purchase_price’))).order_by(‘month’) serializer = ProfitChartSerializer(queryset, many=True) return Response(serializer.data, status=status.HTTP_200_OK) […]
Django Axes Lockout Not Working as Expected
I’m using Django Axes to lock out users after a certain number of failed login attempts. However, despite my configurations, users are still able to log in immediately after being locked out if they enter the correct credentials. I want to ensure that users are locked out for 1 hour, regardless of whether they enter the correct credentials during that period.
Got KeyError when attempting to get a value for field `date` on serializer
Im trying to do a queryset to show date__month and total of all sale_prices
Unable to update user profile using PUT method (Django DRF)
I am currently working on a mentor-mentee matching service using Django DRF. I have made a ‘users’ app and have completed creating users&logging in. But I can’t edit user info using PUT method.
Here are my project files (models.py, serializers.py, views.py, urls.py, settings.py)
1. models.py
how to add product to my cart in django rest frame work drf
this is my model class Cart(models.Model): id = models.UUIDField(primary_key=True, default=uuid4) created_at = models.DateTimeField(auto_now_add=True) class CartItem(models.Model): cart = models.ForeignKey(Cart, on_delete=models.CASCADE, related_name=’items’) product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name=’cart_items’) quantity = models.PositiveSmallIntegerField() class Meta: unique_together = [[‘cart’, ‘product’]]
Django decorator and middleware issue
My decorator looks like this