django


Invalid distinct with django


I try to get a cars list on my Django project but i'm in trouble with ORM
class Car(models.Model):
name = models.CharField(max_length=200)
owner = models.ForeignKey(User)
With Car.objects.all() I have a list as:
- car#1, user#1
- car#1, user#2
- car#1, user#3
- car#2, user#4
- car#3, user#4
what I would like is:
- car#1
- car#2
- car#3
Then, all cars are distinct by the name, regardless of owner
I've try something like
Cars.objects.all().annotate(Count('owner', distinct=True))
but I still have all cars. Can someone help me with this point ? Documentation suggests annotate and aggregate but it's still hars to understand it.
try this
Cars.objects.values('name').distinct()

Related Links

How do I gather objects related to this primary key
docker-compose service version error
Django. Download Image with requests - edit with PIL - save to model
Django if statement that will affect the front page of the website?
Where to see the logging.error() message i put in code when visit a page using azure web portal
How do I remove the parenthesis from my bs4 results
About Codeanywhere python version
Django model loses its relationship ForeignKey while form is saved
Django Install Not Visible - No Errors
Working with annotation in Django queryset
store data in the log files
Force the Django admin to display in English
Django audiofield
Django Raven only logs once to Sentry
list index out of range in django
How to add custom page to django admin with custom form, not related to any Model?

Categories

HOME
delphi-7
fuelux
css3
pda
pyqt
requirements
cublas
entity-framework-core
x264
nuget-package
syntaxnet
project
octave
reactive-programming
watson-conversation
onedrive-api
plink
libusb
do-while
powershell-v5.0
intershop
swagger-2.0
breadth-first-search
short-url
comparator
ckfinder
froala
dapper-extensions
onload
handler
android-things
python-2.6
biztalk-rule-engine
engine.io
hivemq
docfx
spring-mvc-test
watchface
apollostack
file-sharing
berkeley-db-je
photos
term
remedy
pair-programming
skin
check-mk
jtree
rocks
microstation
dimension
avspeechsynthesizer
swizzling
bizagi
kiosk
yajsw
user-management
state-restoration
assertion
rewrite
computer-architecture
lazybones
jdi
video-player
opserver
dock
toolkit
lasso
dulwich
airbrake
entity-framework-4.3
osc
uncaught-typeerror
jbake
android-vibration
punycode
genymotion-call
codeplex
cancellation
winginx
ios8-extension
multiautocompletetextview
qscrollarea
rfc5322
mysql-error-1044
mysql-error-2013
fb.ui
android-loadermanager
monotouch.dialog
garbage
winmain
unattended-processing
diagrams
commerceserver2007
metaweblog
resharper-6.0
updatesourcetrigger
non-clustered-index
office-2007
folding
zend-rest
opml
nstokenfield
wordprocessingml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App