Posts by Paulo • 9,980 points
164 posts
-
2
votes1
answer650
viewsQ: How to call a function after the user drops the mouse click?
On a page there is an element that the user can drag with the mouse, would like to call a function after the user drop this element (when dropping the mouse click). How to do this without having the…
-
2
votes2
answers1166
viewsA: How to return a query in JSON format with extra values and custom Keys?
I was able to solve it this way: pessoas = Pessoa.objects.values() pessoas_modificado = [] for p in pessoas: # altera o nome das chaves: p['STATUS'] = p.pop('status') p['podeEscrever'] =…
-
2
votes2
answers1166
viewsQ: How to return a query in JSON format with extra values and custom Keys?
I want to return the result in JSON following this format: {"cadastros": [ {"id": 1, "STATUS": true, "pessoas": [], "podeEscrever": true}, {"id": 2, "STATUS": false, "pessoas": ['Maria', 'Ana'],…
-
1
votes1
answer525
viewsA: Filter with Choicefield (Django)
If you want to return everything just check that the value sent is not empty (q != '') and then not perform the filtering. p = Proposal.objects.all().select_related() q =…
-
1
votes2
answers557
viewsA: Can I upload to a subfolder using Filefield?
Using a function in the upload_to it is possible to change the file path/reference, example: def upload_path_handler(instance, filename): return "uploads/%s/%s" % (instance.subpasta, filename) class…
-
2
votes1
answer312
viewsA: Typeerror with calculated field (Django)
This error is occurring because you are trying to multiply an integer by an empty type. Example: >>> price_sale = None >>> quantity = 2 >>> print price_sale * quantity…
-
2
votes2
answers355
viewsA: How to find, check and change file?
A solution creating a new file with the value changed: novo = open('novo_ficheiro.txt', 'w') with open('ficheiro.txt', 'r') as ficheiro: for linha in ficheiro: nova_linha = linha if 'energia' in…
-
3
votes2
answers521
viewsA: How to serve files with access control in Django?
One solution I found to serve (non-static) files is using X-Sendfile. Basically, the application view (in the case of Django) checks that the user is logged in and sends the request with a header…
-
2
votes1
answer1765
viewsA: Django validate Cpf and treat error
We’re missing one else to load the page again with the form if there is an error: def cadastrar_cliente(request): if request.method == 'POST': form = ClienteForm(request.POST) if form.is_valid():…
-
2
votes1
answer848
viewsA: How to return Objects in a Many to Many Django
The mistake says 'QuerySet' object has no attribute 'dealership'. You’re actually doing this: ordens = Ordered.objects.all().dealership.all() For the code to work properly you must loop the orders…
-
1
votes4
answers12261
viewsA: How to know which version in use of a particular package is installed via Pip?
It is interesting that you store in a file the list of all installed packages of your project, as you already know using the command pip freeze the packages and their versions are displayed. To save…
-
3
votes2
answers3930
viewsA: Father Height Element and Sons Position Absolute Elements
Your css is wrong, you can’t put one element inside the other as you put it, it should be like this: .mockup{ padding-bottom: 70px; display: block; position: relative; overflow: auto; height: 270px;…
-
1
votes1
answer140
viewsA: Check random numbers (randint)
The error that is happening is that you are asking if a string is larger or smaller than a number. >>> rinfo = raw_input() 8 >>> type(rinfo) <type 'str'> As you can see the…
-
0
votes1
answer353
viewsA: How to count people by age
Using annotante i could not extract the year and the month using F('birthday') to perform the calculation. If I wanted to get the track it would be something like this: model class…
-
1
votes1
answer225
viewsA: Queryset: Getting the description of the accessories on request (Django)
I would configure the model as follows (example): model class Veiculo(models.Model): nome = models.CharField(_('nome'), max_length=50, unique=True) valor = models.DecimalField(_(u'preço'),…
-
2
votes1
answer64
viewsA: Improving the return of a specific result
In reality it returns only one element in the list, for this just take the first element (unique in this case) and pass to the template. view: d = [{'quant': 236, 'district': 'Centro'}][0] template:…
-
4
votes2
answers804
viewsA: How do you calculate (easily) total and subtotal in Django?
In version 1.8 to generate subtotal you must use annotate and to generate the total you must use aggregate. It is necessary to use Expressionwrapper when performing calculations with different types…
-
16
votes6
answers16210
viewsA: How do I return a value in the Brazilian currency format in the Django view?
They have two simple ways to do that, next: 1) using locate: from django.utils.formats import localize def moeda(request): valor = 1768 valor = localize(valor) return HttpResponse('Valor: %s' %…
-
12
votes6
answers16210
viewsQ: How do I return a value in the Brazilian currency format in the Django view?
How to return the value 1768 in BRL currency format 1.768,00 in the Django view? def moeda(request): valor = 1768 # formata o valor return HttpResponse('Valor: %s' % valor)…
-
0
votes3
answers278
viewsA: How to prevent Django from finding Ids in the template?
You can avoid this numeric formatting using the template tag safe: Entree: data-id="{{ form.instance.id|safe }}" Exit: data-id="1234" Reference:…
-
0
votes1
answer274
viewsA: Return values in Foreignkey and Manytomanyfield in Django
I don’t think it’s a good idea to format the list of products and prices in the model, you can do this directly in the template. In the template would look something like this: {% for produto in…
-
4
votes1
answer470
viewsQ: How to sort a query in Django by ignoring accents?
I’m returning the query Carro.objects.all().order_by(Lower('marca')), but the order is not respecting names that begin with accent, causing these results to appear at the end of the ordination. Is…
-
2
votes2
answers2366
viewsA: How to order Datatables by ignoring accents?
He had built this code based on the code that works the Persian language. He simply replaces accented characters with no accents. jQuery.extend( jQuery.fn.dataTableExt.oSort, { "portugues-pre":…
javascriptanswered Paulo 9,980 -
1
votes2
answers2366
viewsQ: How to order Datatables by ignoring accents?
I’m experimenting with Datatables and by sorting the table that has strings starting with accents, they appear at the end of the table. How to order the table in Brazilian Portuguese format? As you…
javascriptasked Paulo 9,980 -
1
votes2
answers5596
viewsA: How to run a function after Angularjs renders content in the template?
I was able to solve it this way: app.directive('executarAposRenderizar', function ($timeout) { return { restrict: 'A', link: function (scope, element, attr) { if (scope.$last === true) {…
-
0
votes2
answers5596
viewsQ: How to run a function after Angularjs renders content in the template?
I would like to call a function after Angularjs renders the content in the template, just as it removes the display:none when using the ng-cloak. function executaAposRenderizar(){...}…
-
1
votes2
answers148
viewsA: Google Maps Information
The ideal would be to use Google Maps' own resources and draw the regions instead of placing an image inside. I created in the Jsfiddle an example. Basically you define the coordinates of the region…
-
6
votes4
answers5471
viewsA: Count occurrences in a list according to prefixes
I could do it this way: >>> palavras = ['rato', 'roeu', 'rolha', 'rainha', 'rei', 'russia'] >>> prefixos = ['ro', 'ra', 'r'] >>> len(filter(None, [p if…
-
2
votes2
answers2875
viewsA: How to allow a Decimalfield with the BR currency format in Django?
To accept point in the thousand separation just put localize=True in the field, in the template Django will print the input guy text: class CarroForm(forms.ModelForm): valor =…
-
3
votes2
answers2875
viewsQ: How to allow a Decimalfield with the BR currency format in Django?
I have the following class: class Carro(models.Model): valor = models.DecimalField(max_digits=8, decimal_places=2, default=0) And its respective form: class CarroForm(forms.ModelForm): class Meta():…
-
2
votes3
answers1346
viewsQ: How to replace all attributes using jQuery/Javascript?
I’m looking to replace every incident I have __prefix__ by a number, how to accomplish this using jQuery/Javascript? HTML <div class='form-modelo'> <input id="id_form-__prefix__-nome"…
-
1
votes1
answer1140
viewsQ: How to change formatNoMatches in Lect2 4.0.0?
I’m using the Lect2 4.0.0 and I am having trouble changing the way the message is shown which indicates not having found results. In the old version used formatNoMatches to change the presentation,…
-
1
votes1
answer66
viewsQ: How to assign a class to a field type in Django?
I’m trying to figure out which field is a DateField and thereby assign a class='date'. How do I know the guy from the field? The following code does not work but presents the logic: class…
-
8
votes4
answers2315
viewsQ: How to format a value in Javascript?
What is the simplest way to format the value 1234213412341 for 1234.2134.1234-1 using Javascript? <script> function formatar_valor(strvalor){ var formatado; // formata return formatado }…
-
4
votes1
answer130
viewsQ: How to resolve the conflict between Angularjs and Django?
What is the most efficient way to solve the conflict problem between Django and Angularjs when using {{ }} in the templates?
-
3
votes2
answers6243
viewsQ: How to make a CSS background gradient (gradient)?
How do I do in CSS with which three div have the background gradient (gradient) changing color green for yellow and finally blue, being the first from top to bottom, the second from left to right…
-
0
votes2
answers1301
viewsA: How to format datetime in YYYY-MM-Ddthh:mm:ss.sTZD format in Django/Python?
To return Timezone as configured in Settings.py ('America/Sao_Paulo'), should be used timezone.localtime(). Example: >>> from django.utils import timezone >>>…
-
4
votes2
answers1301
viewsQ: How to format datetime in YYYY-MM-Ddthh:mm:ss.sTZD format in Django/Python?
I’m having a hard time in Django returning the datetime in the local Timezone. No Django configurei USE_TZ=True and TIME_ZONE = 'America/Sao_Paulo' By calling timezone.now(), returns the datetime…
-
2
votes1
answer165
viewsQ: How to build a queryset that returns only the cars with the last approved revision?
I’m looking to create a queryset that returns only the cars that have had the last approved review. It is known that there may be n cars, and each car has a history of revisions, so there may be n…
-
2
votes1
answer2775
viewsQ: How to return the weather forecast via the prediction API dotempo.org?
I’m trying to return a weather forecast query via the http://www.previsaodotempo.org but I’m not succeeding. Where I’m going wrong?…
-
9
votes3
answers15464
viewsA: For increment in Python
To decrease: for i in range(10, 1, -1): print i To increment every two: for i in range(1, 10, 2): print i To make i++ there’s no way, you’d have to use contador+=1…
-
3
votes3
answers10914
viewsA: How to remove the first element from a list in python?
Another way would be to pick up items from the second item in the list: >>> a = [a, b, c, d, e, f] >>> a = a[1:] [b, c, d, e, f]
-
1
votes2
answers833
viewsA: How do I know if request.FILES is empty?
Checking if there is any file being sent can be used as you put in your example if request.FILES Could specifically check can also be done this way: try: request.FILES['arquivo'] except KeyError:…
-
2
votes1
answer753
viewsA: How to make blog posts appear on the page when you click the menu?
If I understand correctly, what you want to do is filter posts by tag. In the menu the links should point to the post related tag. Example: http://seusite.blogspot.com.br/search/label/Noticias In…
-
1
votes3
answers1694
viewsA: How to do when a button is clicked is created an element on the page?
You can use .load() to load another HTML page into the modal, so you separate the content from the page and reuse it in other. The following example is triggered when the modal opening is requested:…
-
47
votes4
answers40074
viewsQ: What is the difference between display:None and visibility:Hidden?
I know you’re both hiding the element, but there’s actually a difference between: #foo{ display:none; } and #foo { visibility:hidden; }…
-
2
votes1
answer94
viewsA: Make DIV occupy page remnant with CSS
You can use display:table and display:table-cell to be able to manipulate the way you want. Example: .principal { width:100%; display:table; } .principal div{ display:table-cell; height:200px; }…
-
2
votes4
answers542
viewsA: Subsequent Calls in Ajax
Normally I would make an accountant and go through the entire list until I reached the total number of companies: var lista = $('.lista').find('li'); function calcular(loop){ if (loop <=…
-
0
votes1
answer190
viewsA: Fullcalendar with strange behavior when displaying events in "Month View" ending before 9 o'clock
To change this default behavior you need to change the property nextDayThreshold, responsible for setting the minimum hours to be considered an event day in the Month view. It is by default…
fullcalendaranswered Paulo 9,980 -
0
votes1
answer190
viewsQ: Fullcalendar with strange behavior when displaying events in "Month View" ending before 9 o'clock
Fullcalendar has a default behavior for display on Month view that ignores the end of events when they end before 9 am, example: Week view: (ending before 9am of day 4) As shown in Month view: Week…
fullcalendarasked Paulo 9,980