Questions tagged as 'django-queryset'

3
answers

Annotate: Returning the cheapest product and vendor name (Django)

Given the following table product;company;price AAAAA;forn1;395.69 BBBBB;forn1;939.45 CCCCC;forn1;480.33 DDDDD;forn1;590.59 EEEEE;forn1;847.69 AAAAA;forn2;227.31 BBBBB;forn2;375.90 CCCCC;forn2;602.18 DDDDD;forn2;615.02 EEEEE;forn2;84...
asked by 03.09.2015 / 18:32
2
answers

Access related table columns via ORAN DJANGO

How to access the object user and its attributes after a join ? This is my query Idea.objects.select_related("user").values("author_id").annotate( qtd=Count('author_id')) Example of a result: <QuerySet [{'author...
asked by 22.11.2018 / 15:29
1
answer

Django and Oracle database (accessing your views via ORM)

Hello, despite the self explanatory title. I'll detail my doubt below. I have a pre-existing Oracle database, I integrated it with django by configuring the default connection in settings and running manage.py inspectdb > _models.py. So cr...
asked by 24.05.2017 / 04:58
1
answer

How to return objects num many to many Django

Consider the template class Dealership(models.Model): dealership = models.CharField(max_length=50) class Ordered(models.Model): customer = models.ForeignKey("Customer") dealership = models.ManyToManyField("Dealership") status...
asked by 16.06.2015 / 04:39
1
answer

Improving the return of a specific result

I think I'm unlearning the basics! I have a result that returns only one element in the dictionary: [{'quant': 236, 'district': 'Centro'}] My context is: context['Districts'] = d As I do in the template I write something like {{ D...
asked by 07.06.2015 / 04:24
1
answer

How to count people by age

I have class Person(TimeStampedModel, Address): name = models.CharField(_('nome'), max_length=100) birthday = models.DateField(_('data de nascimento')) and the function import datetime from datetime import date ''' http://keyes.i...
asked by 08.06.2015 / 08:53
2
answers

Get logged in to Django globally

All my models have relationship with User , and by default all my query_set will be made based on the user logged into the system. How would you do to get the user logged into any area of the app, for example the model , why will...
asked by 26.04.2017 / 19:25
2
answers

Group by Day in Django

Does anyone have an example of a "bat-ready" grouping by date? I've tried all of this here ... Subscription.objects.extra(select={'day': 'date(created_at)'}).values('day').annotate(available=Count('created_at')) from django.db.models.aggregat...
asked by 22.01.2016 / 23:08
1
answer

Difference between get_context_data and get_queryset and code improvement (Django)

I wanted to know the difference between get_context_data and get_queryset. And I'd like to hear from you about my codes. What is right and what is wrong with them? link class SaleDetailView(DetailView): template_name = 'vendas/s...
asked by 18.06.2015 / 04:20
1
answer

QuerySet model Category, Product and ProductImage

Hello, help me build this queryset. Briefly, the model model.py class Category(models.Model): name = models.CharField('Nome', max_length=100) slug = models.SlugField(max_length=100, unique=True) created = models.DateFiel...
asked by 08.02.2017 / 00:09