Posts by Puam Dias • 837 points
32 posts
-
0
votes1
answer321
viewsA: Get the user logged in to the form
You have to override your form’s init. class MeuForm(forms.ModelForm): ... def __init__(self, *args, **kwargs): super(MeuForm, self).__init__(*args, **kwargs) usuario = kwargs['initial']['usuario']…
-
1
votes1
answer96
viewsA: Creating a form that has the Choice pre defined
You must override your form’s init. class ItemForm(forms.ModelForm): ... def __init__(self, *args, **kwargs): self.fields['categoria'].queryset = SubCategoria.objects.filter(categoria='1')…
-
0
votes1
answer677
views -
1
votes1
answer91
viewsA: Python / Django: sending emails resulting in 535 (gmail working)
This is your smtp service authentication error. It’s not just putting in another host domain and another user and that’s it. You have to look at the documentation of the new smtp service, see what…
-
0
votes2
answers442
viewsA: How to go to a Django url regardless of the path we are on?
It is not recommended that you use urls this way, because this can lead to silent errors in your application. If one day you end up changing your url to 'profile-something', when accessing this…
-
0
votes2
answers1513
viewsA: How to save Base64 in Imagefiled Django / data:image/jpeg;Base64,?
Remove the data:image/jpeg;base64, of your string before using the b64decode. img = request.GET['img'].replace('data:image/jpeg;base64,','')
-
1
votes1
answer92
viewsA: Changing the template_name in Templateview (Django)
Good guy, if you have a different view for an authenticated person and one that isn’t authenticated, study the possibility of leaving a view for each thing. If information handling increases, this…
-
2
votes2
answers15001
viewsA: How do I ignore a file after it’s already in a commit?
For git to ignore a particular file, this file cannot be in the repository. If you committed it previously and want to remove it, you have to remove it from git for gitignore to work. #gitignore…
-
3
votes2
answers2629
viewsA: How do I "turn" a specific commit into a branch?
To view commit history, type: git log After that, just grab the commit ID you want: git commit -b nomebranch 7e85bcb18b1fcf58738f3ec6a2e04171975ef442 Or: git checkout…
-
2
votes1
answer240
viewsA: Django Template Email
Whoa, I hope this helps: from django.template.loader import get_template from django.utils.safestring import mark_safe from django.template import Context from django.core.mail import EmailMessage…
-
1
votes1
answer859
viewsA: Word search in excel spreadsheet and return of the entire line containing that word in PYTHON
Particularly I like working with csv more than with xls. Just convert your xls to csv. You can use regex or findall for this: import re data = open('seu_arquivo.csv') texto = "Bem vindo ao python!"…
-
0
votes1
answer514
viewsA: How to work with Updateview and Forms in the template
If you just want to display a client’s data in a template, you can use Detailview https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-display/#detailview class…
-
1
votes1
answer491
viewsA: How to add fields dynamically in Django?
I believe that the filter_horizontal Django will solve your problem. In your admin.py class, put the tag to indicate this. class BookAdmin(admin.ModelAdmin): filter_horizontal = ('author',)…
-
2
votes1
answer1932
viewsA: Error 502: Bad Gateway - How to resolve
Dude, give it a study in status code. It sounds funny but the minimum of knowledge in status code will help you a lot in several things. Has a lot of developer who does not know what a 303, 401,…
-
4
votes1
answer273
viewsA: Django: What’s the difference between importing/using include() and not using when configuring a URL?
In a system, there can be hundreds of urls. It gets a bit disorganized you put everything in just one url file. There is a main urls.py file that comes in the same directory as Settings. include…
-
2
votes2
answers295
viewsA: Unknown command: 'syncdb' Visual Studio 2013
If you are using Django 1.9, syncdb has been removed, see the release: https://docs.djangoproject.com/en/1.9/releases/1.9/#Features-Removed-in-1-9 To run migrations, you must use makemigrations and…
-
2
votes1
answer86
viewsA: Session in Forms
This problem is happening because your form has no 'request'. Your request happens in the view, when you call a form, there is no sending the request or any parameter to it. The first thing to be…
-
3
votes2
answers577
viewsA: Instance in Django model with problem
First thing is to check the folder structure of your project, maybe you have to put from seuprojeto.emails.models import GerenciarEmails If this is not the case, it is probably the problem that…
-
4
votes3
answers7119
viewsA: How to see the methods or attributes of an object in Python?
It is important that you know the python terminal. This will help your life a lot. sudo apt-get install ipython. You can install in virtualenv as well: pip install ipython Type ipython in the…
-
2
votes2
answers841
viewsA: Block source code Django
Dude, if the below is not yours or your indication, the responsibility is the customer’s own. Each *.py qye file you have, when compiled, it generates a *.pyc file, which is nothing more than python…
-
2
votes1
answer1820
viewsA: How to make a Join with Django?
The Django queries happen in a very simple way, for example: CHOICE_CLIENTE = ( ('pessoa_fisica','Pessoa Física'), ('pessoa_juridica','Pessoa Jurídica'), ) class Cliente(models.Model): nome =…
-
4
votes1
answer508
viewsA: POO using Django
No, it’s not the right way. Simply put, Jango works with apps. Every app you create on your system should follow the context of something. For example: If in my system I have the following models:…
-
1
votes1
answer82
viewsA: Remove Session Data Dictionary with ajax in Django
To remove the item from your list from the index, you can use list.pop, for example: lista = [{"0":"0"},{"1":"1"},{"2":"2"},{"3":"3"},{"4":"4"},{"5":"5"}] lista.pop(1) # {'1': '1'} lista # [{'0':…
-
3
votes2
answers403
viewsA: TDD in existing function (Django)
Tdd works with a cycle: test fail >> test pass >> refactory >> test fail >> test pass >> test refactory It’s very complicated to give an exact example because you’re…
-
2
votes1
answer163
viewsA: How to register a data matrix in Django
How’s that product listing? Since it is a data list, you should use bulk_create for this: #se sua listagem for um dict produtos = request.session['produtos'] lista = [] for produto in produtos:…
-
1
votes2
answers120
viewsA: Problem with pk that doesn’t exist yet
Assuming Contract has a Foreignkey Proposal, you can assign the value at the time of saving, for example: #models class Contract(models.Model): proposal = models.ForeignKey('Proposal', blank=True)…
-
5
votes1
answer1550
viewsA: List date filter (Django)
You must convert your date before the search: from datetime import datetime dmin = self.request.GET.get('min_date') dmax = self.request.GET.get('max_date') min_date = datetime.strptime(dmin,…
-
1
votes1
answer1636
viewsA: Django - Getting form information
You must put your GET form on the page itself: ... <form method="GET"> ... In your view, you should check if you have any initial and final data_parameter to make the query. from datetime…
-
0
votes1
answer1219
viewsA: Facebook API Python
Have you tried replacing Friends with groups in the url? Remember that to access this information, the user must authorize access. In configuring your app, you must access the permissions and…
-
1
votes1
answer77
viewsA: Performance in Queryset CBV
To analyze the performance you can install the django-debug-toolbar: pip install django-debug-toolbar With it you can analyze how many darlings are made in a consultation. But the prefetch_related…
-
0
votes2
answers1186
viewsA: Problem connecting Mysql in Python 3.4
You must install mysql-python: pip install mysql-python
-
0
votes1
answer108
viewsA: Using python and Django, querys problem
Your query should be used in a query: Model.objects.filter(banca2__in=projetos) . This Return query plays the query to where?