#Model Query Issues
88 messages · Page 1 of 1 (latest)
customer/views https://pastebin.com/LaKUWB18
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
that's the error when going to a customer detail
what im trying to do is when i go to a customer detail page, it loops through the addreses associated with the customer
Its set to private or doesn't exist
So can't really see the entire error message
Consider using https://hastebin.skyra.pw/ next time maybe?
This one is interesting
def CustomerDetail(request, cpk):
customer = Customer.objects.get(Customer.id)
customeraddresses = Address.objects.filter(customer)
customer_detail = Customer.objects.get(id=cpk)
context = {'customer_detail':customer_detail, 'cpk':cpk, 'customeradresses':customeraddresses }
return render(request, 'customer/customerdetail.html', context)
'''
# this one works
def CustomerDetail(request, cpk):
customer_detail = Customer.objects.get(id=cpk)
context = {'customer_detail':customer_detail, 'cpk':cpk }
return render(request, 'customer/customerdetail.html', context)
'''
Why does the one that "works" commented? Why not use that?
You could continue and get the customer address from there
Something like
def CustomerDetail(request, cpk):
customer = Customer.objects.get(id=cpk)
customeraddresses = Address.objects.filter(customer)
context = {'customer_detail':customer, 'cpk':cpk, 'customeradresses':customeraddresses }
return render(request, 'customer/customerdetail.html', context)
i commented it out because its the one that doesnt crash the site and copied it to try to add the functionality, i will try your suggestion real quick, thank you so much
https://hastebin.skyra.pw/rureyomiwi.htm is what i get when i use that code, im going to github this stuff soon, i freaked myself out when i accidentally deleted all of my code one time from noodling around with a github extension
i was thinking maybe the foreignkey relationship is screwed up maybe? like maybe it should be a many to one relationship
thank you so much for helping me by the way
im going to TRY to pay it forward in the chat
just hit me in the head if im wrong
i use pastebin because i just want to be able to get back to my paste😠😠ðŸ˜
i stuck all of this stuff in a github, should i make it public so people on discord can see it?
yeah
its been awhile so what's the problem? I recall that the "customer detail" view function should have worked?
it didnt, says the objects not interable or something like that, let me try that again
There's no requirements.txt file. I assume there's no other dependencies other than Django?
TypeError at /customerdetail/3
cannot unpack non-iterable Customer object
Request Method: GET
Request URL: http://127.0.0.1:8000/customerdetail/3
Django Version: 5.0.1
Exception Type: TypeError
Exception Value:
cannot unpack non-iterable Customer object
Exception Location: /home/pangaea/dev/nine11/env/lib/python3.10/site-packages/django/db/models/sql/query.py, line 1481, in build_filter
Raised during: customer.views.CustomerDetail
Python Executable: /home/pangaea/dev/nine11/env/bin/python
Python Version: 3.10.12
Python Path:
['/home/pangaea/dev/nine11/nineeleven',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/home/pangaea/dev/nine11/env/lib/python3.10/site-packages']
Server time: Sun, 12 May 2024 16:13:39 +0000
how do i make that
pip freeze > requirements.txt
done
that was so easy a caveman could do it🤣
alright
I've set up Django and opened up the browser. How do I trigger this error?
click customers then a name
https://imgur.com/a/9FhfbH5 there's no customers data to click
oh crap
its in the database
its on my own server at home
OK but how do I add customer data?
After clicking "Add Customer" button, there's nothing to fill in
i add the customers from the admin, i havent created the form for adding customers yet
Environment:
Request Method: GET
Request URL: http://localhost:8000/customerdetail/1
Django Version: 5.0.6
Python Version: 3.10.13
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'address',
'authentication',
'customer',
'permits']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/workspaces/nineeleven/customer/views.py", line 18, in CustomerDetail
custaddresses = Address.objects.get(customer=customer_detail)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/query.py", line 649, in get
raise self.model.DoesNotExist(
Exception Type: DoesNotExist at /customerdetail/1
Exception Value: Address matching query does not exist.
😠😠ðŸ˜
need to have an address with the same customer assigned to it
add an address, with the customer you added
what is supposed to happen is you add a customer, or addresses, or both, then when you go to the address it lists the owner associated with it
or when you go to a customer it lists ALL of the addresses for the customer
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
yes that what i get
Its the same error as you "unpack value" error
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
This is incorrect way of using filter:
customeraddresses = Address.objects.filter(customer)
maybe i need to specify a many to one relationship somewhere
You need to specify the other field and its value
Try this:
def CustomerDetail(request, cpk):
customer_detail = Customer.objects.get(id=cpk)
custaddresses = Address.objects.filter(customer__id=cpk)
context = {'customer_detail':customer_detail, 'cpk':cpk, 'custaddresses':custaddresses }
return render(request, 'customer/customerdetail.html', context)
oky
And then in your jinja template change it so it loads the individual customer address:
{% for i in custaddresses %}
{{ i.street }}
{{ i.city }}
{{ i.state }}
{{ i.zip }}
{% endfor %}
howd you get so good
practice
np
do i owe you anything
You're not obligated to
You could buy me coffee. https://buymeacoffee.com/qoyyuum
Again, no pressure
I just like helping ppl 🙂
Wow thanks!
yessir
ill need you more soon i imagine
hahahaha
haha
if not at least for a swift kick in the ass