23 questions
0
votes
0
answers
61
views
Check if Django is able to connect with given parameters or return an error message, instead of causing an internal server error (500)
I'm trying to build dynamic connections to databases. This because I just now and then have to query them to get some data. The sources change over time, so I'm not in favor of adding them to settings....
0
votes
0
answers
60
views
Django database function to extract week from date (if week starts on Saturday)
loads_of_dedicated_customers = Load.objects.filter(customer__is_dedicated=True).exclude(load_status='Cancelled').values('customer__name').annotate(year=ExtractYear('drop_date'), week=ExtractWeek('...
0
votes
1
answer
219
views
Changing Year, Month, or Day in a Django model's date field using annotate
I have a Django model MyModel
class MyModel(models.Model):
"""My Model that stores date."""
date = models.DateField()
In my API I am receiving a param, review_month
...
1
vote
1
answer
41
views
django orm - annotate / aggregation (avg) in subquery
I have this model:
class UserMovieRel(models.Model):
user = models.ForeignKey("register.User", on_delete=models.CASCADE)
movie = models.ForeignKey("Movie", on_delete=models....
0
votes
1
answer
56
views
Referencing more than one field on a Django Model
I am trying to reference 2 fields from a particular django model but it keeps giving me error. The models are displayed below, i want to reference 'building_type' and 'location' from property table to ...
1
vote
2
answers
975
views
SOLVED: Django ORM: How to round down (truncate) a query number?
SOLVED
I'm working with sensitive currency values. In my case, i have to reproduce a sheet with it's formulas.
The point is that i need to round down a currency value with 2 decimal places. A ...
1
vote
1
answer
1k
views
How to get table data (including child table and sub child data) based on id which obtains from another table data? Django
views
company = Company.objects.get(id = company_id) # getting input from django urls (<int:company_id>)
vehicles = CompanyContainVehicles.objects.filter(company_id=company.id) # Give all rows ...
1
vote
1
answer
2k
views
Filter an object that has multiple related objects in Django
Let's say I have two models that have one-to-many relationships as the code below.
I'd like to only get order objects that have more than one shipment object.
The only way I can think of is getting it ...
3
votes
0
answers
198
views
How to filter an annotated queryset by - Window function - without changing the value of the annotated field
I have a queryset of users, after annotating the rank of each user using Django Window function, I want to query for a user without modifying the rank value
users_points_query = users.order_by(
...
3
votes
1
answer
57
views
Filtering down through multiple ForeignKey relations in django
I am trying to get down through multiple-foreign key relationship where each Hotel has many Rooms, each Room has many Rateplans, each Rateplan has many Prices.
It resembles Christmas tree if you think ...
0
votes
1
answer
289
views
Django DB migration adds new columns, but do not edit the values already in the table
I have a python script for creating the tables and specifying the values that should be added to it. I use the following two commands to do the migration.
python manage.py makemigrations
python manage....
1
vote
2
answers
259
views
Django annotate + SUM how to get all entries
My models
class Machine(models.Model):
machineName = models.CharField(verbose_name="Machine Name", max_length=20, blank=False, null=False)
class SalesReport(models.Model):
machine = ...
1
vote
2
answers
536
views
while connecting to MicrosoftSQL server using Django facing django.db.utils.OperationalError:
drivers available with me
**python shell**
'''In [2]: pyodbc.drivers()'''
**Output:**
**Out[2]: ['SQL Server']**
code in settings.py django:
**Settings.py in django**
'''# Database
...
0
votes
1
answer
23
views
IntegrityError in database stored vlaues in django?
'''
My problem is database values can't stored properly
In below I uploded views functions file,model file as an images. so in model there are three fields but database stored only image stored and ...
3
votes
1
answer
698
views
Django bulk update with data two tables over
I want to bulk update a table with data two tables over. A solution has been given for the simpler case mentioned in the documentation of:
Entry.objects.update(headline=F('blog__name'))
For that ...
1
vote
1
answer
436
views
Compare year from DateTimeField/DateField Django ORM
I have a model configuration as below,
class Foo(models.Model):
start = models.DateTimeField()
end = models.DateTimeField()
How can I retrieve Foo instances with same Year?
Unsuccessfull try:
...
0
votes
2
answers
113
views
django not able to save all incidents in database
I have a working code which gets all incident details.
But i am unable to save complete data in database only the last record gets saved
def incidents(request):
incidentsServicenow = ...
0
votes
1
answer
289
views
How to save model form Data(User input of multiple users) into the database or dict in Django
I am trying to set up a Website for Employee Scheduling with Django. I am new to Web development, therefore I run into some problems, scince I have the feeling the Web handles things differently. I ...
24
votes
1
answer
17k
views
How to make/use a custom database function in Django
Prologue:
This is a question arising often in SO:
Equivalent of PostGIS ST_MakeValid in Django GEOS
Geodjango: How to Buffer From Point
Get random point from django PolygonField
Django custom for ...
1
vote
1
answer
4k
views
How to link existing tables in database to Django Models?
I am learning Django and i need to know whether i can link a table already present in the database to a model (since, i heard that tables are created by Django for whatever models we are creating ...
4
votes
0
answers
500
views
Django group by consecutive days (Friday, Saturday, Sunday)
I have an event that occurs everyday. Here is the model
class Event(models.Model):
date = models.DateField()
plays = models.IntegerField()
viewers = models.IntegerField()
time = ...
-3
votes
1
answer
31
views
How to get several records to be shown in one row in MySQL?
I have questions related to SELECT statement for this case:
For example there are 4 tables, which are StdCandidate, CourseChoice, Course, and EntranceTest.
The tables are shown in the image
-->
enter ...
9
votes
4
answers
10k
views
How to annotate a difference of datetime in days
I have a Booking model that has start and end datetime fields. I want to know how many days a booking covers. I can do this in Python but I need this value for further annotations.
Here's what I've ...