Victor
I don't know if it works, but it deserves a try
Vitaly
I don't know if it works, but it deserves a try
Didn't work total_weight = models.GeneratedField(verbose_name="Some name", expression=F('person__weight') * 2, output_field=models.FloatField(), db_persist=True) Error: Joined field references are not permitted in this query
Mirco
it does not work, it is translated only in the admin panel, plz help
It works, it works Working with it daily and it works if set it up correctly
A
I check through the postman the fields are not being translated, I go to the admin panel is it being translated, is this how it should be?
A
maybe the browser doesn't support other languages?
Nasrullah
Is it possible to get fields that contain data and ignore empty model fields?
Rose
User Sabbir Hossain has 1/3 warnings; be careful! Reason: this is neither a job board nor a bulletin board
Nasrullah
Field1 = models.charfield(...) Field2 = models.charfield(...) Field3 = models.charfield(...) Field1 and field3 has data but field2 is left empty i want to ignore it while getting class objects, How to do it, need help please
Thiago
I'm using django 1.5 @transaction.commit_on_success def view_increment(product_id): try: product = Product.objects.get(id=product_id) product.view_count += 1 product.save() except Product.DoesNotExist: pass Is this the right way to count user views on a product? It takes too long to load the product when I call the view_increment function.
.
when i can start learn django ?
.
not when sorry
.
where
Charly
where
Start witht he official tutorial
Charly
On Django's website
.
thanks
amin
when i can start learn django ?
the best way for learning anything is the official website documentation, but for django it's not beginner friendly. there are many free course in YouTube. also you can check it on w3schools website.
amin
yes I agree, but which level of beginners! I just suggested more resource out of the box 📦
Anonymous
when i can start learn django ?
When you have learned Python completely
Anonymous
Django's oficial tutorial is perfectly fine for beginners.
I think Django's documentation sometimes gives more information than a beginner needs, and not all of them are needed to get started
Anonymous
Kevin
Nasrullah
YourModel.objects.exclude(Field2='').all()
I have almost 12 objects and they are linked to specific users and users can decide which fields to fill according to thier need, after that those fields which left empty should be disabled or something like this
eiverflow
Django-ckeditor's content not being styled in html as they look in the admin page why?
Firdaus
Django-ckeditor's content not being styled in html as they look in the admin page why?
Tried this? https://django-ckeditor.readthedocs.io/en/latest/#outside-of-django-admin
Karthi
Django payment access code
Jimmies San
Use pastebin ffs And delete your message please
Jimmies San
why delete?
because the code snippets should be shared using a pastebin services, not walltext here
Jimmies San
so if they do right no need to have a huge useless message in this chat
summit
Hi! What is best, def views? Or class views? Thanks!
Poya
Use pastebin ffs And delete your message please
Thanks, I didn't know the rules
Rose
Your question is not related to Django. If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Sid
This Serverless Function has crashed. Your connection is working correctly. Vercel is working correctly. 500: INTERNAL_SERVER_ERROR Code: FUNCTION_INVOCATION_FAILED ID: hkg1::6vwz9-1708496306679-4faf32ab1821
Sid
i encountered this error on vercel when i want to deploy my django project with pgsql
DeathLikeSilence
hello everyone how can I deploy django-react project in cpanle with application manager? I do not have setup python app in software
Никита
Hello! Please tell me how best to organize the structure of the application. I have an "account" application, where there is logic for authorization, registration, password recovery, logout, personal account (with two pages with logic), and settings (with four pages with logic). It turns out that if you write everything in one views.py file, it will be too large, as well as forms and urls. Is it possible, for example, to divide the application logic into packages, each with its own views.py, urls.py, forms.py?
Никита
Or is there some other way out?
سید مصطفی
Hello There is another way to load files in html
سید مصطفی
I want to display the files that I have stored in the database in the html file
Rose
I want to display the files that I have stored in the database in the html file
Read this please: http://catb.org/~esr/faqs/smart-questions.html#intro
Oviyan S
I have a problem with my Django code can anyone help me share I can share the code as a document file but not in the group because I'm unable to share documents in good group
Madhur
Can anyone share online platform where I can do DRF hands on. Or please suggest good project for microservice using drf.
Sannon
Hello everyone. Please, How can I fix "KeyError at / 'Unknown language code ht." https://nopaste.ml/#XQAAAQCuAwAAAAAAAAAcjD0szXAaFwlmhCRRCOd4hqA9wTH/4XiBimHp1+8JSINaNr7GA2vjmoWcyhvFcT0F7MY2OVRJZYq7IhWwMFIjqJmasBaq/aUaSA2OkDaAtn3bgHIzniPL9kXxd1g9k7A4DM4jwwDM0VzD2xeJEzu8t77Ly1cWr/LoJUyhc1x7aNYp13PRzzRbP+UCwYXsq71ExNpDJnEORO+mJ9lgPfzA4tNH8i6OfaIPOO6nEbUMC5Hi/stpMrFoNU+ND6AUjCeNLeIUXDNB4wHpI8L0SvQ+a7UDwgMVCZUmqKDCn+gl9fc/VWOxZlHIaFf0SzC6LqFvKDvChS9q5EaXlV0Z7xiykweDirsHe+moa1ZTTofldhK5Imc2+JWDRrHXjHAC5R7+kjL5WCuSAd/LCFtORlF2A3B3kVeLfcch22BAO/RHG4TB7DdwuU4oqo55mncWFfTzTvSA36u6089ewEJ/HaJDaTDHLMlDac2Kxms6pNE5wsAvQGJL9I3TWUXNagD97HBkUrMDfQwHQQSxmXC3oz3YUTrGeQIAL58bxY76c6LsxlTl90+oTZR8XyE0zM4KmwU0M/BZRv/KMcA9
Arsen
An error occurred. Please try again later. (Playback ID: _8sob2IH7ocm2wmO) Learn More i have this problem in my django app how can i fix it?
User
guys i am bit confuse is it necessary to create virtual environment for django project.
User
please answer
User
as there are many tutorials that do not create virtual environment
Eric
guys i am bit confuse is it necessary to create virtual environment for django project.
It's a better choice to use a virtualenv for your Django projects, especially if you want to share then with others via git. Use poetry or pipenv, it'll make your life easier
amin
base on this models: class Cart(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4) created_at = models.DateTimeField(auto_now_add=True) class CartItem(models.Model): cart = models.ForeignKey(Cart, on_delete=models.CASCADE, related_name="items") variant = models.ForeignKey( ProductVariant, on_delete=models.CASCADE, related_name="cart_items" ) quantity = models.PositiveIntegerField(validators=[MinValueValidator(1)]) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: unique_together = [["cart", "variant"]] and this urls: from rest_framework_nested import routers from apps.shop.views.cart_views.cart_view import CartViewSet, CartItemViewSet from apps.shop.views.product_views.image_view import ProductImageViewSet from apps.shop.views.product_views.product_view import ProductViewSet from apps.shop.views.product_views.variant_view import VariantViewSet router = routers.DefaultRouter() router.register("products", ProductViewSet, basename="product") router.register("variants", VariantViewSet, basename="variant") router.register("carts", CartViewSet, basename="cart") products_router = routers.NestedDefaultRouter(router, "products", lookup="product") products_router.register("images", ProductImageViewSet, basename="product-images") cart_items_router = routers.NestedDefaultRouter(router, "carts", lookup="cart") cart_items_router.register("items", CartItemViewSet, basename="cart-items") urlpatterns = router.urls + products_router.urls + cart_items_router.urls and this serializers: class UpdateCartItemSerializer(serializers.ModelSerializer): class Meta: model = CartItem fields = ["id", "quantity"] def to_representation(self, instance): cart_item_serializer = CartItemSerializer(instance) return cart_item_serializer.data def validate(self, data): variant = self.instance.variant quantity = data["quantity"] # validate quantity and stock if not quantity: raise serializers.ValidationError( "Quantity should be a positive number greater than 0." ) if not variant.stock: raise serializers.ValidationError("This product is currently not in stock.") if quantity > variant.stock: raise serializers.ValidationError("Quantity exceeds available stock!") return data class CartItemSerializer(serializers.ModelSerializer): variant = CartVariantSerializer() image = serializers.SerializerMethodField() item_total = serializers.SerializerMethodField() class Meta: model = CartItem fields = ["id", "variant", "image", "quantity", "item_total"] class CartSerializer(serializers.ModelSerializer): items = CartItemSerializer(many=True, read_only=True) total_price = serializers.SerializerMethodField() class Meta: model = Cart fields = ["id", "items", "total_price"] read_only_fields = [ "id", ] and this view: class CartItemViewSet(ModelViewSet): http_method_names = ["post", "get", "patch", "delete"] def get_queryset(self): cart_pk = self.kwargs["cart_pk"] try: uuid.UUID(cart_pk, version=4) except ValueError: raise ValidationError( {"cart_pk": "Invalid cart_pk. It must be a valid UUID4."} ) return CartItem.objects.select_related("variant").filter(cart_id=cart_pk).all() def get_serializer_class(self): if self.request.method == "POST": return AddCartItemSerializer elif self.request.method == "PATCH": return UpdateCartItemSerializer return CartItemSerializer I need to validate cart_pk but the validation should not be in the get_queryset(), so what is the best practice for validate cart_pk ?
User
ok i am going to use vscode for my projects earlier i used pycham in that we dont have to manually create virtual env but in cli we have to create . yesterday i first installed django by mistake and then virtual env and then pycharm and then i uninstalled the virual env so my python path got corrupted i had to uninstall the python now i have installed fresh. And what i want is that django project should be created in d drive so that it should not take my cdrive memory. what should i do ? Should i install virtual env using pip in ddrive or cdrive and then install django in it or i simply install virtual env in cdrive install django in virtual env on same c drive location but for creating projects i should use d drive will it work as i am doing it for my normal python programs i dont want my c drive to get consumed unnecessarily. Please help will it work?
amin
base on this models: class Cart(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4) created_at = models.DateTimeField(auto_now_add=True) class CartItem(models.Model): cart = models.ForeignKey(Cart, on_delete=models.CASCADE, related_name="items") variant = models.ForeignKey( ProductVariant, on_delete=models.CASCADE, related_name="cart_items" ) quantity = models.PositiveIntegerField(validators=[MinValueValidator(1)]) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: unique_together = [["cart", "variant"]] and this urls: from rest_framework_nested import routers from apps.shop.views.cart_views.cart_view import CartViewSet, CartItemViewSet from apps.shop.views.product_views.image_view import ProductImageViewSet from apps.shop.views.product_views.product_view import ProductViewSet from apps.shop.views.product_views.variant_view import VariantViewSet router = routers.DefaultRouter() router.register("products", ProductViewSet, basename="product") router.register("variants", VariantViewSet, basename="variant") router.register("carts", CartViewSet, basename="cart") products_router = routers.NestedDefaultRouter(router, "products", lookup="product") products_router.register("images", ProductImageViewSet, basename="product-images") cart_items_router = routers.NestedDefaultRouter(router, "carts", lookup="cart") cart_items_router.register("items", CartItemViewSet, basename="cart-items") urlpatterns = router.urls + products_router.urls + cart_items_router.urls and this serializers: class UpdateCartItemSerializer(serializers.ModelSerializer): class Meta: model = CartItem fields = ["id", "quantity"] def to_representation(self, instance): cart_item_serializer = CartItemSerializer(instance) return cart_item_serializer.data def validate(self, data): variant = self.instance.variant quantity = data["quantity"] # validate quantity and stock if not quantity: raise serializers.ValidationError( "Quantity should be a positive number greater than 0." ) if not variant.stock: raise serializers.ValidationError("This product is currently not in stock.") if quantity > variant.stock: raise serializers.ValidationError("Quantity exceeds available stock!") return data class CartItemSerializer(serializers.ModelSerializer): variant = CartVariantSerializer() image = serializers.SerializerMethodField() item_total = serializers.SerializerMethodField() class Meta: model = CartItem fields = ["id", "variant", "image", "quantity", "item_total"] class CartSerializer(serializers.ModelSerializer): items = CartItemSerializer(many=True, read_only=True) total_price = serializers.SerializerMethodField() class Meta: model = Cart fields = ["id", "items", "total_price"] read_only_fields = [ "id", ] and this view: class CartItemViewSet(ModelViewSet): http_method_names = ["post", "get", "patch", "delete"] def get_queryset(self): cart_pk = self.kwargs["cart_pk"] try: uuid.UUID(cart_pk, version=4) except ValueError: raise ValidationError( {"cart_pk": "Invalid cart_pk. It must be a valid UUID4."} ) return CartItem.objects.select_related("variant").filter(cart_id=cart_pk).all() def get_serializer_class(self): if self.request.method == "POST": return AddCartItemSerializer elif self.request.method == "PATCH": return UpdateCartItemSerializer return CartItemSerializer I need to validate cart_pk but the validation should not be in the get_queryset(), so what is the best practice for validate cart_pk ?
fixed: class CartItemViewSet(ModelViewSet): ... def validate_cart_pk(self, cart_pk): try: uuid.UUID(cart_pk, version=4) except ValueError: raise serializers.ValidationError( {"cart_pk": "Invalid cart_pk. It must be a valid UUID4."} ) def update(self, request, *args, **kwargs): cart_pk = self.kwargs["cart_pk"] self.validate_cart_pk(cart_pk) return super().update(request, *args, **kwargs)
SK
Hi all, can someone help on below how to call the respective attribute from database and display those fields only and execute the function to respective attribute... Not getting an idea how to proceed
Rose
User Muhammadali has 1/3 warnings; be careful! Reason: learn how to share code
amin
How can I generate simulated traffic on my Django application running locally, to test and monitor performance under a high volume of requests?
Toni Fer.
Hi everyone, sorry, I am new developing with Django and I'd appreciate your help. I want let the users upload en excelword file but I want to know how can I prevent that somebody uploads a file with virus... is there an easy eay to manager it? Thanks
Java
Good afternoon, do you generally work in django with views based or in classes with views based on functions? Thank you for your responses
Java
I understand, thank you very much. One last question, how bad is the job market currently? I ask because I have projects and I study but I go to LinkedIn and I see proposals where they almost ask you to have an infinity jewel and above all I see that there are many applicants...