Posts by Paulo • 9,980 points
164 posts
- 
		1 votes1 answer700 viewsA: Model field processing before writing to the database (Python + Django)I use the django.contrib.auth.hashers to handle passwords. Basically you can use the method make_password and check_password to work with cryptography. Example: from django.contrib.auth.hashers… 
- 
		0 votes1 answer355 viewsA: Click the Save button and change boolean Django 2.0If you just want to change the field value BooleanField, alter in this way: if form.is_valid(): form_ = form.save(commit=False) form_.cancela = True form_.save() return redirect('listaEspera')… 
- 
		1 votes2 answers174 viewsA: Doubt when ranking using Jango!Use the tag forloop.counter: {% for perfil in perfis %} <tr> <td>{{ forloop.counter }}</td> <td>{{ perfil.nome }}</td> <td>{{ perfil.pontuacao_ultima }}… 
- 
		2 votes1 answer320 viewsA: Total values in Django templateTo load the subjects, topics or posts the user wants to read, you must pass a parameter so that the view Select the selected items. Example of logic: Using the template tag urls you can link to the… 
- 
		1 votes1 answer178 viewsA: Error in Django formError occurred because you wrote meta instead of Meta, the correct would be: class TopicoForm(forms.ModelForm): class Meta: model = Topico fields = '__all__'… 
- 
		5 votes1 answer6199 viewsA: How to use Objects.filter in Django?It’s very simple, take the category and then list the subjects related to it: Example 1: categoria = Categoria.objects.get(id=1) assuntos_da_categoria = categoria.assunto_set.all() Or Filtre… 
- 
		1 votes3 answers969 viewsA: Consulting a JSON via an ANGULAR POSTTo send data via POST, you must use the $http angularjs. Example: var data = {"data":"2017-04-03","data":"2017-04-03"} $http.post('/suaURL', data).then(successCallback, function errorCallback(){});… 
- 
		1 votes1 answer834 viewsA: How to select all elements of the same id in Javascript in DjangoYour code is not written correctly, you should not create a script inside the loop, that js is affecting not only the loop HTML, but everything that was rendered on the page. The correct logic would… 
- 
		2 votes1 answer75 viewsA: Ng-repeat passing a numberIt is not good practice value dynamically generated. I recommend creating a list of dictionaries or tuples and indicating the value and the text. // dicionario novoCadastro.curso.periodo = [{1:… 
- 
		1 votes1 answer268 viewsA: Working with Data on ngInitExpected `1996-10-01` to be a date As the error, you are inserting a String, but an object of the type Date. Simply via javascript convert, example: new Date('1996-10-01'). The ideal is to do all… 
- 
		1 votes2 answers81 viewsA: How to limit the Slider widget Handler for jQuery UI?I solved the problem with a very simple solution, I created another div simulating the Slider background, and using padding on the sides was enough to create this visual limitation. To solve the… 
- 
		2 votes2 answers81 viewsQ: How to limit the Slider widget Handler for jQuery UI?I’m using the Slider of jQuery UI, and I’m hoping that the Handle responsible for moving the slider, stay within the limits of the slider. Currently it is like this: Limit 0%: Limit 100%: I want him… 
- 
		0 votes2 answers83 viewsA: Jquery does not exclude rows from the tableFormatting logic is not cool, use <table> for tabular data only, but if you still want to use <table>, let the add and remove buttons off the table. Simple example using jQuery:… 
- 
		2 votes2 answers67 viewsQ: How to perform an arithmetic operation by changing numerous database fields efficiently?There is a table with 200 records and one of the fields is responsible for indicating the order that these data are shown (0, 1, 2, 3, 4, 5, ...). I need to rearrange this data, take the record from… 
- 
		1 votes1 answer89 viewsA: Django collectstatic AWS S3The correct is for you to send only what you have changed, it makes no sense to send 100MB of files to S3 if you have only changed 1 10kb file. I usually organize my directories well, example:… 
- 
		0 votes1 answer90 viewsA: Midia Object has no attribute 'get_absolute_url'I don’t know if you put the wrong code in the question, but the indentation is wrong, the right one would be: class Midia(models.Model): analista = models.CharField(max_length=50) denuncia =… 
- 
		4 votes1 answer439 viewsA: Django Urlconfs name parameterThe parameter name serves to reference the URL. For example, if you want to point a link to the index in the template, you would use the following code: <a href="{% url 'index' %}">Acessar o… 
- 
		2 votes3 answers76 viewsQ: Is there any difference in performance depending on what you seek?There is some difference in performance when searching the database, depending on the number of characters reported in the query? For example, if a query is made for any record that has the… 
- 
		1 votes2 answers174 viewsA: How to write the date and time of an error in the Django log?I tested here and really was not showing the date and time, but just indicate the format of the log that worked, in this case I put formatter: 'verbose', that verbose is formatted with the date:… 
- 
		1 votes1 answer738 viewsA: Passing an array via Ajax to view DjangoFirst you must inform the csrf token in order to be able to submit 'POST' safely. Second, when you send an array, Django receives the variable with brackets at the end of it, in case it would be:… 
- 
		1 votes1 answer155 viewsA: installing Django in a venvThe message tells you to use --upgrade command, because Django is already installed. Use: pip install --upgrade django Thus the old version will be replaced by the newer one… 
- 
		1 votes2 answers915 viewsA: how to override save method of modelsIt is not exporting the last registered because the method save() inside the model works as pre_save. To solve this problem you must use Signal post_save. from django.dispatch import receiver from… 
- 
		5 votes2 answers3711 viewsQ: How to store Credit Card data securely?Currently I use third party services to handle online transactions via credit card, they store the card data themselves and make the charge. I am wanting to store the customer’s credit card data in… 
- 
		1 votes1 answer281 viewsA: request.post() does not work properly generating a 301 redirect on NginxAfter writing the question in detail, I was able to find the problem. URL requests.post() has to end with \, the fact that it is not finishing, there is a redirection to the same URL with bars at… 
- 
		0 votes1 answer281 viewsQ: request.post() does not work properly generating a 301 redirect on NginxI have a problem when I use request.post('url', data), for some reason when the server receives this request, it redirects (301) the request to the same url losing the POST data, ending as a GET… 
- 
		7 votes1 answer150 viewsQ: What are the rules for building an HTML email?I’m about to build an HTML email, but I see there are differences for a common website page. I want the HTML email to have css and appear both on desktop access and tablet and mobile, and should… 
- 
		0 votes2 answers1819 viewsQ: How to calculate the percentage of items performed in a data tree in the list format?There is the following list: [ [0, False], [1, True], [1, False], [2, False], [2, True], [2, False], [3, False], [3, True], [2, False], [1, False], [2, False] ] This list forms the following tree:… 
- 
		1 votes2 answers602 viewsA: Group by Day in Django*To group per day, simply group by date. Being of the type DateField, just do it this way: >>> from django.db.models import Count >>>… 
- 
		3 votes2 answers1004 viewsA: What is the difference between Forms. Form and Forms.Modelform?The difference is simple, the Modelform is used to create a Model form. # Formulário que salva artigos no seu banco de dados. class ArticleForm(ModelForm): class Meta: model = Artigo fields =… 
- 
		1 votes1 answer38 viewsQ: How to prevent Highchart from connecting the ends of the series?I’m creating a chart using Highcharts that shows results that end the following month, example from day 5 December 2015 to 4 de January de 2016. As you can see, in the image there is a line… highchartsasked Paulo 9,980
- 
		2 votes0 answers262 viewsQ: How to create a custom model field by inheriting Foreignkey in Django?I’m looking to build a custom model field that behaves like Foreignkey, only with a few additional details. This custom field will automatically register a document, passing as reference the model… 
- 
		0 votes2 answers1451 viewsA: How to show Radio Button type fields in the form using Django?You will have to create a Form for your Model, and in it indicate that the field should have the widget Radioselect: In Forms.py class ForensicTrafficForm(forms.ModelForm): lighting =… 
- 
		3 votes3 answers1818 viewsA: How to convert datetime/date to milliseconds in Python?It is possible to convert in several ways: Solution 1 Using datetime.timestamp() present in Python 3. >>> import datetime >>> hoje = datetime.datetime(2015, 9, 30) >>>… 
- 
		3 votes3 answers1818 viewsQ: How to convert datetime/date to milliseconds in Python?How to convert a type date and a datetime millisecond? >>> ontem # tipo date datetime.date(2015, 9, 29) >>> hoje # tipo datetime datetime.datetime(2015, 9, 30, 18, 15, 36, 856736)… 
- 
		0 votes3 answers1652 viewsA: How to start a Django project using virtualenv?I have searched and found several different ways and conventions for the creating a project in Django using a virtual environment (virtualenv). Creating a project in Django has no relation to… 
- 
		1 votes2 answers552 viewsA: I cannot print a variable that receives the value of a list positionYou can return the lowest and highest value using min() and max() respectively. Example: vetor = [] quantidade = int(input('Digite a quantidade de elementos: ')) for i in range(quantidade): elemento… 
- 
		1 votes1 answer886 viewsA: Create a list of python DictWhen you use tempDict.clear() it affects the variable that has also been placed in the list, just change to tempDict = {}. def playersID(self, listDetals): listPlayersID = [] for x in listDetals:… 
- 
		1 votes1 answer51 viewsA: How to improve Testcase speed in Django?I was able to improve performance by changing the bank to sqlite3 and directing the test to a specific app: py Settings. (at the end of the archive): import sys if 'test' in sys.argv:… 
- 
		0 votes1 answer51 viewsQ: How to improve Testcase speed in Django?I’m running a test on Django with only two querys and the timer is taking 1 min and 10 seconds to complete the test. Is there any settings you can adjust to speed up the tests? I’m currently using… 
- 
		4 votes3 answers314 viewsQ: How to destroy a jQuery.fn whenever called?I built a plugin using jQuery.fn.algumaCoisa = function(options, callback){};, But when I call several times on the same element, it multiplies the behavior instead of overlapping. Has some way of… 
- 
		1 votes1 answer354 viewsA: Autocomplete with jQuery and DjangoError happens because you are getting one CharField instead of receiving an instance of Patient. Remove the paciente from your Forms.py: class AgendaForm(forms.ModelForm): # linha removida class… 
- 
		3 votes1 answer169 viewsA: Have two versions of Python in OSX, no overwriteJust install Homebrew from the terminal (you need Xcode installed): ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Then just install Python 3 via the… 
- 
		6 votes3 answers9505 viewsA: Difference between dates/times in PythonWhen you subtract dates in format datetime an object is returned timedelta who has a method total_seconds() that gives you the total seconds: from datetime import datetime s = '2015/08/05 08:12:23'… 
- 
		3 votes3 answers211 viewsA: How could I improve the code?I would make the code more readable and make some modifications: lista = [0,0,0,0,0] nota_acumulada = 0 arquivo = open("notas","w") for x in range(5): lista[x]= float(input("Insira uma nota por… 
- 
		4 votes2 answers23399 viewsA: Picking up parent div attributes through child elementsYou can do it this way using parent() and then data(): $('button').on('click', function(){ alert($(this).parent().parent().data('id')); });… 
- 
		3 votes3 answers70 viewsQ: Strange behavior when displaying an attribute using click();I’m developing a script that requires calling a click() from a button as it is invisible on the page, however jQuery does not seem to return the updated attributes when they are changed. Take this… 
- 
		7 votes4 answers268 viewsA: How to improve this jQuery code?Your code is best used in another logic, for example, if there are only two states ativado and desativado, so you can omit the "disabled" leaving the default element with this behavior, and change… 
- 
		3 votes2 answers666 viewsA: Check file extension in template - DjangoIn addition to the mgibsonbr solution, I would prefer to make a template so that you can reuse logic in other templates. seuprojeto/seuapp/templatetags/extensao.py from django import template… 
- 
		1 votes1 answer116 viewsA: Treating error in search field with text and integer (Django)The ideal is for you to pass a parameter stating what the user wants to search for and to perform a specific filtering, the way the filter is returning any result that contains the searched word,… 
- 
		1 votes1 answer535 viewsA: Single CPF but with Blank=TrueIf you define unique=True means that you cannot repeat any value, even NULL. The solution to this problem is to make a check before saving, if any repeated returns error to the users. In the…