Posts by mazulo • 595 points
29 posts
-
0
votes1
answer184
viewsA: Form in Django with more than one Model
The reason for the error is that you are "saving" the collaborator with commit=False, thus: colaborador = data['colaborador'].save(commit=False) The commit=False causes the object to not be…
-
1
votes1
answer78
viewsA: I can’t display a comment list for a post in the Django template
I think to solve this, you’d need to change your method of retrieving comments a little bit: @property def get_comments(self): comments = Post.objects.filter(type_post='1', commented_post=self) The…
-
0
votes1
answer466
viewsA: Django: Local Postgresql and Heroku?
I have basically the same configuration and can make use of postgres locally and in Heroku. I install the same lib: pip install dj-database-url With him installed, there in my .env I have something…
-
1
votes1
answer125
viewsA: Django. Only change in the database via html
When you want to send something to backend (your system) without having to reload the page, then you will need to use an AJAX call using javascript. In that post and in that you will see a way to do…
-
1
votes1
answer70
viewsA: Django + Postgresql Object has no attribute
You will have access to the form data (after validated) through the attribute .cleaned_data. So it would be something like this: if form.is_valid() and form.cleaned_data['termAccepted'] == True:…
-
0
votes1
answer32
viewsA: How to simulate production in dev while maintaining data secrecy?
What is customary for some companies to do is: A demo environment with fictitious data as close to the relations that the production would have A sandbox/preprod environment with production data, to…
-
1
votes1
answer147
viewsA: Django Rest Framework with Images
From what I see in the code you put on view.py, you are using the model Servico but at the same time creating a variable with the same name Servico.
-
0
votes1
answer1126
viewsA: Django datetimefield as text
By default, the forms.DateTimeField will use widget DateTimeInput that has as input_type ''text. A way to solve this, would be like this: class DateInput(forms.DateInput): input_type = 'date' class…
-
0
votes1
answer152
viewsA: Return more than one Django data list
I think a good option would be for you to separate the contexts. def list_product(request, template_name='home/index.html'): menu_all_products = Product.objects.all() page_active_products =…
-
0
votes1
answer250
views -
1
votes1
answer205
viewsA: Error accessing localhost:8000/profile
The problem is that in your urls.py you are mapping your view to a different URL than the one you are accessing. See: urlpatterns = patterns ('', url(r'^$', 'perfis.views.index'),…
-
0
votes1
answer247
viewsA: Filter Models in the Django view
The simplest way for you to do this is to create different Urls and views for each of them. Let’s say you’ll get the URL /cao/ and /gato/. After that you would also have the views cao and gato. def…
-
1
votes2
answers2615
viewsA: Password Validation with Python
I think the best option is for you to write your own Validator and add it to your settings.py. Here in django doc you can see how to do, but it would be something like this draft I did below (I…
-
0
votes1
answer1019
viewsA: Pass a GET parameter through the Django view
I think the solution would be for you to redirect already with the query string, something like: from django.shortcuts import redirect def schedule(request): # varios codigos return…
-
0
votes2
answers206
viewsA: Image displayed on one machine, and another not on Django
In development/production mode, Django will not actually serve the static files (since he expects this responsibility to be passed on to an apache/Nginx). But for ease’s sake, it still allows you to…
-
3
votes1
answer999
viewsA: Python, Django with multiple databases
You will be able to do this through Automatic Database Routing. It is a rather extensive setup, but let’s use a simple and practical example (taken from the documentation). This one’s gonna have…
-
1
votes1
answer1187
viewsA: Problems loading Static files to Django in deploy on Heroku
Maybe what is missing is you set so that in development mode Django serves the static files. In documentation you enter the code below as a hack in the urls.py of your project to be able to do this:…
-
1
votes1
answer32
viewsA: Verificaciones periodicas Django
What you want to do, could be easily achieved through the Celery, more specifically of Periodic Tasks. In the documentation you will find examples with Django.…
-
2
votes1
answer578
viewsA: Django Admin: Changing display format of a date field
One way to do this would be by using the following in your settings.py: from django.conf.locale.pt_BR import formats as br_formats br_formats.DATE_FORMAT = 'd/m/Y' It is inside this file that you…
-
1
votes2
answers3598
viewsA: Images with Django - exhibition and Static
I believe the problem is the way you are trying to render the file path. In the listing you do so: <img src="{{item.photo}}" class="img-responsive" alt="..."> And on the Detail page you do so:…
-
2
votes1
answer781
viewsA: Upload and view PDF’s Django admin
I believe the only detail missing is that you enable Django to serve the static and media files, which he does not do by default. To do this, just do this on your urls.py of the project: from…
-
1
votes1
answer42
viewsA: App name error in Django
It seems that Django 1.10 is not installed correctly, because render does not even have this argument current_app in this version anymore. Uninstall Django, and install again, but without using the…
-
0
votes1
answer503
viewsA: Import attributes from models classes from another app
A very simple way for you to do this is by defining a method in your BolsistaAdmin that returns this information. So it could be more or less like this: from django.contrib import admin from…
-
0
votes1
answer2713
viewsA: Unicode-Objects must be encoded before hashing
This error is also due to the difference that Python 2 and 3 handle strings differently. Python 2 >>> type(str(random.random()).encode('utf-8')) <type 'str'> >>>…
-
0
votes2
answers258
viewsA: How to save Django objects with quantity validation?
You can use your own validators of Django. As the Maxvaluevalidator, who will launch a ValidationError [...] if the value is greater than the max_value (translated and shortened from doc). Your…
-
3
votes1
answer93
viewsA: CSS error - Django Formfield
The problem is that you are using unnecessary code. See this part: {% for field in form %} <div class="form-group"> <label for={{ field.label_tag }}> {{ field_label_tag }} </label>…
-
1
votes3
answers1652
viewsA: How to start a Django project using virtualenv?
Taking into account that you already have Pip installed, to use the isolated environments approach is very simple, even more so with virtualenvwrapper. virtualenvwrapper is, as the name implies, a…
-
1
votes1
answer168
viewsA: Returning get_FIELD_display from a dictionary-transformed list (Django)
The way you’re doing, the get_item_display would be an attribute previously passed by the context, when in reality it is a method created for each field that has a choices setate. See that you’ve…
-
0
votes3
answers430
viewsA: Problem when importing model
If your serializer file is in the same module as your model, a way to import: from .models import Contrato