.
jūdê
you are programmer
Yes
A backend engineer
For the sake of understanding what goes on in the framework as you develop
I’ll advise you go with Corey Schafer
He tends to use simple examples to give you a picture of what goes on under the hood and why you should follow certain rules over other things.
It’s better you start off learning certain rules so that you don’t have to unlearn a lot in the future but always keep an open mind.
jūdê
Can anyone explain how is annotate() and aggregate() connected
Annotate() performs an operation for each object of a queryset.
Aggregate() performs an operation over all the objects of a queryset.
So if you do a count using Count for lets say, a field in a model over a queryset:
If you use annotate, it would ascribe that count of the field of each object to each object.
But if you use aggregate, it would return the count of the field of all the objects.
Annotate would return a Queryset with the ascribed values.
Aggregate would return the summary as requested.
jūdê
Let me find an article for you
.
jūdê
Let me find an article for you
https://stackoverflow.com/questions/7981837/aggregate-vs-annotate-in-django
https://www.scaler.com/topics/django/aggregating-and-annotating-objects/
Then the docs gives a lot of examples too
https://docs.djangoproject.com/en/4.2/topics/db/aggregation/
.
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 13: 'else', expected 'endblock'. Did you forget to register or load this tag
?
.
i have a problem what is this
Kuda
Else first
Kuda
Then endif
.
Kuda
.
{% extends 'tasks/base.html' %}
2
3 {% block content %}
4 {% if tasks %}
5 {% for task in tasks %}
6 <div>
7 <h2>{{task.title}}</h2><br>
8 <p>Created: {{task.created_at}}</p>
9 <a href="{% url 'tasks:task_detail' task.pk %}">View</a>
10 </div>
11 {% endfor %}
12 {% else %}
13 {% endif %}
14 <p>There is no task!</p>
.
it don't work
Vitt
Vitt
What's your else doing here?
.
Vitt
.
{% if tasks %}
.
that is problem
Vitt
I don't remember Jinja exactly
.
Jayashree
Helle everyone,
How to save data to the database by using the database name.?
I have used serializer.save(using=database_name) but before this line I have used serializer.is_valid(raise_exception = True). This line will throw an error
(1146, "Table 'testdb.brand' doesn't exist") but the brand table is in the testdb_1 database
Rupesh
You are save data to database using djangorestfremwork
Rupesh
Use api
Jayashree
I have used
Jayashree
Still it will not save.
Jayashree
Serializer.is_valid() will throw an error
jūdê
Jayashree
jūdê
Yea
The serializer is a ModelSerializer
The model serializer would go the model and I think that’s where the problem is
jūdê
The serializer.is_valid is probably calling the Model manager in some way(I’m not sure about it) and the model manager most likely goes to the default DB.
So the only thing I can think of now is that maybe you should create a custom manager that indicates the database it is using for that model?
Or
Override the validation method of the serializer to fit your needs, maybe validate all the fields yourself in a pythonic way
jūdê
Use this stackoverflow post to see if it helps you in anyway
https://stackoverflow.com/questions/70887881/django-drf-post-for-multiple-database-connections
Anonymous
Does anyone know about mssql configuration on python django4?
Anonymous
I installed mssql-django
Neha
How to use order by with distinct in django orm?
Jayashree
Kumar Shreyansh
You need to use PyODBC package to connect with any other SQL server
Kumar Shreyansh
The current packages exist for sqlite, MySQL, Postgres, Oracle
Jayashree
Jayashree
jūdê
Okay I'll check. Thank you
I’d suggest you use serializers.Serializer class for the deserialisation and validation
And then using the model manager to update or create it manually:
Foo.objects.db_manager(“database_name”).create()
Or
foo1 = Foo(**fields_value)
foo1.save(using=“database_name”).
Until you figure out a better way
Neha
ТинМин
from myapp.views import indexImportError: cannot import name 'index' from 'myapp.views' (E:\pi\coolsite\myapp\views.py)
ТинМин
I dont nou
ТинМин
where eroorr
Maxim
where eroorr
probably there is no index in myapp.views
ТинМин
from django.urls import pathfrom myapp.views import index
from myapp.views import index
urlpatterns = [ path('', index, name='index'),
]
Maxim
ТинМин
from django.shortcuts import render
def index(request): if request.method == 'POST':
index = request.POST.get('index') return render(request, 'myapp/index.html', {'index': index})
else: return render(request, 'myapp/index.html')
Jahongir
can you use so from .views import index
M. Hossein
Why post_save signal works in API views but not in admin page?
Mirco
.
<link rel="stylesheet" type="text/css" href="{% static 'static/css/page.css' %}">
.
How can i connect css with django
.
Виктор
Виктор
.
[17/Jul/2023 16:16:58] "GET /static/css/page.css HTTP/1.1" 404 1795
Error
.
Hanane
hello guys how can we solve this : The 'image' attribute has no file associated with it. ?
Jwalant
Hanane
i have this in my models.py : image = models.ImageField(blank=True,upload_to='images') and i checked under media there is a folder with the name images .. any idea what could be the issue ?
Hu
Hello
I am getting a 405 "get method not allowed" when I try to make a post api request using Django rest framework
How do resolve it
Askat
Hu
Askat
Fedor
Hello everyone, I need to deal with one very large project on Django, the task is to add two models, but I need to figure out where.
Charly
Charly
Also please edit your message help must be provided here not in private
Fedor
Fedor
The project is very, very big