Re: Using one query set for another query

2023-04-09 Thread Harsh Vyas
Hi,
Need a slight justification on your case what exactly is the use case you 
need to resolve.
So far, I understood you need to know details about unpaid bills, 

Approach 1:- 
Model bill_payment_history will have data for field date_paid in case of 
only paid bills, so you can try 
to query something like

queryset= bill_payment_history.objects.filter(date_paid= None)

Approach 2:- 
You can annotate a field on all known_bills object using case statement for
 which different between current date and excepted_due_date is already 
breached.

For annotate and case refer to below docs:-
https://docs.djangoproject.com/en/4.2/ref/models/conditional-expressions/

Hope this solve your use case

On Wednesday, 29 March 2023 at 07:26:58 UTC+5:30 lone...@gmail.com wrote:

> Hello all,
>
> I am trying to use the query of:
> paid_bills = bill_payment_history.objects.filter(date_paid__year='2023', 
> date_paid__month='03')
>
> as criteria for another query to only show the unpaid bills.
>
> The known_bills model is my control list of known bills that occur 
> frequently.
> The  bill_payment_history model is my bill transaction table.  It is a 
> running history of transactions for bill payment.
>
> A sample of known_bills records is:
> bill_1
> bill_2
> bill_3
>
> A sample of  bill_payment_history is:
> bill_1 paid last month
> bill_2 paid last month
> bill_3 paid last month
> bill_1 paid this month
> bill_2 paid this month
> bill_3 paid this month
>
> What I am trying to do is use bill_payment_history filtered on date_paid 
> by year and month and query the known_bills table to see what bills have 
> not been paid yet.  I keep trying something similar to:  results = 
> paid_bills.exclude(short_description__in=known_bills)
>
> but my results either keep coming up with all of the records or none of 
> them.  What am I doing wrong?
>
> Here is the model information:
>
> class known_bills(models.Model):
> #Full bank transaction
> description = models.CharField(max_length=255)
> #String value to search the CSV file with.
> short_description = models.CharField(max_length=255, unique=True)
> #Value I know it as.
> friendly_name = models.CharField(max_length=255)
> expected_due_date = models.DateField()
> expected_cost = models.DecimalField(max_digits=6,decimal_places=2)
>
> class bill_payment_history(models.Model):
> description = models.CharField(max_length=255)
> short_description = models.ForeignKey(known_bills, 
> on_delete=models.CASCADE)
> friendly_name = models.CharField(max_length=255)
> date_paid = models.DateField()
> cost = models.DecimalField(max_digits=6,decimal_places=2)
>
> class Meta:
> unique_together = (
> ('short_description',
> 'date_paid'),
> )
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/066fd675-7a0a-4ed0-834e-2f44c6786ecan%40googlegroups.com.


Using one query set for another query

2023-03-28 Thread lone...@gmail.com
Hello all,

I am trying to use the query of:
paid_bills = bill_payment_history.objects.filter(date_paid__year='2023', 
date_paid__month='03')

as criteria for another query to only show the unpaid bills.

The known_bills model is my control list of known bills that occur 
frequently.
The  bill_payment_history model is my bill transaction table.  It is a 
running history of transactions for bill payment.

A sample of known_bills records is:
bill_1
bill_2
bill_3

A sample of  bill_payment_history is:
bill_1 paid last month
bill_2 paid last month
bill_3 paid last month
bill_1 paid this month
bill_2 paid this month
bill_3 paid this month

What I am trying to do is use bill_payment_history filtered on date_paid by 
year and month and query the known_bills table to see what bills have not 
been paid yet.  I keep trying something similar to:  results = 
paid_bills.exclude(short_description__in=known_bills)

but my results either keep coming up with all of the records or none of 
them.  What am I doing wrong?

Here is the model information:

class known_bills(models.Model):
#Full bank transaction
description = models.CharField(max_length=255)
#String value to search the CSV file with.
short_description = models.CharField(max_length=255, unique=True)
#Value I know it as.
friendly_name = models.CharField(max_length=255)
expected_due_date = models.DateField()
expected_cost = models.DecimalField(max_digits=6,decimal_places=2)

class bill_payment_history(models.Model):
description = models.CharField(max_length=255)
short_description = models.ForeignKey(known_bills, 
on_delete=models.CASCADE)
friendly_name = models.CharField(max_length=255)
date_paid = models.DateField()
cost = models.DecimalField(max_digits=6,decimal_places=2)

class Meta:
unique_together = (
('short_description',
'date_paid'),
)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a9327f8-6a00-49d2-8411-bd9fb03c64c0n%40googlegroups.com.


How to write query user between dates no leaves?

2023-02-24 Thread Prashanth Patelc
How to write orm query?

User don't have any leave between two dates in django ?

leave_data =
EmployeeLeaves.objects.filter(~Q(approval_status='Approved'),~Q(approval_status='Cancelled'),~Q(approval_status='Rejected'),

 from_date__gte=month_first_date, to_date__lte=month_last_day,
   employee=request.user)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMCU6CqyQeOn1O%2B0LHHbphHBqHDDYbSWa0msn5%3DJigi6WF1t%2BQ%40mail.gmail.com.


Fwd: How to create orm query if data is exist or not ?

2023-02-23 Thread Prashanth Patelc
-- Forwarded message -
From: Prashanth Patelc 
Date: Thu, Feb 23, 2023 at 5:11 PM
Subject: How to create orm query if data is exist or not ?
To: 


Hi all,

How to create orm query with data exist or not ?

How to check if approval_status Pending and Rejected with same user
contains

from_date   approval_status   User
2023-01-20  - ApprovedNewUser
2023-01-12  - Rejected   NewUser
2023-01-06  -Approved   NewUser



If User contains above details in month between Create "
Timesheet Model" Eg:
Timesheet.objects.create(date=date,emaployee=emp,status=1)

leave_data =
EmployeeLeaves.objects.filter(~Q(approval_status='Approved'),~Q(approval_status='Cancelled'),~Q(approval_status='Rejected'),

 from_date__gte=month_first_date, to_date__lte=month_last_day,
   employee=request.user).


If User Contains Pending Don't create Model

leaves_data = EmployeeLeaves.objects.filter(~Q(approval_status='Pending'),

from_date__gte=month_first_date, to_date__lte=month_last_day,
employee=request.user).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMCU6Cq7tCAKeSmmyZmcTtLH2kSRMhtqHKzz0HqDyQWyhEyK4Q%40mail.gmail.com.


How to create orm query if data is exist or not ?

2023-02-23 Thread Prashanth Patelc
Hi all,

How to create orm query with data exist or not ?

How to check if approval_status Pending and Rejected with same user
contains

from_date   approval_status   User
2023-01-20  - ApprovedNewUser
2023-01-12  - Rejected   NewUser
2023-01-06  -Approved   NewUser



If User contains above details in month between Create "
Timesheet Model" Eg:
Timesheet.objects.create(date=date,emaployee=emp,status=1)

leave_data =
EmployeeLeaves.objects.filter(~Q(approval_status='Approved'),~Q(approval_status='Cancelled'),~Q(approval_status='Rejected'),

 from_date__gte=month_first_date, to_date__lte=month_last_day,
   employee=request.user).


If User Contains Pending Don't create Model

leaves_data = EmployeeLeaves.objects.filter(~Q(approval_status='Pending'),

from_date__gte=month_first_date, to_date__lte=month_last_day,
employee=request.user).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMCU6CoJkrj6b0Th5NnGMnq4hpcNbtFE1X6ZqREJfBK2KA-wRg%40mail.gmail.com.


Orm query

2023-02-17 Thread Prashanth Patelc
Hi all,

This is my model if model contain previous month dates I need to and store
the data If user is new previous data is not available I need to store
directly to db .
How to write orm query?


Attendance.object.filter(user=emp,date=enddate,crea_date=strdate)



If dates is not available in attendance model how to write orm query?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMCU6CpfDPBznuRHVuz%3DbaJF8-R4Zn2U9GamBfm52fRMQqZ9rQ%40mail.gmail.com.


Complex Query

2022-11-20 Thread sebasti...@gmail.com
Hello Guys,

you find my question in attachment because tabs in tables are not shown 
when i send it in gmail.

Please help me on my question who make i a complex query.

Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/935740cb-8289-4341-80c4-407b0100e3adn%40googlegroups.com.


Question
Description: Binary data


Re: manage.py loaddata: Problem installing fixture... Email matching query does not exist

2022-10-17 Thread Luiz Angelo Daros de Luca
Hello Moritz,

I have good news. I managed to migrate from sqlite3 to postgresql.

You need to apply this patch and load each mailman app individually
because it conflicts with existing objects, truncating the *_profile
tables on the way.

https://gitlab.com/mailman/hyperkitty/-/merge_requests/469

The commit message has a little how-to.

I still haven't tested it on my production server but I might do it soon.

Regards,

Luiz

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJq09z7ZMFHkUy46b2tJHLcny_bHmMyCfzP%3DCRQwXMgQZzJnzQ%40mail.gmail.com.


Re: manage.py loaddata: Problem installing fixture... Email matching query does not exist

2022-09-27 Thread Luiz Angelo Daros de Luca
Hello Moritz,

I got the same problem doing the same mailman3 migration (but to a postgres 
db).
Do you have a solution?

Regards,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e8afbea0-8517-41ee-94ef-4e893005dae4n%40googlegroups.com.


DoesNotExist at /admin/blog/blog/add/: blog matching query does not exist

2022-09-13 Thread Jaap van Wingerde
Suddenly I can no longer add blogs to Django. Django says 'blog
matching query does not exist'. That seems strange to me because I want
to add something to the database and not request a blog. What could be
going on here?

admin.py:
class blogadmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if not change:
obj.added_by_user = request.user.username
obj.ip_added = request.META['REMOTE_ADDR']
if obj.ip_added == '127.0.0.1':
obj.ip_added = request.META['HTTP_X_FORWARDED_FOR']
obj.publish = False
del obj.publish_date
else:
obj.changed_by_user = request.user.username
obj.ip_changed = request.META['REMOTE_ADDR']
if obj.ip_changed == '127.0.0.1':
obj.ip_changed = request.META['HTTP_X_FORWARDED_FOR']
if obj.publish == True:
if not obj.publish_date:
obj.publish_date = obj.datetime_changed
super(blogadmin,self).save_model(request, obj, form, change)

I can add text, photographs etc., but no blogs, changing is ok.

Notifications:
DoesNotExist at /admin/blog/blog/add/

blog matching query does not exist.

Request Method: POST
Request URL:http://127.0.0.1:8001/admin/blog/blog/add/
Django Version: 4.1.1
Exception Type: DoesNotExist
Exception Value:

blog matching query does not exist.

Traceback
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8001/admin/blog/blog/add/

Django Version: 4.1.1
Python Version: 3.10.5
Installed Applications:
['grappelli',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog.apps.BlogConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.contrib.admindocs.middleware.XViewMiddleware']

Traceback (most recent call last):
  File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/core/handlers/exception.py",
line 55, in inner response = get_response(request) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/core/handlers/base.py",
line 197, in _get_response response = wrapped_callback(request,
*callback_args, **callback_kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
line 686, in wrapper return self.admin_site.admin_view(view)(*args,
**kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
line 133, in _wrapped_view response = view_func(request, *args,
**kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/views/decorators/cache.py",
line 62, in _wrapped_view_func response = view_func(request, *args,
**kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/sites.py",
line 242, in inner return view(request, *args, **kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
line 1890, in add_view return self.changeform_view(request, None,
form_url, extra_context) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
line 46, in _wrapper return bound_method(*args, **kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
line 133, in _wrapped_view response = view_func(request, *args,
**kwargs) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
line 1750, in changeform_view return self._changeform_view(request,
object_id, form_url, extra_context) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
line 1802, in _changeform_view self.save_model(request, new_object,
form, not add) File "/var/django/liakoster.nl/blog-1/blog/admin.py",
line 26, in save_model super(blogadmin,self).save_model(request, obj,
form, change) File
"/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
line 1225, in save_model obj.save() File
"/var/django/liakoster.nl/blog-1/lib/python3.10/si

How to get last child object of a parent model by query

2022-08-05 Thread Sencer Hamarat
Hi,

Let's say there are two related models

class Parent(models.Model):
...

class Child(models.Model):
parent = models.ForeingKey(Parent)

I need to fetch every last child of specific parent objects by query.
Is there a way to do this instead iterating Parent objects to gather last
childs like:

last_childs = list()
for parent in Parent.objects.filter(id__in=[1, 2, 3, 4]):
last_childs.append(parent.child_set.last())


Kind regards,
Sencer HAMARAT

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZhhNW0bAZjpetbvwQdRx03fiVTtL2gYGTtuvzFKRKJfvQ%40mail.gmail.com.


Casting a variable as array in a query

2022-07-26 Thread Sencer Hamarat
I'm having a problem with this query:

I believe,

Q(bundle__contains=OuterRef("book_id"))

part of the query is expecting an array instead of single value.

I'm getting this error:


ProgrammingError: operator does not exist: jsonb @> bigint
LINE 1: ...lisher"."book_id") OR U0."bundle" @> ("publisher_...
 ^
HINT: No operator matches the given name and argument types. You might need
to add explicit type casts.



Is there a way to handle this error? How can I cast the value into an array
within the query?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZgfrDY6ceG5jTcX81-6%3DDQHAf0sZms7%3D3B_iyDiX2949g%40mail.gmail.com.


Re: Pass or refer parent query value into subquery

2022-07-26 Thread Ross Meredith
Sorry I haven't used the JSONField myself before.

On Tue, Jul 26, 2022 at 5:01 PM Sencer Hamarat 
wrote:

> Thanks Ross,
> Very appreciated.
> That's what I need.
>
> I'm also having a problem with this query after I implemented the solution:
>
> I believe,
> Q(bundle__contains=OuterRef("book_id"))
> part of the query is expecting an array instead of direct value.
>
> I'm getting this error:
>
> ProgrammingError: operator does not exist: jsonb @> bigint
> LINE 1: ...lisher"."book_id") OR U0."bundle" @> ("publisher_...
>  ^
> HINT:  No operator matches the given name and argument types. You might
> need to add explicit type casts.
>
> Is there a way to handle this error? How can I cast the value into an
> array?
>
>
>
> Regards,
> Sencer HAMARAT
>
>
>
> On Tue, Jul 26, 2022 at 6:34 PM Ross Meredith 
> wrote:
>
>>
>> https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.OuterRef
>>
>> On Tue, Jul 26, 2022 at 4:27 PM Sencer Hamarat 
>> wrote:
>>
>>> Hi,
>>>
>>> I need to pass the parent query book_id value into the subquery.
>>> Here is the model and the current state of the query I reached.
>>>
>>> class Publisher(models.Model):
>>> book = models.ForeignKey(Book)
>>> bundle = models.JSONField()
>>>
>>>
>>> current_sales_count_query = Publisher.objects.filter(
>>> Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
>>> ).values('id')
>>>
>>> query = Publisher.objects.filter(
>>>  **query_params,
>>> ).select_related(
>>>  'book',
>>> ).annotate(
>>>
>>> current_sales_count=Count(Subquery(current_sales_count_query)),
>>> )
>>>
>>> Sql Output:
>>>
>>> SELECT "publisher"."id",
>>>..
>>>COUNT((SELECT U0."id"
>>>   FROM "publisher" U0
>>>   WHERE (U0."book_id" = (U0."logbook_id") OR
>>> U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
>>>"books"."id",
>>>
>>> FROM "publisher"
>>>  INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
>>> WHERE "publisher"."book_id" IN (1, 2, 12)
>>> GROUP BY "publisher"."id", "books"."id"
>>>
>>> But subquery insists on using book_id from itself with that query.
>>> What should I do to make things right?
>>>
>>>
>>>
>>> King regards,
>>> Sencer HAMARAT
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACp8TZiY-bcdC4%3DbwCde7MVothzqtYjYL%3Doi2dcmL2KZPYe6nQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACp8TZiY-bcdC4%3DbwCde7MVothzqtYjYL%3Doi2dcmL2KZPYe6nQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA1Tdz2uKnKXnTrTkj47meDjkf8c3uJSo4AC4txq%3Dhfro8dYWw%40mail.gmail.com.


Re: Pass or refer parent query value into subquery

2022-07-26 Thread Sencer Hamarat
Thanks Ross,
Very appreciated.
That's what I need.

I'm also having a problem with this query after I implemented the solution:

I believe,
Q(bundle__contains=OuterRef("book_id"))
part of the query is expecting an array instead of direct value.

I'm getting this error:

ProgrammingError: operator does not exist: jsonb @> bigint
LINE 1: ...lisher"."book_id") OR U0."bundle" @> ("publisher_...
 ^
HINT:  No operator matches the given name and argument types. You might
need to add explicit type casts.

Is there a way to handle this error? How can I cast the value into an array?



Regards,
Sencer HAMARAT



On Tue, Jul 26, 2022 at 6:34 PM Ross Meredith  wrote:

>
> https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.OuterRef
>
> On Tue, Jul 26, 2022 at 4:27 PM Sencer Hamarat 
> wrote:
>
>> Hi,
>>
>> I need to pass the parent query book_id value into the subquery.
>> Here is the model and the current state of the query I reached.
>>
>> class Publisher(models.Model):
>> book = models.ForeignKey(Book)
>> bundle = models.JSONField()
>>
>>
>> current_sales_count_query = Publisher.objects.filter(
>> Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
>> ).values('id')
>>
>> query = Publisher.objects.filter(
>>  **query_params,
>> ).select_related(
>>  'book',
>> ).annotate(
>>
>> current_sales_count=Count(Subquery(current_sales_count_query)),
>> )
>>
>> Sql Output:
>>
>> SELECT "publisher"."id",
>>..
>>COUNT((SELECT U0."id"
>>   FROM "publisher" U0
>>   WHERE (U0."book_id" = (U0."logbook_id") OR
>> U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
>>"books"."id",
>>
>> FROM "publisher"
>>  INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
>> WHERE "publisher"."book_id" IN (1, 2, 12)
>> GROUP BY "publisher"."id", "books"."id"
>>
>> But subquery insists on using book_id from itself with that query.
>> What should I do to make things right?
>>
>>
>>
>> King regards,
>> Sencer HAMARAT
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZiY-bcdC4%3DbwCde7MVothzqtYjYL%3Doi2dcmL2KZPYe6nQ%40mail.gmail.com.


Re: Pass or refer parent query value into subquery

2022-07-26 Thread Ross Meredith
https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.OuterRef

On Tue, Jul 26, 2022 at 4:27 PM Sencer Hamarat 
wrote:

> Hi,
>
> I need to pass the parent query book_id value into the subquery.
> Here is the model and the current state of the query I reached.
>
> class Publisher(models.Model):
> book = models.ForeignKey(Book)
> bundle = models.JSONField()
>
>
> current_sales_count_query = Publisher.objects.filter(
> Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
> ).values('id')
>
> query = Publisher.objects.filter(
>  **query_params,
> ).select_related(
>  'book',
> ).annotate(
> current_sales_count=Count(Subquery(current_sales_count_query)),
> )
>
> Sql Output:
>
> SELECT "publisher"."id",
>..
>COUNT((SELECT U0."id"
>   FROM "publisher" U0
>   WHERE (U0."book_id" = (U0."logbook_id") OR
> U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
>"books"."id",
>....
> FROM "publisher"
>  INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
> WHERE "publisher"."book_id" IN (1, 2, 12)
> GROUP BY "publisher"."id", "books"."id"
>
> But subquery insists on using book_id from itself with that query.
> What should I do to make things right?
>
>
>
> King regards,
> Sencer HAMARAT
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA1Tdz1N422oNtAkTtQpw1yu529PfdCPeevW%2BWbuBWfk_XO0RQ%40mail.gmail.com.


Pass or refer parent query value into subquery

2022-07-26 Thread Sencer Hamarat
Hi,

I need to pass the parent query book_id value into the subquery.
Here is the model and the current state of the query I reached.

class Publisher(models.Model):
book = models.ForeignKey(Book)
bundle = models.JSONField()


current_sales_count_query = Publisher.objects.filter(
Q(book_id=F("book_id")) | Q(bundle__contains=F("book_id")),
).values('id')

query = Publisher.objects.filter(
 **query_params,
).select_related(
 'book',
).annotate(
current_sales_count=Count(Subquery(current_sales_count_query)),
)

Sql Output:

SELECT "publisher"."id",
   ..
   COUNT((SELECT U0."id"
  FROM "publisher" U0
  WHERE (U0."book_id" = (U0."logbook_id") OR
U0."current_tree_level" @> (U0."book_id") "current_rejected_count",
   "books"."id",
   
FROM "publisher"
 INNER JOIN "books" ON ("publisher"."book_id" = "books"."id")
WHERE "publisher"."book_id" IN (1, 2, 12)
GROUP BY "publisher"."id", "books"."id"

But subquery insists on using book_id from itself with that query.
What should I do to make things right?



King regards,
Sencer HAMARAT

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZjKRQS2_OZsTey%2BPiJJF2nDzCjLR3uf09Y6seZ9_gc5Yg%40mail.gmail.com.


Re: Help to implement join query in django orm

2022-07-25 Thread 'Amitesh Sahay' via Django users
10. How to perform join operations in django ORM? — Django ORM Cookbook 2.0 
documentation (agiliq.com)



Try this 

On Monday, 25 July, 2022 at 01:18:44 pm IST, Mihir Patel 
 wrote:  
 
 is anyone having login issue? , i am unable to authenticate a user in my 
website
On Sun, Jul 24, 2022 at 10:37 PM Jitendra kumar Patra 
 wrote:

Ping me 7008080545
On Fri, 22 Jul, 2022, 12:16 Avi shah,  wrote:

I have two tables Tbl 1 & Tbl 2 
I need to connect the two tables using a join 

Thanks and regards, Avi shah 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa7AFNmoep5MT3MwoYn1ZF0S%3DENPUdVAO-_3EmVyAzCub_Jkg%40mail.gmail.com.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOAROf%3DgMPbSQ37f81A0rpRr7NgiUFF8ZyTsF8bZ-KG9Sgh%3DkA%40mail.gmail.com.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC10kRFL%3D1a6T0-DG%3DZTsBugJa2_iFf-itHjSwAc9-2vHOnB7g%40mail.gmail.com.
  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1973455060.1368718.1658735565276%40mail.yahoo.com.


Re: Help to implement join query in django orm

2022-07-25 Thread Mihir Patel
is anyone having login issue? , i am unable to authenticate a user in my
website

On Sun, Jul 24, 2022 at 10:37 PM Jitendra kumar Patra <
jitendrapatra...@gmail.com> wrote:

> Ping me 7008080545
>
> On Fri, 22 Jul, 2022, 12:16 Avi shah,  wrote:
>
>> I have two tables
>> Tbl 1
>> &
>> Tbl 2
>>
>> I need to connect the two tables using a join
>>
>>
>> Thanks and regards,
>> Avi shah
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALa7AFNmoep5MT3MwoYn1ZF0S%3DENPUdVAO-_3EmVyAzCub_Jkg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOAROf%3DgMPbSQ37f81A0rpRr7NgiUFF8ZyTsF8bZ-KG9Sgh%3DkA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC10kRFL%3D1a6T0-DG%3DZTsBugJa2_iFf-itHjSwAc9-2vHOnB7g%40mail.gmail.com.


Re: Help to implement join query in django orm

2022-07-24 Thread Jitendra kumar Patra
Ping me 7008080545

On Fri, 22 Jul, 2022, 12:16 Avi shah,  wrote:

> I have two tables
> Tbl 1
> &
> Tbl 2
>
> I need to connect the two tables using a join
>
>
> Thanks and regards,
> Avi shah
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALa7AFNmoep5MT3MwoYn1ZF0S%3DENPUdVAO-_3EmVyAzCub_Jkg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOAROf%3DgMPbSQ37f81A0rpRr7NgiUFF8ZyTsF8bZ-KG9Sgh%3DkA%40mail.gmail.com.


Re: Help to implement join query in django orm

2022-07-24 Thread Abhishek Gupta
Hey, you have to write custom raw query for join tables which are not
connected with foreign key relationship in django.

On Sun, Jul 24, 2022, 11:17 Lalit Suthar  wrote:

> this can be helpful
>
> https://betterprogramming.pub/django-select-related-and-prefetch-related-f23043fd635d
>
> On Sun, 24 Jul 2022 at 00:30, Ryan Nowakowski  wrote:
>
>> On Fri, Jul 22, 2022 at 12:16:14PM +0530, Avi shah wrote:
>> > I have two tables
>> > Tbl 1
>> > &
>> > Tbl 2
>> >
>> > I need to connect the two tables using a join
>>
>> If these tables were created outside of Django, in other words, not
>> using manage.py migrate, you can use Django's legacy database support to
>> auto generate the models[1].  After that, each table will have a model
>> associated with it.  You can then use Django's ForeignKey support to query
>> the tables.
>>
>>
>> [1] https://docs.djangoproject.com/en/4.0/howto/legacy-databases/
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/20220723185935.GB15838%40fattuba.com
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGp2JVHauj%2BS47HfmcYOrNQHJk3bTQbtdBm%3DdLRNx_8woM6XwQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAGp2JVHauj%2BS47HfmcYOrNQHJk3bTQbtdBm%3DdLRNx_8woM6XwQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABwiCvrSuY6AmBkARJFt%2BaCeR_wFVGf%3DKWdLP227GApDW4AcWQ%40mail.gmail.com.


Re: Help to implement join query in django orm

2022-07-23 Thread Lalit Suthar
this can be helpful
https://betterprogramming.pub/django-select-related-and-prefetch-related-f23043fd635d

On Sun, 24 Jul 2022 at 00:30, Ryan Nowakowski  wrote:

> On Fri, Jul 22, 2022 at 12:16:14PM +0530, Avi shah wrote:
> > I have two tables
> > Tbl 1
> > &
> > Tbl 2
> >
> > I need to connect the two tables using a join
>
> If these tables were created outside of Django, in other words, not
> using manage.py migrate, you can use Django's legacy database support to
> auto generate the models[1].  After that, each table will have a model
> associated with it.  You can then use Django's ForeignKey support to query
> the tables.
>
>
> [1] https://docs.djangoproject.com/en/4.0/howto/legacy-databases/
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20220723185935.GB15838%40fattuba.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGp2JVHauj%2BS47HfmcYOrNQHJk3bTQbtdBm%3DdLRNx_8woM6XwQ%40mail.gmail.com.


Re: Help to implement join query in django orm

2022-07-23 Thread Ryan Nowakowski
On Fri, Jul 22, 2022 at 12:16:14PM +0530, Avi shah wrote:
> I have two tables
> Tbl 1
> &
> Tbl 2
> 
> I need to connect the two tables using a join

If these tables were created outside of Django, in other words, not
using manage.py migrate, you can use Django's legacy database support to
auto generate the models[1].  After that, each table will have a model
associated with it.  You can then use Django's ForeignKey support to query
the tables.


[1] https://docs.djangoproject.com/en/4.0/howto/legacy-databases/
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20220723185935.GB15838%40fattuba.com.


Help to implement join query in django orm

2022-07-21 Thread Avi shah
I have two tables
Tbl 1
&
Tbl 2

I need to connect the two tables using a join


Thanks and regards,
Avi shah

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa7AFNmoep5MT3MwoYn1ZF0S%3DENPUdVAO-_3EmVyAzCub_Jkg%40mail.gmail.com.


manage.py loaddata: Problem installing fixture... Email matching query does not exist

2022-07-07 Thread Moritz Both

Greetings, 
 I am a mailman3 user and trying to migrate the database from sqlite to 
mysql. I did it like here: 
https://www.rockandnull.com/django-dumpdata/

Basically I exported the data from sqlite using "dumpdate" and try to 
import using "loaddata". I did do "migrate --run-syncdb"

Unfortunatlly I get the error below. I am totally new to django. On the 
mailman3 mailing list, folks pointed me here - this seems to be a django 
issue?

Thank you inadvance for any help.
Moritz

Mailman Core Version GNU Mailman 3.3.5 (Tom Sawyer) 
Mailman Core API Version 3.1 
Mailman Core Python Version 3.8.13 (default, May 19 2022, 15:06:19) 
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] 

Traceback (most recent call last): 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py",
 
line 173, in __get__ 
rel_obj = self.field.get_cached_value(instance) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/fields/mixins.py",
 
line 15, in get_cached_value 
return instance._state.fields_cache[cache_name] 
KeyError: 'starting_email' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
  File "manage.py", line 10, in  
execute_from_command_line(sys.argv) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/__init__.py",
 
line 419, in execute_from_command_line 
utility.execute() 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/__init__.py",
 
line 413, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/base.py",
 
line 354, in run_from_argv 
self.execute(*args, **cmd_options) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/base.py",
 
line 398, in execute 
output = self.handle(*args, **options) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py",
 
line 78, in handle 
self.loaddata(fixture_labels) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py",
 
line 123, in loaddata 
self.load_label(fixture_label) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py",
 
line 190, in load_label 
obj.save(using=self.using) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/core/serializers/base.py",
 
line 223, in save 
models.Model.save_base(self.object, using=using, raw=True, **kwargs) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/base.py", 
line 763, in save_base 
pre_save.send( 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/dispatch/dispatcher.py",
 
line 180, in send 
return [ 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/dispatch/dispatcher.py",
 
line 181, in  
(receiver, receiver(signal=self, sender=sender, **named)) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/hyperkitty/signals.py", 
line 96, in Thread_on_pre_save 
kwargs["instance"].on_pre_save() 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/hyperkitty/models/thread.py",
 
line 157, in on_pre_save 
self.find_starting_email() 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/hyperkitty/models/thread.py",
 
line 149, in find_starting_email 
if self.starting_email is not None: 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py",
 
line 187, in __get__ 
rel_obj = self.get_object(instance) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py",
 
line 307, in get_object 
return super().get_object(instance) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py",
 
line 154, in get_object 
return qs.get(self.field.get_reverse_related_filter(instance)) 
  File 
"*/home/daneben/*.local/lib/python3.8/site-packages/django/db/models/query.py", 
line 435, in get 
raise self.model.DoesNotExist( 
hyperkitty.models.email.DoesNotExist: Problem installing fixture 
'/home/daneben/mailman-suite/datadump.json': Email matching query does not 
exist. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a0a4a372-5270-4e70-9507-a8a6d2df0b04n%40googlegroups.com.


Lost connection to MySQL server during query

2022-06-17 Thread Larry Martell
I have a standalone python script (i.e. not part of a web app) that
makes use of the ORM. I call djago.setup(), make some queries, then
call a function that can take 8 hours or more to run. When the
function returns I want to make more queries, but they fail with 'Lost
connection to MySQL server during query'. My DB wait_timeout is set to
8 hours and if the function returns in less than 8 hours I don't get
the error, so I thought I understood what was going on.

But then I read about CONN_MAX_AGE which we do not set. If that is not
set it should default to 0, which should mean that it gets a new
connection for each request so we should not get the Lost connection
message. Does that not work when using djago.setup()?

Further reading I saw said to call close_old_connections() or
connection.close() before calling the long running function. What is
the difference between these 2 and is one a better practice than the
other?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY4tBWRsLBW5URC%3DNcBgmuFhMaSxTO_y1rGf8HUD80B3Rw%40mail.gmail.com.


Re: Negated filtering by lookup expression sent via url query

2022-05-31 Thread Lalit Suthar
you can write custom filtering classes and methods using Django filters.
There you can define fields and methods according to your use case
example:
https://stackoverflow.com/questions/43009538/use-custom-filter-with-django-modelchoice-filter

On Tue, 31 May 2022 at 19:16, Sencer Hamarat 
wrote:

>
> Hi,
>
> Is there any way to negate filtering with the django-filter package which
> lookup expression sent via url query, such as:
>
> http://example.com/?name__not_contains=john
>
>
> The request above has to be passed through the django filterset class and
> the class has to be returned with the queryset exclude query with name
> argument and "john" value.
>
> Something like:
>
> self.queryset.exclude(name="john")
>
> Kind regards,
> Sencer HAMARAT
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACp8TZg0QFj2kST7m%3DoM4AoS3%3D3DOBhTm0MzDpJvLup_woYEYQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACp8TZg0QFj2kST7m%3DoM4AoS3%3D3DOBhTm0MzDpJvLup_woYEYQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGp2JVHoA9dHLDdmrwDJ4X65NTEq30dvfBn5ia3FTUkbijmPoQ%40mail.gmail.com.


Negated filtering by lookup expression sent via url query

2022-05-31 Thread Sencer Hamarat
Hi,

Is there any way to negate filtering with the django-filter package which
lookup expression sent via url query, such as:

http://example.com/?name__not_contains=john


The request above has to be passed through the django filterset class and
the class has to be returned with the queryset exclude query with name
argument and "john" value.

Something like:

self.queryset.exclude(name="john")

Kind regards,
Sencer HAMARAT

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZg0QFj2kST7m%3DoM4AoS3%3D3DOBhTm0MzDpJvLup_woYEYQ%40mail.gmail.com.


Can I use session.userid in models FK restriction query?

2022-02-11 Thread lone...@gmail.com
Hello all,

 I am curious if I can use the session.userid in a model FK restriction 
query.

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/18762bd6-5b1d-4397-b76d-e95e8a12f2ean%40googlegroups.com.


Re: Employee matching query does not exist

2022-01-05 Thread Gwanghyeon Gim
Two possible scenarios.

1. self.request.POST doesn't have any key named 'employee_id', so 
self.request.POST.get('employee_id') returns None
2. self.request.POST.get('employee_id') has value like 'Sam', but Employee 
model doesn't have any object whose name equals to 
self.request.POST.get('employee_id').

On Wednesday, 5 January 2022 at 22:53:30 UTC+9 reyo...@gmail.com wrote:

> Django don't saw a employe who have this ID
>  so you can use filter if there's not matching in your database he return 
> [ ]. 
>
> obj.employee= 
> Employee.objects.filter(name=self.request.POST.get('employee_id'))
>
> Le mardi 4 janvier 2022 à 15:44:55 UTC+1, jitendra...@gmail.com a écrit :
>
>> name column row's data not matching from database
>>
>> Show that you are getting error .
>>
>>
>> So we use the Expection then you can easily handle the error ..
>>
>> On Tue, 4 Jan 2022, 8:05 pm yassin kamanyile,  wrote:
>>
>>> please team ..i  got an error from that line below
>>>
>>> obj.employee = Employee.objects.get(name=self.request.POST.get(
>>> 'employee_id'))
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a458eed7-ace9-4ff7-9d41-dbf679389144n%40googlegroups.com.


Re: Employee matching query does not exist

2022-01-05 Thread Julio Cojom
Hi,

Try the following.

employee =self.request.POST.get('employee_id')
print(employee)
obj.employee= Employee.objects.filter(name=employee)

It will crash again, but you can see in the console if it's printing the id
correctly.

I've assume this is a function, not a class view by the way that you are
handling the query set. And I believe with the poor information that you
give us, that the 'employee_id' isn't the right keyword to get the value
desired.

Usually you can use the name in your models to refer to the field that you
want the data. If you want the primary key, you should use pk of an
existing record in the database.

Also you can print self.request.POST to see all the data that I has, that
is a dictionary so you can see they keyword you need and the data in brings.

Regards.

Julio Cojom.






El mié., 5 de enero de 2022 7:53 a. m., Rey Ondiyo 
escribió:

> Django don't saw a employe who have this ID
>  so you can use filter if there's not matching in your database he return
> [ ].
>
> obj.employee=
> Employee.objects.filter(name=self.request.POST.get('employee_id'))
>
> Le mardi 4 janvier 2022 à 15:44:55 UTC+1, jitendra...@gmail.com a écrit :
>
>> name column row's data not matching from database
>>
>> Show that you are getting error .
>>
>>
>> So we use the Expection then you can easily handle the error ..
>>
>> On Tue, 4 Jan 2022, 8:05 pm yassin kamanyile,  wrote:
>>
>>> please team ..i  got an error from that line below
>>>
>>> obj.employee = Employee.objects.get(name=self.request.POST.get(
>>> 'employee_id'))
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7e08fe8e-bd4e-4779-be29-79d5453ea116n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7e08fe8e-bd4e-4779-be29-79d5453ea116n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHRQUH%3D_46u4BugGaX4qaLTOCjsfQA830a6wES8tWFOrALMv_Q%40mail.gmail.com.


Re: Employee matching query does not exist

2022-01-05 Thread Rey Ondiyo
Django don't saw a employe who have this ID
 so you can use filter if there's not matching in your database he return [ 
]. 

obj.employee= 
Employee.objects.filter(name=self.request.POST.get('employee_id'))

Le mardi 4 janvier 2022 à 15:44:55 UTC+1, jitendra...@gmail.com a écrit :

> name column row's data not matching from database
>
> Show that you are getting error .
>
>
> So we use the Expection then you can easily handle the error ..
>
> On Tue, 4 Jan 2022, 8:05 pm yassin kamanyile,  wrote:
>
>> please team ..i  got an error from that line below
>>
>> obj.employee = Employee.objects.get(name=self.request.POST.get(
>> 'employee_id'))
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e08fe8e-bd4e-4779-be29-79d5453ea116n%40googlegroups.com.


Re: Employee matching query does not exist

2022-01-04 Thread Jitendra kumar Patra
name column row's data not matching from database

Show that you are getting error .


So we use the Expection then you can easily handle the error ..

On Tue, 4 Jan 2022, 8:05 pm yassin kamanyile,  wrote:

> please team ..i  got an error from that line below
>
> obj.employee = Employee.objects.get(name=self.request.POST.get(
> 'employee_id'))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOAROfn%2Bd7C4JDSAFZpqoSm2kVxCBL16qdA93PS0oXvRD3-VoA%40mail.gmail.com.


Employee matching query does not exist

2022-01-04 Thread yassin kamanyile
please team ..i  got an error from that line below

obj.employee = Employee.objects.get(name=self.request.POST.get('employee_id'
))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com.


Re: User matching query does not exist.

2021-10-18 Thread Nicholas Bartlett
Hi all, I have a similar issue on my DB. 

Internal Server Error: /ms_app/customers/19

Traceback (most recent call last):

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/core/handlers/exception.py",
 
line 47, in inner

response = get_response(request)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/core/handlers/base.py",
 
line 204, in _get_response

response = response.render()

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/response.py",
 
line 105, in render

self.content = self.rendered_content

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/response.py",
 
line 83, in rendered_content

return template.render(context, self._request)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/backends/django.py",
 
line 61, in render

return self.template.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 170, in render

return self._render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 162, in _render

return self.nodelist.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 938, in render

bit = node.render_annotated(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 905, in render_annotated

return self.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/loader_tags.py",
 
line 150, in render

return compiled_parent._render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 162, in _render

return self.nodelist.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 938, in render

bit = node.render_annotated(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 905, in render_annotated

return self.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/loader_tags.py",
 
line 62, in render

result = block.nodelist.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 938, in render

bit = node.render_annotated(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 905, in render_annotated

return self.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/defaulttags.py",
 
line 211, in render

nodelist.append(node.render_annotated(context))

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 905, in render_annotated

return self.render(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/defaulttags.py",
 
line 305, in render

match = condition.eval(context)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/defaulttags.py",
 
line 889, in eval

return self.value.resolve(context, ignore_failures=True)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/template/base.py",
 
line 698, in resolve

new_obj = func(obj, *arg_vals)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/MSNDashboard/msCentral/mscentral_project/ms_app/templatetags/custom_tags.py",
 
line 8, in is_group

group = Group.objects.get(name=group_name)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/db/models/manager.py",
 
line 85, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

  File 
"/Users/nicholasbartlett/Documents/Dashboard/djangodash/djenv/lib/python3.8/site-packages/django/db/models/query.py",
 
line 435, 

Re: SQL query to django

2021-10-10 Thread Eugene TUYIZERE
Thank y'all

On Sun, 10 Oct 2021 at 11:49, Sebastian Jung 
wrote:

> Hello Eugene,
>
> You can also take a raw query...
>
> https://docs.djangoproject.com/en/3.2/topics/db/sql/
>
> Regards
>
> Eugene TUYIZERE  schrieb am Sa., 9. Okt. 2021,
> 10:52:
>
>> Dear all,
>>
>> I have a table let call it *YY*. Some fields in this table are status,
>> time_frame, etc.
>> time frame is in terms of years and status are Not started, In progress
>> and Completed. I want to display all services Not started, in progress and
>> completed in each year.
>> And at the end to display this on bar chart. but What I most want is the
>> query.
>>
>> I want to transform this SQL query in Django:
>>
>> SELECT status from YY group by time_frame;
>>
>> please assist
>>
>> --
>> *TUYIZERE Eugene*
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKGT9mzGkqVRSUjNWuU%2B1kyYB4vRCBh3ZjBTP-Ha0g71VaHyiA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAKGT9mzGkqVRSUjNWuU%2B1kyYB4vRCBh3ZjBTP-Ha0g71VaHyiA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHtF7wQnqjb3Ypf1VXDeQUW6_XEpHFVRHjYm6Oh3w5BRXg%40mail.gmail.com.


Re: SQL query to django

2021-10-10 Thread Sebastian Jung
Hello Eugene,

You can also take a raw query...

https://docs.djangoproject.com/en/3.2/topics/db/sql/

Regards

Eugene TUYIZERE  schrieb am Sa., 9. Okt. 2021,
10:52:

> Dear all,
>
> I have a table let call it *YY*. Some fields in this table are status,
> time_frame, etc.
> time frame is in terms of years and status are Not started, In progress
> and Completed. I want to display all services Not started, in progress and
> completed in each year.
> And at the end to display this on bar chart. but What I most want is the
> query.
>
> I want to transform this SQL query in Django:
>
> SELECT status from YY group by time_frame;
>
> please assist
>
> --
> *TUYIZERE Eugene*
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mzGkqVRSUjNWuU%2B1kyYB4vRCBh3ZjBTP-Ha0g71VaHyiA%40mail.gmail.com.


Re: SQL query to django

2021-10-09 Thread carlos
ok, try this but is only idea (i don't is working)

from django.db.models import Count

result = (YY.objects
.values('time_frame','status')
.annotate(timecount=Count('time_frame'))
.order_by('status')
)

read this for understand
https://docs.djangoproject.com/en/3.2/topics/db/aggregation/

if this no help you maybe this way

results = YY.objects.raw('SELECT status FROM YY GROUP BY time_frame')

and read this too for understand
https://docs.djangoproject.com/en/3.2/topics/db/sql/#topics-db-sql

Cheers

On Sat, Oct 9, 2021 at 2:52 AM Eugene TUYIZERE 
wrote:

> Dear all,
>
> I have a table let call it *YY*. Some fields in this table are status,
> time_frame, etc.
> time frame is in terms of years and status are Not started, In progress
> and Completed. I want to display all services Not started, in progress and
> completed in each year.
> And at the end to display this on bar chart. but What I most want is the
> query.
>
> I want to transform this SQL query in Django:
>
> SELECT status from YY group by time_frame;
>
> please assist
>
> --
> *TUYIZERE Eugene*
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
att.
Carlos Rocha

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO1KKmhjhCbFfO756tqwgOaKsAN-qiL-MhH%3D8KiGfbd9XQ%40mail.gmail.com.


SQL query to django

2021-10-09 Thread Eugene TUYIZERE
Dear all,

I have a table let call it *YY*. Some fields in this table are status,
time_frame, etc.
time frame is in terms of years and status are Not started, In progress and
Completed. I want to display all services Not started, in progress and
completed in each year.
And at the end to display this on bar chart. but What I most want is the
query.

I want to transform this SQL query in Django:

SELECT status from YY group by time_frame;

please assist

-- 
*TUYIZERE Eugene*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com.


Re: Django Query

2021-10-05 Thread Adeyemi Deji
You can read up the documentation regarding MPTT, sure to be useful.
https://django-mptt.readthedocs.io/en/latest

On Tuesday, October 5, 2021 at 10:05:42 AM UTC+2 eugenet...@gmail.com wrote:

> Is there any one with a typical example or tutorial  (of Django mptt) that 
> tolks on the similar  issue as mine and share with me? 
>
> regards, 
>
> On Tue, 5 Oct 2021 at 01:00, Sebastian Jung  wrote:
>
>> Hello Eugene,
>>
>> I think that django mptt can Store and display such a tree.
>>
>> Regards
>>
>> Eugene TUYIZERE  schrieb am Mo., 4. Okt. 2021, 
>> 20:29:
>>
> Team,
>>>
>>> Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have 
>>> Province, District and Sector field names respectively in each table. 
>>>
>>> How can you display in the Django template the following table?
>>>
>>> Province District Sectors 
>>> A A1 A11 
>>> A12 
>>> A2 A21 
>>> A22 
>>> A3 A31 
>>> A32 
>>>
>>> Any assistance will be appreciated
>>> -- 
>>>
>> *TUYIZERE Eugene*
>>>
>>>
>>>
>>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>>
>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAKGT9mwz%3D0FA27Yr8xxiZPK6O4v9t1CwVFXNtr3DMK-xxobmKw%40mail.gmail.com
>>  
>> 
>> .
>>
>
>
> -- 
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal 
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene@aims-cameroon.org
>eugenet...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bd62dc5d-1b53-4dbd-bbba-0b36c30679een%40googlegroups.com.


Re: Django Query

2021-10-05 Thread Eugene TUYIZERE
Is there any one with a typical example or tutorial  (of Django mptt) that
tolks on the similar  issue as mine and share with me?

regards,

On Tue, 5 Oct 2021 at 01:00, Sebastian Jung 
wrote:

> Hello Eugene,
>
> I think that django mptt can Store and display such a tree.
>
> Regards
>
> Eugene TUYIZERE  schrieb am Mo., 4. Okt. 2021,
> 20:29:
>
>> Team,
>>
>> Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have
>> Province, District and Sector field names respectively in each table.
>>
>> How can you display in the Django template the following table?
>>
>> Province District Sectors
>> A A1 A11
>> A12
>> A2 A21
>> A22
>> A3 A31
>> A32
>>
>> Any assistance will be appreciated
>> --
>> *TUYIZERE Eugene*
>>
>>
>>
>> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKGT9mwz%3D0FA27Yr8xxiZPK6O4v9t1CwVFXNtr3DMK-xxobmKw%40mail.gmail.com
> 
> .
>


-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsjjwOhAJKQ35ke5LhGspo%2BTFrt%3Dgeiu-khGcDmKbbrAA%40mail.gmail.com.


Re: Django Query

2021-10-04 Thread Sebastian Jung
Hello Eugene,

I think that django mptt can Store and display such a tree.

Regards

Eugene TUYIZERE  schrieb am Mo., 4. Okt. 2021,
20:29:

> Team,
>
> Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have
> Province, District and Sector field names respectively in each table.
>
> How can you display in the Django template the following table?
>
> Province District Sectors
> A A1 A11
> A12
> A2 A21
> A22
> A3 A31
> A32
>
> Any assistance will be appreciated
> --
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene.tuyiz...@aims-cameroon.org
>eugenetuyiz...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mwz%3D0FA27Yr8xxiZPK6O4v9t1CwVFXNtr3DMK-xxobmKw%40mail.gmail.com.


Django Query

2021-10-04 Thread Eugene TUYIZERE
Team,

Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have
Province, District and Sector field names respectively in each table.

How can you display in the Django template the following table?

Province District Sectors
A A1 A11
A12
A2 A21
A22
A3 A31
A32

Any assistance will be appreciated
-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com.


Re: Query help

2021-09-21 Thread J.T.
Makes sense, I probably should have realized this from the beginning.

Appreciate the help.

On Monday, September 20, 2021 at 6:17:05 PM UTC-5 Sean wrote:

> Add a property to count Y for each column
>
> Or add a computed field that tallies that on save 
>
> For reference
>
>
> https://stackoverflow.com/questions/1454727/do-properties-work-on-django-model-fields
>
>
> On Mon, Sep 20, 2021 at 6:41 PM J.T.  wrote:
>
>> I have a model called member that has 6  columns: ID, Value1, Value2, 
>> Value3, Value4, Value5
>>
>> The values in columns Value1, Value2, Value3, Value4, Value5 are either Y 
>> or N.
>>
>> I'm trying to query by ID to count the number of Y values for each member.
>>
>> For example one row would be: 5, Y, N, Y, N, N
>>
>> I would like to return: 2 (since that is the number of Y in that member's 
>> row)
>>
>> I've tried using Aggregate, Annotate, F, Q, Sum, Count in different ways 
>> and I'm missing the mark. I've been through the docs and SO for about 2 
>> hours.
>> I would post my errors but it's on my work computer and I have to post 
>> here from my personal laptop.
>>
>> I feel like I may be over-thinking it but I can't quite figure it out. 
>> Any help would be greatly appreciated. 
>>
>> Jason
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b9f48d2e-acd7-44e0-b8d9-0fa348443f48n%40googlegroups.com.


Re: Query help

2021-09-20 Thread Lalit Suthar
Sum, Count works when we try to get sum/count for a column,
for this case you can try something like this

def get_yes_count_by(id):
user = User.objects.get(id=id)
count = 0
for val in user.__dict__.values():
if val == "YES":
count += 1
return count

On Tue, 21 Sept 2021 at 04:11, J.T.  wrote:

> I have a model called member that has 6  columns: ID, Value1, Value2,
> Value3, Value4, Value5
>
> The values in columns Value1, Value2, Value3, Value4, Value5 are either Y
> or N.
>
> I'm trying to query by ID to count the number of Y values for each member.
>
> For example one row would be: 5, Y, N, Y, N, N
>
> I would like to return: 2 (since that is the number of Y in that member's
> row)
>
> I've tried using Aggregate, Annotate, F, Q, Sum, Count in different ways
> and I'm missing the mark. I've been through the docs and SO for about 2
> hours.
> I would post my errors but it's on my work computer and I have to post
> here from my personal laptop.
>
> I feel like I may be over-thinking it but I can't quite figure it out. Any
> help would be greatly appreciated.
>
> Jason
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGp2JVG_Cwyp7bSPfNGDcOg_VKSRtke-dHwtz5A5kRohERV4oQ%40mail.gmail.com.


Re: Query help

2021-09-20 Thread Sean Collins
Add a property to count Y for each column

Or add a computed field that tallies that on save

For reference

https://stackoverflow.com/questions/1454727/do-properties-work-on-django-model-fields


On Mon, Sep 20, 2021 at 6:41 PM J.T.  wrote:

> I have a model called member that has 6  columns: ID, Value1, Value2,
> Value3, Value4, Value5
>
> The values in columns Value1, Value2, Value3, Value4, Value5 are either Y
> or N.
>
> I'm trying to query by ID to count the number of Y values for each member.
>
> For example one row would be: 5, Y, N, Y, N, N
>
> I would like to return: 2 (since that is the number of Y in that member's
> row)
>
> I've tried using Aggregate, Annotate, F, Q, Sum, Count in different ways
> and I'm missing the mark. I've been through the docs and SO for about 2
> hours.
> I would post my errors but it's on my work computer and I have to post
> here from my personal laptop.
>
> I feel like I may be over-thinking it but I can't quite figure it out. Any
> help would be greatly appreciated.
>
> Jason
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADMeFRHuHw4fvKD76QVu%3D7qch-Vt9S6bK8eMNrQ-H3dN%3D8ZmdA%40mail.gmail.com.


Query help

2021-09-20 Thread J.T.
I have a model called member that has 6  columns: ID, Value1, Value2, 
Value3, Value4, Value5

The values in columns Value1, Value2, Value3, Value4, Value5 are either Y 
or N.

I'm trying to query by ID to count the number of Y values for each member.

For example one row would be: 5, Y, N, Y, N, N

I would like to return: 2 (since that is the number of Y in that member's 
row)

I've tried using Aggregate, Annotate, F, Q, Sum, Count in different ways 
and I'm missing the mark. I've been through the docs and SO for about 2 
hours.
I would post my errors but it's on my work computer and I have to post here 
from my personal laptop.

I feel like I may be over-thinking it but I can't quite figure it out. Any 
help would be greatly appreciated. 

Jason


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com.


Re: iterate over query set

2021-07-26 Thread DJANGO DEVELOPER
because you have provided the get_department with index 0. so it will only
give you the info about first department.

On Tue, Jul 27, 2021 at 3:17 AM sum abiut  wrote:

> I am trying to get the values of the userid by iterating through the
> queryset. However not all the values are displayed. I am not sure why I am
> not getting all the values when I iterate through it.
>
> users - Users.objects.filter(depid=get_department[0].depid)
> print(users) #when i test it here it pring all the values
> #however it only prints one value when i loop through it below. i want to
> be able to print all the #values
> for a in users:
>   print(a)# this only print value for the first user
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPCf-y65WJVjZC2PA4tz3ZubOtP5CjLtdHegiThhRnK8W5hSiw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKPY9pkp-vCz8%2BfJoGRkjfL-ohECO%2Bq1nH9mfZ3o-isYB3NUXg%40mail.gmail.com.


iterate over query set

2021-07-26 Thread sum abiut
I am trying to get the values of the userid by iterating through the
queryset. However not all the values are displayed. I am not sure why I am
not getting all the values when I iterate through it.

users - Users.objects.filter(depid=get_department[0].depid)
print(users) #when i test it here it pring all the values
#however it only prints one value when i loop through it below. i want to
be able to print all the #values
for a in users:
  print(a)# this only print value for the first user

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCf-y65WJVjZC2PA4tz3ZubOtP5CjLtdHegiThhRnK8W5hSiw%40mail.gmail.com.


Re: use of annotate in django query

2021-07-26 Thread V. J
al_date'])
>>>>>>>> sumdata.append(listd['num_req'])
>>>>>>>> arriva_days = {
>>>>>>>> 'name': 'Datess',
>>>>>>>> 'data': sumdata,
>>>>>>>> 'color': 'green'
>>>>>>>> }
>>>>>>>> chart = {
>>>>>>>> 'chart': {'type': 'column'},
>>>>>>>> 'title': {'text': 'Previous statistics'},
>>>>>>>> 'xAxis': {'replist': replist},
>>>>>>>> 'series': [arriva_days]
>>>>>>>> }
>>>>>>>> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>>>>>>>> return render(request,'summarizedchart.html',{'chart': dump})
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi there!
>>>>>>>>> make these couple of changes
>>>>>>>>>
>>>>>>>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>>>>>>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>>>>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Dear Suthar,
>>>>>>>>>>
>>>>>>>>>> Your idea works well , but I want now to display the result on
>>>>>>>>>> chart. Below is the code I am trying to use:
>>>>>>>>>> but Am getting the error message:
>>>>>>>>>>
>>>>>>>>>> Exception Value:
>>>>>>>>>>
>>>>>>>>>> Object of type date is not JSON serializable
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> def reqChart(request):
>>>>>>>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(
>>>>>>>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>>>>>>> print(aa)
>>>>>>>>>> datesb = list()
>>>>>>>>>> sumdata = list()
>>>>>>>>>> for dd in aa:
>>>>>>>>>> datesb.append(dd['arrival_date'])
>>>>>>>>>> sumdata.append(dd['num_req'])
>>>>>>>>>> arriva_days = {
>>>>>>>>>> 'name': 'Datess',
>>>>>>>>>> 'data': sumdata,
>>>>>>>>>> 'color': 'green'
>>>>>>>>>> }
>>>>>>>>>> chart3 = {
>>>>>>>>>> 'chart': {'type': 'column'},
>>>>>>>>>> 'title': {'text': 'Previous statistics'},
>>>>>>>>>> 'xAxis': {'datesb': datesb},
>>>>>>>>>> 'series': [arriva_days]
>>>>>>>>>> }
>>>>>>>>>> dump3 = json.dumps(chart3)
>>>>>>>>>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>>>>>>>>>
>>>>>>>>>> Please once again
>>>>>>>>>>
>>>>>>>>>> regards,
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, 3 Jun 2021 at 09:00, lalit suthar 
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> this will do
>>>>>>>>>>>
>>>>>>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>>>>>>>>>
>>>>>>>>>>> On Thursday, 3 June 202

Re: complex math calculation from query set # SOLVED

2021-07-24 Thread Franck Tchouanga
Guys I got a good place to manage all your django and good enough developer
and designers for your project just check out the below link to get it all

https://bit.ly/3eUJJcX

On Sat, Jul 24, 2021 at 7:36 PM esteem learning center <
ahmeddauda.dr...@gmail.com> wrote:

> If you want to do some basic django calculations, you can use
> django-mathfilters is simple to use for add, subtract, mul, and div
>
> On Sat, Jul 24, 2021, 3:33 PM mab.mo...@gmail.com 
> wrote:
>
>> Thank you Derek for the information. For those that are having similar
>> problems this is the solution that worked for me based on Derek's lead
>>
>> ## METHOD 1 ##
>>
>> # view
>>
>> def position_view(request):
>>
>> packet_data =
>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>
>> # loop through query set and add new dictionary key-value pair
>>
>> for row in packet_data:
>>
>> row.distance = row.lat*row.lon # example only of calculation
>> only not real
>>
>> return render(request, 'main/position.html',
>> {'packet_data':packet_data,})
>>
>> # html template snippet
>>
>> {% for row in packet_data %}
>>
>> 
>> {{row.callsign}}
>> {{row.lat|floatformat:2}} N
>> {{row.lon|floatformat:2}} W 
>> > style='text-align:right;'>{{row.distance|floatformat:1}} miles
>> > style='text-align:right;'>{{row.bearing|floatformat:0}} deg
>> {{row.dt_heard|date:"D
>> m/d H:i"}}
>> 
>>
>> {% endfor %}
>>
>> ## METHOD 2 use @property in the model.py file
>>
>> # Put the data calculations in the model.py file
>>
>> class TncData(models.Model):
>> callsign = models.TextField(max_length=20)
>> lat = models.FloatField(null=True, blank=True, default=None)
>> lon = models.FloatField(null=True, blank=True, default=None)
>> path = models.TextField(max_length=250)
>> message = models.TextField(max_length=250)
>> dt_heard = models.DateTimeField(auto_now_add=False)
>>
>> def __str__(self):
>> return str(self.callsign)
>>
>> ## HAVERSINE FORMULA
>>
>> @property
>> def calculate_distance(self):
>>
>> # Variables
>>
>> r = 6371 # radius earth km
>>
>> lat_1 = radians(42.97)
>> lon_1 = radians(89.77)
>>
>> lat_2 = radians(self.lat)
>> lon_2 = radians(self.lon)
>>
>> dlat = lat_1 - lat_2
>> dlon = lon_1 - lon_2
>>
>> a = sin(dlat / 2)**2 + cos(lat_1) * cos(lat_2) * sin(dlon / 2)**2
>>
>> c = 2 * asin(sqrt(a))
>>
>> distance_km = c*r
>> distance = distance_km * 0.621
>>
>> return(distance)
>>
>> # html template snippet
>>
>> {% for row in packet_data %}
>>
>> 
>> {{row.callsign}}
>> {{row.lat|floatformat:2}} N
>> {{row.lon|floatformat:2}} W 
>> {{
>> *row.calculate_distance|*floatformat:1}} miles
>> > style='text-align:right;'>{{row.bearing|floatformat:0}} deg
>> {{row.dt_heard|date:"D
>> m/d H:i"}}
>> 
>>
>>
>> {% endfor %}
>>
>>
>> On Wednesday, July 21, 2021 at 5:01:02 PM UTC-5 mab.mo...@gmail.com
>> wrote:
>>
>>> Thanks Derek. I'll give it a try
>>>
>>> On Wednesday, July 21, 2021 at 8:55:08 AM UTC-5 Derek wrote:
>>>
>>>> See:
>>>> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>>>>
>>>>
>>>> VIEW
>>>>
>>>> def position_view(request):
>>>>
>>>> packet_data =
>>>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>>> for packet in packet_data:
>>>> *# my complex math calculation*
>>>> *packet.distance = "# complex math formula using packet.lat and
>>>> packet.lon"*
>>>>
>>>> return render(
>>>> request,
>>>> 'main/position.html',
>>>> {'packet_data': packet_data, 'distance': distance})
>>>>
>>>> TEMPLATE
>>>>
>>>> *# suggest you use a better term than "field" => maybe "record"?*
>>>> {% for field in packet_data %

Re: complex math calculation from query set # SOLVED

2021-07-24 Thread esteem learning center
If you want to do some basic django calculations, you can use
django-mathfilters is simple to use for add, subtract, mul, and div

On Sat, Jul 24, 2021, 3:33 PM mab.mo...@gmail.com 
wrote:

> Thank you Derek for the information. For those that are having similar
> problems this is the solution that worked for me based on Derek's lead
>
> ## METHOD 1 ##
>
> # view
>
> def position_view(request):
>
> packet_data =
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>
> # loop through query set and add new dictionary key-value pair
>
> for row in packet_data:
>
> row.distance = row.lat*row.lon # example only of calculation  only
> not real
>
> return render(request, 'main/position.html',
> {'packet_data':packet_data,})
>
> # html template snippet
>
> {% for row in packet_data %}
>
> 
> {{row.callsign}}
> {{row.lat|floatformat:2}} N
> {{row.lon|floatformat:2}} W 
>  style='text-align:right;'>{{row.distance|floatformat:1}} miles
>  style='text-align:right;'>{{row.bearing|floatformat:0}} deg
> {{row.dt_heard|date:"D
> m/d H:i"}}
> 
>
> {% endfor %}
>
> ## METHOD 2 use @property in the model.py file
>
> # Put the data calculations in the model.py file
>
> class TncData(models.Model):
> callsign = models.TextField(max_length=20)
> lat = models.FloatField(null=True, blank=True, default=None)
> lon = models.FloatField(null=True, blank=True, default=None)
> path = models.TextField(max_length=250)
> message = models.TextField(max_length=250)
> dt_heard = models.DateTimeField(auto_now_add=False)
>
> def __str__(self):
> return str(self.callsign)
>
> ## HAVERSINE FORMULA
>
> @property
> def calculate_distance(self):
>
> # Variables
>
> r = 6371 # radius earth km
>
> lat_1 = radians(42.97)
> lon_1 = radians(89.77)
>
> lat_2 = radians(self.lat)
> lon_2 = radians(self.lon)
>
> dlat = lat_1 - lat_2
> dlon = lon_1 - lon_2
>
> a = sin(dlat / 2)**2 + cos(lat_1) * cos(lat_2) * sin(dlon / 2)**2
>
> c = 2 * asin(sqrt(a))
>
> distance_km = c*r
> distance = distance_km * 0.621
>
> return(distance)
>
> # html template snippet
>
> {% for row in packet_data %}
>
> 
> {{row.callsign}}
> {{row.lat|floatformat:2}} N
> {{row.lon|floatformat:2}} W 
> {{
> *row.calculate_distance|*floatformat:1}} miles
>  style='text-align:right;'>{{row.bearing|floatformat:0}} deg
> {{row.dt_heard|date:"D
> m/d H:i"}}
> 
>
>
> {% endfor %}
>
>
> On Wednesday, July 21, 2021 at 5:01:02 PM UTC-5 mab.mo...@gmail.com wrote:
>
>> Thanks Derek. I'll give it a try
>>
>> On Wednesday, July 21, 2021 at 8:55:08 AM UTC-5 Derek wrote:
>>
>>> See:
>>> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>>>
>>>
>>> VIEW
>>>
>>> def position_view(request):
>>>
>>> packet_data =
>>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>> for packet in packet_data:
>>> *# my complex math calculation*
>>> *packet.distance = "# complex math formula using packet.lat and
>>> packet.lon"*
>>>
>>> return render(
>>> request,
>>> 'main/position.html',
>>> {'packet_data': packet_data, 'distance': distance})
>>>
>>> TEMPLATE
>>>
>>> *# suggest you use a better term than "field" => maybe "record"?*
>>> {% for field in packet_data %}
>>> 
>>> {{field.callsign}}
>>> {{field.lat|floatformat:2}} N
>>> {{field.lon|floatformat:2}} W 
>>> 
>>> *{{field.distance}}*
>>>
>>>
>>> HTH!
>>>
>>> On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:
>>>
>>>> Hello,
>>>>
>>>> I am trying to perform a complex math calculation from a django query
>>>> set. How can I pass the results to the template for display? Annotations
>>>> won't work since the math is not a simple sum, diff or average.
>>>>
>>>> MODEL
>>>>
>>>> class TncData(models.Model):
>>>> callsign = models.TextField(max_length=20)
>>>

Re: complex math calculation from query set # SOLVED

2021-07-24 Thread mab.mo...@gmail.com
Thank you Derek for the information. For those that are having similar 
problems this is the solution that worked for me based on Derek's lead

## METHOD 1 ##

# view

def position_view(request):

packet_data = TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]

# loop through query set and add new dictionary key-value pair

for row in packet_data:

row.distance = row.lat*row.lon # example only of calculation  only 
not real 

return render(request, 'main/position.html', 
{'packet_data':packet_data,})

# html template snippet

{% for row in packet_data %}


{{row.callsign}}
{{row.lat|floatformat:2}} N 
{{row.lon|floatformat:2}} W 
{{row.distance|floatformat:1}} miles
{{row.bearing|floatformat:0}} deg
{{row.dt_heard|date:"D 
m/d H:i"}}


{% endfor %}

## METHOD 2 use @property in the model.py file 

# Put the data calculations in the model.py file

class TncData(models.Model):
callsign = models.TextField(max_length=20)
lat = models.FloatField(null=True, blank=True, default=None)
lon = models.FloatField(null=True, blank=True, default=None)
path = models.TextField(max_length=250)
message = models.TextField(max_length=250)
dt_heard = models.DateTimeField(auto_now_add=False)

def __str__(self):
return str(self.callsign)

## HAVERSINE FORMULA

@property
def calculate_distance(self):

# Variables

r = 6371 # radius earth km

lat_1 = radians(42.97)
lon_1 = radians(89.77)

lat_2 = radians(self.lat)
lon_2 = radians(self.lon)

dlat = lat_1 - lat_2
dlon = lon_1 - lon_2

a = sin(dlat / 2)**2 + cos(lat_1) * cos(lat_2) * sin(dlon / 2)**2

c = 2 * asin(sqrt(a))

distance_km = c*r
distance = distance_km * 0.621

return(distance)

# html template snippet

{% for row in packet_data %}


{{row.callsign}}
{{row.lat|floatformat:2}} N 
{{row.lon|floatformat:2}} W 
{{*row.calculate_distance|*floatformat:1}} 
miles
{{row.bearing|floatformat:0}} deg
{{row.dt_heard|date:"D 
m/d H:i"}}



{% endfor %}


On Wednesday, July 21, 2021 at 5:01:02 PM UTC-5 mab.mo...@gmail.com wrote:

> Thanks Derek. I'll give it a try
>
> On Wednesday, July 21, 2021 at 8:55:08 AM UTC-5 Derek wrote:
>
>> See:  
>> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>>  
>>
>> VIEW
>>
>> def position_view(request):
>>
>> packet_data = 
>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>> for packet in packet_data:
>> *# my complex math calculation*
>> *packet.distance = "# complex math formula using packet.lat and 
>> packet.lon"*
>>
>> return render(
>> request, 
>> 'main/position.html',
>> {'packet_data': packet_data, 'distance': distance})
>>
>> TEMPLATE
>>
>> *# suggest you use a better term than "field" => maybe "record"?*
>> {% for field in packet_data %}
>> 
>> {{field.callsign}}
>> {{field.lat|floatformat:2}} N 
>> {{field.lon|floatformat:2}} W 
>> 
>> *{{field.distance}}*
>>
>>
>> HTH!
>>
>> On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:
>>
>>> Hello,
>>>
>>> I am trying to perform a complex math calculation from a django query 
>>> set. How can I pass the results to the template for display? Annotations 
>>> won't work since the math is not a simple sum, diff or average. 
>>>
>>> MODEL
>>>
>>> class TncData(models.Model):
>>> callsign = models.TextField(max_length=20)
>>> lat = models.FloatField(null=True, blank=True, default=None)
>>> lon = models.FloatField(null=True, blank=True, default=None)
>>> path = models.TextField(max_length=250)
>>> message = models.TextField(max_length=250)
>>> dt_heard = models.DateTimeField(auto_now_add=False)
>>>
>>> def __str__(self):
>>> return str(self.callsign)
>>>
>>> VIEW
>>>
>>> def position_view(request):
>>>
>>> packet_data = 
>>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>>
>>> *# my complex math calculation*
>>> * # need to do something like append distance to packet_data like 
>>> packet_data.distance*
>>>
>>> *distance = "# complex math formula using packet_data.lat and 
>>> packet_data.lon"*
>

Query Optimization and profiling for celery tasks

2021-07-24 Thread Hamidreza Mahmoodian

Hello everyone

Django-debug-toolbar and Django-silk are two famous tools for profiling 
HTTP requests. Is it possible to analyze a celery task or any other 
function inside the code? for instance, I have a celery task like this:

def main_task(): 
while _condition: 
logic() 
sleep(_t) 
return True

I need some information like duplicate and similar queries in logic() for 
every loop.
Unfortunately no one answered similar question to me in Stackoverflow.
thanks






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7ee5aa4a-9860-45b6-ab50-76bad4a668cdn%40googlegroups.com.


Re: complex math calculation from query set

2021-07-21 Thread mab.mo...@gmail.com
Thanks Derek. I'll give it a try

On Wednesday, July 21, 2021 at 8:55:08 AM UTC-5 Derek wrote:

> See:  
> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>  
>
> VIEW
>
> def position_view(request):
>
> packet_data = 
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
> for packet in packet_data:
> *# my complex math calculation*
> *packet.distance = "# complex math formula using packet.lat and 
> packet.lon"*
>
> return render(
> request, 
> 'main/position.html',
> {'packet_data': packet_data, 'distance': distance})
>
> TEMPLATE
>
> *# suggest you use a better term than "field" => maybe "record"?*
> {% for field in packet_data %}
> 
> {{field.callsign}}
> {{field.lat|floatformat:2}} N 
> {{field.lon|floatformat:2}} W 
> 
> *{{field.distance}}*
>
>
> HTH!
>
> On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:
>
>> Hello,
>>
>> I am trying to perform a complex math calculation from a django query 
>> set. How can I pass the results to the template for display? Annotations 
>> won't work since the math is not a simple sum, diff or average. 
>>
>> MODEL
>>
>> class TncData(models.Model):
>> callsign = models.TextField(max_length=20)
>> lat = models.FloatField(null=True, blank=True, default=None)
>> lon = models.FloatField(null=True, blank=True, default=None)
>> path = models.TextField(max_length=250)
>> message = models.TextField(max_length=250)
>> dt_heard = models.DateTimeField(auto_now_add=False)
>>
>> def __str__(self):
>> return str(self.callsign)
>>
>> VIEW
>>
>> def position_view(request):
>>
>> packet_data = 
>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>
>> *# my complex math calculation*
>> * # need to do something like append distance to packet_data like 
>> packet_data.distance*
>>
>> *distance = "# complex math formula using packet_data.lat and 
>> packet_data.lon"*
>>
>> return render(request, 'main/position.html', 
>> {'packet_data':packet_data,})
>>
>> TEMPLATE
>>
>> {% for field in packet_data %}
>>
>> 
>> {{field.callsign}}
>> {{field.lat|floatformat:2}} N 
>> {{field.lon|floatformat:2}} W 
>> 
>> *{{packet_data.distance}}*
>> {{field.dt_heard|date:"D m/d H:i"}}
>> 
>>
>> {% endfor %}
>>  
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf59ba37-b95e-4279-adbb-723e39596af6n%40googlegroups.com.


Re: complex math calculation from query set

2021-07-21 Thread Derek
Ignore the "'distance': distance" in the return - that should not be there.

On Wednesday, 21 July 2021 at 15:55:08 UTC+2 Derek wrote:

> See:  
> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>  
>
> VIEW
>
> def position_view(request):
>
> packet_data = 
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
> for packet in packet_data:
> *# my complex math calculation*
> *packet.distance = "# complex math formula using packet.lat and 
> packet.lon"*
>
> return render(
> request, 
> 'main/position.html',
> {'packet_data': packet_data, 'distance': distance})
>
> TEMPLATE
>
> *# suggest you use a better term than "field" => maybe "record"?*
> {% for field in packet_data %}
> 
> {{field.callsign}}
> {{field.lat|floatformat:2}} N 
> {{field.lon|floatformat:2}} W 
> 
> *{{field.distance}}*
>
>
> HTH!
>
> On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:
>
>> Hello,
>>
>> I am trying to perform a complex math calculation from a django query 
>> set. How can I pass the results to the template for display? Annotations 
>> won't work since the math is not a simple sum, diff or average. 
>>
>> MODEL
>>
>> class TncData(models.Model):
>> callsign = models.TextField(max_length=20)
>> lat = models.FloatField(null=True, blank=True, default=None)
>> lon = models.FloatField(null=True, blank=True, default=None)
>> path = models.TextField(max_length=250)
>> message = models.TextField(max_length=250)
>> dt_heard = models.DateTimeField(auto_now_add=False)
>>
>> def __str__(self):
>> return str(self.callsign)
>>
>> VIEW
>>
>> def position_view(request):
>>
>> packet_data = 
>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>
>> *# my complex math calculation*
>> * # need to do something like append distance to packet_data like 
>> packet_data.distance*
>>
>> *distance = "# complex math formula using packet_data.lat and 
>> packet_data.lon"*
>>
>> return render(request, 'main/position.html', 
>> {'packet_data':packet_data,})
>>
>> TEMPLATE
>>
>> {% for field in packet_data %}
>>
>> 
>> {{field.callsign}}
>> {{field.lat|floatformat:2}} N 
>> {{field.lon|floatformat:2}} W 
>> 
>> *{{packet_data.distance}}*
>> {{field.dt_heard|date:"D m/d H:i"}}
>> 
>>
>> {% endfor %}
>>  
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b95c65b-c341-46cd-8125-1b13409c7bb9n%40googlegroups.com.


Re: complex math calculation from query set

2021-07-21 Thread Derek
See:  
https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset 

VIEW

def position_view(request):

packet_data = TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
for packet in packet_data:
*# my complex math calculation*
*packet.distance = "# complex math formula using packet.lat and 
packet.lon"*

return render(
request, 
'main/position.html',
{'packet_data': packet_data, 'distance': distance})

TEMPLATE

*# suggest you use a better term than "field" => maybe "record"?*
{% for field in packet_data %}

{{field.callsign}}
{{field.lat|floatformat:2}} N 
{{field.lon|floatformat:2}} W 

*{{field.distance}}*


HTH!

On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:

> Hello,
>
> I am trying to perform a complex math calculation from a django query set. 
> How can I pass the results to the template for display? Annotations won't 
> work since the math is not a simple sum, diff or average. 
>
> MODEL
>
> class TncData(models.Model):
> callsign = models.TextField(max_length=20)
> lat = models.FloatField(null=True, blank=True, default=None)
> lon = models.FloatField(null=True, blank=True, default=None)
> path = models.TextField(max_length=250)
> message = models.TextField(max_length=250)
> dt_heard = models.DateTimeField(auto_now_add=False)
>
> def __str__(self):
> return str(self.callsign)
>
> VIEW
>
> def position_view(request):
>
> packet_data = 
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>
> *# my complex math calculation*
> * # need to do something like append distance to packet_data like 
> packet_data.distance*
>
> *distance = "# complex math formula using packet_data.lat and 
> packet_data.lon"*
>
> return render(request, 'main/position.html', 
> {'packet_data':packet_data,})
>
> TEMPLATE
>
> {% for field in packet_data %}
>
> 
> {{field.callsign}}
> {{field.lat|floatformat:2}} N 
> {{field.lon|floatformat:2}} W 
> 
> *{{packet_data.distance}}*
> {{field.dt_heard|date:"D m/d H:i"}}
> 
>
> {% endfor %}
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dfe26aa8-1947-4576-9700-2fec733894e7n%40googlegroups.com.


complex math calculation from query set

2021-07-20 Thread mab.mo...@gmail.com
Hello,

I am trying to perform a complex math calculation from a django query set. 
How can I pass the results to the template for display? Annotations won't 
work since the math is not a simple sum, diff or average. 

MODEL

class TncData(models.Model):
callsign = models.TextField(max_length=20)
lat = models.FloatField(null=True, blank=True, default=None)
lon = models.FloatField(null=True, blank=True, default=None)
path = models.TextField(max_length=250)
message = models.TextField(max_length=250)
dt_heard = models.DateTimeField(auto_now_add=False)

def __str__(self):
return str(self.callsign)

VIEW

def position_view(request):

packet_data = TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]

*# my complex math calculation*
* # need to do something like append distance to packet_data like 
packet_data.distance*

*distance = "# complex math formula using packet_data.lat and 
packet_data.lon"*

return render(request, 'main/position.html', 
{'packet_data':packet_data,})

TEMPLATE

{% for field in packet_data %}


{{field.callsign}}
{{field.lat|floatformat:2}} N 
{{field.lon|floatformat:2}} W 

*{{packet_data.distance}}*
{{field.dt_heard|date:"D m/d H:i"}}


{% endfor %}
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49f44d93-e011-4d00-a022-3eb064dfac86n%40googlegroups.com.


Re: Django Query vs SQL query

2021-06-15 Thread Nikeet NA
use the related name on the staff model for project field with __ lookup as 
in 
class Staff(models.Model):
.
.

project = foreignkey relationship (related_name='staffs')

SO the query would be Projects.objects.filter(staffs__project_id=F('pk'))

On Tuesday, 15 June 2021 at 14:13:26 UTC+5:30 eugenet...@gmail.com wrote:

> Team,
>
> I am a little bit confused: I have a table callect Projects and another 
> called Staffs. I want a particular staff member to view only the project 
> he/she has a role in. In the Staffs table I have a project foreign key 
> project_id. But I am confused about how to construct the query. I think of 
> the SQL as below
>
> *Select * from Projects where Projects.id = Staffs.projects_id *
>
> I want to transform this query into a django query.
>
> Assist please
>
> -- 
> *Eugene*
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f74a18a-9798-4080-a462-6eff3231d7acn%40googlegroups.com.


Django Query vs SQL query

2021-06-15 Thread Eugene TUYIZERE
Team,

I am a little bit confused: I have a table callect Projects and another
called Staffs. I want a particular staff member to view only the project
he/she has a role in. In the Staffs table I have a project foreign key
project_id. But I am confused about how to construct the query. I think of
the SQL as below

*Select * from Projects where Projects.id = Staffs.projects_id *

I want to transform this query into a django query.

Assist please

-- 
*Eugene*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHupgm6_OKgPZ1QX3J3vRwtx%2BajTNYDwm%2Bf-DGy%3DTRDfsg%40mail.gmail.com.


Re: User matching query does not exist.

2021-06-12 Thread sachinbg sachin
It means that the data which you are looking for is not exists in that data
base, check properly wether the searching data is exists or not,

Thank you
Sachin b.g

On Sun, 13 Jun, 2021, 6:53 AM Nikeet NA,  wrote:

> There is no user with id 1.
> Wrap this statement inside try catch block :
>user = User.objects.get(id=uid)
>and catch the DoesNotExist exception as except User.DoesNotExist:
>
> On Saturday, 12 June 2021 at 18:13:09 UTC+5:30 shilpa...@gmail.com wrote:
>
>> Environment:
>>
>>
>> Request Method: GET
>> Request URL: http://127.0.0.1:8000/addToCart/1
>>
>> Django Version: 3.2.3
>> Python Version: 3.9.1
>> Installed Applications:
>> ['django.contrib.admin',
>>  'django.contrib.auth',
>>  'django.contrib.contenttypes',
>>  'django.contrib.sessions',
>>  'django.contrib.messages',
>>  'django.contrib.staticfiles',
>>  'MusicalApp.apps.MusicalappConfig',
>>  'CartApp.apps.CartappConfig']
>> Installed Middleware:
>> ['django.middleware.security.SecurityMiddleware',
>>  'django.contrib.sessions.middleware.SessionMiddleware',
>>  'django.middleware.common.CommonMiddleware',
>>  'django.middleware.csrf.CsrfViewMiddleware',
>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>  'django.contrib.messages.middleware.MessageMiddleware',
>>  'django.middleware.clickjacking.XFrameOptionsMiddleware']
>>
>>
>>
>> Traceback (most recent call last):
>>   File
>> "D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\exception.py",
>> line 47, in inner
>> response = get_response(request)
>>   File
>> "D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\base.py", line
>> 181, in _get_response
>> response = wrapped_callback(request, *callback_args,
>> **callback_kwargs)
>>   File "D:\DjangoDemos\CartApp\views.py", line 15, in addToCart
>> user = User.objects.get(id=uid)
>>   File
>> "D:\DjangoDemos\venv\lib\site-packages\django\db\models\manager.py", line
>> 85, in manager_method
>> return getattr(self.get_queryset(), name)(*args, **kwargs)
>>   File "D:\DjangoDemos\venv\lib\site-packages\django\db\models\query.py",
>> line 435, in get
>> raise self.model.DoesNotExist(
>>
>> Exception Type: DoesNotExist at /addToCart/1
>> Exception Value: User matching query does not exist.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1b7cff79-a0eb-4559-ab17-1d9d0f701343n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/1b7cff79-a0eb-4559-ab17-1d9d0f701343n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs61rz3X4KBT9MJdFOoion0N4UvH0V_YM%3DhQA3DY%2BZzce8o3w%40mail.gmail.com.


Re: User matching query does not exist.

2021-06-12 Thread Nikeet NA
There is no user with id 1.
Wrap this statement inside try catch block :
   user = User.objects.get(id=uid)
   and catch the DoesNotExist exception as except User.DoesNotExist:

On Saturday, 12 June 2021 at 18:13:09 UTC+5:30 shilpa...@gmail.com wrote:

> Environment:
>
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/addToCart/1
>
> Django Version: 3.2.3
> Python Version: 3.9.1
> Installed Applications:
> ['django.contrib.admin',
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'MusicalApp.apps.MusicalappConfig',
>  'CartApp.apps.CartappConfig']
> Installed Middleware:
> ['django.middleware.security.SecurityMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
>  'django.middleware.clickjacking.XFrameOptionsMiddleware']
>
>
>
> Traceback (most recent call last):
>   File 
> "D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\exception.py", 
> line 47, in inner
> response = get_response(request)
>   File 
> "D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\base.py", line 
> 181, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File "D:\DjangoDemos\CartApp\views.py", line 15, in addToCart
> user = User.objects.get(id=uid)
>   File 
> "D:\DjangoDemos\venv\lib\site-packages\django\db\models\manager.py", line 
> 85, in manager_method
> return getattr(self.get_queryset(), name)(*args, **kwargs)
>   File "D:\DjangoDemos\venv\lib\site-packages\django\db\models\query.py", 
> line 435, in get
> raise self.model.DoesNotExist(
>
> Exception Type: DoesNotExist at /addToCart/1
> Exception Value: User matching query does not exist.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1b7cff79-a0eb-4559-ab17-1d9d0f701343n%40googlegroups.com.


User matching query does not exist.

2021-06-12 Thread Shilpa Agrawal
Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/addToCart/1

Django Version: 3.2.3
Python Version: 3.9.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'MusicalApp.apps.MusicalappConfig',
 'CartApp.apps.CartappConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File 
"D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\exception.py", 
line 47, in inner
response = get_response(request)
  File 
"D:\DjangoDemos\venv\lib\site-packages\django\core\handlers\base.py", line 
181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\DjangoDemos\CartApp\views.py", line 15, in addToCart
user = User.objects.get(id=uid)
  File "D:\DjangoDemos\venv\lib\site-packages\django\db\models\manager.py", 
line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "D:\DjangoDemos\venv\lib\site-packages\django\db\models\query.py", 
line 435, in get
raise self.model.DoesNotExist(

Exception Type: DoesNotExist at /addToCart/1
Exception Value: User matching query does not exist.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/879bff80-9f96-445c-a46f-7ca28f0c62f4n%40googlegroups.com.


Re: use of annotate in django query

2021-06-05 Thread Lalit Suthar
> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>>>>>>> return render(request,'summarizedchart.html',{'chart': dump})
>>>>>>>
>>>>>>>
>>>>>>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi there!
>>>>>>>> make these couple of changes
>>>>>>>>
>>>>>>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>>>>>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>>>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Dear Suthar,
>>>>>>>>>
>>>>>>>>> Your idea works well , but I want now to display the result on
>>>>>>>>> chart. Below is the code I am trying to use:
>>>>>>>>> but Am getting the error message:
>>>>>>>>>
>>>>>>>>> Exception Value:
>>>>>>>>>
>>>>>>>>> Object of type date is not JSON serializable
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> def reqChart(request):
>>>>>>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(
>>>>>>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>>>>>> print(aa)
>>>>>>>>> datesb = list()
>>>>>>>>> sumdata = list()
>>>>>>>>> for dd in aa:
>>>>>>>>> datesb.append(dd['arrival_date'])
>>>>>>>>> sumdata.append(dd['num_req'])
>>>>>>>>> arriva_days = {
>>>>>>>>> 'name': 'Datess',
>>>>>>>>> 'data': sumdata,
>>>>>>>>> 'color': 'green'
>>>>>>>>> }
>>>>>>>>> chart3 = {
>>>>>>>>> 'chart': {'type': 'column'},
>>>>>>>>> 'title': {'text': 'Previous statistics'},
>>>>>>>>> 'xAxis': {'datesb': datesb},
>>>>>>>>> 'series': [arriva_days]
>>>>>>>>> }
>>>>>>>>> dump3 = json.dumps(chart3)
>>>>>>>>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>>>>>>>>
>>>>>>>>> Please once again
>>>>>>>>>
>>>>>>>>> regards,
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thu, 3 Jun 2021 at 09:00, lalit suthar 
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> this will do
>>>>>>>>>>
>>>>>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>>>>>>>>
>>>>>>>>>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> to display last 30 records you can write your code like this:
>>>>>>>>>>> Customer_Requests.objects.all()[-30]
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE <
>>>>>>>>>>> eugenet...@gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Dear Latit,
>>>>>>>>>>>>
>>>>>>>>>>>> Thank you very much. Now how can I display 30 last records?
>>>>>>>>>>>> Regardless of how many records I may have ! Just the last 30 
>>>>>>>>>>>> records!
>>>>>>>>>>>>
>>>>>>>>>>>> Thank 

Re: use of annotate in django query

2021-06-04 Thread Eugene TUYIZERE
p3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Dear Suthar,
>>>>>>>>
>>>>>>>> Your idea works well , but I want now to display the result on
>>>>>>>> chart. Below is the code I am trying to use:
>>>>>>>> but Am getting the error message:
>>>>>>>>
>>>>>>>> Exception Value:
>>>>>>>>
>>>>>>>> Object of type date is not JSON serializable
>>>>>>>>
>>>>>>>>
>>>>>>>> def reqChart(request):
>>>>>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(
>>>>>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>>>>> print(aa)
>>>>>>>> datesb = list()
>>>>>>>> sumdata = list()
>>>>>>>> for dd in aa:
>>>>>>>> datesb.append(dd['arrival_date'])
>>>>>>>> sumdata.append(dd['num_req'])
>>>>>>>> arriva_days = {
>>>>>>>> 'name': 'Datess',
>>>>>>>> 'data': sumdata,
>>>>>>>> 'color': 'green'
>>>>>>>> }
>>>>>>>> chart3 = {
>>>>>>>> 'chart': {'type': 'column'},
>>>>>>>> 'title': {'text': 'Previous statistics'},
>>>>>>>> 'xAxis': {'datesb': datesb},
>>>>>>>> 'series': [arriva_days]
>>>>>>>> }
>>>>>>>> dump3 = json.dumps(chart3)
>>>>>>>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>>>>>>>
>>>>>>>> Please once again
>>>>>>>>
>>>>>>>> regards,
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, 3 Jun 2021 at 09:00, lalit suthar 
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> this will do
>>>>>>>>>
>>>>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>>>>>>>
>>>>>>>>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> to display last 30 records you can write your code like this:
>>>>>>>>>> Customer_Requests.objects.all()[-30]
>>>>>>>>>>
>>>>>>>>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE <
>>>>>>>>>> eugenet...@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Dear Latit,
>>>>>>>>>>>
>>>>>>>>>>> Thank you very much. Now how can I display 30 last records?
>>>>>>>>>>> Regardless of how many records I may have ! Just the last 30 
>>>>>>>>>>> records!
>>>>>>>>>>>
>>>>>>>>>>> Thank you
>>>>>>>>>>>
>>>>>>>>>>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar 
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> > in brief, I want to transform this query in django query
>>>>>>>>>>>> this will be equivalent to this query in django
>>>>>>>>>>>>
>>>>>>>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE <
>>>>>>>>>>>> eugenet...@gmai

Re: use of annotate in django query

2021-06-03 Thread Lalit Suthar
my pleasure :)

On Thu, 3 Jun 2021 at 20:28, Eugene TUYIZERE 
wrote:

> Dear Suthar,
>
> Thank you very much. It works well.
>
>
> On Thu, 3 Jun 2021 at 16:48, Lalit Suthar 
> wrote:
>
>> not sure but maybe this can work inside views replace
>> chart = {
>>   'chart': {'type': 'column'},
>>   'title': {'text': 'Previous statistics'},
>>   'xAxis': {'replist': replist},
>>   'series': [arriva_days]
>> }
>> with
>> chart = {
>>   'chart': {'type': 'column'},
>>   'title': {'text': 'Previous statistics'},
>>   'xAxis': {'categories': replist},
>>   'series': [arriva_days]
>> }
>>
>> On Thu, 3 Jun 2021 at 18:00, Eugene TUYIZERE 
>> wrote:
>>
>>> This what I have in summarizedchart.html:
>>>
>>> {% extends "layouts/base.html" %}
>>> {% load static %}
>>> {% block title %} Repport {% endblock %}
>>>
>>> 
>>> {% block stylesheets %}{% endblock stylesheets %}
>>>
>>> {% block content %}
>>>
>>> 
>>> 
>>> 
>>> 
>>> 
>>> Report
>>>
>>> 
>>>
>>> 
>>>
>>> 
>>> 
>>> Highcharts.chart('container', {{ chart|safe }});
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> {% endblock content %}
>>> {% block custom_js %}
>>>
>>> {% endblock custom_js %}
>>>
>>> On Thu, 3 Jun 2021 at 14:22, Lalit Suthar 
>>> wrote:
>>>
>>>> so the view is not giving error right now but maybe we are passing the
>>>> data in different format then the chart is expecting.
>>>> What are you using for drawing the chart? can I see the code inside
>>>> "summarizedchart.html"
>>>>
>>>> On Thu, 3 Jun 2021 at 17:43, Eugene TUYIZERE 
>>>> wrote:
>>>>
>>>>> Dear Suthar,
>>>>>
>>>>> You saved my day. Once more, the chart is displayed but the date is
>>>>> not displayed on Xaxis. This how it is:
>>>>>
>>>>> [image: image.png]
>>>>>
>>>>> Th codes are:
>>>>> def reqChart(request):
>>>>> current_date = date.today()
>>>>> days_before = date.today()-timedelta(days=30)
>>>>> datelist = Customer_Requests.objects.values("arrival_date").annotate(
>>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>> replist = list()
>>>>> sumdata = list()
>>>>> for listd in datelist:
>>>>> replist.append(listd['arrival_date'])
>>>>> sumdata.append(listd['num_req'])
>>>>> arriva_days = {
>>>>> 'name': 'Datess',
>>>>> 'data': sumdata,
>>>>> 'color': 'green'
>>>>> }
>>>>> chart = {
>>>>> 'chart': {'type': 'column'},
>>>>> 'title': {'text': 'Previous statistics'},
>>>>> 'xAxis': {'replist': replist},
>>>>> 'series': [arriva_days]
>>>>> }
>>>>> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>>>>> return render(request,'summarizedchart.html',{'chart': dump})
>>>>>
>>>>>
>>>>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>>>>> wrote:
>>>>>
>>>>>> Hi there!
>>>>>> make these couple of changes
>>>>>>
>>>>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>>>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>>>> wrote:
>>>>>>
>>>>>>> Dear Suthar,
>>>>>>>
>>>>>>> Your idea works well , but I want now to display the result on
>>>>>>> chart. Below is the code I am trying to use:
>>>>>>> but Am getting the error message:
>>>>>>>
>>>>>>> Exception Value:
>>>>&

Re: use of annotate in django query

2021-06-03 Thread Eugene TUYIZERE
Dear Suthar,

Thank you very much. It works well.


On Thu, 3 Jun 2021 at 16:48, Lalit Suthar  wrote:

> not sure but maybe this can work inside views replace
> chart = {
>   'chart': {'type': 'column'},
>   'title': {'text': 'Previous statistics'},
>   'xAxis': {'replist': replist},
>   'series': [arriva_days]
> }
> with
> chart = {
>   'chart': {'type': 'column'},
>   'title': {'text': 'Previous statistics'},
>   'xAxis': {'categories': replist},
>   'series': [arriva_days]
> }
>
> On Thu, 3 Jun 2021 at 18:00, Eugene TUYIZERE 
> wrote:
>
>> This what I have in summarizedchart.html:
>>
>> {% extends "layouts/base.html" %}
>> {% load static %}
>> {% block title %} Repport {% endblock %}
>>
>> 
>> {% block stylesheets %}{% endblock stylesheets %}
>>
>> {% block content %}
>>
>> 
>> 
>> 
>> 
>> 
>> Report
>>
>> 
>>
>> 
>>
>> 
>> 
>> Highcharts.chart('container', {{ chart|safe }});
>> 
>> 
>> 
>> 
>> 
>> 
>> {% endblock content %}
>> {% block custom_js %}
>>
>> {% endblock custom_js %}
>>
>> On Thu, 3 Jun 2021 at 14:22, Lalit Suthar 
>> wrote:
>>
>>> so the view is not giving error right now but maybe we are passing the
>>> data in different format then the chart is expecting.
>>> What are you using for drawing the chart? can I see the code inside
>>> "summarizedchart.html"
>>>
>>> On Thu, 3 Jun 2021 at 17:43, Eugene TUYIZERE 
>>> wrote:
>>>
>>>> Dear Suthar,
>>>>
>>>> You saved my day. Once more, the chart is displayed but the date is not
>>>> displayed on Xaxis. This how it is:
>>>>
>>>> [image: image.png]
>>>>
>>>> Th codes are:
>>>> def reqChart(request):
>>>> current_date = date.today()
>>>> days_before = date.today()-timedelta(days=30)
>>>> datelist = Customer_Requests.objects.values("arrival_date").annotate(
>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>> replist = list()
>>>> sumdata = list()
>>>> for listd in datelist:
>>>> replist.append(listd['arrival_date'])
>>>> sumdata.append(listd['num_req'])
>>>> arriva_days = {
>>>> 'name': 'Datess',
>>>> 'data': sumdata,
>>>> 'color': 'green'
>>>> }
>>>> chart = {
>>>> 'chart': {'type': 'column'},
>>>> 'title': {'text': 'Previous statistics'},
>>>> 'xAxis': {'replist': replist},
>>>> 'series': [arriva_days]
>>>> }
>>>> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>>>> return render(request,'summarizedchart.html',{'chart': dump})
>>>>
>>>>
>>>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>>>> wrote:
>>>>
>>>>> Hi there!
>>>>> make these couple of changes
>>>>>
>>>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>>> wrote:
>>>>>
>>>>>> Dear Suthar,
>>>>>>
>>>>>> Your idea works well , but I want now to display the result on chart.
>>>>>> Below is the code I am trying to use:
>>>>>> but Am getting the error message:
>>>>>>
>>>>>> Exception Value:
>>>>>>
>>>>>> Object of type date is not JSON serializable
>>>>>>
>>>>>>
>>>>>> def reqChart(request):
>>>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(
>>>>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>>> print(aa)
>>>>>> datesb = list()
>>>>>> sumdata = list()
>>>>>> for dd in aa:
>>>>>> 

Re: use of annotate in django query

2021-06-03 Thread Lalit Suthar
not sure but maybe this can work inside views replace
chart = {
  'chart': {'type': 'column'},
  'title': {'text': 'Previous statistics'},
  'xAxis': {'replist': replist},
  'series': [arriva_days]
}
with
chart = {
  'chart': {'type': 'column'},
  'title': {'text': 'Previous statistics'},
  'xAxis': {'categories': replist},
  'series': [arriva_days]
}

On Thu, 3 Jun 2021 at 18:00, Eugene TUYIZERE 
wrote:

> This what I have in summarizedchart.html:
>
> {% extends "layouts/base.html" %}
> {% load static %}
> {% block title %} Repport {% endblock %}
>
> 
> {% block stylesheets %}{% endblock stylesheets %}
>
> {% block content %}
>
> 
> 
> 
> 
> 
> Report
>
> 
>
> 
>
> 
> 
> Highcharts.chart('container', {{ chart|safe }});
> 
> 
> 
> 
> 
> 
> {% endblock content %}
> {% block custom_js %}
>
> {% endblock custom_js %}
>
> On Thu, 3 Jun 2021 at 14:22, Lalit Suthar 
> wrote:
>
>> so the view is not giving error right now but maybe we are passing the
>> data in different format then the chart is expecting.
>> What are you using for drawing the chart? can I see the code inside
>> "summarizedchart.html"
>>
>> On Thu, 3 Jun 2021 at 17:43, Eugene TUYIZERE 
>> wrote:
>>
>>> Dear Suthar,
>>>
>>> You saved my day. Once more, the chart is displayed but the date is not
>>> displayed on Xaxis. This how it is:
>>>
>>> [image: image.png]
>>>
>>> Th codes are:
>>> def reqChart(request):
>>> current_date = date.today()
>>> days_before = date.today()-timedelta(days=30)
>>> datelist = Customer_Requests.objects.values("arrival_date").annotate(
>>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>>> replist = list()
>>> sumdata = list()
>>> for listd in datelist:
>>> replist.append(listd['arrival_date'])
>>> sumdata.append(listd['num_req'])
>>> arriva_days = {
>>> 'name': 'Datess',
>>> 'data': sumdata,
>>> 'color': 'green'
>>> }
>>> chart = {
>>> 'chart': {'type': 'column'},
>>> 'title': {'text': 'Previous statistics'},
>>> 'xAxis': {'replist': replist},
>>> 'series': [arriva_days]
>>> }
>>> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>>> return render(request,'summarizedchart.html',{'chart': dump})
>>>
>>>
>>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>>> wrote:
>>>
>>>> Hi there!
>>>> make these couple of changes
>>>>
>>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>>> wrote:
>>>>
>>>>> Dear Suthar,
>>>>>
>>>>> Your idea works well , but I want now to display the result on chart.
>>>>> Below is the code I am trying to use:
>>>>> but Am getting the error message:
>>>>>
>>>>> Exception Value:
>>>>>
>>>>> Object of type date is not JSON serializable
>>>>>
>>>>>
>>>>> def reqChart(request):
>>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(num_req
>>>>> =Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>>> print(aa)
>>>>> datesb = list()
>>>>> sumdata = list()
>>>>> for dd in aa:
>>>>> datesb.append(dd['arrival_date'])
>>>>> sumdata.append(dd['num_req'])
>>>>> arriva_days = {
>>>>> 'name': 'Datess',
>>>>> 'data': sumdata,
>>>>> 'color': 'green'
>>>>> }
>>>>> chart3 = {
>>>>> 'chart': {'type': 'column'},
>>>>> 'title': {'text': 'Previous statistics'},
>>>>> 'xAxis': {'datesb': datesb},
>>>>&

Re: use of annotate in django query

2021-06-03 Thread Eugene TUYIZERE
This what I have in summarizedchart.html:

{% extends "layouts/base.html" %}
{% load static %}
{% block title %} Repport {% endblock %}


{% block stylesheets %}{% endblock stylesheets %}

{% block content %}






Report







Highcharts.chart('container', {{ chart|safe }});






{% endblock content %}
{% block custom_js %}

{% endblock custom_js %}

On Thu, 3 Jun 2021 at 14:22, Lalit Suthar  wrote:

> so the view is not giving error right now but maybe we are passing the
> data in different format then the chart is expecting.
> What are you using for drawing the chart? can I see the code inside
> "summarizedchart.html"
>
> On Thu, 3 Jun 2021 at 17:43, Eugene TUYIZERE 
> wrote:
>
>> Dear Suthar,
>>
>> You saved my day. Once more, the chart is displayed but the date is not
>> displayed on Xaxis. This how it is:
>>
>> [image: image.png]
>>
>> Th codes are:
>> def reqChart(request):
>> current_date = date.today()
>> days_before = date.today()-timedelta(days=30)
>> datelist = Customer_Requests.objects.values("arrival_date").annotate(
>> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
>> replist = list()
>> sumdata = list()
>> for listd in datelist:
>> replist.append(listd['arrival_date'])
>> sumdata.append(listd['num_req'])
>> arriva_days = {
>> 'name': 'Datess',
>> 'data': sumdata,
>> 'color': 'green'
>> }
>> chart = {
>> 'chart': {'type': 'column'},
>> 'title': {'text': 'Previous statistics'},
>> 'xAxis': {'replist': replist},
>> 'series': [arriva_days]
>> }
>> dump = json.dumps(chart,cls=DjangoJSONEncoder)
>> return render(request,'summarizedchart.html',{'chart': dump})
>>
>>
>> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
>> wrote:
>>
>>> Hi there!
>>> make these couple of changes
>>>
>>> 1) from django.core.serializers.json import DjangoJSONEncoder
>>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com
>>> wrote:
>>>
>>>> Dear Suthar,
>>>>
>>>> Your idea works well , but I want now to display the result on chart.
>>>> Below is the code I am trying to use:
>>>> but Am getting the error message:
>>>>
>>>> Exception Value:
>>>>
>>>> Object of type date is not JSON serializable
>>>>
>>>>
>>>> def reqChart(request):
>>>> aa = Customer_Requests.objects.values("arrival_date").annotate(num_req=
>>>> Count("request_name")).order_by('-arrival_date')[:20:-1]
>>>> print(aa)
>>>> datesb = list()
>>>> sumdata = list()
>>>> for dd in aa:
>>>> datesb.append(dd['arrival_date'])
>>>> sumdata.append(dd['num_req'])
>>>> arriva_days = {
>>>> 'name': 'Datess',
>>>> 'data': sumdata,
>>>> 'color': 'green'
>>>> }
>>>> chart3 = {
>>>> 'chart': {'type': 'column'},
>>>> 'title': {'text': 'Previous statistics'},
>>>> 'xAxis': {'datesb': datesb},
>>>> 'series': [arriva_days]
>>>> }
>>>> dump3 = json.dumps(chart3)
>>>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>>>
>>>> Please once again
>>>>
>>>> regards,
>>>>
>>>>
>>>>
>>>> On Thu, 3 Jun 2021 at 09:00, lalit suthar  wrote:
>>>>
>>>>> this will do
>>>>>
>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>>>
>>>>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com
>>>>> wrote:
>>>>>
>>>>>> to display last 30 records you can write your code like this:
>>>>>> Customer_Requests.objects.all()[-30]
>>>>>>
>>>>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE 
>>>>>> wrote:
>>>>>>
>>>>>>> Dear 

Re: use of annotate in django query

2021-06-03 Thread Lalit Suthar
so the view is not giving error right now but maybe we are passing the data
in different format then the chart is expecting.
What are you using for drawing the chart? can I see the code inside
"summarizedchart.html"

On Thu, 3 Jun 2021 at 17:43, Eugene TUYIZERE 
wrote:

> Dear Suthar,
>
> You saved my day. Once more, the chart is displayed but the date is not
> displayed on Xaxis. This how it is:
>
> [image: image.png]
>
> Th codes are:
> def reqChart(request):
> current_date = date.today()
> days_before = date.today()-timedelta(days=30)
> datelist = Customer_Requests.objects.values("arrival_date").annotate(
> num_req=Count("request_name")).order_by('-arrival_date')[:20:-1]
> replist = list()
> sumdata = list()
> for listd in datelist:
> replist.append(listd['arrival_date'])
> sumdata.append(listd['num_req'])
> arriva_days = {
> 'name': 'Datess',
> 'data': sumdata,
> 'color': 'green'
> }
> chart = {
> 'chart': {'type': 'column'},
> 'title': {'text': 'Previous statistics'},
> 'xAxis': {'replist': replist},
> 'series': [arriva_days]
> }
> dump = json.dumps(chart,cls=DjangoJSONEncoder)
> return render(request,'summarizedchart.html',{'chart': dump})
>
>
> On Thu, 3 Jun 2021 at 13:27, lalit suthar 
> wrote:
>
>> Hi there!
>> make these couple of changes
>>
>> 1) from django.core.serializers.json import DjangoJSONEncoder
>> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
>> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com wrote:
>>
>>> Dear Suthar,
>>>
>>> Your idea works well , but I want now to display the result on chart.
>>> Below is the code I am trying to use:
>>> but Am getting the error message:
>>>
>>> Exception Value:
>>>
>>> Object of type date is not JSON serializable
>>>
>>>
>>> def reqChart(request):
>>> aa = Customer_Requests.objects.values("arrival_date").annotate(num_req=
>>> Count("request_name")).order_by('-arrival_date')[:20:-1]
>>> print(aa)
>>> datesb = list()
>>> sumdata = list()
>>> for dd in aa:
>>> datesb.append(dd['arrival_date'])
>>> sumdata.append(dd['num_req'])
>>> arriva_days = {
>>> 'name': 'Datess',
>>> 'data': sumdata,
>>> 'color': 'green'
>>> }
>>> chart3 = {
>>> 'chart': {'type': 'column'},
>>> 'title': {'text': 'Previous statistics'},
>>> 'xAxis': {'datesb': datesb},
>>> 'series': [arriva_days]
>>> }
>>> dump3 = json.dumps(chart3)
>>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>>
>>> Please once again
>>>
>>> regards,
>>>
>>>
>>>
>>> On Thu, 3 Jun 2021 at 09:00, lalit suthar  wrote:
>>>
>>>> this will do
>>>>
>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>>
>>>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com
>>>> wrote:
>>>>
>>>>> to display last 30 records you can write your code like this:
>>>>> Customer_Requests.objects.all()[-30]
>>>>>
>>>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE 
>>>>> wrote:
>>>>>
>>>>>> Dear Latit,
>>>>>>
>>>>>> Thank you very much. Now how can I display 30 last records?
>>>>>> Regardless of how many records I may have ! Just the last 30 records!
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar 
>>>>>> wrote:
>>>>>>
>>>>>>> > in brief, I want to transform this query in django query
>>>>>>> this will be equivalent to this query in django
>>>>>>>
>>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>>>>>
>>>>>>>
>>>>>>> On Thu, 3 Jun 2021 at 02:02, E

Re: use of annotate in django query

2021-06-03 Thread Eugene TUYIZERE
Dear Suthar,

You saved my day. Once more, the chart is displayed but the date is not
displayed on Xaxis. This how it is:

[image: image.png]

Th codes are:
def reqChart(request):
current_date = date.today()
days_before = date.today()-timedelta(days=30)
datelist = Customer_Requests.objects.values("arrival_date").annotate(num_req
=Count("request_name")).order_by('-arrival_date')[:20:-1]
replist = list()
sumdata = list()
for listd in datelist:
replist.append(listd['arrival_date'])
sumdata.append(listd['num_req'])
arriva_days = {
'name': 'Datess',
'data': sumdata,
'color': 'green'
}
chart = {
'chart': {'type': 'column'},
'title': {'text': 'Previous statistics'},
'xAxis': {'replist': replist},
'series': [arriva_days]
}
dump = json.dumps(chart,cls=DjangoJSONEncoder)
return render(request,'summarizedchart.html',{'chart': dump})


On Thu, 3 Jun 2021 at 13:27, lalit suthar  wrote:

> Hi there!
> make these couple of changes
>
> 1) from django.core.serializers.json import DjangoJSONEncoder
> 2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
> On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com wrote:
>
>> Dear Suthar,
>>
>> Your idea works well , but I want now to display the result on chart.
>> Below is the code I am trying to use:
>> but Am getting the error message:
>>
>> Exception Value:
>>
>> Object of type date is not JSON serializable
>>
>>
>> def reqChart(request):
>> aa = Customer_Requests.objects.values("arrival_date").annotate(num_req=
>> Count("request_name")).order_by('-arrival_date')[:20:-1]
>> print(aa)
>> datesb = list()
>> sumdata = list()
>> for dd in aa:
>> datesb.append(dd['arrival_date'])
>> sumdata.append(dd['num_req'])
>> arriva_days = {
>> 'name': 'Datess',
>> 'data': sumdata,
>> 'color': 'green'
>> }
>> chart3 = {
>> 'chart': {'type': 'column'},
>> 'title': {'text': 'Previous statistics'},
>> 'xAxis': {'datesb': datesb},
>> 'series': [arriva_days]
>> }
>> dump3 = json.dumps(chart3)
>> return render(request,'summarizedchart.html',{'chart3': dump3})
>>
>> Please once again
>>
>> regards,
>>
>>
>>
>> On Thu, 3 Jun 2021 at 09:00, lalit suthar  wrote:
>>
>>> this will do
>>>
>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>>
>>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com wrote:
>>>
>>>> to display last 30 records you can write your code like this:
>>>> Customer_Requests.objects.all()[-30]
>>>>
>>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE 
>>>> wrote:
>>>>
>>>>> Dear Latit,
>>>>>
>>>>> Thank you very much. Now how can I display 30 last records? Regardless
>>>>> of how many records I may have ! Just the last 30 records!
>>>>>
>>>>> Thank you
>>>>>
>>>>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar 
>>>>> wrote:
>>>>>
>>>>>> > in brief, I want to transform this query in django query
>>>>>> this will be equivalent to this query in django
>>>>>>
>>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>>>>
>>>>>>
>>>>>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE 
>>>>>> wrote:
>>>>>>
>>>>>>> in brief, I want to transform this query in django query
>>>>>>>
>>>>>>> [image: image.png]
>>>>>>>
>>>>>>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Dear Sebatian,
>>>>>>>>
>>>>>>>> This is what I get:
>>>>>>>>
>>>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>>&

Re: use of annotate in django query

2021-06-03 Thread lalit suthar
Hi there! 
make these couple of changes 

1) from django.core.serializers.json import DjangoJSONEncoder 
2) dump3 = json.dumps(chart3, cls=DjangoJSONEncoder)
On Thursday, 3 June 2021 at 16:18:15 UTC+5:30 eugenet...@gmail.com wrote:

> Dear Suthar,
>
> Your idea works well , but I want now to display the result on chart. 
> Below is the code I am trying to use:
> but Am getting the error message:
>
> Exception Value: 
>
> Object of type date is not JSON serializable
>
>
> def reqChart(request): 
> aa = Customer_Requests.objects.values("arrival_date").annotate(num_req=
> Count("request_name")).order_by('-arrival_date')[:20:-1]
> print(aa)
> datesb = list()
> sumdata = list()
> for dd in aa:
> datesb.append(dd['arrival_date'])
> sumdata.append(dd['num_req'])
> arriva_days = {
> 'name': 'Datess',
> 'data': sumdata,
> 'color': 'green'
> }
> chart3 = {
> 'chart': {'type': 'column'},
> 'title': {'text': 'Previous statistics'},
> 'xAxis': {'datesb': datesb},
> 'series': [arriva_days]
> }
> dump3 = json.dumps(chart3)
> return render(request,'summarizedchart.html',{'chart3': dump3})
>
> Please once again
>
> regards, 
>
>
>
> On Thu, 3 Jun 2021 at 09:00, lalit suthar  wrote:
>
>> this will do 
>>
>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>>
>> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com wrote:
>>
>>> to display last 30 records you can write your code like this: 
>>> Customer_Requests.objects.all()[-30]
>>>
>>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE  
>>> wrote:
>>>
>>>> Dear Latit,
>>>>
>>>> Thank you very much. Now how can I display 30 last records? Regardless 
>>>> of how many records I may have ! Just the last 30 records!
>>>>
>>>> Thank you
>>>>
>>>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar  wrote:
>>>>
>>>>> > in brief, I want to transform this query in django query
>>>>> this will be equivalent to this query in django 
>>>>>
>>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>>>
>>>>>
>>>>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE  
>>>>> wrote:
>>>>>
>>>>>> in brief, I want to transform this query in django query
>>>>>>
>>>>>> [image: image.png]
>>>>>>
>>>>>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE  
>>>>>> wrote:
>>>>>>
>>>>>>> Dear Sebatian,
>>>>>>>
>>>>>>> This is what I get:
>>>>>>>
>>>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` 
>>>>>>> >= 
>>>>>>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY 
>>>>>>> NULL
>>>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` 
>>>>>>> >= 
>>>>>>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY 
>>>>>>> NULL
>>>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` 
>>>>>>> >= 
>>>>>>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY 
>>>>>>> NULL
>>>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` 
>>>>>>> >= 
>>>>>>> 2021-05-06 GROUP B

Re: use of annotate in django query

2021-06-03 Thread Eugene TUYIZERE
Dear Suthar,

Your idea works well , but I want now to display the result on chart. Below
is the code I am trying to use:
but Am getting the error message:

Exception Value:

Object of type date is not JSON serializable


def reqChart(request):
aa = Customer_Requests.objects.values("arrival_date").annotate(num_req=Count
("request_name")).order_by('-arrival_date')[:20:-1]
print(aa)
datesb = list()
sumdata = list()
for dd in aa:
datesb.append(dd['arrival_date'])
sumdata.append(dd['num_req'])
arriva_days = {
'name': 'Datess',
'data': sumdata,
'color': 'green'
}
chart3 = {
'chart': {'type': 'column'},
'title': {'text': 'Previous statistics'},
'xAxis': {'datesb': datesb},
'series': [arriva_days]
}
dump3 = json.dumps(chart3)
return render(request,'summarizedchart.html',{'chart3': dump3})

Please once again

regards,



On Thu, 3 Jun 2021 at 09:00, lalit suthar  wrote:

> this will do
>
> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]
>
> On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com wrote:
>
>> to display last 30 records you can write your code like this:
>> Customer_Requests.objects.all()[-30]
>>
>> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE 
>> wrote:
>>
>>> Dear Latit,
>>>
>>> Thank you very much. Now how can I display 30 last records? Regardless
>>> of how many records I may have ! Just the last 30 records!
>>>
>>> Thank you
>>>
>>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar  wrote:
>>>
>>>> > in brief, I want to transform this query in django query
>>>> this will be equivalent to this query in django
>>>>
>>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>>
>>>>
>>>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE 
>>>> wrote:
>>>>
>>>>> in brief, I want to transform this query in django query
>>>>>
>>>>> [image: image.png]
>>>>>
>>>>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
>>>>> wrote:
>>>>>
>>>>>> Dear Sebatian,
>>>>>>
>>>>>> This is what I get:
>>>>>>
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>>>> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>>>> COUNT(`c

Re: use of annotate in django query

2021-06-02 Thread lalit suthar
this will do 
Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name")).order_by("-id")[:30:-1]

On Thursday, 3 June 2021 at 11:37:26 UTC+5:30 abubak...@gmail.com wrote:

> to display last 30 records you can write your code like this: 
> Customer_Requests.objects.all()[-30]
>
> On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE  
> wrote:
>
>> Dear Latit,
>>
>> Thank you very much. Now how can I display 30 last records? Regardless of 
>> how many records I may have ! Just the last 30 records!
>>
>> Thank you
>>
>> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar  wrote:
>>
>>> > in brief, I want to transform this query in django query
>>> this will be equivalent to this query in django 
>>>
>>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>>
>>>
>>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE  
>>> wrote:
>>>
>>>> in brief, I want to transform this query in django query
>>>>
>>>> [image: image.png]
>>>>
>>>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE  
>>>> wrote:
>>>>
>>>>> Dear Sebatian,
>>>>>
>>>>> This is what I get:
>>>>>
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_customer_requests`.`arrival_date`, 
>>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM 
>>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >= 
>>>>> 2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>>> SELECT `crms_custo

Re: use of annotate in django query

2021-06-02 Thread DJANGO DEVELOPER
to display last 30 records you can write your code like this:
Customer_Requests.objects.all()[-30]

On Thu, Jun 3, 2021 at 10:51 AM Eugene TUYIZERE 
wrote:

> Dear Latit,
>
> Thank you very much. Now how can I display 30 last records? Regardless of
> how many records I may have ! Just the last 30 records!
>
> Thank you
>
> On Thu, 3 Jun 2021 at 06:51, Lalit Suthar 
> wrote:
>
>> > in brief, I want to transform this query in django query
>> this will be equivalent to this query in django
>>
>> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>>
>>
>> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE 
>> wrote:
>>
>>> in brief, I want to transform this query in django query
>>>
>>> [image: image.png]
>>>
>>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
>>> wrote:
>>>
>>>> Dear Sebatian,
>>>>
>>>> This is what I get:
>>>>
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-13 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>>> SELECT `crms_customer_requests`.`arrival_date`,
>>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>>> 2021-05-14 GROUP BY `crms_

Re: use of annotate in django query

2021-06-02 Thread Eugene TUYIZERE
Dear Latit,

Thank you very much. Now how can I display 30 last records? Regardless of
how many records I may have ! Just the last 30 records!

Thank you

On Thu, 3 Jun 2021 at 06:51, Lalit Suthar  wrote:

> > in brief, I want to transform this query in django query
> this will be equivalent to this query in django
>
> Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))
>
>
> On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE 
> wrote:
>
>> in brief, I want to transform this query in django query
>>
>> [image: image.png]
>>
>> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
>> wrote:
>>
>>> Dear Sebatian,
>>>
>>> This is what I get:
>>>
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-13 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-14 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>>> 2021-05-15 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>>> SELECT `crms_customer_requests`.`arrival_date`,
>>> COUNT(`crms_customer_requests`.`r

Re: use of annotate in django query

2021-06-02 Thread Lalit Suthar
> in brief, I want to transform this query in django query
this will be equivalent to this query in django
Customer_Requests.objects.values("arrival_date").annotate(num_req=Count("request_name"))


On Thu, 3 Jun 2021 at 02:02, Eugene TUYIZERE 
wrote:

> in brief, I want to transform this query in django query
>
> [image: image.png]
>
> On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
> wrote:
>
>> Dear Sebatian,
>>
>> This is what I get:
>>
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-13 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-14 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-15 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-16 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELECT `crms_customer_requests`.`arrival_date`,
>> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
>> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
>> 2021-05-17 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
>> SELEC

Re: use of annotate in django query

2021-06-02 Thread Eugene TUYIZERE
in brief, I want to transform this query in django query

[image: image.png]

On Wed, 2 Jun 2021 at 21:56, Eugene TUYIZERE 
wrote:

> Dear Sebatian,
>
> This is what I get:
>
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-13 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-14 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-15 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-16 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-17 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-18 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SELECT `crms_customer_requests`.`arrival_date`,
> COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
> `crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
> 2021-05-19 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
> SEL

Re: use of annotate in django query

2021-06-02 Thread Eugene TUYIZERE
Dear Sebatian,

This is what I get:

SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-03 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-04 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-05 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-06 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-07 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-08 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-09 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-10 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-11 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-12 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-13 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-14 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-15 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-16 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-17 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-18 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-19 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-20 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_date`,
COUNT(`crms_customer_requests`.`request_name`) AS `count` FROM
`crms_customer_requests` WHERE `crms_customer_requests`.`arrival_date` >=
2021-05-21 GROUP BY `crms_customer_requests`.`arrival_date` ORDER BY NULL
SELECT `crms_customer_requests`.`arrival_

Re: use of annotate in django query

2021-06-02 Thread Sebastian Jung
Hi Eugene,

Please make Print(report.query) then you get SQL querys and Most of time i
get an Idea what's wrong

Regards

Eugene TUYIZERE  schrieb am Mi., 2. Juni 2021,
21:41:

> Dear Team,
>
> I need help. I am working on a project where one of the tables is about
> requests. I want to have a report of the number of requests on each day in
> the last 30 days, something like this:
> [image: image.png]I I used the code below just before displaying on the
> chart but the code gives me wrong information
>
> def reqChart(request):
> current_date = date.today()
> days_before = date.today()-timedelta(days=30)
> for dt in daterange(days_before,current_date):
> reports = Customer_Requests.objects.filter(arrival_date__gte=dt).\
> extra({'day':"date(arrival_date)"}).\
> values('arrival_date').annotate(count=Count('request_name'))
> print(reports)
>
>
> And I need help
> --
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene.tuyiz...@aims-cameroon.org
>eugenetuyiz...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHstWyfMVKQhJb%3DxGKff3p3V%2BFQ_w3DkYVpOe-pEW2ySKg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9myp4HU6%2BZo6d-JqeaTPsevFBMi_DzU_xuwo3LUja%3DxzRw%40mail.gmail.com.


use of annotate in django query

2021-06-02 Thread Eugene TUYIZERE
Dear Team,

I need help. I am working on a project where one of the tables is about
requests. I want to have a report of the number of requests on each day in
the last 30 days, something like this:
[image: image.png]I I used the code below just before displaying on the
chart but the code gives me wrong information

def reqChart(request):
current_date = date.today()
days_before = date.today()-timedelta(days=30)
for dt in daterange(days_before,current_date):
reports = Customer_Requests.objects.filter(arrival_date__gte=dt).\
extra({'day':"date(arrival_date)"}).\
values('arrival_date').annotate(count=Count('request_name'))
print(reports)


And I need help
-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHstWyfMVKQhJb%3DxGKff3p3V%2BFQ_w3DkYVpOe-pEW2ySKg%40mail.gmail.com.


Re: Help with a huge database query.

2021-05-31 Thread 'odrzen' via Django users
If I use the values() or values_list() the request in database has a long 
waiting time and some time I also got a MemoryError (because 4GB RAM is not 
enough).
My examples:

Apple.objects.select_related('Orange').filter(state='fresh').values_list(
# Fields I don't want:
'field1',
'field2',
'field3'
# . ,
'field37'
)

( yes I want 37 different values ).

I also try with .only() with very nice response time, but in the end I will get 
all the fields. For example:
temp = Apple.objects.select_related('Orange').filter(state='fresh').only(
'field1',
'field2',
'field3' )

temp_json = serializers.serialize('json', temp)
return HttpResponse(temp_json, content_type='application/json')

it returns me all the fields! Not only the 'field2', 'field2' and 'field3'.
Could you explain me why ?

Finally, I also tried to run a query with raw() but the response time is 
disappointing.

‐‐‐ Original Message ‐‐‐
On Friday, May 28, 2021 2:13 AM, David Nugent  wrote:

> I think a better approach to using QuerySet.defer() is to use .values() 
> instead, explicitly specifying which fields you need to export.
>
> Just FYI rest_framework handles this out of the box and provides an API to 
> specify not only which fields to export but filters as well.
>
> Regards
> /d
>
> On Fri, May 28, 2021 at 8:10 AM 'odrzen' via Django users 
>  wrote:
>
>> Hello Django community o/
>>
>> I want to create a API call in order to get all data from a specific model ( 
>> table ) - but I want to exclude-remove only specific fields from this.
>> So, I try to find a right way to execute this difficult and "heavy" 
>> query/request with a efficient way.
>> This is what I have achieved so far:
>>
>> ```
>> #from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
>> #from django.core import serializers
>> from apples.models import Apple
>> from oranges.models import Orange
>>
>> published_fruits = 
>> Apple.objects.select_related('Orange').filter(state='published').defer(
>> # Fields I don't want:
>> 'field1',
>> 'field2',
>> 'field3'
>> )
>>
>> So, I have the following results:
>> [
>> {
>> "model": "apples.apple",
>> "pk": "5326t236-8415-48f4-89e5-1789vc9of442",
>> "fields": {
>> "id": "apple-type1",
>> "name": "Brazil",
>> ".": "",
>> "exports ": []
>> }
>> },
>> { ... }
>> {
>> "model": "apples.apple",
>> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
>> "fields": {
>> "id": "apple-type2",
>> "name": "India",
>> ".": "",
>> "exports ": []
>> }
>> }
>> ]
>> ```
>>
>> My proble is :
>> 1. The fields who I don't want (exclude), finally I got it.
>> 2. I want to directly pass all this response to a JSON http output for the 
>> users and I have it with the following way:
>> ```
>> json_response = serializers.serialize('json', published_fruits)
>> return HttpResponse(json_response, content_type='application/json')
>> ```
>> I get all the respone in JSON, but ( as you can see above ) with the 
>> following stracture:
>> ```
>> {
>> "model": "apples.apple",
>> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
>> "fields": {
>> "id": "apple-type2",
>> "name": "India",
>> ".": "",
>> "exports ": []
>> }
>> }
>> ```
>>
>> Please, could you help me to avoid the following part from each record :
>> ```
>> "model": "apples.apple",
>> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
>> "fields": {
>> ```
>> from the JSON ?
>>
>> Thank you very much in advance!
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> [https://groups.googl

Re: Help with a huge database query.

2021-05-27 Thread David Nugent
I think a better approach to using QuerySet.defer() is to use .values()
instead, explicitly specifying which fields you need to export.

Just FYI rest_framework handles this out of the box and provides an API to
specify not only which fields to export but filters as well.

Regards
/d


On Fri, May 28, 2021 at 8:10 AM 'odrzen' via Django users <
django-users@googlegroups.com> wrote:

> Hello Django community o/
>
> I want to create a API call in order to get *all data* from a specific
> model ( table ) - but I want to exclude-remove only specific fields from
> this.
> So, I try to find a right way to execute this difficult and "*heavy*"
> query/request with a efficient way.
> This is what I have achieved so far:
>
> ```
> #from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
> #from django.core import serializers
> from apples.models import Apple
> from oranges.models import Orange
>
> published_fruits =
> Apple.objects.select_related('Orange').filter(state='published').defer(
># Fields I don't want:
>'field1',
>'field2',
>'field3'
>)
>
> So, I have the following results:
> [
>   {
> "model": "apples.apple",
> "pk": "5326t236-8415-48f4-89e5-1789vc9of442",
> "fields": {
>   "id": "apple-type1",
>   "name": "Brazil",
>   ".": "",
>   "exports ": []
> }
>   },
>   { ... }
>   {
> "model": "apples.apple",
> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
> "fields": {
>   "id": "apple-type2",
>   "name": "India",
> ".": "",
>   "exports ": []
> }
>   }
> ]
> ```
>
>
> My proble is :
> 1. The fields who I don't want (exclude), finally I got it.
> 2. I want to directly *pass all this response to a JSON http output* for
> the users and I have it with the following way:
> ```
> json_response = serializers.serialize('json', published_fruits)
> return HttpResponse(json_response, content_type='application/json')
> ```
> I get all the respone in JSON, but ( *as you can see above* ) with the
> following stracture:
> ```
>   {
> "model": "apples.apple",
> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
> "fields": {
>   "id": "apple-type2",
>   "name": "India",
> ".": "",
>   "exports ": []
> }
>   }
> ```
>
> Please, could you help me to avoid the following part from each record  :
> ```
> "model": "apples.apple",
> "pk": "6435673472-fret2-523t-523t-d41159t23432213",
> "fields": {
> ```
> from the JSON ?
>
> Thank you very much in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/MvvGE0gJ6x5v1Geo7zgnHdB8TLr79HKJwubqhQzrOKUSB3Q4oHPeWCctdFmOAJ74PbqQ9gHkg44hKVrPqp9BFiZ7Bn7E-LzM30aNrbhcf7s%3D%40protonmail.com
> <https://groups.google.com/d/msgid/django-users/MvvGE0gJ6x5v1Geo7zgnHdB8TLr79HKJwubqhQzrOKUSB3Q4oHPeWCctdFmOAJ74PbqQ9gHkg44hKVrPqp9BFiZ7Bn7E-LzM30aNrbhcf7s%3D%40protonmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgX04DNGPHS%2BgpC7UdT2Kwj40%2BZ6UqKckSQ0G8RL5mHb0A%40mail.gmail.com.


Help with a huge database query.

2021-05-27 Thread 'odrzen' via Django users
Hello Django community o/

I want to create a API call in order to get all data from a specific model ( 
table ) - but I want to exclude-remove only specific fields from this.
So, I try to find a right way to execute this difficult and "heavy" 
query/request with a efficient way.
This is what I have achieved so far:

```
#from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
#from django.core import serializers
from apples.models import Apple
from oranges.models import Orange

published_fruits = 
Apple.objects.select_related('Orange').filter(state='published').defer(
# Fields I don't want:
'field1',
'field2',
'field3'
)

So, I have the following results:
[
{
"model": "apples.apple",
"pk": "5326t236-8415-48f4-89e5-1789vc9of442",
"fields": {
"id": "apple-type1",
"name": "Brazil",
".": "",
"exports ": []
}
},
{ ... }
{
"model": "apples.apple",
"pk": "6435673472-fret2-523t-523t-d41159t23432213",
"fields": {
"id": "apple-type2",
"name": "India",
".": "",
"exports ": []
}
}
]
```

My proble is :
1. The fields who I don't want (exclude), finally I got it.
2. I want to directly pass all this response to a JSON http output for the 
users and I have it with the following way:
```
json_response = serializers.serialize('json', published_fruits)
return HttpResponse(json_response, content_type='application/json')
```
I get all the respone in JSON, but ( as you can see above ) with the following 
stracture:
```
{
"model": "apples.apple",
"pk": "6435673472-fret2-523t-523t-d41159t23432213",
"fields": {
"id": "apple-type2",
"name": "India",
".": "",
"exports ": []
}
}
```

Please, could you help me to avoid the following part from each record :
```
"model": "apples.apple",
"pk": "6435673472-fret2-523t-523t-d41159t23432213",
"fields": {
```
from the JSON ?

Thank you very much in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/MvvGE0gJ6x5v1Geo7zgnHdB8TLr79HKJwubqhQzrOKUSB3Q4oHPeWCctdFmOAJ74PbqQ9gHkg44hKVrPqp9BFiZ7Bn7E-LzM30aNrbhcf7s%3D%40protonmail.com.


Re: how to use reverse query data from a child model to do arithmetic's in parent model?

2021-03-28 Thread Ryan Nowakowski



On March 28, 2021 1:42:50 AM CDT, Vansh Jagyasi -IIITK 
 wrote:
>I have created a model location, and a model transaction which has a
>many 
>to one relation with location which has the information of a
>transaction 
>done at a particular location, say 3 dollars spent at macdonalds, now I
>
>want to find all the transactions related to a particular location and
>add 
>the amount to find the total amount spent,please help

You probably want to use `Sum` from Django aggregate:

https://docs.djangoproject.com/en/3.1/topics/db/aggregation/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2133D582-868F-4F2D-B09F-F8AB37001CDE%40fattuba.com.


how to use reverse query data from a child model to do arithmetic's in parent model?

2021-03-28 Thread Vansh Jagyasi -IIITK
I have created a model location, and a model transaction which has a many 
to one relation with location which has the information of a transaction 
done at a particular location, say 3 dollars spent at macdonalds, now I 
want to find all the transactions related to a particular location and add 
the amount to find the total amount spent,please help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a3cba46-c475-49f1-9011-74dd037de8c8n%40googlegroups.com.
from django.db import models


class location(models.Model):
name=models.CharField(max_length=100)
total_amount_spent=models.FloatField(default=0)
def __str__(self):
return self.name

class transaction(models.Model):
location_name=models.ForeignKey(location,on_delete=models.CASCADE,null=True)
date_time=models.DateTimeField(null=True)
amount=models.FloatField(null=True)
def __int__(self):
return self.id











Re: View / Query Set not showing with filter

2021-03-19 Thread Héctor Alonso Lozada Echezuría
my friend,

I'm checking your code, and I can't continue without seeing the template
and how you make the request.

However I will try to make a dissection of the code to evaluate what
happens, so I will forward your code to you in the pastebin link with some
notes: https://pastebin.com/QbxqcTrh

Note: if you are doing an ajax request you should not return a template,
https://docs.djangoproject.com/en/3.1/ref/request-response/#jsonresponse-objects

So I would return a template with the context: https://pastebin.com/BYre4Dig
and so I would return it in an ajax request: https://pastebin.com/CJ2YA8gz


El vie, 19 mar 2021 a las 16:29, Manuel Buri ()
escribió:

> *Booking Model*
> from django.db import models
> from django.utils import timezone
> from users.models import Account
> from organization.models import Organization, Office
>
>
> class Booking(models.Model):
> LOCATION_OPTIONS = (
> ('H', 'Home Office'),
> ('O', 'Office'),
> ('N', 'Not indicated'),
> )
> account = models.ForeignKey(Account,
> on_delete=models.CASCADE)
> organization= models.ForeignKey(Organization,
> on_delete=models.CASCADE)
> office  = models.ForeignKey(Office,
> on_delete=models.CASCADE)
> booking_time= models.DateTimeField(default=timezone.now)
> location= models.CharField(max_length=1,
> choices=LOCATION_OPTIONS)
> class Meta:
> unique_together = ('account', 'booking_time',)
>
> *View*
> def overview_view(request):
>
> context = {}
>
> if request.method == 'GET':
> start_date = None
> end_date = None
> if request.is_ajax():
> booking_times = request.GET.get('day')
> start_date = datetime.strptime(booking_times, "%Y-%m-%d")
> end_date = start_date + timedelta(days=4)
> start_date = start_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
> end_date = end_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
>
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range =
> (start_date, end_date))
> context['office'] =
> Office.objects.filter(organization_id__exact=request.user.organization_id)
>
> return render(request, 'overview/overview.html', context)
> return render(request, 'overview/overview.html', context)
>
> haha sorry for not using pastebin before :D
>
> Thank you so much.
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11
> M: manuel.b...@gmail.com
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 23:22, Héctor Alonso Lozada Echezuría <
> ima...@gmail.com> wrote:
>
>> Can you share your "Booking" model and the view (function or class) that
>> renders the template?, and I beg you, please use pastebin.com for share
>> your code :D
>>
>> El vie, 19 mar 2021 a las 16:17, Manuel Buri ()
>> escribió:
>>
>>> @anornymou...@gmail.com and ima...@gmail.com
>>> your suggestion is unfortunately not working too
>>>
>>> @All:
>>> So as said my queryset is not empty, meaning that the query works.
>>> However, the results is not in the rendered HTML file.
>>> This would imply that with my template is something wrong, don't you
>>> think?
>>>
>>> {% for office in office.all %}
>>> {{ office.office_name }}
>>> {% for booking in bookings %}
>>> 
>>> 
>>> {{ booking.account.first_name }} {{ 
>>> booking.account.last_name }}
>>> {% if booking.get_location_display == 'House' %}
>>> 🏢 {{ booking.get_location_display 
>>> }}
>>> {% elif booking.get_location_display == 'Home' %}
>>> 🏠 {{ booking.get_location_display 
>>> }}
>>> {% else %}
>>> 🤔 {{ booking.get_location_display 
>>> }}
>>>     {% endif %}
>>> 
>>> 
>>> {% endfor %}
>>> {% endfor %}
>>>
>>>
>>> What do you think?
>>>
>>> Thank you so much for your help !
>>>
>>> Best wishes,
>>>
>>&g

Re: View / Query Set not showing with filter

2021-03-19 Thread Arisophy
Hi Manuelf

I understand what you say.
Now, I think It's not the problem of Querym , too.
The problem is that field data is not displayed in HTML.

You use the wrong variable name "office" in Template.

try this.

(View)
context['office'] = 
↓
context['offices']  = ...

(Template)

× {% for office in office.all %}
 ↓
{% for office in offices %}


regards

Arisophy

2021年3月20日(土) 7:31 Manuel Buri :

> *Booking Model*
> from django.db import models
> from django.utils import timezone
> from users.models import Account
> from organization.models import Organization, Office
>
>
> class Booking(models.Model):
> LOCATION_OPTIONS = (
> ('H', 'Home Office'),
> ('O', 'Office'),
> ('N', 'Not indicated'),
> )
> account = models.ForeignKey(Account,
> on_delete=models.CASCADE)
> organization= models.ForeignKey(Organization,
> on_delete=models.CASCADE)
> office  = models.ForeignKey(Office,
> on_delete=models.CASCADE)
> booking_time= models.DateTimeField(default=timezone.now)
> location= models.CharField(max_length=1,
> choices=LOCATION_OPTIONS)
> class Meta:
> unique_together = ('account', 'booking_time',)
>
> *View*
> def overview_view(request):
>
> context = {}
>
> if request.method == 'GET':
> start_date = None
> end_date = None
> if request.is_ajax():
> booking_times = request.GET.get('day')
> start_date = datetime.strptime(booking_times, "%Y-%m-%d")
> end_date = start_date + timedelta(days=4)
> start_date = start_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
> end_date = end_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
>
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range =
> (start_date, end_date))
> context['office'] =
> Office.objects.filter(organization_id__exact=request.user.organization_id)
>
> return render(request, 'overview/overview.html', context)
> return render(request, 'overview/overview.html', context)
>
> haha sorry for not using pastebin before :D
>
> Thank you so much.
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11
> M: manuel.b...@gmail.com
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 23:22, Héctor Alonso Lozada Echezuría <
> ima...@gmail.com> wrote:
>
>> Can you share your "Booking" model and the view (function or class) that
>> renders the template?, and I beg you, please use pastebin.com for share
>> your code :D
>>
>> El vie, 19 mar 2021 a las 16:17, Manuel Buri ()
>> escribió:
>>
>>> @anornymou...@gmail.com and ima...@gmail.com
>>> your suggestion is unfortunately not working too
>>>
>>> @All:
>>> So as said my queryset is not empty, meaning that the query works.
>>> However, the results is not in the rendered HTML file.
>>> This would imply that with my template is something wrong, don't you
>>> think?
>>>
>>> {% for office in office.all %}
>>> {{ office.office_name }}
>>> {% for booking in bookings %}
>>> 
>>> 
>>> {{ booking.account.first_name }} {{ 
>>> booking.account.last_name }}
>>> {% if booking.get_location_display == 'House' %}
>>> 🏢 {{ booking.get_location_display 
>>> }}
>>> {% elif booking.get_location_display == 'Home' %}
>>> 🏠 {{ booking.get_location_display 
>>> }}
>>> {% else %}
>>> 🤔 {{ booking.get_location_display 
>>> }}
>>> {% endif %}
>>> 
>>> 
>>> {% endfor %}
>>> {% endfor %}
>>>
>>>
>>> What do you think?
>>>
>>> Thank you so much for your help !
>>>
>>> Best wishes,
>>>
>>> Manuel
>>>
>>>
>>>
>>> Manuel Buri
>>> T:  +41 79 933 01 11
>>> M: manuel.b...@gmail.com
>>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>>

Re: View / Query Set not showing with filter

2021-03-19 Thread Manuel Buri
*Booking Model*
from django.db import models
from django.utils import timezone
from users.models import Account
from organization.models import Organization, Office


class Booking(models.Model):
LOCATION_OPTIONS = (
('H', 'Home Office'),
('O', 'Office'),
('N', 'Not indicated'),
)
account = models.ForeignKey(Account,
on_delete=models.CASCADE)
organization= models.ForeignKey(Organization,
on_delete=models.CASCADE)
office  = models.ForeignKey(Office,
on_delete=models.CASCADE)
booking_time= models.DateTimeField(default=timezone.now)
location= models.CharField(max_length=1,
choices=LOCATION_OPTIONS)
class Meta:
unique_together = ('account', 'booking_time',)

*View*
def overview_view(request):

context = {}

if request.method == 'GET':
start_date = None
end_date = None
if request.is_ajax():
booking_times = request.GET.get('day')
start_date = datetime.strptime(booking_times, "%Y-%m-%d")
end_date = start_date + timedelta(days=4)
start_date = start_date.replace(hour=0, minute=0, second=0,
microsecond=0, tzinfo=pytz.utc)
end_date = end_date.replace(hour=0, minute=0, second=0,
microsecond=0, tzinfo=pytz.utc)

context['bookings']=Booking.objects.filter(
Q(organization_id=request.user.organization_id), Q(booking_time__range =
(start_date, end_date))
context['office'] =
Office.objects.filter(organization_id__exact=request.user.organization_id)

return render(request, 'overview/overview.html', context)
return render(request, 'overview/overview.html', context)

haha sorry for not using pastebin before :D

Thank you so much.

Best wishes,

Manuel



Manuel Buri
T:  +41 79 933 01 11
M: manuel.b...@gmail.com
W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>


On Fri, 19 Mar 2021 at 23:22, Héctor Alonso Lozada Echezuría <
ima...@gmail.com> wrote:

> Can you share your "Booking" model and the view (function or class) that
> renders the template?, and I beg you, please use pastebin.com for share
> your code :D
>
> El vie, 19 mar 2021 a las 16:17, Manuel Buri ()
> escribió:
>
>> @anornymou...@gmail.com and ima...@gmail.com
>> your suggestion is unfortunately not working too
>>
>> @All:
>> So as said my queryset is not empty, meaning that the query works.
>> However, the results is not in the rendered HTML file.
>> This would imply that with my template is something wrong, don't you
>> think?
>>
>> {% for office in office.all %}
>> {{ office.office_name }}
>> {% for booking in bookings %}
>> 
>> 
>> {{ booking.account.first_name }} {{ 
>> booking.account.last_name }}
>> {% if booking.get_location_display == 'House' %}
>> 🏢 {{ booking.get_location_display 
>> }}
>> {% elif booking.get_location_display == 'Home' %}
>> 🏠 {{ booking.get_location_display 
>> }}
>> {% else %}
>> 🤔 {{ booking.get_location_display 
>> }}
>> {% endif %}
>> 
>> 
>> {% endfor %}
>> {% endfor %}
>>
>>
>> What do you think?
>>
>> Thank you so much for your help !
>>
>> Best wishes,
>>
>> Manuel
>>
>>
>>
>> Manuel Buri
>> T:  +41 79 933 01 11
>> M: manuel.b...@gmail.com
>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>
>>
>> On Fri, 19 Mar 2021 at 22:51, Thomas Lockhart 
>> wrote:
>>
>>> Why use Q? afaict simple filter syntax should get you what you want.
>>>
>>> Booking.objects.filter(organization_id=request.user.organization_id,
>>> booking_time__range= (start_date, end_date))
>>>
>>> Not sure if this will get you closer to the query you expect.
>>>
>>> You might also find it useful to use "./manage.py shell" to test the
>>> queries by hand. Import a few models, put in “11” for the organization_id,
>>> and see what happens.
>>>
>>> - Tom
>>>
>>> > On Mar 19, 2021, at 2:11 PM, Manuel Buri 
>>> wrote:
>>> >
>>> > I want to fetch all bookings for the users organization_id between
>>> start_date and end_date.
>>> > I am achieving this via this queryset, however, as soon as I add

Re: View / Query Set not showing with filter

2021-03-19 Thread Héctor Alonso Lozada Echezuría
Can you share your "Booking" model and the view (function or class) that
renders the template?, and I beg you, please use pastebin.com for share
your code :D

El vie, 19 mar 2021 a las 16:17, Manuel Buri ()
escribió:

> @anornymou...@gmail.com and ima...@gmail.com
> your suggestion is unfortunately not working too
>
> @All:
> So as said my queryset is not empty, meaning that the query works.
> However, the results is not in the rendered HTML file.
> This would imply that with my template is something wrong, don't you think?
>
> {% for office in office.all %}
> {{ office.office_name }}
> {% for booking in bookings %}
> 
> 
> {{ booking.account.first_name }} {{ 
> booking.account.last_name }}
> {% if booking.get_location_display == 'House' %}
> 🏢 {{ booking.get_location_display 
> }}
> {% elif booking.get_location_display == 'Home' %}
> 🏠 {{ booking.get_location_display 
> }}
> {% else %}
> 🤔 {{ booking.get_location_display 
> }}
> {% endif %}
> 
> 
> {% endfor %}
> {% endfor %}
>
>
> What do you think?
>
> Thank you so much for your help !
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11
> M: manuel.b...@gmail.com
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 22:51, Thomas Lockhart 
> wrote:
>
>> Why use Q? afaict simple filter syntax should get you what you want.
>>
>> Booking.objects.filter(organization_id=request.user.organization_id,
>> booking_time__range= (start_date, end_date))
>>
>> Not sure if this will get you closer to the query you expect.
>>
>> You might also find it useful to use "./manage.py shell" to test the
>> queries by hand. Import a few models, put in “11” for the organization_id,
>> and see what happens.
>>
>> - Tom
>>
>> > On Mar 19, 2021, at 2:11 PM, Manuel Buri  wrote:
>> >
>> > I want to fetch all bookings for the users organization_id between
>> start_date and end_date.
>> > I am achieving this via this queryset, however, as soon as I add the
>> second filter (bold), it is not rendered in the template anymore and I,
>> therefore, do not see it in my HTML file.
>> > context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id), Q(booking_time__range=
>> (start_date, end_date)))
>> >
>> > Thank you so much for your help.
>> > Best wishes,
>> >
>> > Manuel
>> >
>> >
>> >
>> > Manuel Buri
>> > T:  +41 79 933 01 11
>> > M: manuel.b...@gmail.com
>> > W: www.manuelburi.com
>> >
>> >
>> > On Fri, 19 Mar 2021 at 22:07, Anornymous u 
>> wrote:
>> > I mean what you want to fetch and the conditions
>> >
>> > On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>> > Hi,
>> >
>> > I am having this query set in my view:
>> > context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id), Q(booking_time__range=
>> (start_date, end_date)))
>> >
>> > It produces a non-empty query set!
>> > However, I am NOT able to display it in my template.
>> >
>> > If I get rid of Q(booking_time__range= (start_date, end_date) and only
>> do:
>> > context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id))
>> > then it is also non-empty AND it is displaying it in my template.
>> >
>> > What am I missing here?
>> >
>> > Thank you for your help.
>> >
>> > Manuel
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to django-users+unsubscr...@googlegroups.com.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>> .
>> >
>> > --
>> > You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> > To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
&

Re: View / Query Set not showing with filter

2021-03-19 Thread Manuel Buri
@anornymou...@gmail.com and ima...@gmail.com
your suggestion is unfortunately not working too

@All:
So as said my queryset is not empty, meaning that the query works.
However, the results is not in the rendered HTML file.
This would imply that with my template is something wrong, don't you think?

{% for office in office.all %}
{{ office.office_name }}
{% for booking in bookings %}


{{ booking.account.first_name }} {{
booking.account.last_name }}
{% if booking.get_location_display == 'House' %}
🏢 {{
booking.get_location_display }}
{% elif booking.get_location_display == 'Home' %}
🏠 {{
booking.get_location_display }}
{% else %}
🤔 {{
booking.get_location_display }}
{% endif %}


{% endfor %}
{% endfor %}


What do you think?

Thank you so much for your help !

Best wishes,

Manuel



Manuel Buri
T:  +41 79 933 01 11
M: manuel.b...@gmail.com
W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>


On Fri, 19 Mar 2021 at 22:51, Thomas Lockhart 
wrote:

> Why use Q? afaict simple filter syntax should get you what you want.
>
> Booking.objects.filter(organization_id=request.user.organization_id,
> booking_time__range= (start_date, end_date))
>
> Not sure if this will get you closer to the query you expect.
>
> You might also find it useful to use "./manage.py shell" to test the
> queries by hand. Import a few models, put in “11” for the organization_id,
> and see what happens.
>
> - Tom
>
> > On Mar 19, 2021, at 2:11 PM, Manuel Buri  wrote:
> >
> > I want to fetch all bookings for the users organization_id between
> start_date and end_date.
> > I am achieving this via this queryset, however, as soon as I add the
> second filter (bold), it is not rendered in the template anymore and I,
> therefore, do not see it in my HTML file.
> > context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range=
> (start_date, end_date)))
> >
> > Thank you so much for your help.
> > Best wishes,
> >
> > Manuel
> >
> >
> >
> > Manuel Buri
> > T:  +41 79 933 01 11
> > M: manuel.b...@gmail.com
> > W: www.manuelburi.com
> >
> >
> > On Fri, 19 Mar 2021 at 22:07, Anornymous u 
> wrote:
> > I mean what you want to fetch and the conditions
> >
> > On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
> > Hi,
> >
> > I am having this query set in my view:
> > context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range=
> (start_date, end_date)))
> >
> > It produces a non-empty query set!
> > However, I am NOT able to display it in my template.
> >
> > If I get rid of Q(booking_time__range= (start_date, end_date) and only
> do:
> > context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id))
> > then it is also non-empty AND it is displaying it in my template.
> >
> > What am I missing here?
> >
> > Thank you for your help.
> >
> > Manuel
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
> .
> >
> > --
> > You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> > To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
> .
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com
&g

Re: View / Query Set not showing with filter

2021-03-19 Thread Thomas Lockhart
Why use Q? afaict simple filter syntax should get you what you want.

Booking.objects.filter(organization_id=request.user.organization_id, 
booking_time__range= (start_date, end_date))

Not sure if this will get you closer to the query you expect.

You might also find it useful to use "./manage.py shell" to test the queries by 
hand. Import a few models, put in “11” for the organization_id, and see what 
happens.

- Tom

> On Mar 19, 2021, at 2:11 PM, Manuel Buri  wrote:
> 
> I want to fetch all bookings for the users organization_id between start_date 
> and end_date.
> I am achieving this via this queryset, however, as soon as I add the second 
> filter (bold), it is not rendered in the template anymore and I, therefore, 
> do not see it in my HTML file.
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id), Q(booking_time__range= 
> (start_date, end_date)))
> 
> Thank you so much for your help.
> Best wishes,
> 
> Manuel
> 
> 
> 
> Manuel Buri
> T:  +41 79 933 01 11 
> M: manuel.b...@gmail.com
> W: www.manuelburi.com
> 
> 
> On Fri, 19 Mar 2021 at 22:07, Anornymous u  wrote:
> I mean what you want to fetch and the conditions
> 
> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
> Hi,
> 
> I am having this query set in my view:
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id), Q(booking_time__range= 
> (start_date, end_date)))
> 
> It produces a non-empty query set!
> However, I am NOT able to display it in my template.
> 
> If I get rid of Q(booking_time__range= (start_date, end_date) and only do:
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id))
> then it is also non-empty AND it is displaying it in my template.
> 
> What am I missing here?
> 
> Thank you for your help.
> 
> Manuel
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com.
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7C87F855-5ECE-4470-A8CA-916B64F7CFF5%40gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Anornymous u
Yes, I this can work

On Sat, Mar 20, 2021, 00:17 Héctor Alonso Lozada Echezuría 
wrote:

> I think you should reconsider the query
>
> context['bookings']=Booking.objects.filter(Q(organization_id=request.user.organization_id),
>  Q(booking_time__date__gte=start_date),
> Q(booking_time__date__lte=end_date)))
>
> El vie, 19 mar 2021 a las 15:14, Héctor Alonso Lozada Echezuría (<
> ima...@gmail.com>) escribió:
>
>> https://docs.djangoproject.com/en/3.1/ref/models/querysets/#range
>>
>> [image: image.png]
>>
>> El vie, 19 mar 2021 a las 15:12, Manuel Buri ()
>> escribió:
>>
>>> I want to fetch all bookings for the users organization_id between
>>> start_date and end_date.
>>> I am achieving this via this queryset, however, as soon as I add the
>>> second filter (*bold*), it is not rendered in the template anymore and
>>> I, therefore, do not see it in my HTML file.
>>> context['bookings']=Booking.objects.filter(
>>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>>> (start_date, end_date))*)
>>>
>>> Thank you so much for your help.
>>> Best wishes,
>>>
>>> Manuel
>>>
>>>
>>>
>>> Manuel Buri
>>> T:  +41 79 933 01 11
>>> M: manuel.b...@gmail.com
>>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>>
>>>
>>> On Fri, 19 Mar 2021 at 22:07, Anornymous u 
>>> wrote:
>>>
>>>> I mean what you want to fetch and the conditions
>>>>
>>>> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I am having this query set in my view:
>>>>> context['bookings']=Booking.objects.filter(
>>>>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>>>>> (start_date, end_date))*)
>>>>>
>>>>> It produces a *non-empty* query set!
>>>>> However, I am NOT able to display it in my template.
>>>>>
>>>>> If I get *rid* of Q(booking_time__range= (start_date, end_date) and
>>>>> only do:
>>>>>
>>>>> context['bookings']=Booking.objects.filter( 
>>>>> Q(organization_id=request.user.organization_id))
>>>>> then it is also non-empty AND it is displaying it in my template.
>>>>>
>>>>> *What am I missing here?*
>>>>>
>>>>> Thank you for your help.
>>>>>
>>>>> Manuel
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "Django users" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> django-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com
>&

Re: View / Query Set not showing with filter

2021-03-19 Thread Héctor Alonso Lozada Echezuría
I think you should reconsider the query

context['bookings']=Booking.objects.filter(Q(organization_id=request.user.organization_id),
Q(booking_time__date__gte=start_date),
Q(booking_time__date__lte=end_date)))

El vie, 19 mar 2021 a las 15:14, Héctor Alonso Lozada Echezuría (<
ima...@gmail.com>) escribió:

> https://docs.djangoproject.com/en/3.1/ref/models/querysets/#range
>
> [image: image.png]
>
> El vie, 19 mar 2021 a las 15:12, Manuel Buri ()
> escribió:
>
>> I want to fetch all bookings for the users organization_id between
>> start_date and end_date.
>> I am achieving this via this queryset, however, as soon as I add the
>> second filter (*bold*), it is not rendered in the template anymore and
>> I, therefore, do not see it in my HTML file.
>> context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>> (start_date, end_date))*)
>>
>> Thank you so much for your help.
>> Best wishes,
>>
>> Manuel
>>
>>
>>
>> Manuel Buri
>> T:  +41 79 933 01 11
>> M: manuel.b...@gmail.com
>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>
>>
>> On Fri, 19 Mar 2021 at 22:07, Anornymous u 
>> wrote:
>>
>>> I mean what you want to fetch and the conditions
>>>
>>> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>>>
>>>> Hi,
>>>>
>>>> I am having this query set in my view:
>>>> context['bookings']=Booking.objects.filter(
>>>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>>>> (start_date, end_date))*)
>>>>
>>>> It produces a *non-empty* query set!
>>>> However, I am NOT able to display it in my template.
>>>>
>>>> If I get *rid* of Q(booking_time__range= (start_date, end_date) and
>>>> only do:
>>>>
>>>> context['bookings']=Booking.objects.filter( 
>>>> Q(organization_id=request.user.organization_id))
>>>> then it is also non-empty AND it is displaying it in my template.
>>>>
>>>> *What am I missing here?*
>>>>
>>>> Thank you for your help.
>>>>
>>>> Manuel
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Héctor Alonso Lozada Echezuría
>


-- 
Héctor Alonso Lozada Echezuría

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTS2YzkuucPM%2BmSqmzzW2tEgxyaa_-ffB8dCAQEDH9rZe6TeQ%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Héctor Alonso Lozada Echezuría
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#range

[image: image.png]

El vie, 19 mar 2021 a las 15:12, Manuel Buri ()
escribió:

> I want to fetch all bookings for the users organization_id between
> start_date and end_date.
> I am achieving this via this queryset, however, as soon as I add the
> second filter (*bold*), it is not rendered in the template anymore and I,
> therefore, do not see it in my HTML file.
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
> (start_date, end_date))*)
>
> Thank you so much for your help.
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11
> M: manuel.b...@gmail.com
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 22:07, Anornymous u  wrote:
>
>> I mean what you want to fetch and the conditions
>>
>> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>>
>>> Hi,
>>>
>>> I am having this query set in my view:
>>> context['bookings']=Booking.objects.filter(
>>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>>> (start_date, end_date))*)
>>>
>>> It produces a *non-empty* query set!
>>> However, I am NOT able to display it in my template.
>>>
>>> If I get *rid* of Q(booking_time__range= (start_date, end_date) and
>>> only do:
>>>
>>> context['bookings']=Booking.objects.filter( 
>>> Q(organization_id=request.user.organization_id))
>>> then it is also non-empty AND it is displaying it in my template.
>>>
>>> *What am I missing here?*
>>>
>>> Thank you for your help.
>>>
>>> Manuel
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Héctor Alonso Lozada Echezuría

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTS2YwcFMFPwWV_gRwW6Tj-BWGL%2B8%3D1SzQcVMM%2B5XcgcwGs%3DA%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Manuel Buri
I want to fetch all bookings for the users organization_id between
start_date and end_date.
I am achieving this via this queryset, however, as soon as I add the second
filter (*bold*), it is not rendered in the template anymore and I,
therefore, do not see it in my HTML file.
context['bookings']=Booking.objects.filter(
Q(organization_id=request.user.organization_id), *Q(booking_time__range=
(start_date, end_date))*)

Thank you so much for your help.
Best wishes,

Manuel



Manuel Buri
T:  +41 79 933 01 11
M: manuel.b...@gmail.com
W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>


On Fri, 19 Mar 2021 at 22:07, Anornymous u  wrote:

> I mean what you want to fetch and the conditions
>
> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>
>> Hi,
>>
>> I am having this query set in my view:
>> context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>> (start_date, end_date))*)
>>
>> It produces a *non-empty* query set!
>> However, I am NOT able to display it in my template.
>>
>> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
>> do:
>>
>> context['bookings']=Booking.objects.filter( 
>> Q(organization_id=request.user.organization_id))
>> then it is also non-empty AND it is displaying it in my template.
>>
>> *What am I missing here?*
>>
>> Thank you for your help.
>>
>> Manuel
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Anornymous u
I mean what you want to fetch and the conditions

On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:

> Hi,
>
> I am having this query set in my view:
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
> (start_date, end_date))*)
>
> It produces a *non-empty* query set!
> However, I am NOT able to display it in my template.
>
> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
> do:
>
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id))
> then it is also non-empty AND it is displaying it in my template.
>
> *What am I missing here?*
>
> Thank you for your help.
>
> Manuel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Anornymous u
Tell us exactly what you are looking for from your query

On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:

> Hi,
>
> I am having this query set in my view:
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
> (start_date, end_date))*)
>
> It produces a *non-empty* query set!
> However, I am NOT able to display it in my template.
>
> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
> do:
>
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id))
> then it is also non-empty AND it is displaying it in my template.
>
> *What am I missing here?*
>
> Thank you for your help.
>
> Manuel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMXTB%3DeRwhUB1bQboLTVn08w6Mdfg-_oVv%3DXJKUkOF979JgWCQ%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Manuel Buri
the field is this (copied from my Model):

booking_time= models.DateTimeField(default=timezone.now)


sent from my phone.
sorry for typos.

On Fri, 19 Mar 2021, 21:28 Anornymous u,  wrote:

> What is the name of the field, this part that reads range
>
> On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:
>
>> Hi,
>>
>> I am having this query set in my view:
>> context['bookings']=Booking.objects.filter(
>> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
>> (start_date, end_date))*)
>>
>> It produces a *non-empty* query set!
>> However, I am NOT able to display it in my template.
>>
>> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
>> do:
>>
>> context['bookings']=Booking.objects.filter( 
>> Q(organization_id=request.user.organization_id))
>> then it is also non-empty AND it is displaying it in my template.
>>
>> *What am I missing here?*
>>
>> Thank you for your help.
>>
>> Manuel
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcX1xFLcEhHS_abDCvmr7npG8-TKLH29WYyFxhqfKOfWQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMXTB%3DcX1xFLcEhHS_abDCvmr7npG8-TKLH29WYyFxhqfKOfWQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACx7KOQOM2_ye2rkB6TUk2WHTBRtuA8UW0tMk6j6453LPZ%3D0gQ%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Anornymous u
What is the name of the field, this part that reads range

On Fri, Mar 19, 2021, 16:01 Manuel Buri  wrote:

> Hi,
>
> I am having this query set in my view:
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
> (start_date, end_date))*)
>
> It produces a *non-empty* query set!
> However, I am NOT able to display it in my template.
>
> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
> do:
>
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id))
> then it is also non-empty AND it is displaying it in my template.
>
> *What am I missing here?*
>
> Thank you for your help.
>
> Manuel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMXTB%3DcX1xFLcEhHS_abDCvmr7npG8-TKLH29WYyFxhqfKOfWQ%40mail.gmail.com.


Re: View / Query Set not showing with filter

2021-03-19 Thread Manuel Buri
Hi Tom, thanks for getting back to me.

As said, it is super weird:
both start_date and end_date are both datetime.datetime.

furthermore the queryset is as said non-empty:
),
'location': 'H'}, {'id': 10, 'account_id': 4, 'organization_id': 11,
'office_id': 1, 'booking_time': datetime.datetime(2021, 3, 21, 0, 0,
tzinfo=), 'location': 'H'}]>

However, it is not working, and then if I remove the __range (see initial
question): I have this queryset (while the above queryset is obviously
included in the below one):
),
'location': 'H'}, {'id': 2, 'account_id': 12, 'organization_id': 11,
'office_id': 1, 'booking_time': datetime.datetime(2021, 3, 18, 23, 0,
tzinfo=), 'location': 'H'}, {'id': 3, 'account_id': 2,
'organization_id': 11, 'office_id': 1, 'booking_time':
datetime.datetime(2021, 3, 18, 0, 0, tzinfo=), 'location': 'H'},
{'id': 8, 'account_id': 3, 'organization_id': 11, 'office_id': 1,
'booking_time': datetime.datetime(2021, 3, 18, 0, 0, tzinfo=),
'location': 'H'}, {'id': 9, 'account_id': 4, 'organization_id': 11,
'office_id': 1, 'booking_time': datetime.datetime(2021, 3, 20, 0, 0,
tzinfo=), 'location': 'H'}, {'id': 10, 'account_id': 4,
'organization_id': 11, 'office_id': 1, 'booking_time':
datetime.datetime(2021, 3, 21, 0, 0, tzinfo=), 'location': 'H'}]>

I am really clueless why this is happening.
Do I need to think about something specific in the template when filtering
for dates?

sent from my phone.
sorry for typos.

On Fri, 19 Mar 2021, 20:21 Thomas Lockhart,  wrote:

> Almost certainly start_date and end_date are not what you expect.
>
> Do the types match? In any case print them out and see what you are
> actually getting.
>
> hth
>
> - Tom
>
> On Mar 19, 2021, at 6:00 AM, Manuel Buri  wrote:
>
> Hi,
>
> I am having this query set in my view:
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), *Q(booking_time__range=
> (start_date, end_date))*)
>
> It produces a *non-empty* query set!
> However, I am NOT able to display it in my template.
>
> If I get *rid* of Q(booking_time__range= (start_date, end_date) and only
> do:
>
> context['bookings']=Booking.objects.filter( 
> Q(organization_id=request.user.organization_id))
> then it is also non-empty AND it is displaying it in my template.
>
> *What am I missing here?*
>
> Thank you for your help.
>
> Manuel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/83B24C06-8DA4-4F38-9384-FF4C19DBE262%40gmail.com
> <https://groups.google.com/d/msgid/django-users/83B24C06-8DA4-4F38-9384-FF4C19DBE262%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACx7KOQ%3DUGG%3DDxAzJR-6mbruUoDB4HmpdG0zW2zrBCJcOvi42g%40mail.gmail.com.


  1   2   3   4   5   6   7   8   9   10   >