how can i get all values of a field

40 views
Skip to first unread message

dotaa...@gmail.com

unread,
May 23, 2014, 8:36:57 AM5/23/14
to django...@googlegroups.com
In Models i declare Novel: name,category
table structure:
---------------------------------------
id    |   name   |    category
---------------------------------------


now i want to get all category,but i have no idea,who can help me?

my english is poor,please don't joke me

carlos

unread,
May 23, 2014, 11:12:13 AM5/23/14
to django...@googlegroups.com


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27a36b70-7f89-4a02-97d5-a5e27789068e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dotaa...@gmail.com

unread,
May 23, 2014, 10:23:28 PM5/23/14
to django...@googlegroups.com
i can't find a more effective method from the documentation,but thank you all the same

在 2014年5月23日星期五UTC+8下午11时12分13秒,sacrac写道:

Jonathan Querubina

unread,
May 23, 2014, 10:33:38 PM5/23/14
to django...@googlegroups.com
Hi dota and java,

If your model for the categories is Category, you would use:

Category.objects.all()

Sent from my iPad

Lachlan Musicman

unread,
May 23, 2014, 11:13:55 PM5/23/14
to django...@googlegroups.com
No, that wouldn't work because Category looks like a var on Novel, not
a model in it's own right.

Novels.objects.filter(category="comedy") is how to get a distinct category.

To get the list of categories used, use distinct for a quick hack -
something like:

Novel.objects.order_by('category').distinct('category')

Cheers
L.
> https://groups.google.com/d/msgid/django-users/4800DB60-6DD7-43A1-9B1F-2E518C56242F%40gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
The idea of anathematising all of a person’s good works because of
something else they said or did is just as alien and repellent to us
as our reaction is to someone who wishes Hacker News would die because
Paul Graham is kind of a dick sometimes. ... Sergey Bratus points out
that keeping works by “ideologically impure” persons out of public
view was instrumental to Soviet systems of social control. And as
@puellavulnerata acutely observes, a culture that encourages judging
people unilaterally, rather than judging their actions in context, is
one that allows socially-adept hierarchy climbers to decontextualise
their own self-serving cruelties as “necessary for the cause” and
stage witchcraft trials against the weirdoes on the margin.
-----------------------------------------------------------------------------------------------------------
https://medium.com/p/31895b01e68c
Reply all
Reply to author
Forward
0 new messages