Hello, You need to clearly understand Python objects because the ORM maps fields directly to that.
Please check out: https://docs.djangoproject.com/en/2.0/topics/db/queries/ So if you print out the object as a string i.e. people = People.objects.al() print people OR person = People.objects.get(pk=1) print person The string returned by the __str__ or __unicode__ method is what is displayed. To access other columns you need to access the attributes like: person.address or person.occupation. Through foreign keys too e.g. person.town.name. Read through the docs and follow those examples first. You'll easily understand thereafter. Kind regards On Sat, May 12, 2018 at 9:12 AM, Gerald Brown <gsbrow...@gmail.com> wrote: > I was getting the same as you are as I had just first_name & last_name set > in the "def __str__(self)". I added a couple of more fields to that > statement but they are still not showing up even after running a > makemigration which says "No Change" > > I tried "p.address" but it gave me an error message, (which I don't > remember) as I did not know about the "[]"s. Now if I do "p.[0].address" > it gives me the address. Also if I do "p[0].town" it show me the town name, > which is in another table and is a FK to that table. > > Like I said in my original message, I am just starting to use Django > Queries so there is a lot to learn so I thank you for your assistance. > > On Saturday, 12 May, 2018 01:34 PM, Mark Phillips wrote: > > Please provide the exact output you are seeing. It may be that the output > has been truncated, which is correct behavior. > > For example, when I run this query on the command line for my model > Document, > > >>> Document.objects.all() > <QuerySet [<Document: a new title 2>, <Document: adfadfasdf>, <Document: > gggggg>, <Document: the title>]> > > I get a QuerySet with 4 entries, as there are 4 rows/records in the > Document table. All the fields are there, just not shown. The __str__ > method in the Document model returns the title of the document, which is > what is shown above for each Document in the QuerySet. I am guessing but > your People table probably defines the __str__ method to return the first > and last name. > > I can look at one of the returned rows like this: > > >>> d=Document.objects.all() > >>> d[0] > <Document: a new title 2> > >>> d[0].document_id > 2 > >>> d[0].title > 'a new title 2' > >>> d[0].description > 'a new description 2' > >>> d[0].document_state > 1 > >>> d[0].storage_file_name > <FieldFile: c4b592c8-662c-437a-819e-c36df8867a9c.png> > >>> > > title, document_id, description, and storage_file_name are all fields > defined in the model for Document (along with others). > > Read the django documentation about models and queries for more > information. > > Mark > > On Fri, May 11, 2018 at 9:34 PM, Joseph Mutumi <jjmut...@gmail.com> wrote: > >> Hello, >> >> That's strange what does your people model look like? Notice it >> will only populate the fields you have defined in the model not >> the columns of the table in the database. >> >> Did you run migrations after adding new fields to the model? >> $ python manage.py migrate >> >> Kind regards >> >> On Sat, May 12, 2018 at 5:15 AM, Gerald Brown <gsbrow...@gmail.com> >> wrote: >> >>> Greetings: >>> >>> I have just started to use Django Queries and I am having some problems. >>> >>> When i use the query: "p = People.objects.all()" & then "p" it shows >>> just the lastname & firstname fields even though there are many more fields >>> in the table. >>> >>> I thought ALL means ALL, ALL fields & ALL records!!! >>> >>> Only 2 records so far in the DB and it shows both of them so ALL RECORDS >>> is working. >>> >>> Another table I have has a date field and a ForeignKey to the people >>> table plus some additional fields. The query returns the date and the >>> firstname and lastname from the people table ONLY. >>> >>> It looks like it is only showing the first two fields in the table. >>> >>> Any ideas on how I can get it to show ALL fields? >>> >>> Thanks. >>> >>> -- >>> 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+unsubscr...@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/ms >>> gid/django-users/7e90ad4d-bffe-5690-2559-ec4655fc79b6%40gmail.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+unsubscr...@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/ms >> gid/django-users/CAN5idp8%2B4gx6_MOoXT-JAsbq4nbZLAZj%3DTL8MD >> Md%2Bg_oQwip2A%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAN5idp8%2B4gx6_MOoXT-JAsbq4nbZLAZj%3DTL8MDMd%2Bg_oQwip2A%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> >> >> 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+unsubscr...@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/CAEqej2N-WCBwQX9s2r3E2bRKDPMbd% > 2B1Hg2xFN7AoSxaVDQQu2A%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAEqej2N-WCBwQX9s2r3E2bRKDPMbd%2B1Hg2xFN7AoSxaVDQQu2A%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > 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+unsubscr...@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/c2eb898e-cf9a-ca70-b3d1-8d37e437fa7f%40gmail.com > <https://groups.google.com/d/msgid/django-users/c2eb898e-cf9a-ca70-b3d1-8d37e437fa7f%40gmail.com?utm_medium=email&utm_source=footer> > . > > 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+unsubscr...@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/CAN5idp_S%3D1XZTJDo4nqFw3oYouSO8icKsKCkRghu1n8fVfe7NA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.