Monday, January 29, 2018

Re: Get request, has PK, how do I access the PK data with in the model

Hi,

It's really hard to understand what you exactly want.

Without showing your code it'll be even harder to understand how / what you want to do. We have to guess from the little information you are giving.... However. if you want to query cars with the same year as the user for example, you could do this:

user = User.objects.get(pk=1)
cars = Car.objects.filter(year=user.birthday.year).all()

Regards,

Andréas

2018-01-29 14:30 GMT+01:00 Travis Pickle <travisray2004@gmail.com>:

I'm assuming not a single person has read what is in my body of my message and has only read the subject. I know bots have read the body.

if
http://somesite.com/user/1 ,where 1 is the pk,
i want to use in the view pk relation to gather all fields, and use fields to generate other query sets to pass to the templates

user model has

name
birthday
gender

and car model has
make
model
year
description
and

profiles just have a one-to-one relationship to users
favorite_car
location
..etc

so for example, this isn't data isn't what i am working on, but it gets me to where i need to. I want to lookup(get_objects) where cars age is same as user PK 1, and also want to look up other users around same age, and report location.


Cant really disclose the code of this project at this time. but just note, I am trying to look for objects based on values from PK1. if I knew how to assign them, and then use it for a search it would have different questions.





On Monday, January 29, 2018 at 4:30:03 AM UTC-5, Daniel Roseman wrote:
On Sunday, 28 January 2018 19:01:35 UTC, Travis Pickle wrote:
I am using django 1.8.

I read though the docs, however, i not seeing how I can get the PK other attributes to use in model searching. 

As others have stated, this is *fully* covered in the tutorial, specifically in part 3. Potted answer, though: you capture it as a URL argument and accept it in your view function. If you've read that part of the tutorial and still can't work it out, you'll need to post some actual code.
-- 
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/da574efa-cfc8-47fc-8441-a9168e005e15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCfAJwN3vpGcTtjys1rk_QU6wq9_tK1Aq5htHfgKU%2BsR%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment