Most voted "django-queryset" questions
38 questions
Sort by count of
-
6
votes3
answers450
viewsAnnotate: Returning the cheapest product and supplier name (Django)
Given the table below 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…
-
5
votes1
answer178
viewsWhat is Lazy, Laziness in Python/Django?
I’m starting to program and reading the documentation from Django, I saw some references about lazyObject, about Django being Lazy and that Querysets sane Lazy. I’ve done some research but I haven’t…
-
3
votes1
answer353
viewsHow 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…
-
2
votes1
answer64
viewsImproving the return of a specific result
I think I’m letting go of the basics! I have a result that returns me only one element in the dictionary: [{'quant': 236, 'district': 'Centro'}] My context is: context['Districts'] = d How do I make…
-
2
votes1
answer848
viewsHow to return Objects in a Many to Many Django
Consider the model class Dealership(models.Model): dealership = models.CharField(max_length=50) class Ordered(models.Model): customer = models.ForeignKey("Customer") dealership =…
-
2
votes1
answer467
viewsDjango and Oracle database (accessing your views via ORM)
Hello, despite the title self explanatory. I will detail my doubt to follow. I have a pre-existing Oracle database, integrated it with Django by configuring the default connection in Settings and…
-
2
votes2
answers763
viewsAccess related table columns through ORM DJANGO
How to access the object user and its attributes after a join? This is my consultation Idea.objects.select_related("user").values("author_id").annotate( qtd=Count('author_id')) Example of a result:…
-
1
votes1
answer1346
viewsDifference 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 would like to know your opinion about my codes. What’s right and what’s wrong in them?…
-
1
votes2
answers602
viewsGroup by Day in Django
Does anyone there have an example of a "bat-ready" grouping by date? I tried all this here... Subscription.objects.extra(select={'day':…
-
1
votes3
answers1776
viewsGet user logged in to Django globally
All my models has relationship with the User, and for default all of mine query_set will be made based on the user logged in to the system. How would you get the user logged in to any area of the…
-
1
votes1
answer57
viewsRelationship Problems between "Table" and Django User
I am working with Django to develop an application for a Help Desk, I have the following situation: I have a table named "Unit" that will be the table responsible for separating my systems into 4 or…
-
1
votes1
answer1442
viewsPick a select value in Django
The HTML code: <!doctype html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,…
-
1
votes4
answers92
viewsField match, referenced in previous field
I started learning about Python from Jango and am trying to develop a simple vehicle management system. I am beating head to perform the following procedure: as soon as the registration plate is…
-
1
votes1
answer246
viewsDropdown with dynamic options in Django form
I have an expense form that has a field to select the category, but I need the options to be obtained from the database. These days this is mine forms.py: from django import forms from .models…
-
1
votes1
answer420
viewsqueries in Django’s views and template
I have two tables (Client) and (Animal), the animal table is related through a Foreign key with the Client table, currently I can register only client, register client and animal together, in the…
-
1
votes1
answer161
viewsHow to use a Python function in Django
I’m currently having a problem where I haven’t found any solution that I’ve been able to understand and execute. I will be summarizing here the scope of what I need, otherwise it would be very…
python-3.x django django-templates django-rest-framework django-querysetasked 4 years, 2 months ago Bruno Marques 21 -
1
votes0
answers75
viewsHow to perform a Queryset returning the biggest date with Django
I’m trying to perform a Queryset using Django, I want to return the most recent dates present in the database, along with the other fields, where I used the prefetch_related(). However, the use of…
-
0
votes1
answer744
viewsUsing search and pagination field with Function Based View in Django
I have the following code: #decorators.py from django.contrib.auth.decorators import user_passes_test def superuser_required(func): return user_passes_test( lambda u: u.is_authenticated() and…
-
0
votes1
answer104
viewsQueryset model Category, Product and Productimage
Hello, help me assemble 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)…
-
0
votes0
answers68
viewsMultipleobjectsreturned
When I create two topics with the same name, error:Multipleobjectsreturned class ForumView(ListView): paginate_by = 5 template_name = 'forum/forum.html' def get_queryset(self): queryset =…
-
0
votes1
answer70
viewsSET TIMEZONE in raw query
The raw query below shows the following error: query = Resume.objects.raw(""" SET TIMEZONE='America/Sao_Paulo'; SELECT id, datetime_now FROM resume; """) raise AssertionError("database connection…
-
0
votes1
answer196
viewsHow to filter an Apiview to show messages related to a user?
I want to create a view using Apiview, which shows all messages sent by a user specified in the url. py.models: class Message(models.Model): body = models.CharField(max_length=500) normaluser =…
-
0
votes1
answer131
viewsHow to create tuple with key receiving value?
I would like to create a method that returns the Django ORM FILTER parameters. I will have to use these filters at various times, I would like to create this generic method. Follow the example: def…
-
0
votes1
answer145
viewsChoices values are being stored like this ['Dog', 'Cat', 'Birds']
I have a system that will have the option of choosing 1 or multiple options in the same field. Bad problem is that I need my field inside the model to be charfield and in Forms to be…
-
0
votes1
answer59
viewsGenerate a context from another instance in Createview
Hello! I need to render a context in the Createview template. no requeste to passing an id, and I want to put the name of that id in the Createview template py.url urlpatterns = […
-
0
votes1
answer120
viewsDjango associative table query
Well... I’m trying to do an application on Django for residential energy consumption... I have three tables: Environment, Device and an associative, Appareil_environment where I have foreign keys to…
-
0
votes1
answer249
viewsDjango - Filter queryset into a form using a value present in the view
I am creating this site where the first step of the user is to create the company he works for: ''''models.py''' class Empresa(models.Model): cnpj = models.CharField(unique=True, max_length=20,…
-
0
votes0
answers25
viewsQueryset to select maximum values per group - using mysql
I am trying to select the highest values per group and I would like to receive all attributes from my table, tried this solution: dropWorst1 =…
-
0
votes0
answers19
viewsDjango Favorite view
I’m trying to create a favorite button for an app’s posts, but I can’t figure out how to create one because it contains an entire number. When the user clicks on the favorite button. The button will…
-
0
votes2
answers22
viewsDjango queries Related Objects
So with two models created : class Questao(models.Model): texto = models.CharField(max_length=220) quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE) created =…
-
0
votes1
answer16
viewsUse of _set in Django framework
I’m following the framework tutorial but I got lost in the use of the command _set of the shell initialized by python manager.py shell. The sequence of commands is as follows:: from polls.models…
-
-1
votes1
answer25
viewsError in the user’s Manytomanyfield link
I’ve created a routine where you register a cost center. This cost center is linked through a Manytomanyfield when I register the User. Below the models.py of these registration: user models: class…
-
-1
votes1
answer322
viewsDjango: Form not saved in Django database
When I click to register the page simply refreshes and nothing is saved in the database. In the Django console I get the message: "GET /people/ HTTP/1.1" 200 898 "POST /person-add/ HTTP/1.1" 200 898…
-
-1
votes1
answer900
viewsAttributeerror: 'list' Object has no attribute '_meta'
I’m trying to edit an object but I’m not being able to instantiate it by the desired id filter to show in my form and edit. Django 2.1.15 Python 3.8.1 my views.py def Alterar_Pessoa(request, id):…
-
-1
votes1
answer41
viewsHow to relate two form Fields in Django?
Good afternoon! I am new to Jango and I am creating a system that will serve as a spreadsheet to help in the analysis of some demands. The demands will be a certificate called CAT requested by…
-
-1
votes1
answer31
viewsHow to filter form options by foreign key? - Django Admin
I need to show only objects that have the same foreign key company in Django in the admin view. What I got was to show only the related objects using get_queryset, but in the form fields appear all…
-
-1
votes0
answers19
viewsReturn student name in query along with matricula - python and Django admin
Base Class: class Base(models.Model): IncPor = models.IntegerField('Incluido Por', null=True, blank=True) AltPor = models.IntegerField('Alterado Por', null=True, blank=True) IncEm =…
-
-2
votes1
answer168
viewsType Object 'datetime.datetime' has no attribute 'datetime'
I have a view that matters some functions of a model, and when I import the model within the view, I have a problem with datetime. The function that exists in the model works perfectly, but in the…