Anonymous
[<CartItem: Royal Watches 2>, <CartItem: Royal Watches 2>] i want this from it ['Royal Watches 2','Royal Watches 2',] how can i do this
Anonymous
sorry from this <QuerySet [<CartItem: Royal Watches 2>, <CartItem: Royal Watches 2>]> bro i am beginner so i don't know that much
Вин Король Саксов
sorry from this <QuerySet [<CartItem: Royal Watches 2>, <CartItem: Royal Watches 2>]> bro i am beginner so i don't know that much
If you are begginer go learn django, I don't know what you want to get from queryset, learn how to work with it, and you will understand why you dont need list for this
Вин Король Саксов
Queryset is already a list(simplified)
Вин Король Саксов
I still don't understand what you want, but if you need to 'connect' two queryests into one you can do that with: queryset1 |= queryset2
Anonymous
i don't want to connect them i am working on ecommerce website in which i want to merge the two carts 1 cart = local withou login 2 cart = online on database
игорь/igor
sorry from this <QuerySet [<CartItem: Royal Watches 2>, <CartItem: Royal Watches 2>]> bro i am beginner so i don't know that much
Watch some videos on YouTube at least to get familiar with django. I don't sometimes understand you people are jumping into building e-commerce without getting familiar. Start from basics, please.
Anonymous
Watch some videos on YouTube at least to get familiar with django. I don't sometimes understand you people are jumping into building e-commerce without getting familiar. Start from basics, please.
bro didn't jumped i purchased the udemy cource and teacher directly started this his code is working mine not can you suggest any another course i am going to cancel that one
First name (optional)
Hi, how can I add some extra key/values to cleaned_data ? I mean, I have a form with x and y fields, but I want a "z" in my cleaned data which is the result of x + y
игорь/igor
bro didn't jumped i purchased the udemy cource and teacher directly started this his code is working mine not can you suggest any another course i am going to cancel that one
Don't know what to advise you, I never bought courses, there are tons of stuff on YouTube. Just start from basics, blog with comments, auth, tags, categories or even a todo-app.
Anonymous
Don't know what to advise you, I never bought courses, there are tons of stuff on YouTube. Just start from basics, blog with comments, auth, tags, categories or even a todo-app.
i will but here is final code that i need try: if user is not None: cart = Cart.objects.get(cart_id = _cart_id(request)) cart_item = CartItem.objects.filter(cart=cart) prodcut_vari = cart_item.values_list('product__name', flat=True) prodcut_vari = list(prodcut_vari) print(prodcut_vari) cart_item = CartItem.objects.filter(user=user) ex_vart = cart_item.values_list('product__name', flat=True) ex_vart = list(ex_vart) id = [] for i in cart_item: id.append(i.id) for pr in prodcut_vari: if pr in ex_vart: index = ex_vart.index(pr) item_id = id[index] item = CartItem.objects.get(id=item_id) item.quantity +=1 item.user = user item.save() else: cart_item = CartItem.objects.filter(cart =cart) for item in cart_item: item.user = user item.save() else: pass auth.login(request,user) return redirect('home')
Anonymous
thanks a lot to everyone now i will start from youtube
Asadbek
Hi, how can I add some extra key/values to cleaned_data ? I mean, I have a form with x and y fields, but I want a "z" in my cleaned data which is the result of x + y
just use them like z = form.cleaned_data['y'] + form.cleaned_data['x'] that there is no advetage appending extra key/values to it, I guess.
First name (optional)
First name (optional)
First name (optional)
I tried to declear a new field named z and then in clean_z() I did return x + y but unfortunately it won't show up in cleaned_data
First name (optional)
do you want to save the data in that fields ?
Yes I want to save something like x + y in z
First name (optional)
to your model
No, not model
Asadbek
No, not model
what else ? or they should be rendered in views ?
First name (optional)
what else ? or they should be rendered in views ?
Yes it's just a regular form which will be rendered in templates
Asadbek
Yes it's just a regular form which will be rendered in templates
cleaned_data is dictionary , so maybe you can use update method like that s = {} s.update({'a' : 1}) # adding 'a' key with value of 1 then you can use s['a'] like that it will return -> 1
First name (optional)
cleaned_data is dictionary , so maybe you can use update method like that s = {} s.update({'a' : 1}) # adding 'a' key with value of 1 then you can use s['a'] like that it will return -> 1
I want to add the z to cleaned_data using the form class itself. I mean like: class MyForm(Form): x = ... y = ... z = ... def clean_z(self): return self.data.get("x") + self.data.get("y") THEN IN VIEWS: form = MyForm(request.POST) form.is_valid() print(form.cleaned_data) And I expect this result: {"x":1, "y":2, "z":3} But it shows: {"x":1, "y":2} ( I did not rendered z in my template )
B
This is my url in postman what should be the url for urls.py in http://127.0.0.1:8000/api/v1/division/list/?school_id=d7a72306-046b-40ff-9d01-d0252507e4c7
B
This is my url in postman what should be the url for urls.py in http://127.0.0.1:8000/api/v1/division/list/?school_id=d7a72306-046b-40ff-9d01-d0252507e4c7
I tried this but not working. re_path(r'^api/v1/division/list/(?P<school_id>[\w\d-]+)/$', division_view.get, name='list'),
First name (optional)
dont put z as field in form , simply get z in your view diectly through request.POST['x']+request.POST['Y']
Need validations on z. x + y is simplified function, it's not the actual thing I want
First name (optional)
def clean_additional_costs(self): keys = self.data.getlist('additional_costs_key') values = self.data.getlist('additional_costs_value') cleaned_keys = list(filter(lambda x: x not in [None, '', ' '], keys)) cleaned_values = list(filter(lambda x: x not in [None, '', ' '], values)) if not len(cleaned_keys) == len(cleaned_values): raise forms.ValidationError( "invalid len!", code="invalid_len", ) return dict(zip(cleaned_keys, cleaned_values))
First name (optional)
clean_additional_costs is clean_z
игорь/igor
clean_additional_costs is clean_z
My guess is that you can override form's clean() method, thus your fields gonna be validated and you gonna have access to form's errors, you would be able to use add_error() method to your z field.
First name (optional)
Seems clean_z only runs when I render it in template and there is something like z_htmlName in my POST data
игорь/igor
игорь/igor
Yes i guess it's possible but I coudn't find out how to add z to it and also run clean_z
Why do you need to run clean_z if z is dependent on other fields, might be a stupid question though. And yeah, why not just use clean_z() method. Or z.validate(). Data is cleaned when validation begins, so you would have access to cleaned_data. Read https://docs.djangoproject.com/en/3.2/ref/forms/validation/
Mitnick_Mady
raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: WSGI application '(my_app_name).wsgi.application' could not be loaded; Error importing module. Can anyone help for this error?
First name (optional)
Why do you need to run clean_z if z is dependent on other fields, might be a stupid question though. And yeah, why not just use clean_z() method. Or z.validate(). Data is cleaned when validation begins, so you would have access to cleaned_data. Read https://docs.djangoproject.com/en/3.2/ref/forms/validation/
z needs to be validated to check if len(x) and len(y) are equal after filtering None and empty input values, then return them as a zip, so each x key have a y value, otherwise raise an error in form The problem is clean_z will not run at all
First name (optional)
x and y are a fieldset for additional costs, they are connected to each other on template x is title and y is price User can clone() [ in js ] them and add more additional costs So if user send 10 x and y they all have same names and ids Then I need to bind all that additinal costs to each other, so any title have a price I want to have access to these as a dict in z field
игорь/igor
is_valid() should trigger any validations even custom, but you need to tell your form fields to use specific validation. Sorry if I am not helpfull
First name (optional)
is_valid() should trigger any validations even custom, but you need to tell your form fields to use specific validation. Sorry if I am not helpfull
Validation is decleared in clean_z, please reffer to the code I've sent But it won't run it, like z field doesn't exists at all
N3CRO
Anyone who acknowledges the heroku deployment for django project pls dm me i am stuck in and i need help
First name (optional)
You can validate in your view and add error in form from there also
Yeah it's a way but I wanted to use form :( I guess I have to validate in views anyway
Optimus
Yeah it's a way but I wanted to use form :( I guess I have to validate in views anyway
Yeah ultimately u gonna push error in form only, that can be done through view also
Parsa
Hi guys I I'm expert in Python and I know also OOP , how can I learn Django?
Vasilii
Alex
It's better than YouTube?
Did you learn python and oop on youtube?
Vasilii
reading is faster, it's only begginer's guide
Vasilii
next you can build an ecommerce site or blog, I think blog will be better for begginer
Parsa
Did you learn python and oop on youtube?
No, I have learned it by training and by persian articles
Vasilii
I think it's enough to start with
Vasilii
then you will know what to google
Parsa
Alex
It's better than YouTube?
Don't mess a framework itself and what you can do with it. The docs describe at least 90% of what you need to know about django. On the other hand - creation of applications is a matter of oo-decomposition and architecture.
Alex
Does documentary teach this?
If you ask such a question, I would advise you to recheck your knowledge of OOP for it seems you know not much than "classes have methods and can go inheritance"
Abhinav
I am facing an error /ws not found. It seems that it cannot read the routing.py URL pattern but working fine when using python manage.py runserver. Hosted on AWS Ec2 instance ubuntu Any idea why?
B
Hi who know django best
Gordrick
Hi who know django best
Do you have a specific question
Doragonsureiyā
Hi who know django best
Don't ask meta questions like: "Any user of $x here?" "Anyone used technology $y?" "Hello, I need help on $z!" Just ask directly! The better you are at explaining the problem, the more likely you are to get help. Asking smart questions
N3CRO
Guys can anyone get me rid out of my django hosting issue on heroku?
Tonnie
Hello guys I am building a blog website using django. I have already configured everything except the logic of how the content will be posted so as to be viewed on the web. Any help please