Posts by Hugo Brilhante • 348 points
16 posts
-
2
votes2
answers79
viewsA: Creating routers for multiple databases in Django
I believe a better approach would be to use multitenancy. That one applying makes it very simple.…
-
2
votes2
answers225
viewsA: Make a Relationship Many for Many
You can filter students this way: MdlUserEnrolments.objects.filter(enrolid__courseid=course.id).count() Say you want to put the filter value in each course of context: courses =…
-
1
votes2
answers528
viewsA: How to call class method in another app?
You don’t need to create a class for this. You can create a config.py file with a dictionary and then import that dictionary where you want to use it. In the file config.py parameters = { 'url_m' :…
-
0
votes1
answer2522
viewsA: Problem with Django form:Integrityerror: NOT NULL Constraint failed
Like the attribute avaliacao is a Foreignkey and is not mandatory, you can set it as null. avaliacao = models.ForeignKey(Criterio, null=True, blank=True) More details on documentation…
-
0
votes2
answers783
viewsA: Set the User logged in to the model as default | Django + Python3
There is a method called .save_model in Modeladmin that aims to make pre and post save operations. class TicketAdmin(admin.ModelAdmin): ... def save_model(self, request, obj, form, change): obj.user…
-
0
votes1
answer377
viewsA: How to access data from a dynamic imput of a form with Django?
Let’s say you want to access the list of criteria the user added: Remove the [] of criterio[]. When inputs are sent with same name a list is created automatically. Now just access the view : def…
-
1
votes1
answer104
viewsA: Queryset model Category, Product and Productimage
First upgrade your Productimage model with related_name: class ProductImage(models.Model): product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='images') image =…
-
1
votes2
answers152
viewsA: Is it possible to compare two variables coming from a view in Django?
According to the documentation is possible yes. I suggest you debug the code to see if the condition is being met.…
-
1
votes1
answer94
viewsA: Djandorestframework standardize endpoints for methods with different permissions
Overwrite the method .get_permissions is a solution: class ContactView(ListCreateAPIView): ... def get_permissions(self): if self.request.method == 'POST': self.permission_classes = (AllowAny,)…
-
0
votes1
answer30
viewsA: Error running project migrated from Django 1.7 to Django 1.10
In the documentation explains that just pass the name of the view to the redirect that the reverse will be used. def my_view(request): ... return redirect('some-view-name', foo='bar')…
djangoanswered Hugo Brilhante 348 -
0
votes1
answer155
viewsA: How to extract data from a Django Queryset
In importing the file you could do something like this: Assuming that your model has all the fields mentioned above and the file had the following format:…
-
1
votes1
answer816
viewsA: Security Authentication Token Django Rest Framework
I suggest using Sessionauthetication for web version and Tokenauthentication for mobile version, since it is possible to use more than one authentication scheme due to the way the authentication is…
-
0
votes1
answer63
viewsA: How to remove elements placed by Django (1.7.5) in the template
One of the ways to solve this is by using the property list style type of css. Another way is to customize the html output of the form see the documentation.…
-
1
votes1
answer97
viewsA: Django Debug Toolbar
Missing a comma separating applications notification and debug_toolbar. INSTALLED_APPS = ( ... notification, debug_toolbar ... )…
djangoanswered Hugo Brilhante 348 -
2
votes1
answer149
viewsA: Rest API Django does not work
PrimaryKeyRelatedField can be used to represent the relation using your primary key: class SchoolSerializer(serializers.ModelSerializer): school_application_info =…
-
2
votes1
answer263
viewsA: Django-Rest password validations in two fields
To do any other validation that requires access to multiple fields, add a method called .validate() to your subclass Serializer. This method uses a single argument, which is a dictionary of field…
django-rest-frameworkanswered Hugo Brilhante 348