Posts by Ernesto Casanova • 1,344 points
84 posts
-
1
votes2
answers319
viewsA: I made a script that calculates the average of a class or student. But I couldn’t find a way to ask the user if he wants to do another calculation or not
Simplifying and using your base, just a while and remove one that is unnecessary. while True: print('Olá!\nPara calcular a nota de um aluno, digite 1.\nPara calcular a nota de uma turma, digite 2.')…
pythonanswered Ernesto Casanova 1,344 -
1
votes1
answer207
viewsA: How to use the Django admin template non my form
Live on admin.py put only the following. from django.contrib import admin from pokedb.models import * admin.site.register(Pokemon) admin.site.register(TypePoke) Result, this is the right expected?…
-
1
votes1
answer62
viewsA: Where should the mediafiles directory be in the Django configuration to be able to download the files on the Heroku server (free app)?
You need to implement a solution that loads to a Bucket or Storage blob, AWS or Azure or GCS, and stores the image/file path/name in the database. Here is the full explanation of documentation of…
-
0
votes2
answers564
viewsA: Show login error messages in Python with Django
Live create a template for errors, and make include in the templates you want to show errors. Now I don’t know why you are reading the users of a txt file, when using db is simpler. html errors. {%…
-
0
votes1
answer26
viewsA: Prevent change of subject matter in the relationship
Hi, I’ve been analyzing and a simple solution with admin would be to add a flag to your models and when using these models you pass this flag to true, and in admin with an additional function you…
djangoanswered Ernesto Casanova 1,344 -
0
votes1
answer120
viewsA: Django associative table query
Your solution is very close to the one that works, since you indicate that it already returns the expected, you only need to change a line in your html. {% for ambiente in ambientes %} <button…
-
0
votes1
answer203
viewsA: How to create 2 Forms simultaneously in Django and configure the views
Alive, you can create multiples Forms, there is even inlineformset_factory among others, depends on the use case. Even here in this "class based Generic views", you can use a different one that best…
-
1
votes1
answer203
viewsA: Error - "Required field" in image upload using Django
Hi, I’d say the problem is how you’re setting Null. Define it like this. What version of Django are you using? A note, the parameters set with 'None' are unnecessary, I did not put them in the…
-
1
votes1
answer42
viewsA: Information does not appear in the form when editing
Hey, your code had some problems, I don’t know if you’re doing the same in the rest of html here with more details and suggestions. I fixed your code, but it will only show the data you want if you…
-
1
votes1
answer108
viewsA: Search problem using Django queryset when editing
with the filter you get a queryset, so the result is not id, for id_sector and id_company, use something like this: @login_required(login_url='/login/') def ed_ramal(request): id_ramal =…
-
0
votes1
answer45
viewsA: How can I use sp_executesql to execute a query mounted on a variable?
Hi, you only need to change the @CLONE variable to NVARCHAR, is what the error is indicating..."...expects Parameter '@statement' of type 'ntext/nchar/nvarchar'." SET NOCOUNT ON; DECLARE @COLUNA…
-
0
votes2
answers102
viewsA: My function only returns None
Here’s the solution and with context manager. The problem was in this if if conversa1 == line.strip(' n'): def responder(conversa1, posicao): with open('conversas.txt', 'r') as a: for linha in…
-
2
votes2
answers44
viewsA: How can I check if two values of two matrices are in the same position?
Alive, you can simplify a lot and you don’t even need to use for loop, but instead of using two arrays which seems strange to validate the position, use instead a Dictionary, with the key is your…
-
0
votes1
answer74
viewsA: How to page a search page in Django?
Hey, your code had a lot of problems. On the server in views.py where you can use the Django Page and combine it as your search and have a search with paged results. py views. from…
-
0
votes1
answer179
viewsA: Reset password via RG Django
Okay, I’ll rework the code, just what I needed to change, so you can update yours with the issues solved. You may have to change the order also the route that I enclose below, I had to put it before…
djangoanswered Ernesto Casanova 1,344 -
1
votes1
answer603
viewsA: Nameerror: name X' is not defined - Django Rest framework
Hi, it matters this way: py. from [a_tua_app_name].loja import views NOTE: Test case replaces [a_tua_app_name] by your app name. Or from .loja import views Or from django.urls import path import…
-
0
votes1
answer105
viewsA: Error using matplotlib
The problem is that you were passing strings to the function, Plot. When you load the data from txt, it is strings, needs to be converted, to float. Here’s the package documentation matplotlib. def…
-
0
votes1
answer179
viewsA: Confirmation Modal with Django
Good, I implemented days ago and I did not find a very direct solution, had to be with a hack, but I share and decide if it resolves for you. confirm_delete_modal.html <!-- Confirm detele…
-
0
votes1
answer54
viewsA: Function to increment the file name - python(opencv)
All you have to do is this: import os filename = 'video0.avi' if os.path.exists(filename): tmp = filename.split('.avi') count = tmp[0].replace('video', '') or 0 count = int(count) + 1 new_filename =…
-
0
votes1
answer35
viewsA: Django query with dynamic timedelta
Hi, what you are trying to do is not possible unless you perform the query previously, because you are trying to filter with your own result ('rating__revision_period'), this is not possible, at…
-
0
votes3
answers78
viewsA: Insert a list into a database made with Django
For Bulk Insert, I already shared a link with a possible solution, but it uses a class and at first glance seems more complicated, but simplifying. Here is the solution. array_objects = [] lista =…
-
1
votes1
answer111
viewsA: Delete without giving error
Live the problem is that you cannot effectively delete a record if it exists in another table like fk, it violates referential integrity. Being in Django admin you don’t need to do anything it…
-
4
votes4
answers1030
viewsA: Sum the n odd terms ,using Loop for ,without using list, allowed functions:input,int,print and range
Here’s the solution. I don’t understand what you’re adding up to n + n? n =(int(input("Digite o número de termos:"))) result = 0 for i in range(n): if not i % 2 == 0: result += i print(result)…
-
1
votes2
answers661
viewsA: Get Python logged in user ID
As already indicated, the request already contains the logged user. However, when you have to use for several objects, I use a class Abstract, and here I define the attributes that are always equal,…
-
1
votes1
answer693
viewsA: Filter and Join with Django ORM
You can use your queries directly, but being able to use the ORM, many things are much easier. You need to do something like this, use the "select_related" operator of the Django ORM: def…
-
2
votes1
answer25
viewsA: Manipulate string with Substring
You can do it using Trim instead of substring, like this: string oldString = ",,,,,1001,1002,1003,1004,1005,1006,1007,1008"; string newString = oldString.TrimStart(',');…
c#answered Ernesto Casanova 1,344 -
1
votes1
answer337
viewsA: Javascript is not working on Django
Explaining better, download jQuery and put it in the templates folder in your app and put it like this. login.html {% load static %} <!doctype html> <html lang="en"> <head>…
-
1
votes1
answer32
viewsA: Used AUTO_INCREMENT to create ID numbers
When you use auto increment, it will increment in all the added Rows, then when you eliminate you can use multiple approaches. Being all the data at once, uses the truncate table that will reseed to…
-
0
votes1
answer53
viewsA: Error creating routes dynamically in Django
Your problem is missing '%' at tag close, put that line in place of your. <a href="{% url 'Blog:fortag' slug=tag.slug %}" class="mr-1 balde balde-info"> {{ tag }} </a> Additionally, in…
-
1
votes1
answer144
viewsA: How to do this kind of relationship in Django?
From what I understand you only need to show the data in the Django admin table this way. To do so, create a class in the admin file, with the following: class AssinanteAdmin(admin.ModelAdmin):…
-
8
votes2
answers583
viewsA: A recursive function can replace while and for?
If you implement recursiveness for high values, with a thousand for example will return an error: recursion error Maximum recursion Depth exceeded It is a protection against stack overflow, yes.…
-
0
votes2
answers783
viewsA: Set the User logged in to the model as default | Django + Python3
Another solution that I typically use is to create an "Abstract" class, which implements the typical logic of saving the user who created the register or updated the register, but here adapted to…
-
2
votes1
answer73
viewsA: Code does not work [PYTHON]
A solution is to validate if the value you enter exists the number of positions in Dict, "general variable". file py. dados = [] geral = list() while True: dados.append(input('Nome do aluno: '))…
-
6
votes4
answers727
viewsA: Check Object inside an Array using index()
Using index but with map help. But for the value of your object, and not the object. In this case will return 1, the value of the Indice {number:2}. numberObjects.map((e) => { return e.number;…
javascriptanswered Ernesto Casanova 1,344 -
1
votes3
answers182
viewsA: Select returns nothing when I have NULL in foreign key
Use something like that: SELECT a.codigo, ISNULL(q.nome, '') AS nomesubprojeto, a.subprojeto FROM comprovante a LEFT JOIN subprojeto q ON a.subprojeto = q.codigo WHERE a.codigo = 3…
mysqlanswered Ernesto Casanova 1,344 -
1
votes2
answers230
viewsA: Working with querysets and Celery
I share my example, with Celery and Rabbitmq, and parameters when invoking tasks: py serializers. class SensorsSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Sensor fields =…
-
9
votes1
answer64
viewsA: What is the advantage of implementing the Angular lifecycle event interfaces?
Use of the lifecycle angular interfaces is optional. They only help you as a Veloper. Technically, Typescript is converted to Javascript, with the transpile process, which has no interfaces. Simply…
angularanswered Ernesto Casanova 1,344 -
0
votes1
answer322
viewsA: Django: Form not saved in Django database
You have your route calling the wrong function. Change your urls.py to: from django.urls import path from .views import * urlpatterns = [ path('', home), path('pessoas/', pessoas,…
-
0
votes1
answer326
viewsA: Django: Show report earnings and expenses of a Django management system
Hello live a way to get the sum, it’s like this: In Python 2: from django.db.models import Sum total = MovDiario.objects.filter(pago=True).aggregate(Sum('valor')).values()[0] In Python 3: from…
-
0
votes1
answer500
viewsA: Multiple connections via rtsp using Opencv and Python
I take it you’re trying to run multiple clients on the same machine, right? A server socket is listed on a single port, gives here a look at more info. All client connections established on that…
-
1
votes1
answer417
viewsA: How do I check if today’s date matches a date created in a Django application?
A solution, and you’ve already mentioned, is to use Celery & Rabbitmq. I recently developed a streaming solution that involves making somewhat high processing cost calculations. My choice was to…
-
1
votes2
answers483
viewsA: access field value within Django template
Since the data type is a Dictionary, you can access it like this: {% for key, values in dados.items %} {{ key }} {% for item in values %} {{ item }} {% endfor %} {% endfor %} NOTE: For the first…
-
2
votes1
answer90
viewsA: Ternary condition in Django Templates
Live you can see more details here, that is, there are several ways to use the Ernary condition: {% firstof var1 var2 var3 %} Or {{ value|yesno:"yeah,no,maybe" }} In the link above you have more…
-
0
votes1
answer424
viewsA: Convert Varchar in Int or Int in Varchar (SQL Procedure)
Forehead with the following: SELECT ISNUMERIC(Cod_Fabricante) FROM PRODUTO Will return one or zero, so validates if they are all Numeric Rows.
-
0
votes1
answer57
viewsA: Django application (NGINX and WSGI) consuming only one core, reaching 100% and locking
Python default is single thread, however there are ways to transform into multiprocess, analyzes more info here and here. There are several approaches and solutions, I will explain the one I used. I…
-
0
votes1
answer99
viewsA: Setar tab bootstrap when clicking the link (Django)
What defines as the default tab in load is the class [class="Nav-link active"] on the line: <a class="nav-link active" id="nav-pendentes-tab" data-toggle="tab" href="#nav-pendentes"…
-
1
votes2
answers67
viewsA: Spacing in table
Living Ola adds something like this. Using media darlings, you can customize / change behaviors for mobile tablet, and various super wide screen resolutions, etc. I share your example that solves…
-
0
votes3
answers127
viewsA: How to get dates with X days interval?
A solution will be to load all the data to a cursor, and use the interval value (7) in a variable and increment with 7 in each iteration and so fetch all the intervals of the database, until…
-
1
votes1
answer55
viewsA: Search records filtering by Count from a subconsulta
Hello alive as you did not share your example in Sqlfiddle, I share a possible sollution but without testing in your example: SELECT * FROM ( SELECT f1.name, (SELECT COUNT(pre.qtd) FROM premios pre…
-
0
votes2
answers791
viewsA: Django Models - Foreignkey how to call method within the class by Admin
Hi viva I realized after your sharing that your app is really big and there is a lot to install to help you with a fully functional example. As for what you want, part of what you need has already…