Re: Increasing iteration count for the PBKDF2 password hasher

2024-05-23 Thread Mike Dewhirst

On 23/05/2024 6:12 pm, Shaheed Haque wrote:

Hi,

As happens from time-to-time, I see the 5.1 alpha recently announced 
has increased the iteration count for the PBKDF2 password hasher (from 
720k to 870k), and the putative release notes for 5.2 mention a 
further increase (to 1M).


I assume this iteration count has something to do with the noticeable 
time it takes to run User.set_password()? Is there something that can 
be done to mitigate any further increase in the execution time of 
.set_password(), or am I barking up the wrong tree?


My understanding is the intention is to make brute force attacks more 
expensive for the attacker.


Don't know whether there might be a better way.



Thanks, Shaheed
--
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/CAHAc2jcETxAtMbHfnD1GQFVgWwR8ABOAy%3DjaRuhRW7mQhnOxeQ%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAHAc2jcETxAtMbHfnD1GQFVgWwR8ABOAy%3DjaRuhRW7mQhnOxeQ%40mail.gmail.com?utm_medium=email_source=footer>.



--
We recommend signal.org

Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.

--
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/9c7c7294-08fd-4a6a-91de-e99ab27d4a61%40dewhirst.com.au.


OpenPGP_signature.asc
Description: OpenPGP digital signature


Increasing iteration count for the PBKDF2 password hasher

2024-05-23 Thread Shaheed Haque
Hi,

As happens from time-to-time, I see the 5.1 alpha recently announced has
increased the iteration count for the PBKDF2 password hasher (from 720k to
870k), and the putative release notes for 5.2 mention a further increase
(to 1M).

I assume this iteration count has something to do with the noticeable time
it takes to run User.set_password()? Is there something that can be done to
mitigate any further increase in the execution time of .set_password(), or
am I barking up the wrong tree?

Thanks, Shaheed

-- 
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/CAHAc2jcETxAtMbHfnD1GQFVgWwR8ABOAy%3DjaRuhRW7mQhnOxeQ%40mail.gmail.com.


Django-annotate(),Count()

2023-01-12 Thread Priya
Hi Everyone,

This is the output i get used this code 

https://groups.google.com/d/msgid/django-users/95dedc5d-5f24-4b57-b525-248c01953bddn%40googlegroups.com.


Queryset for get all objects with count of some of them.

2022-07-25 Thread Sencer Hamarat
Hi,

Is there a way to get all model objects, but including count of some of
them within one db transaction.

Say, I have this model:

class AModel(models.Model):
field_choices = (
(0, "a"),
(1, "b"),
(2, "c")
)

field_one = models.CharField(max_length=32)
field_two = models.IntegerField(coices=field_choices, default=0)

And this model has 100's of records with mixed choices.

I want to fetch all model objects bu also included count of field_choice
equals "c" ones which means field_two equals to 1

Is that can be fetched by query like this?

AModel.objects.all(
).annotate(
c_count=Count(
    Amodel.objects.filter(field_two=1).count()
)
)



Saygılarımla,
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/CACp8TZhJhroy24aL38C8yJ0k1t_CdF8jNxF78yG_fY5%3DX08xEQ%40mail.gmail.com.


Re: After user click on like button page should not refresh(redirect) and update count of likes

2021-05-05 Thread Aadil Rashid
You need write Ajax for this functionality to implement

On Wed, 5 May, 2021, 6:40 PM Derek,  wrote:

> You'll need to use javascript for this - have a look at
> https://data-flair.training/blogs/ajax-in-django/ for an example.
>
> On Wednesday, 5 May 2021 at 05:30:59 UTC+2 sali...@rohteksolutions.com
> wrote:
>
>> When user click to like a post the web page should not refresh(redirect)
>> and count of the likes should be updated.
>>  How can I achieve this please help me.
>>
>> Here is my block of code
>> ```
>> >   href="/post_comment_like/{{j.id}}">
>>> aria-hidden="true"
>>   style="color: gray;">
>> ```
>> views.py
>> ```
>> def post_comment_like(request, id):
>> if (request.session.get('email') is None) or
>> (request.session.get('email') == ""):
>> return HttpResponseRedirect("/home")
>>
>> email = request.session.get('email')
>> qury = Comment.objects.get(id=id)
>> obj_id = qury.object_id
>> qury_like = Comment_like.objects.filter(email=email)
>> qury_like = Comment_like.objects.filter(email=email, object_id=
>> qury.id, dislike_comment="1").first()
>> if qury_like:
>> qury_like.delete()
>> save_form = Comment_like(email=email,
>> user_name=request.session.get('name'),
>> content_type=qury.content_type,
>> object_id=qury.id,
>> content=qury.content,
>> flag_reply=qury.flag_reply,
>> flag_comment_id=qury.flag_comment_id,
>> flag_level=qury.flag_level,
>> like_comment='1')
>> save_form.save()
>> qury.like_comment = '1'
>> qury.dislike_comment = '0'
>> qury.save()
>> # return redirect(request.META.get('HTTP_REFERER'))
>> return HttpResponseRedirect(reverse('detail', args=[str(obj_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/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com?utm_medium=email_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/CAAYXZx_T8fqHCFyEs48cWDWmp07%3D1EN4H%3DzxMrF487xGcZXiOQ%40mail.gmail.com.


Re: After user click on like button page should not refresh(redirect) and update count of likes

2021-05-05 Thread Derek
You'll need to use javascript for this - have a look 
at https://data-flair.training/blogs/ajax-in-django/ for an example.

On Wednesday, 5 May 2021 at 05:30:59 UTC+2 sali...@rohteksolutions.com 
wrote:

> When user click to like a post the web page should not refresh(redirect) 
> and count of the likes should be updated.
>  How can I achieve this please help me.
>
> Here is my block of code
> ```
>href="/post_comment_like/{{j.id}}">
> aria-hidden="true"
>   style="color: gray;">
> ```
> views.py
> ```
> def post_comment_like(request, id):
> if (request.session.get('email') is None) or 
> (request.session.get('email') == ""):
> return HttpResponseRedirect("/home")
>
> email = request.session.get('email')
> qury = Comment.objects.get(id=id)
> obj_id = qury.object_id
> qury_like = Comment_like.objects.filter(email=email)
> qury_like = Comment_like.objects.filter(email=email, object_id=qury.id, 
> dislike_comment="1").first()
> if qury_like:
> qury_like.delete()
> save_form = Comment_like(email=email, 
> user_name=request.session.get('name'),
> content_type=qury.content_type,
> object_id=qury.id,
> content=qury.content,
> flag_reply=qury.flag_reply,
> flag_comment_id=qury.flag_comment_id,
> flag_level=qury.flag_level,
> like_comment='1')
> save_form.save()
> qury.like_comment = '1'
> qury.dislike_comment = '0'
> qury.save()
> # return redirect(request.META.get('HTTP_REFERER'))
> return HttpResponseRedirect(reverse('detail', args=[str(obj_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/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com.


After user click on like button page should not refresh(redirect) and update count of likes

2021-05-04 Thread Salima Begum
When user click to like a post the web page should not refresh(redirect)
and count of the likes should be updated.
 How can I achieve this please help me.

Here is my block of code
```

   
```
views.py
```
def post_comment_like(request, id):
if (request.session.get('email') is None) or
(request.session.get('email') == ""):
return HttpResponseRedirect("/home")

email = request.session.get('email')
qury = Comment.objects.get(id=id)
obj_id = qury.object_id
qury_like = Comment_like.objects.filter(email=email)
qury_like = Comment_like.objects.filter(email=email, object_id=qury.id,
dislike_comment="1").first()
if qury_like:
qury_like.delete()
save_form = Comment_like(email=email,
user_name=request.session.get('name'),
content_type=qury.content_type,
object_id=qury.id,
content=qury.content,
flag_reply=qury.flag_reply,
flag_comment_id=qury.flag_comment_id,
flag_level=qury.flag_level,
like_comment='1')
save_form.save()
qury.like_comment = '1'
qury.dislike_comment = '0'
qury.save()
# return redirect(request.META.get('HTTP_REFERER'))
return HttpResponseRedirect(reverse('detail', args=[str(obj_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/CAMSz6bnXp1Mh8h%2BXvmQ7aW-uyB9dxqHwSmMMd8LB34vw515BkQ%40mail.gmail.com.


how to store count value in python(django)?

2021-02-07 Thread Shailesh Yadav
Hi Everyone,

Can you please look into below Stackoverflow question and let me know how I 
can define 
count list in *DB *and use it in view and reset it based on some time 
duration.

Now I have defined it globally and it is working fine but the problem is 
when else block is executing it is not showing *messages.info(request, 
'Sorry you are uploading more than 15 records so records') *before sleep 
time got completed so the user will not get to know what is happening.

Any help on this will be highly appreciated!

https://stackoverflow.com/questions/66086710/how-to-store-count-value-in-pythondjango

-- 
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/cdb05f8b-174b-4231-bf18-0ed18b62ff02n%40googlegroups.com.


Django Aggregate(annotate, count) is working differently.

2020-06-18 Thread Himanshu Pharawal
models.py
class Intrest(models.Model):
 user = models.ForeignKey(User, related_name='intrests', on_delete=models.
CASCADE)
 keyword = models.CharField(max_length=100)

class SponsoredBook(models.Model):
 title = models.CharField(max_length=20)

class Keyword(models.Model):
 sponsored_book = models.ForeignKey(SponsoredBook, related_name='keywords', 
on_delete=models.CASCADE)
 title = models.CharField(max_length=50, unique=True)


views.py
def get(self, request):
 user = User.objects.filter(id=3).prefetch_related('intrests')
 sub = Subquery(user[0].intrests.annotate(key=Lower('keyword')).values('key'
))
 sponsored_books = models.SponsoredBook.objects.annotate(tit=Lower(
'keywords__title')).filter(tit__in=sub).annotate(points=Count('id')).
order_by('points')[:6]
 all_sponsored_books = models.SponsoredBook.objects.all()[:6]
 for sponsored_book in sponsored_books:
 print(sponsored_book.__dict__)
 print()

Case explained
There are two interests stored in db for user(id=3) names as

   1. python
   2. programming

And three sponsored books stored in db with their correspond interests 
named as 

   1. Test1 - Interests(ptyhon, programming)
   2. Test2 - Interests(python, A)
   3. Test3 - Interests(B, C)

Problem
For the above database, models and views it shows Test1 book two times and 
Test2 book one time but expectation was to having Test1 one time and Test2 
also one time only the order should be affect but here query set is able to 
group by books with there id and give them points on the basis of 
there repetition repetition.

*Let me know if you need for more information on the same.*

-- 
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/bc724ec0-99ad-4180-919e-f036a051b8a6o%40googlegroups.com.


Re: How to create a function like Count

2020-05-26 Thread Kushal Neupane
I think this in template will help you.

Total Table Numbers
{{tableNumber_total}}


On Tue, May 26, 2020 at 10:50 AM Saurabh Adhikary 
wrote:

> I want to create a custom function which will get modified into a sql
> querry and will work like Count ...i.e. for every row of the queryset
>
> --
> 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/7a301d3e-d690-4b49-b6da-02d00c97758e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7a301d3e-d690-4b49-b6da-02d00c97758e%40googlegroups.com?utm_medium=email_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/CAFWyajUTEA%3D7GyGrk9hsn2tgS1zWVWswHMsO%3DHeGHETqHWa18A%40mail.gmail.com.


How to create a function like Count

2020-05-25 Thread Saurabh Adhikary
I want to create a custom function which will get modified into a sql 
querry and will work like Count ...i.e. for every row of the queryset

-- 
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/7a301d3e-d690-4b49-b6da-02d00c97758e%40googlegroups.com.


Re: How to count total number of student to display in template

2020-04-30 Thread lumwakapuku
Okeyy you are welcomeSent from Samsung tablet.
 Original message From: Kushal Neupane  
Date: 30/04/2020  16:43  (GMT+03:00) To: django-users@googlegroups.com Subject: 
Re: How to count total number of student to display in template Thank you 
sir.On Thu, Apr 30, 2020, 19:28 lumwakapuku  wrote:In 
you are view create a function Eg def student():       student = 
Student.objects.all()       Tt_student = student.count()        Context = { 
"student":student, "Tt_student":Tt_student }        Return render(request, 
"your templete here", context)In you templete render it as {{ Tt_student  
}}Sent from Samsung tablet. Original message From: Kushal 
Neupane  Date: 30/04/2020  16:20  (GMT+03:00) To: Django 
users  Subject: How to count total number of 
student to display in template The following are  the models and template where 
i wnat to display the count. The displayed is static. Now, i wanna make 
dynamic. Thank you. Help me.



-- 
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/3691ca10-2ed3-466e-a2ee-7d1c1947701c%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/5eaad5d6.1c69fb81.22e8b.bae9%40mx.google.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/CAFWyajVLaj1e6TD6JhcZ8Xc0FSxPJjDQp7o%2BYd7J0COt%3D6gW%2Bw%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/5eaad846.1c69fb81.c6612.d0f7%40mx.google.com.


Re: How to count total number of student to display in template

2020-04-30 Thread Kushal Neupane
Thank you sir.

On Thu, Apr 30, 2020, 19:28 lumwakapuku  wrote:

> In you are view create a function
> Eg
> def student():
>student = Student.objects.all()
>Tt_student = student.count()
> Context = { "student":student, "Tt_student":Tt_student }
> Return render(request, "your templete here", context)
>
> In you templete render it as
> {{ Tt_student  }}
>
>
>
> Sent from Samsung tablet.
>
>
>  Original message 
> From: Kushal Neupane 
> Date: 30/04/2020 16:20 (GMT+03:00)
> To: Django users 
> Subject: How to count total number of student to display in template
>
> The following are  the models and template where i wnat to display the
> count. The displayed is static. Now, i wanna make dynamic. Thank you. Help
> me.
>
>
>
> --
> 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/3691ca10-2ed3-466e-a2ee-7d1c1947701c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3691ca10-2ed3-466e-a2ee-7d1c1947701c%40googlegroups.com?utm_medium=email_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/5eaad5d6.1c69fb81.22e8b.bae9%40mx.google.com
> <https://groups.google.com/d/msgid/django-users/5eaad5d6.1c69fb81.22e8b.bae9%40mx.google.com?utm_medium=email_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/CAFWyajVLaj1e6TD6JhcZ8Xc0FSxPJjDQp7o%2BYd7J0COt%3D6gW%2Bw%40mail.gmail.com.


RE: How to count total number of student to display in template

2020-04-30 Thread lumwakapuku
In you are view create a function Eg def student():       student = 
Student.objects.all()       Tt_student = student.count()        Context = { 
"student":student, "Tt_student":Tt_student }        Return render(request, 
"your templete here", context)In you templete render it as {{ Tt_student  
}}Sent from Samsung tablet.
 Original message From: Kushal Neupane  
Date: 30/04/2020  16:20  (GMT+03:00) To: Django users 
 Subject: How to count total number of student 
to display in template The following are  the models and template where i wnat 
to display the count. The displayed is static. Now, i wanna make dynamic. Thank 
you. Help me.



-- 
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/3691ca10-2ed3-466e-a2ee-7d1c1947701c%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/5eaad5d6.1c69fb81.22e8b.bae9%40mx.google.com.


How to count total number of student to display in template

2020-04-30 Thread Kushal Neupane
The following are  the models and template where i wnat to display the 
count. The displayed is static. Now, i wanna make dynamic. Thank you. Help 
me.



-- 
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/3691ca10-2ed3-466e-a2ee-7d1c1947701c%40googlegroups.com.


Re: user visit count

2020-04-16 Thread Motaz Hejaze
Great

On Thu, 16 Apr 2020, 6:53 am shreehari Vaasistha L, 
wrote:

> Done
>
> On Wednesday, April 15, 2020 at 6:55:37 PM UTC+5:30, Motaz Hejaze wrote:
>>
>> no standard for this , but thinking out loud with you ..
>>
>> you can make a many to many model ( table ) of 3 columns , first column
>> will be user id , second column will be object id , third column will be
>> number of visits ( integer  initial value 0 ) ,  every time the object view
>> is called you'll query the table for object.id if not found ( for first
>> time , create a new row with this object.id and request.user.id and put
>> number_of_visits column  = 1 ) , if found then filter by user.id , if
>> found increase number in number_of_visits column by one , if filter not
>> returning thing then create a new row with object.id and user.id and put
>> number_of_visits column  = 1
>>
>> On Wed, Apr 15, 2020 at 2:29 PM shreehari Vaasistha L <
>> shreeh...@gmail.com> wrote:
>>
>>> Thank you!
>>> But can there be any simple implementation as i just want to count
>>> number of times a user has viewed a post
>>>
>>> On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>>>>
>>>> I'm planning to use django-hitcount too, but please be aware that it's
>>>> not yet compatible with Django 3.x. There's a patch that needs to be
>>>> applied and a release forthcoming that should take care of it.
>>>>
>>>> -Tim
>>>>
>>>> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>>>>
>>>> Django hit count package will help you..
>>>>
>>>> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L <
>>>> shreeh...@gmail.com> wrote:
>>>>
>>>> how can i get the number of views of an endpoint by a single 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...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>>>
>>>> --
>>>> Tim Wilson
>>>> President, Savvy Technology Group
>>>> phone: 612-599-5470
>>>>
>>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com?utm_medium=email_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/9c1ca4ac-5b9d-4a87-811f-185f539c6de7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9c1ca4ac-5b9d-4a87-811f-185f539c6de7%40googlegroups.com?utm_medium=email_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/CAHV4E-fsBxq-OM2j1x8or9eyjKhw85aXhY_SFu9Y4E9BUY1-nQ%40mail.gmail.com.


Re: user visit count

2020-04-15 Thread shreehari Vaasistha L
Done

On Wednesday, April 15, 2020 at 6:55:37 PM UTC+5:30, Motaz Hejaze wrote:
>
> no standard for this , but thinking out loud with you ..
>
> you can make a many to many model ( table ) of 3 columns , first column 
> will be user id , second column will be object id , third column will be 
> number of visits ( integer  initial value 0 ) ,  every time the object view 
> is called you'll query the table for object.id if not found ( for first 
> time , create a new row with this object.id and request.user.id and put 
> number_of_visits column  = 1 ) , if found then filter by user.id , if 
> found increase number in number_of_visits column by one , if filter not 
> returning thing then create a new row with object.id and user.id and put 
> number_of_visits column  = 1
>
> On Wed, Apr 15, 2020 at 2:29 PM shreehari Vaasistha L  > wrote:
>
>> Thank you!
>> But can there be any simple implementation as i just want to count number 
>> of times a user has viewed a post
>>
>> On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>>>
>>> I'm planning to use django-hitcount too, but please be aware that it's 
>>> not yet compatible with Django 3.x. There's a patch that needs to be 
>>> applied and a release forthcoming that should take care of it.
>>>
>>> -Tim
>>>
>>> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>>>
>>> Django hit count package will help you..
>>>
>>> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L  
>>> wrote:
>>>
>>> how can i get the number of views of an endpoint by a single 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>>>
>>> -- 
>>> Tim Wilson
>>> President, Savvy Technology Group
>>> phone: 612-599-5470
>>>
>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com?utm_medium=email_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/9c1ca4ac-5b9d-4a87-811f-185f539c6de7%40googlegroups.com.


Re: user visit count

2020-04-15 Thread shreehari Vaasistha L
cool man
i was trying exactly the same thing... if you try to get it work then post 
it here please.

On Wednesday, April 15, 2020 at 6:55:37 PM UTC+5:30, Motaz Hejaze wrote:
>
> no standard for this , but thinking out loud with you ..
>
> you can make a many to many model ( table ) of 3 columns , first column 
> will be user id , second column will be object id , third column will be 
> number of visits ( integer  initial value 0 ) ,  every time the object view 
> is called you'll query the table for object.id if not found ( for first 
> time , create a new row with this object.id and request.user.id and put 
> number_of_visits column  = 1 ) , if found then filter by user.id , if 
> found increase number in number_of_visits column by one , if filter not 
> returning thing then create a new row with object.id and user.id and put 
> number_of_visits column  = 1
>
> On Wed, Apr 15, 2020 at 2:29 PM shreehari Vaasistha L  > wrote:
>
>> Thank you!
>> But can there be any simple implementation as i just want to count number 
>> of times a user has viewed a post
>>
>> On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>>>
>>> I'm planning to use django-hitcount too, but please be aware that it's 
>>> not yet compatible with Django 3.x. There's a patch that needs to be 
>>> applied and a release forthcoming that should take care of it.
>>>
>>> -Tim
>>>
>>> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>>>
>>> Django hit count package will help you..
>>>
>>> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L  
>>> wrote:
>>>
>>> how can i get the number of views of an endpoint by a single 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>>>
>>> -- 
>>> Tim Wilson
>>> President, Savvy Technology Group
>>> phone: 612-599-5470
>>>
>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com?utm_medium=email_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/1030889f-25f8-49d7-b026-e0d715d2891f%40googlegroups.com.


Re: user visit count

2020-04-15 Thread Motaz Hejaze
no standard for this , but thinking out loud with you ..

you can make a many to many model ( table ) of 3 columns , first column
will be user id , second column will be object id , third column will be
number of visits ( integer  initial value 0 ) ,  every time the object view
is called you'll query the table for object.id if not found ( for first
time , create a new row with this object.id and request.user.id and put
number_of_visits column  = 1 ) , if found then filter by user.id , if found
increase number in number_of_visits column by one , if filter not returning
thing then create a new row with object.id and user.id and put
number_of_visits column  = 1

On Wed, Apr 15, 2020 at 2:29 PM shreehari Vaasistha L <
shreehari9...@gmail.com> wrote:

> Thank you!
> But can there be any simple implementation as i just want to count number
> of times a user has viewed a post
>
> On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>>
>> I'm planning to use django-hitcount too, but please be aware that it's
>> not yet compatible with Django 3.x. There's a patch that needs to be
>> applied and a release forthcoming that should take care of it.
>>
>> -Tim
>>
>> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>>
>> Django hit count package will help you..
>>
>> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L 
>> wrote:
>>
>> how can i get the number of views of an endpoint by a single 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...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>>
>> --
>> Tim Wilson
>> President, Savvy Technology Group
>> phone: 612-599-5470
>>
>> --
> 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/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com?utm_medium=email_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/CAHV4E-c6AkWw%2Bk1jkVioQBYgAMxNaTTUECbezWWiz3iKQrYFYw%40mail.gmail.com.


Re: user visit count

2020-04-15 Thread shreehari Vaasistha L
Thank you!
But can there be any simple implementation as i just want to count number 
of times a user has viewed a post

On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>
> I'm planning to use django-hitcount too, but please be aware that it's not 
> yet compatible with Django 3.x. There's a patch that needs to be applied 
> and a release forthcoming that should take care of it.
>
> -Tim
>
> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>
> Django hit count package will help you..
>
> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L  > wrote:
>
> how can i get the number of views of an endpoint by a single 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
>
> -- 
> Tim Wilson
> President, Savvy Technology Group
> phone: 612-599-5470
>
>

-- 
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/36fd6a9b-e959-49ee-9183-f18c26daf1c9%40googlegroups.com.


Re: user visit count

2020-04-15 Thread shreehari Vaasistha L
I'm using django 3.x.
Anyother simple implementation ?
i just want to get number of times a particular user has viewed an object.

On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:
>
> I'm planning to use django-hitcount too, but please be aware that it's not 
> yet compatible with Django 3.x. There's a patch that needs to be applied 
> and a release forthcoming that should take care of it.
>
> -Tim
>
> On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
>
> Django hit count package will help you..
>
> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L  > wrote:
>
> how can i get the number of views of an endpoint by a single 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
>
> -- 
> Tim Wilson
> President, Savvy Technology Group
> phone: 612-599-5470
>
>

-- 
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/ad0c493d-1e92-496a-924b-609819cb848d%40googlegroups.com.


Re: user visit count

2020-04-15 Thread Tim Wilson
I'm planning to use django-hitcount too, but please be aware that it's not yet 
compatible with Django 3.x. There's a patch that needs to be applied and a 
release forthcoming that should take care of it.

-Tim

On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:
> Django hit count package will help you..
> 
> On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L  
> wrote:
>> how can i get the number of views of an endpoint by a single 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/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com?utm_medium=email_source=footer>.

-- 
Tim Wilson
President, Savvy Technology Group
phone: 612-599-5470

-- 
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/602f830a-0d4d-44f5-b346-406b6b39b5db%40www.fastmail.com.


Re: user visit count

2020-04-15 Thread Omkar Parab
Django hit count package will help you..

On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L 
wrote:

> how can i get the number of views of an endpoint by a single 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/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com?utm_medium=email_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/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com.


user visit count

2020-04-15 Thread shreehari Vaasistha L
how can i get the number of views of an endpoint by a single 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/b9e434ba-8378-45cb-a67f-b344773340b6%40googlegroups.com.


Re: Count the number of emails sent everyday

2020-03-13 Thread Santhosh Sridharan
Is there any third party apis that you suggest please?


On Fri, 13 Mar, 2020, 8:07 PM Suraj Thapa FC, 
wrote:

> You can use some 3rd party apis
>
> On Fri, 13 Mar 2020, 4:42 pm Santhosh sridhar, 
> wrote:
>
>> Hi,
>> I am working on django and I trigger emails to multiple email IDs in
>> different scenarios, Is there a way to get the count of emails sent
>> everyday instead of storing it in tables.
>>
>> Regards,
>> Santhosh
>>
>> --
>> 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/b2ef2992-ed9c-45f5-86ad-06e0feb76085%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/b2ef2992-ed9c-45f5-86ad-06e0feb76085%40googlegroups.com?utm_medium=email_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/CAPjsHcExpo-%2BHBweDqEhszb0ZEqfeVvt7B70TzdmNVkTwhChyQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPjsHcExpo-%2BHBweDqEhszb0ZEqfeVvt7B70TzdmNVkTwhChyQ%40mail.gmail.com?utm_medium=email_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/CALVhFDtspfFOJQ0B88Wt1PKC1Q88FEC1whbCADd98dQ_2yKyzg%40mail.gmail.com.


Re: Count the number of emails sent everyday

2020-03-13 Thread Suraj Thapa FC
You can use some 3rd party apis

On Fri, 13 Mar 2020, 4:42 pm Santhosh sridhar, 
wrote:

> Hi,
> I am working on django and I trigger emails to multiple email IDs in
> different scenarios, Is there a way to get the count of emails sent
> everyday instead of storing it in tables.
>
> Regards,
> Santhosh
>
> --
> 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/b2ef2992-ed9c-45f5-86ad-06e0feb76085%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b2ef2992-ed9c-45f5-86ad-06e0feb76085%40googlegroups.com?utm_medium=email_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/CAPjsHcExpo-%2BHBweDqEhszb0ZEqfeVvt7B70TzdmNVkTwhChyQ%40mail.gmail.com.


Count the number of emails sent everyday

2020-03-13 Thread Santhosh sridhar
Hi,
I am working on django and I trigger emails to multiple email IDs in 
different scenarios, Is there a way to get the count of emails sent 
everyday instead of storing it in tables.

Regards,
Santhosh

-- 
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/b2ef2992-ed9c-45f5-86ad-06e0feb76085%40googlegroups.com.


Re: How to write raw SQL or ORM for Count

2019-12-12 Thread Dvs Khamele
Hi We are worlds first affordable Python, Django Based Web Developement
Startup.
And can help you in this and related tasks / projects immidiately mere at
$7 per hour.

On Mon, 2 Dec 2019 at 19:13, xiaopeng luo  wrote:

> I am new to django ORM, I want query something like this:
>
> input:
> AAAfemale1
> AAAfemale2
> BBBmale   1
> BBBmale   3
> AAAmale   2
>
>
>
> output
> AAAfemale3
> AAAmale   2
> BBBmale   4
>
>
> Sorry, my english is not good. Thanks for everyone help me.
>
> --
> 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/a297dc1f-6821-4bba-b04c-e8ce271b5a8d%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/CAH9mneU3KwZzm%2BrpU7FFR3qgXg%2Beg7yO97gHuXNArhoh5sg2-w%40mail.gmail.com.


Re: How to write raw SQL or ORM for Count

2019-12-02 Thread Luqman Shofuleji
You need to do some little reading about Django aggregation
https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#topics-db-aggregation


Example
from django.db.models import Max, Count, Sum
Publisher.objects.values('name').annotate(*dcount*=Count('name'))

As seen above you can apply similar method to get Max, Sum and others


On Mon, Dec 2, 2019 at 2:43 PM xiaopeng luo  wrote:

> I am new to django ORM, I want query something like this:
>
> input:
> AAAfemale1
> AAAfemale2
> BBBmale   1
> BBBmale   3
> AAAmale   2
>
>
>
> output
> AAAfemale3
> AAAmale   2
> BBBmale   4
>
>
> Sorry, my english is not good. Thanks for everyone help me.
>
> --
> 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/a297dc1f-6821-4bba-b04c-e8ce271b5a8d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a297dc1f-6821-4bba-b04c-e8ce271b5a8d%40googlegroups.com?utm_medium=email_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/CAHyB84qihZj5mVNnL2C-BmE%3D2RAdsvVoOYfrfiH04BaPQ%3D5E2Q%40mail.gmail.com.


Re: How to write raw SQL or ORM for Count

2019-12-02 Thread RONAK JAIN
What you want to hear please cear that one..

Thanks

On Mon, 2 Dec 2019, 19:13 xiaopeng luo,  wrote:

> I am new to django ORM, I want query something like this:
>
> input:
> AAAfemale1
> AAAfemale2
> BBBmale   1
> BBBmale   3
> AAAmale   2
>
>
>
> output
> AAAfemale3
> AAAmale   2
> BBBmale   4
>
>
> Sorry, my english is not good. Thanks for everyone help me.
>
> --
> 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/a297dc1f-6821-4bba-b04c-e8ce271b5a8d%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/CA%2BAqMUewuq-ugJTBZ-%2BfFrWT8hvNN%3D3-g7V7W3Tzj2iLV3mf7A%40mail.gmail.com.


How to write raw SQL or ORM for Count

2019-12-02 Thread xiaopeng luo
I am new to django ORM, I want query something like this:

input:
AAAfemale1
AAAfemale2
BBBmale   1
BBBmale   3
AAAmale   2



output
AAAfemale3
AAAmale   2
BBBmale   4


Sorry, my english is not good. Thanks for everyone help me.

-- 
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/a297dc1f-6821-4bba-b04c-e8ce271b5a8d%40googlegroups.com.


Increase Count Value

2019-08-22 Thread Soumen Khatua
Hi Folks,
I want to increase count value of a record after ftech the record each time
in django rest framework.
*This is my model.py*




*class Dataset(models.Model):name = models.CharField(max_length = 100)
  number = models.IntegerField()hits = models.IntegerField(default = 0)*


*api/views.py*










*class DatasetListAPIView(ListAPIView):serializer_class =
DatasetlSerializerdef get_queryset(self):qs =
Dataset.objects.all()word = self.request.query_params.get('word')
  if word is not None:qs  = qs.filter(name__icontains =
word).order_by(Length('name').asc(),'-hits')return qs
  search_fields = ('name',)*

Please help me guys.

Thank You in advance

Regards,
Soumen

-- 
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/CAPUw6WamWbSOYTACSuzbo3MQORbBEadByphzUT3m7YrO8b2Rjg%40mail.gmail.com.


Re: Disable count admin

2019-06-13 Thread Michele Gatti
Thansk

Il giorno sab 8 giu 2019 alle ore 09:03 Derek  ha
scritto:

> Can you use:
>
>
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.show_full_result_count
>
>
> On Monday, 3 June 2019 14:48:23 UTC+2, Michele Gatti wrote:
>>
>> Hi i need to disable paginato on django admin with not managed model.
>> Is possible?
>>
> --
> 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/IlnElmFeICY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/565da33a-3b81-4055-8677-d856f2591154%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKwk%3DN3ooVHg8qKDegXiNmtovsKVwGTKaq4hLDL11GM0kTCjPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disable count admin

2019-06-08 Thread Derek
Can you use:

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.show_full_result_count


On Monday, 3 June 2019 14:48:23 UTC+2, Michele Gatti wrote:
>
> Hi i need to disable paginato on django admin with not managed model.
> Is possible?
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/565da33a-3b81-4055-8677-d856f2591154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Disable count admin

2019-06-03 Thread Michele Gatti
Hi i need to disable paginato on django admin with not managed model.
Is possible?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1f5dfc5f-9609-46be-b380-cd05ec818100%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels thread count is increasing

2018-09-17 Thread Andrew Godwin
There's a reasonably large threadpool that sync_to_async uses (I think it
defaults to number of CPU cores * 5), so you're probably just seeing that.
It should stop growing at some point.

Andrew

On Sat, Sep 15, 2018 at 4:02 PM erkin kabataş  wrote:

> Hi All,
>
> I am new to python and django.
> I am using Python 3.6.5, Django 2.1 and Channels 2.1.2.
> My problem is when I switch to ASGI from WSGI server, in every request,
> thread count is increasing. Same thing is happening when I use
> sync_to_async function in consumers.py. Is this a normal behaviour?
>
> Thanks,
> Erkin
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1upOyJw%2BDKZmF-zJ__Tnyx2X3cA-YrY%2B%3D1iRUzZc4Tq%3DTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels thread count is increasing

2018-09-16 Thread erkin kabataş
Hi,

I followed the channels documentation, you can check from here:

https://channels.readthedocs.io/en/latest/tutorial/part_1.html

After completing this part, in every page refresh, thread count is 
increasing at top 23.

16 Eylül 2018 Pazar 06:05:02 UTC+3 tarihinde vs704263 yazdı:
>
> In post API How to return response to network machine in Django ?
>
>
> On Sun, 16 Sep 2018 at 4:32 AM, erkin kabataş  > wrote:
>
>> Hi All,
>>
>> I am new to python and django. 
>> I am using Python 3.6.5, Django 2.1 and Channels 2.1.2.
>> My problem is when I switch to ASGI from WSGI server, in every request, 
>> thread count is increasing. Same thing is happening when I use 
>> sync_to_async function in consumers.py. Is this a normal behaviour?
>>
>> Thanks,
>> Erkin
>>
>> -- 
>> 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 post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/43fa15e8-5404-4a59-b386-350332511bea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels thread count is increasing

2018-09-15 Thread vishal sharma
In post API How to return response to network machine in Django ?


On Sun, 16 Sep 2018 at 4:32 AM, erkin kabataş  wrote:

> Hi All,
>
> I am new to python and django.
> I am using Python 3.6.5, Django 2.1 and Channels 2.1.2.
> My problem is when I switch to ASGI from WSGI server, in every request,
> thread count is increasing. Same thing is happening when I use
> sync_to_async function in consumers.py. Is this a normal behaviour?
>
> Thanks,
> Erkin
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADdVhnZR8r%2B0T%3DgeLajrxFCwKLtHmgy5MttSUvvxUOJN%3DH9NzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Channels thread count is increasing

2018-09-15 Thread erkin kabataş
Hi All,

I am new to python and django. 
I am using Python 3.6.5, Django 2.1 and Channels 2.1.2.
My problem is when I switch to ASGI from WSGI server, in every request, 
thread count is increasing. Same thing is happening when I use 
sync_to_async function in consumers.py. Is this a normal behaviour?

Thanks,
Erkin

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8635d3c1-c1e6-43d2-a70c-3db2ef3cc1f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Validating count + property of a Many2Many with a through table

2018-07-31 Thread Matthew Pava
Hi Sanjay,
You may want to try signals.
https://docs.djangoproject.com/en/2.0/topics/signals/


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sanjay Bhangar
Sent: Tuesday, July 31, 2018 1:09 PM
To: django-users@googlegroups.com
Subject: Validating count + property of a Many2Many with a through table

Hello!

This is more of a code organization question than a "something is not working" 
question - it might get slightly rambling, so if this kind of question is not 
your cup of tea, you have been warned :-)

So - I have a set of models like this (highly simplified):

class Item(models.Model):
  title = models.CharField(...)
  price = models.IntegerField(...)
  tags = models.ManyToManyField(Tag, through=ItemTag)

class Tag(models.Model):
  name = models.CharField(...)

class ItemTag(models.Model):
  item = models.ForeignKey(Item)
  tag = models.ForeignKey(Tag)
  is_primary = models.BooleanField()


So, I have an Item model that has some properties - it has a ManyToMany 
relationship with Tag, and one or more tags can be selected as "is_primary" 
tags for the model.

Now, to validate properties on the Item model, I call validation methods inside 
a "clean" method on the Item model, something like:

  def clean(self):
if self.price > 1:
  raise ValidationError('Price cannot be so high!")

This is simplified, but you get the idea - this works great, errors are 
propagated in the Admin, as well as raised when I import data via a CSV file 
for example. I know there's a few different places one can define validations - 
I personally like to have them in the model, but I would love to hear alternate 
view-points if this is not the best place to put them.

So, coming to the problem: there is now a requirement to validate that a model 
cannot have more than 3 primary tags associated with it - i.e.
cannot be associated with more than 3 tags with the through table specifying 
is_primary=True.

This, of course, cannot really go in the `clean` method of the Item model. The 
ItemTag relationships don't exist yet, and I don't have the data I need to be 
able to validate a maximum of 3 tags.

The problem is, I cannot seem to be able to do this kind of validation in the 
ItemTag model either, since it depends on knowing how many existing ItemTag 
relationships to Item there are - and before the entire transaction is 
committed to the database, a single ItemTag doesn't know whether the total 
exceeds the allowed 3.

The only place to put it that worked (and made sense) was in the Formset 
definition for the inline form in the admin.

So, we landed up over-riding the formset used for the ItemTag inline in the 
admin, adding our validations to the `clean` method - roughly
like:

class ItemImageInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
image_count = 0
for form in self.forms:
if form.cleaned_data.get('primary') == True:
image_count += 1
if image_count > 3:
raise ValidationError('Cannot have more than 3 primary tags')


This works. However, it seems a bit strange to have validations split between a 
model method, and a subclass of a formset of an admin form.
It seems confusing in terms of maintainability - also, writing tests for the 
validations in the model seemed a lot more straightforward when validations 
were just in the model's `clean` method.

I can see why this is so. Am just wondering if I'm getting something wrong in 
terms of patterns here / if there is a way other folks solve this, to, ideally, 
be able to have all the validation that pertains to a particular model in one 
place, and be able to test all model validations in a consistent manner.

Thank you to whoever read this far :-)

-Sanjay

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG3W7ZFZnemOSOwDRjDN--JLKdF94QEJNrbuTw2MCPoK1QxP7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/981a20654ff4b41e32c600464ddd%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Validating count + property of a Many2Many with a through table

2018-07-31 Thread Sanjay Bhangar
Hello!

This is more of a code organization question than a "something is not
working" question - it might get slightly rambling, so if this kind of
question is not your cup of tea, you have been warned :-)

So - I have a set of models like this (highly simplified):

class Item(models.Model):
  title = models.CharField(...)
  price = models.IntegerField(...)
  tags = models.ManyToManyField(Tag, through=ItemTag)

class Tag(models.Model):
  name = models.CharField(...)

class ItemTag(models.Model):
  item = models.ForeignKey(Item)
  tag = models.ForeignKey(Tag)
  is_primary = models.BooleanField()


So, I have an Item model that has some properties - it has a
ManyToMany relationship with Tag, and one or more tags can be selected
as "is_primary" tags for the model.

Now, to validate properties on the Item model, I call validation
methods inside a "clean" method on the Item model, something like:

  def clean(self):
if self.price > 1:
  raise ValidationError('Price cannot be so high!")

This is simplified, but you get the idea - this works great, errors
are propagated in the Admin, as well as raised when I import data via
a CSV file for example. I know there's a few different places one can
define validations - I personally like to have them in the model, but
I would love to hear alternate view-points if this is not the best
place to put them.

So, coming to the problem: there is now a requirement to validate that
a model cannot have more than 3 primary tags associated with it - i.e.
cannot be associated with more than 3 tags with the through table
specifying is_primary=True.

This, of course, cannot really go in the `clean` method of the Item
model. The ItemTag relationships don't exist yet, and I don't have the
data I need to be able to validate a maximum of 3 tags.

The problem is, I cannot seem to be able to do this kind of validation
in the ItemTag model either, since it depends on knowing how many
existing ItemTag relationships to Item there are - and before the
entire transaction is committed to the database, a single ItemTag
doesn't know whether the total exceeds the allowed 3.

The only place to put it that worked (and made sense) was in the
Formset definition for the inline form in the admin.

So, we landed up over-riding the formset used for the ItemTag inline
in the admin, adding our validations to the `clean` method - roughly
like:

class ItemImageInlineFormset(forms.models.BaseInlineFormSet):
def clean(self):
image_count = 0
for form in self.forms:
if form.cleaned_data.get('primary') == True:
image_count += 1
if image_count > 3:
raise ValidationError('Cannot have more than 3 primary tags')


This works. However, it seems a bit strange to have validations split
between a model method, and a subclass of a formset of an admin form.
It seems confusing in terms of maintainability - also, writing tests
for the validations in the model seemed a lot more straightforward
when validations were just in the model's `clean` method.

I can see why this is so. Am just wondering if I'm getting something
wrong in terms of patterns here / if there is a way other folks solve
this, to, ideally, be able to have all the validation that pertains to
a particular model in one place, and be able to test all model
validations in a consistent manner.

Thank you to whoever read this far :-)

-Sanjay

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG3W7ZFZnemOSOwDRjDN--JLKdF94QEJNrbuTw2MCPoK1QxP7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with comparison of Count outcome in queryset

2018-07-05 Thread Magnus Ljungkrantz
Actually, I tried to do it that way but I never got it working. Not sure 
what is different now but this is what I have working for me now:  

qs = qs.values('make').annotate(model_count=Count('model', distinct=True)).
annotate(
more_than_one_model=Case(
When(model_count__gt=1, then=Value('yes')),
default=Value('no'),
output_field=CharField()
)
)  

Thanks for leading me back on the right track.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9c7276b8-446e-4557-bfef-0f70fd9e2c9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with comparison of Count outcome in queryset

2018-07-05 Thread Jason
try making two separate annotates: one for count and one for the case-when

qs.values('make')
.annotate(count = Count('model', distinct = True))
.annotate(Case(When(count__gt = 1, then='yes', output_field=CharField())

Basically, you need to transform the count annotation into something django 
can use its lookup syntax with.  
On Wednesday, July 4, 2018 at 6:37:27 PM UTC-4, Magnus Ljungkrantz wrote:
>
>
> To give you simplest possible example of my problem, let us say we have a 
> table holding data about physical cars. It has many fields but "make" and 
> "model" are two of them. 
>
> The following SQL will group on make and let me know with "yes "or "no" 
> whether there is more than one model within each group of cars of a 
> specific make. 
>
> SELECT 
>  make,
>  CASE WHEN COUNT(DISTINCT model) > 1 THEN 'yes' ELSE 'no' END AS 
> more_than_one_model
> FROM myapp_car
> GROUP BY make
>
> I know how to group on make and count unique models s  
>
> qs = Car.objects.all().values('make').annotate(model_count=Count('model', 
> distinct=True))
>
> but I cannot figure out how to produce "yes" or "no" result depending on 
> the outcome of a Count(). The following 
>
> qs = qs.values('make').annotate(
> more_than_one_model=Case(
> When(Count('model', distinct=True) > 1, then='yes'),
> default='no'
> ),
> output_field=models.CharField()
> )
>
>
> gives me an exception saying "'>' not supported between instances of 'Count' 
> and 'int'".
>
>
> Any ideas how to accomplish this?
>
>
>  

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c2fbc7a6-54c5-4163-aa1b-c84b13fe5239%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Issue with comparison of Count outcome in queryset

2018-07-04 Thread Magnus Ljungkrantz

To give you simplest possible example of my problem, let us say we have a 
table holding data about physical cars. It has many fields but "make" and 
"model" are two of them. 

The following SQL will group on make and let me know with "yes "or "no" 
whether there is more than one model within each group of cars of a 
specific make. 

SELECT 
 make,
 CASE WHEN COUNT(DISTINCT model) > 1 THEN 'yes' ELSE 'no' END AS 
more_than_one_model
FROM myapp_car
GROUP BY make

I know how to group on make and count unique models s  

qs = Car.objects.all().values('make').annotate(model_count=Count('model', 
distinct=True))

but I cannot figure out how to produce "yes" or "no" result depending on 
the outcome of a Count(). The following 

qs = qs.values('make').annotate(
more_than_one_model=Case(
When(Count('model', distinct=True) > 1, then='yes'),
default='no'
),
output_field=models.CharField()
)


gives me an exception saying "'>' not supported between instances of 'Count' 
and 'int'".


Any ideas how to accomplish this?


 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7dff2c8-cede-4516-8eb8-db7e37455339%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread PASCUAL Eric
Hi Etienne,

I prefer messing with standard distutils/setuptools commands to avoid 
situations like this... ;-)

Messing and restoring system libs is a matter of personnal taste 


Eric


From: Etienne Robillard <tkad...@yandex.com>
Sent: Wednesday, February 14, 2018 11:07:07 AM
To: PASCUAL Eric
Cc: django-users@googlegroups.com
Subject: Re: importError: Count Not import Django inside Virtualenv


Hi Eric,

Le 2018-02-14 à 03:44, PASCUAL Eric a écrit :

Hi,


Hard to say without knowing the exact context, but my gut feeling is that 
you've modified a system wide library at a moment (maybe inadvertently).


My own experience is that it's easy to mess with Python libraries when 
installing packages with sudo , which may happen form time to  time when 
working with virtualenv (or pyenv) since not very long, and being caught up by 
old habits (they tend to survive longer that wanted ).


I prefer messing with standard distutils/setuptools commands to avoid 
situations like this... ;-)

Cheers,
Etienne



From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
<django-users@googlegroups.com><mailto:django-users@googlegroups.com> on behalf 
of tango ward <tangowar...@gmail.com><mailto:tangowar...@gmail.com>
Sent: Wednesday, February 14, 2018 3:40:04 AM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: importError: Count Not import Django inside Virtualenv

Hi Eric,


I tried what you suggested and it works! I was just wondering why my existing 
pet projects have the same problem?

On Wed, Feb 14, 2018 at 10:13 AM, tango ward 
<tangowar...@gmail.com<mailto:tangowar...@gmail.com>> wrote:
Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available 
on your PYTHONPATH environment variable? Did you forget to activate a virtual 
environment?


@Jason,

It's weird because couple of days, I can still run these pet projects without 
any error. If I go to venv folder virtual/lib/python3.6/site-packages, I can 
see django there. It seems that even though virtualenv is activated, the 
packages I installed inside it are not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric 
<eric.pasc...@cstb.fr<mailto:eric.pasc...@cstb.fr>> wrote:

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding 
what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv 
inside which you'll install Django and the additional packages you've added (if 
any). Then restore a copy of your project in this context (if by chance you 
work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in 
sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
<django-users@googlegroups.com<mailto:django-users@googlegroups.com>> on behalf 
of tango ward <tangowar...@gmail.com<mailto:tangowar...@gmail.com>>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: importError: Count Not import Django inside Virtualenv

Hi,

I want to seek some advice about the error. All of my pet projects in my 
desktop are getting the same error even though virtualenv is activated. I can 
confirm that when I started playing around with the projects, I have installed 
Django inside virtualenv without using "sudo". Now, I can't run python 
manage.py runserver and the packages that I am getting whenever I run pip 
freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com<https://groups.go

Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread PASCUAL Eric
Hi,


The copy/paste of the project tree will work of course. Chances are that 
unwanted files can be brought too, but this should not be a problem in a first 
stage.


I have used rsync or tar archives to deploy Django projects in some cases, and 
it worked fine.


Eric


From: django-users@googlegroups.com <django-users@googlegroups.com> on behalf 
of tango ward <tangowar...@gmail.com>
Sent: Wednesday, February 14, 2018 10:09:51 AM
To: django-users@googlegroups.com
Subject: Re: importError: Count Not import Django inside Virtualenv

that's odd. Whenever I test a pacakge, it's always installed first in 
virtualenv. Maybe when I updated my system? Btw, I have some projects which are 
not yet in github, can I just copy and paste them in a new folder with new 
virtualenv?

On Wed, Feb 14, 2018 at 4:44 PM, PASCUAL Eric 
<eric.pasc...@cstb.fr<mailto:eric.pasc...@cstb.fr>> wrote:

Hi,


Hard to say without knowing the exact context, but my gut feeling is that 
you've modified a system wide library at a moment (maybe inadvertently).


My own experience is that it's easy to mess with Python libraries when 
installing packages with sudo , which may happen form time to  time when 
working with virtualenv (or pyenv) since not very long, and being caught up by 
old habits (they tend to survive longer that wanted ).


Even if far less harmful, then --user option is to avoid for projects related 
libs, for the same reasons.


Eric

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
<django-users@googlegroups.com<mailto:django-users@googlegroups.com>> on behalf 
of tango ward <tangowar...@gmail.com<mailto:tangowar...@gmail.com>>
Sent: Wednesday, February 14, 2018 3:40:04 AM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: importError: Count Not import Django inside Virtualenv

Hi Eric,


I tried what you suggested and it works! I was just wondering why my existing 
pet projects have the same problem?

On Wed, Feb 14, 2018 at 10:13 AM, tango ward 
<tangowar...@gmail.com<mailto:tangowar...@gmail.com>> wrote:
Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available 
on your PYTHONPATH environment variable? Did you forget to activate a virtual 
environment?


@Jason,

It's weird because couple of days, I can still run these pet projects without 
any error. If I go to venv folder virtual/lib/python3.6/site-packages, I can 
see django there. It seems that even though virtualenv is activated, the 
packages I installed inside it are not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric 
<eric.pasc...@cstb.fr<mailto:eric.pasc...@cstb.fr>> wrote:

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding 
what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv 
inside which you'll install Django and the additional packages you've added (if 
any). Then restore a copy of your project in this context (if by chance you 
work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in 
sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
<django-users@googlegroups.com<mailto:django-users@googlegroups.com>> on behalf 
of tango ward <tangowar...@gmail.com<mailto:tangowar...@gmail.com>>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: importError: Count Not import Django inside Virtualenv

Hi,

I want to seek some advice about the error. All of my pet projects in my 
desktop are getting the same error even though virtualenv is activated. I can 
confirm that when I started playing around with the projects, I have installed 
Django inside virtualenv without using "sudo". Now, I can't run python 
manage.py runserver and the packages that I am getting whenever I run pip 
freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis

--
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+u

Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread Etienne Robillard

Hi Eric,


Le 2018-02-14 à 03:44, PASCUAL Eric a écrit :


Hi,


Hard to say without knowing the exact context, but my gut feeling is 
that you've modified a system wide library at a moment (maybe 
inadvertently).



My own experience is that it's easy to mess with Python libraries when 
installing packages with sudo , which may happen form time to  time 
when working with virtualenv (or pyenv) since not very long, and being 
caught up by old habits (they tend to survive longer that wanted ).



I prefer messing with standard distutils/setuptools commands to avoid 
situations like this... ;-)


Cheers,
Etienne




*From:* django-users@googlegroups.com <django-users@googlegroups.com> 
on behalf of tango ward <tangowar...@gmail.com>

*Sent:* Wednesday, February 14, 2018 3:40:04 AM
*To:* django-users@googlegroups.com
*Subject:* Re: importError: Count Not import Django inside Virtualenv
Hi Eric,


I tried what you suggested and it works! I was just wondering why my 
existing pet projects have the same problem?


On Wed, Feb 14, 2018 at 10:13 AM, tango ward <tangowar...@gmail.com 
<mailto:tangowar...@gmail.com>> wrote:


Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
    ) from exc
ImportError: Couldn't import Django. Are you sure it's installed
and available on your PYTHONPATH environment variable? Did you
forget to activate a virtual environment?


@Jason,

It's weird because couple of days, I can still run these pet
projects without any error. If I go to venv folder
virtual/lib/python3.6/site-packages, I can see django there. It
seems that even though virtualenv is activated, the packages I
installed inside it are not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric
<eric.pasc...@cstb.fr <mailto:eric.pasc...@cstb.fr>> wrote:

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help
understanding what's happening.


If you haven't already done this, try to restart from a fresh
new virtualenv inside which you'll install Django and the
additional packages you've added (if any). Then restore a copy
of your project in this context (if by chance you work with
git, a simple git clone will do the trick) and test your app
again.


Hoping you haven't already messed your system Python by
installing stuff in sudo mode. The situation could be a little
more complicated then.


Best.


Eric

*From:* django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
<django-users@googlegroups.com
<mailto:django-users@googlegroups.com>> on behalf of tango
ward <tangowar...@gmail.com <mailto:tangowar...@gmail.com>>
*Sent:* Tuesday, February 13, 2018 9:43:45 PM
*To:* django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
*Subject:* importError: Count Not import Django inside Virtualenv
Hi,

I want to seek some advice about the error. All of my pet
projects in my desktop are getting the same error even though
virtualenv is activated. I can confirm that when I started
playing around with the projects, I have installed Django
inside virtualenv without using "sudo". Now, I can't run
python manage.py runserver and the packages that I am getting
whenever I run pip freeze are different from before which
doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis
-- 
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to
django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at
https://groups.google.com/group/django-users
<https://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.c

Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread tango ward
that's odd. Whenever I test a pacakge, it's always installed first in
virtualenv. Maybe when I updated my system? Btw, I have some projects which
are not yet in github, can I just copy and paste them in a new folder with
new virtualenv?

On Wed, Feb 14, 2018 at 4:44 PM, PASCUAL Eric <eric.pasc...@cstb.fr> wrote:

> Hi,
>
>
> Hard to say without knowing the exact context, but my gut feeling is that
> you've modified a system wide library at a moment (maybe inadvertently).
>
>
> My own experience is that it's easy to mess with Python libraries when
> installing packages with sudo , which may happen form time to  time
> when working with virtualenv (or pyenv) since not very long, and being
> caught up by old habits (they tend to survive longer that wanted ).
>
>
> Even if far less harmful, then --user option is to avoid for projects
> related libs, for the same reasons.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Wednesday, February 14, 2018 3:40:04 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: importError: Count Not import Django inside Virtualenv
>
> Hi Eric,
>
>
> I tried what you suggested and it works! I was just wondering why my
> existing pet projects have the same problem?
>
> On Wed, Feb 14, 2018 at 10:13 AM, tango ward <tangowar...@gmail.com>
> wrote:
>
> Hi,
>
> The error message that I am getting is:
>
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ModuleNotFoundError: No module named 'django'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "manage.py", line 14, in 
> ) from exc
> ImportError: Couldn't import Django. Are you sure it's installed and
> available on your PYTHONPATH environment variable? Did you forget to
> activate a virtual environment?
>
>
> @Jason,
>
> It's weird because couple of days, I can still run these pet projects
> without any error. If I go to venv folder virtual/lib/python3.6/site-packages,
> I can see django there. It seems that even though virtualenv is activated,
> the packages I installed inside it are not recognized by the system.
>
>
> On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr>
> wrote:
>
> Hi Jarvis,
>
>
> Can you provide the error messages trace ? It can greatly help
> understanding what's happening.
>
>
> If you haven't already done this, try to restart from a fresh new
> virtualenv inside which you'll install Django and the additional packages
> you've added (if any). Then restore a copy of your project in this context
> (if by chance you work with git, a simple git clone will do the trick) and
> test your app again.
>
>
> Hoping you haven't already messed your system Python by installing stuff
> in sudo mode. The situation could be a little more complicated then.
>
>
> Best.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
> *To:* django-users@googlegroups.com
> *Subject:* importError: Count Not import Django inside Virtualenv
>
> Hi,
>
> I want to seek some advice about the error. All of my pet projects in my
> desktop are getting the same error even though virtualenv is activated. I
> can confirm that when I started playing around with the projects, I have
> installed Django inside virtualenv without using "sudo". Now, I can't run
> python manage.py runserver and the packages that I am getting whenever I
> run pip freeze are different from before which doesn't include Django in
> the list.
>
>
> Any advice pls?
>
>
> Thanks,
> Jarvis
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWb
> e1JNx2YhFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>

Re: importError: Count Not import Django inside Virtualenv

2018-02-14 Thread PASCUAL Eric
Hi,


Hard to say without knowing the exact context, but my gut feeling is that 
you've modified a system wide library at a moment (maybe inadvertently).


My own experience is that it's easy to mess with Python libraries when 
installing packages with sudo , which may happen form time to  time when 
working with virtualenv (or pyenv) since not very long, and being caught up by 
old habits (they tend to survive longer that wanted ).


Even if far less harmful, then --user option is to avoid for projects related 
libs, for the same reasons.


Eric

From: django-users@googlegroups.com <django-users@googlegroups.com> on behalf 
of tango ward <tangowar...@gmail.com>
Sent: Wednesday, February 14, 2018 3:40:04 AM
To: django-users@googlegroups.com
Subject: Re: importError: Count Not import Django inside Virtualenv

Hi Eric,


I tried what you suggested and it works! I was just wondering why my existing 
pet projects have the same problem?

On Wed, Feb 14, 2018 at 10:13 AM, tango ward 
<tangowar...@gmail.com<mailto:tangowar...@gmail.com>> wrote:
Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available 
on your PYTHONPATH environment variable? Did you forget to activate a virtual 
environment?


@Jason,

It's weird because couple of days, I can still run these pet projects without 
any error. If I go to venv folder virtual/lib/python3.6/site-packages, I can 
see django there. It seems that even though virtualenv is activated, the 
packages I installed inside it are not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric 
<eric.pasc...@cstb.fr<mailto:eric.pasc...@cstb.fr>> wrote:

Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding 
what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv 
inside which you'll install Django and the additional packages you've added (if 
any). Then restore a copy of your project in this context (if by chance you 
work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in 
sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
<django-users@googlegroups.com<mailto:django-users@googlegroups.com>> on behalf 
of tango ward <tangowar...@gmail.com<mailto:tangowar...@gmail.com>>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: importError: Count Not import Django inside Virtualenv

Hi,

I want to seek some advice about the error. All of my pet projects in my 
desktop are getting the same error even though virtualenv is activated. I can 
confirm that when I started playing around with the projects, I have installed 
Django inside virtualenv without using "sudo". Now, I can't run python 
manage.py runserver and the packages that I am getting whenever I run pip 
freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.

Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi Eric,


I tried what you suggested and it works! I was just wondering why my
existing pet projects have the same problem?

On Wed, Feb 14, 2018 at 10:13 AM, tango ward <tangowar...@gmail.com> wrote:

> Hi,
>
> The error message that I am getting is:
>
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ModuleNotFoundError: No module named 'django'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "manage.py", line 14, in 
> ) from exc
> ImportError: Couldn't import Django. Are you sure it's installed and
> available on your PYTHONPATH environment variable? Did you forget to
> activate a virtual environment?
>
>
> @Jason,
>
> It's weird because couple of days, I can still run these pet projects
> without any error. If I go to venv folder virtual/lib/python3.6/site-packages,
> I can see django there. It seems that even though virtualenv is activated,
> the packages I installed inside it are not recognized by the system.
>
>
> On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr>
> wrote:
>
>> Hi Jarvis,
>>
>>
>> Can you provide the error messages trace ? It can greatly help
>> understanding what's happening.
>>
>>
>> If you haven't already done this, try to restart from a fresh new
>> virtualenv inside which you'll install Django and the additional packages
>> you've added (if any). Then restore a copy of your project in this context
>> (if by chance you work with git, a simple git clone will do the trick) and
>> test your app again.
>>
>>
>> Hoping you haven't already messed your system Python by installing stuff
>> in sudo mode. The situation could be a little more complicated then.
>>
>>
>> Best.
>>
>>
>> Eric
>> ------
>> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
>> behalf of tango ward <tangowar...@gmail.com>
>> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
>> *To:* django-users@googlegroups.com
>> *Subject:* importError: Count Not import Django inside Virtualenv
>>
>> Hi,
>>
>> I want to seek some advice about the error. All of my pet projects in my
>> desktop are getting the same error even though virtualenv is activated. I
>> can confirm that when I started playing around with the projects, I have
>> installed Django inside virtualenv without using "sudo". Now, I can't run
>> python manage.py runserver and the packages that I am getting whenever I
>> run pip freeze are different from before which doesn't include Django in
>> the list.
>>
>>
>> Any advice pls?
>>
>>
>> Thanks,
>> Jarvis
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWb
>> e1JNx2YhFA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/AM5P193MB0083C66FCD689270720750708CF60%
>> 40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM
>> <https://groups.google.com/d/msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLJCkd0B-0ep8jrUFk1QUp%3D_jQ_AuundhzBMwOSYf7h4fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi,

The error message that I am getting is:

Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in 
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and
available on your PYTHONPATH environment variable? Did you forget to
activate a virtual environment?


@Jason,

It's weird because couple of days, I can still run these pet projects
without any error. If I go to venv folder
virtual/lib/python3.6/site-packages, I can see django there. It seems that
even though virtualenv is activated, the packages I installed inside it are
not recognized by the system.


On Wed, Feb 14, 2018 at 5:38 AM, PASCUAL Eric <eric.pasc...@cstb.fr> wrote:

> Hi Jarvis,
>
>
> Can you provide the error messages trace ? It can greatly help
> understanding what's happening.
>
>
> If you haven't already done this, try to restart from a fresh new
> virtualenv inside which you'll install Django and the additional packages
> you've added (if any). Then restore a copy of your project in this context
> (if by chance you work with git, a simple git clone will do the trick) and
> test your app again.
>
>
> Hoping you haven't already messed your system Python by installing stuff
> in sudo mode. The situation could be a little more complicated then.
>
>
> Best.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com <django-users@googlegroups.com> on
> behalf of tango ward <tangowar...@gmail.com>
> *Sent:* Tuesday, February 13, 2018 9:43:45 PM
> *To:* django-users@googlegroups.com
> *Subject:* importError: Count Not import Django inside Virtualenv
>
> Hi,
>
> I want to seek some advice about the error. All of my pet projects in my
> desktop are getting the same error even though virtualenv is activated. I
> can confirm that when I started playing around with the projects, I have
> installed Django inside virtualenv without using "sudo". Now, I can't run
> python manage.py runserver and the packages that I am getting whenever I
> run pip freeze are different from before which doesn't include Django in
> the list.
>
>
> Any advice pls?
>
>
> Thanks,
> Jarvis
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2Y
> hFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.
> EURP193.PROD.OUTLOOK.COM
> <https://groups.google.com/d/msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLLZyeuQiFL6fe4HvC4a6ogZnTh7kGrc62ni95aPggChyA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread PASCUAL Eric
Hi Jarvis,


Can you provide the error messages trace ? It can greatly help understanding 
what's happening.


If you haven't already done this, try to restart from a fresh new virtualenv 
inside which you'll install Django and the additional packages you've added (if 
any). Then restore a copy of your project in this context (if by chance you 
work with git, a simple git clone will do the trick) and test your app again.


Hoping you haven't already messed your system Python by installing stuff in 
sudo mode. The situation could be a little more complicated then.


Best.


Eric

From: django-users@googlegroups.com <django-users@googlegroups.com> on behalf 
of tango ward <tangowar...@gmail.com>
Sent: Tuesday, February 13, 2018 9:43:45 PM
To: django-users@googlegroups.com
Subject: importError: Count Not import Django inside Virtualenv

Hi,

I want to seek some advice about the error. All of my pet projects in my 
desktop are getting the same error even though virtualenv is activated. I can 
confirm that when I started playing around with the projects, I have installed 
Django inside virtualenv without using "sudo". Now, I can't run python 
manage.py runserver and the packages that I am getting whenever I run pip 
freeze are different from before which doesn't include Django in the list.


Any advice pls?


Thanks,
Jarvis

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/AM5P193MB0083C66FCD689270720750708CF60%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.


Re: importError: Count Not import Django inside Virtualenv

2018-02-13 Thread Jason
if pip freeze doesn't include django in the output, then the django package 
is not installed in the virtualenv.  are you sure the virtualenv was active 
when you installed django?

also, remember that if you installed latest django, eg *pip install django*, 
it won't install for python2 venvs.

On Tuesday, February 13, 2018 at 3:44:42 PM UTC-5, tangoward15 wrote:
>
> Hi,
>
> I want to seek some advice about the error. All of my pet projects in my 
> desktop are getting the same error even though virtualenv is activated. I 
> can confirm that when I started playing around with the projects, I have 
> installed Django inside virtualenv without using "sudo". Now, I can't run 
> python manage.py runserver and the packages that I am getting whenever I 
> run pip freeze are different from before which doesn't include Django in 
> the list.
>
>
> Any advice pls?
>
>
> Thanks,
> Jarvis
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ddf691d-6d16-4fa1-aab0-f534fef445ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


importError: Count Not import Django inside Virtualenv

2018-02-13 Thread tango ward
Hi,

I want to seek some advice about the error. All of my pet projects in my
desktop are getting the same error even though virtualenv is activated. I
can confirm that when I started playing around with the projects, I have
installed Django inside virtualenv without using "sudo". Now, I can't run
python manage.py runserver and the packages that I am getting whenever I
run pip freeze are different from before which doesn't include Django in
the list.


Any advice pls?


Thanks,
Jarvis

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA6wQLKp3oz-6FfDzQ%3Dip4XRsuLPSeOCuwkbUuWbe1JNx2YhFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Saving the count of selected checkboxes

2018-01-23 Thread JSaa
Hello,

I have a model that is used by a few different model forms.

Model
class QuestionAnswer(models.Model):
...
qanswer_answer = models.CharField(max_length=1, null=False, 
default=None, blank=False)

Now I have modelform that I use to collect info from the user. User selects 
all that apply and I want to save only the count of selected checkboxes and 
save it to the QuestionAnswer model. 

Form
class MultiAnswerForm(forms.ModelForm):
qanswer_answer = forms.MultipleChoiceField(choices=MULTIANSWER, 
required=True, widget=forms.CheckboxSelectMultiple)
class Meta:
model = QuestionAnswer
fields = '__all__'

In the view I check that fields are valid and I guess that's where I have 
to save the count instead of actual choices?

View
instance = multi_answer_form.save(commit=False)
instance.qanswer_answer = 
multi_answer_form.cleaned_data.get('qanswer_answer')
instance.save()

How do I get the count of selected checkboxes? 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f557f72-0d69-43b9-b7a6-9fec31f4c636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Can I test for count of a many to many field, in a Q query, along with other filters?

2018-01-16 Thread Mark London
If I'm creating a query using Q, can I make one of Q tests, be a count of a 
manytomany field?I.e., one of the Q filters, should test to see if a 
specific manytomany field, has a count greater than 5,   I know that I can 
use annotate to test for count.   But can annotate be specified within a Q 
query?   

If not, can I make 2 separate queries, and combine them, and eliminate 
duplicates?

Thanks! - Mark 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/198c6f85-ba4c-4f38-844f-cb8cc4d67772%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange query when using annotate and count

2017-12-06 Thread Cristiano Coelho
Update. Found a work around that gets rid of the unnecessary group by (and 
hence speeds up the query, from ~200ms to ~100ms in my use case). Simply 
adding a .values('pk').
Bad thing, every model needs a custom manager and it will still use an 
inner query, still trying to figure out the side effects of it, nothing so 
far...

class FasterCountQuerySet(QuerySet):
> def count(self):
> return super(FasterCountQuerySet, self.values('pk')).count()
>


Makes me wonder if the original count code can be made "smarter" in order 
to prevent the unnecessary group by, or if this simply a bug


El miércoles, 6 de diciembre de 2017, 10:28:22 (UTC-3), Cristiano Coelho 
escribió:
>
> After testing for a while, there really doesn't seem to be a good way to 
> do this. .
>
> Annotation is required since the query is filtered based on the annotated 
> value, so any attempt to clear annotations would fail. Although a lookup 
> could be used for the filtering.
> But a custom lookup is not possible since the query also sorts by the 
> annotated value, so an annotation is required.
>
> This means that I would need to use a custom lookup for count queries, and 
> annotation for result queries, which would mean a lot of duplicated code 
> and also that the Django Paginator class can't be used since it expects 
> only one queryset.
>
>
> Are there really no options to make a count with a custom function to skip 
> the group by clause (and so the inner query)? I mean there's no group by at 
> all with the original query, it's just when count is used.
>
> To summarize, the original query is a bit more complex than the one 
> described on top, reason annotate is needed, and it looks more like:
>
> q = 
> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary')).filter(score__gt=0.6).order_by('-score')
>
> Which is then sent to a paginator, that ends up almost adding 3 times more 
> database query time do to the horrid count query generated.
>
>
> El viernes, 24 de noviembre de 2017, 18:04:21 (UTC-3), Cristiano Coelho 
> escribió:
>>
>> Hello Simon,
>>
>> You are right, the score is really not meant to be attached so a custom 
>> lookup might work, if it wasn't for the issue that an order_by clause would 
>> fail without the annotation. 
>>
>> So it seems it's either update and duplicate a lot of code or find a very 
>> ugly work around, I was hoping I missed some flag or implementation detail 
>> on the custom function to tell the query builder to avoid all the grouping 
>> and subquery stuff, will research more...
>>
>>
>> El viernes, 24 de noviembre de 2017, 14:39:27 (UTC-3), Simon Charette 
>> escribió:
>>>
>>> Hello Cristiano,
>>>
>>> If you are solely using this annotation for querying purpose, that means 
>>> you are
>>> not expecting a `score` attribute to be attached to your `Vulnerability` 
>>> instances,
>>> you could try defining your function as a lookup on CharField/TextField 
>>> instead.
>>>
>>> You could then use it only when required by passing a tuple of values to 
>>> it.
>>>
>>> e.g.
>>>
>>> Vulnerability.objects.filter(summary__wordsimilarity_gt=('test', 
>>> threshold))
>>>
>>> If you need the value annotated I'm afraid the best solution would be to 
>>> use
>>> a custom paginator class. You could give a try at detecting whether or 
>>> not
>>> an annotation is referenced before removing it from query.annotations and
>>> report your finding on the aforementioned ticket but I expect this to be
>>> relatively hard to do correctly. Still it would make implementing 
>>> `alias()`
>>> way easier and provide help for users in the situation as you.
>>>
>>> Best,
>>> Simon
>>>
>>> Le vendredi 24 novembre 2017 08:14:10 UTC-5, Cristiano Coelho a écrit :
>>>>
>>>> Hello Simon,
>>>>
>>>> That private API is good to know, but now that I think of it would 
>>>> still not work for me, since my queryset is passed to a paginator and 
>>>> that's the class that does both the count and actual queryset execution, 
>>>> so 
>>>> need a queryset that can have both the annotation but also clears it if 
>>>> count is called so it doesn't create the redundant sub queries.
>>>>
>>>> I'm wondering what's better, should I try to resolve this at the 
>>>> manager level overriding count? I feel like this might cause issues if the 
>>>> annotation is actual

Re: Strange query when using annotate and count

2017-12-06 Thread Cristiano Coelho
After testing for a while, there really doesn't seem to be a good way to do 
this. .

Annotation is required since the query is filtered based on the annotated 
value, so any attempt to clear annotations would fail. Although a lookup 
could be used for the filtering.
But a custom lookup is not possible since the query also sorts by the 
annotated value, so an annotation is required.

This means that I would need to use a custom lookup for count queries, and 
annotation for result queries, which would mean a lot of duplicated code 
and also that the Django Paginator class can't be used since it expects 
only one queryset.


Are there really no options to make a count with a custom function to skip 
the group by clause (and so the inner query)? I mean there's no group by at 
all with the original query, it's just when count is used.

To summarize, the original query is a bit more complex than the one 
described on top, reason annotate is needed, and it looks more like:

q = 
Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary')).filter(score__gt=0.6).order_by('-score')

Which is then sent to a paginator, that ends up almost adding 3 times more 
database query time do to the horrid count query generated.


El viernes, 24 de noviembre de 2017, 18:04:21 (UTC-3), Cristiano Coelho 
escribió:
>
> Hello Simon,
>
> You are right, the score is really not meant to be attached so a custom 
> lookup might work, if it wasn't for the issue that an order_by clause would 
> fail without the annotation. 
>
> So it seems it's either update and duplicate a lot of code or find a very 
> ugly work around, I was hoping I missed some flag or implementation detail 
> on the custom function to tell the query builder to avoid all the grouping 
> and subquery stuff, will research more...
>
>
> El viernes, 24 de noviembre de 2017, 14:39:27 (UTC-3), Simon Charette 
> escribió:
>>
>> Hello Cristiano,
>>
>> If you are solely using this annotation for querying purpose, that means 
>> you are
>> not expecting a `score` attribute to be attached to your `Vulnerability` 
>> instances,
>> you could try defining your function as a lookup on CharField/TextField 
>> instead.
>>
>> You could then use it only when required by passing a tuple of values to 
>> it.
>>
>> e.g.
>>
>> Vulnerability.objects.filter(summary__wordsimilarity_gt=('test', 
>> threshold))
>>
>> If you need the value annotated I'm afraid the best solution would be to 
>> use
>> a custom paginator class. You could give a try at detecting whether or not
>> an annotation is referenced before removing it from query.annotations and
>> report your finding on the aforementioned ticket but I expect this to be
>> relatively hard to do correctly. Still it would make implementing 
>> `alias()`
>> way easier and provide help for users in the situation as you.
>>
>> Best,
>> Simon
>>
>> Le vendredi 24 novembre 2017 08:14:10 UTC-5, Cristiano Coelho a écrit :
>>>
>>> Hello Simon,
>>>
>>> That private API is good to know, but now that I think of it would still 
>>> not work for me, since my queryset is passed to a paginator and that's the 
>>> class that does both the count and actual queryset execution, so need a 
>>> queryset that can have both the annotation but also clears it if count is 
>>> called so it doesn't create the redundant sub queries.
>>>
>>> I'm wondering what's better, should I try to resolve this at the manager 
>>> level overriding count? I feel like this might cause issues if the 
>>> annotation is actually legit (ie with an aggregate) and it needs the 
>>> subquery after all.
>>> The other option is to subclass the paginator class with a special one 
>>> that does this annotation clearing before running count.
>>>
>>> Even with these cases, if the annotated value is used later with a 
>>> filter query I can't really simply removed, but the sub queries and extra 
>>> function calls really doesn't make sense to be there when doing a count, so 
>>> it seems that all the options are quite bad and hackish.
>>>
>>> Any other options?
>>>
>>>
>>> El viernes, 24 de noviembre de 2017, 1:12:07 (UTC-3), Simon Charette 
>>> escribió:
>>>>
>>>> Hello Cristiano,
>>>>
>>>> > Isn't there a way (even if it's hackish) to simply clear the 
>>>> annotations (and order by)? I know querysets are smart enough to not 
>>>> include the order by clause if there's a count.
>>>>
>>>> The ordering is cleared on `count()

Re: Strange query when using annotate and count

2017-11-24 Thread Cristiano Coelho
Hello Simon,

You are right, the score is really not meant to be attached so a custom 
lookup might work, if it wasn't for the issue that an order_by clause would 
fail without the annotation. 

So it seems it's either update and duplicate a lot of code or find a very 
ugly work around, I was hoping I missed some flag or implementation detail 
on the custom function to tell the query builder to avoid all the grouping 
and subquery stuff, will research more...


El viernes, 24 de noviembre de 2017, 14:39:27 (UTC-3), Simon Charette 
escribió:
>
> Hello Cristiano,
>
> If you are solely using this annotation for querying purpose, that means 
> you are
> not expecting a `score` attribute to be attached to your `Vulnerability` 
> instances,
> you could try defining your function as a lookup on CharField/TextField 
> instead.
>
> You could then use it only when required by passing a tuple of values to 
> it.
>
> e.g.
>
> Vulnerability.objects.filter(summary__wordsimilarity_gt=('test', 
> threshold))
>
> If you need the value annotated I'm afraid the best solution would be to 
> use
> a custom paginator class. You could give a try at detecting whether or not
> an annotation is referenced before removing it from query.annotations and
> report your finding on the aforementioned ticket but I expect this to be
> relatively hard to do correctly. Still it would make implementing `alias()`
> way easier and provide help for users in the situation as you.
>
> Best,
> Simon
>
> Le vendredi 24 novembre 2017 08:14:10 UTC-5, Cristiano Coelho a écrit :
>>
>> Hello Simon,
>>
>> That private API is good to know, but now that I think of it would still 
>> not work for me, since my queryset is passed to a paginator and that's the 
>> class that does both the count and actual queryset execution, so need a 
>> queryset that can have both the annotation but also clears it if count is 
>> called so it doesn't create the redundant sub queries.
>>
>> I'm wondering what's better, should I try to resolve this at the manager 
>> level overriding count? I feel like this might cause issues if the 
>> annotation is actually legit (ie with an aggregate) and it needs the 
>> subquery after all.
>> The other option is to subclass the paginator class with a special one 
>> that does this annotation clearing before running count.
>>
>> Even with these cases, if the annotated value is used later with a filter 
>> query I can't really simply removed, but the sub queries and extra function 
>> calls really doesn't make sense to be there when doing a count, so it seems 
>> that all the options are quite bad and hackish.
>>
>> Any other options?
>>
>>
>> El viernes, 24 de noviembre de 2017, 1:12:07 (UTC-3), Simon Charette 
>> escribió:
>>>
>>> Hello Cristiano,
>>>
>>> > Isn't there a way (even if it's hackish) to simply clear the 
>>> annotations (and order by)? I know querysets are smart enough to not 
>>> include the order by clause if there's a count.
>>>
>>> The ordering is cleared on `count()` because it shouldn't interfere with 
>>> the result in any way. You can clear annotations using 
>>> `queryset.query.annotations.clear()` but be aware that it is a private API 
>>> that could change under your feet. Make sure to make a copy of the queryset 
>>> (e.g. copy = queryset.all()) before performing this change as it will alter 
>>> the queryset in place.
>>>
>>> Best,
>>> Simon
>>>  
>>> Le jeudi 23 novembre 2017 22:41:41 UTC-5, Cristiano Coelho a écrit :
>>>>
>>>> Hello Simon, thanks for the response.
>>>>
>>>> The above code is just an example, the reason behind the annotate 
>>>> because there's some complicated code that builds a queryset and annotates 
>>>> it so it can easily be reused. It works fine 99% of the time except when 
>>>> there's a count involved and it ends up being redundant. The solution 
>>>> would 
>>>> be to not annotate anything and replace the code in multiple places to add 
>>>> the annotate call (or similar using a custom queryset or manager I guess), 
>>>> but that's quite painful and will end up with a lot of duplicated code 
>>>> since there's also an order_by that follows the annotate that needs to be 
>>>> moved over as well
>>>>
>>>> Isn't there a way (even if it's hackish) to simply clear the 
>>>> annotations (and order by)? I know querysets are smart enough to not 
>>>> include the order by clause if 

Re: Strange query when using annotate and count

2017-11-24 Thread Simon Charette
Hello Cristiano,

If you are solely using this annotation for querying purpose, that means 
you are
not expecting a `score` attribute to be attached to your `Vulnerability` 
instances,
you could try defining your function as a lookup on CharField/TextField 
instead.

You could then use it only when required by passing a tuple of values to it.

e.g.

Vulnerability.objects.filter(summary__wordsimilarity_gt=('test', threshold))

If you need the value annotated I'm afraid the best solution would be to use
a custom paginator class. You could give a try at detecting whether or not
an annotation is referenced before removing it from query.annotations and
report your finding on the aforementioned ticket but I expect this to be
relatively hard to do correctly. Still it would make implementing `alias()`
way easier and provide help for users in the situation as you.

Best,
Simon

Le vendredi 24 novembre 2017 08:14:10 UTC-5, Cristiano Coelho a écrit :
>
> Hello Simon,
>
> That private API is good to know, but now that I think of it would still 
> not work for me, since my queryset is passed to a paginator and that's the 
> class that does both the count and actual queryset execution, so need a 
> queryset that can have both the annotation but also clears it if count is 
> called so it doesn't create the redundant sub queries.
>
> I'm wondering what's better, should I try to resolve this at the manager 
> level overriding count? I feel like this might cause issues if the 
> annotation is actually legit (ie with an aggregate) and it needs the 
> subquery after all.
> The other option is to subclass the paginator class with a special one 
> that does this annotation clearing before running count.
>
> Even with these cases, if the annotated value is used later with a filter 
> query I can't really simply removed, but the sub queries and extra function 
> calls really doesn't make sense to be there when doing a count, so it seems 
> that all the options are quite bad and hackish.
>
> Any other options?
>
>
> El viernes, 24 de noviembre de 2017, 1:12:07 (UTC-3), Simon Charette 
> escribió:
>>
>> Hello Cristiano,
>>
>> > Isn't there a way (even if it's hackish) to simply clear the 
>> annotations (and order by)? I know querysets are smart enough to not 
>> include the order by clause if there's a count.
>>
>> The ordering is cleared on `count()` because it shouldn't interfere with 
>> the result in any way. You can clear annotations using 
>> `queryset.query.annotations.clear()` but be aware that it is a private API 
>> that could change under your feet. Make sure to make a copy of the queryset 
>> (e.g. copy = queryset.all()) before performing this change as it will alter 
>> the queryset in place.
>>
>> Best,
>> Simon
>>  
>> Le jeudi 23 novembre 2017 22:41:41 UTC-5, Cristiano Coelho a écrit :
>>>
>>> Hello Simon, thanks for the response.
>>>
>>> The above code is just an example, the reason behind the annotate 
>>> because there's some complicated code that builds a queryset and annotates 
>>> it so it can easily be reused. It works fine 99% of the time except when 
>>> there's a count involved and it ends up being redundant. The solution would 
>>> be to not annotate anything and replace the code in multiple places to add 
>>> the annotate call (or similar using a custom queryset or manager I guess), 
>>> but that's quite painful and will end up with a lot of duplicated code 
>>> since there's also an order_by that follows the annotate that needs to be 
>>> moved over as well
>>>
>>> Isn't there a way (even if it's hackish) to simply clear the annotations 
>>> (and order by)? I know querysets are smart enough to not include the order 
>>> by clause if there's a count.
>>>
>>> You could also suggest using two separate calls or a flag to pass down 
>>> to the internal code so it doesn't include the additional stuff, but that 
>>> wouldn't work since paginators accept only one query set for example and 
>>> internall uses it for both count and results.
>>>
>>>
>>>
>>> El viernes, 24 de noviembre de 2017, 0:05:29 (UTC-3), Simon Charette 
>>> escribió:
>>>>
>>>> Hello Cristiano,
>>>>
>>>> I understand your frustration but please avoid using the developer 
>>>> mailing list
>>>> as a second tier support channel. I suggest you try the IRC #django 
>>>> channel if
>>>> you need to want to get faster support.
>>>>
>>>> What's happening here is that annotate() really means "select this

Re: Strange query when using annotate and count

2017-11-24 Thread Cristiano Coelho
Hello Simon,

That private API is good to know, but now that I think of it would still 
not work for me, since my queryset is passed to a paginator and that's the 
class that does both the count and actual queryset execution, so need a 
queryset that can have both the annotation but also clears it if count is 
called so it doesn't create the redundant sub queries.

I'm wondering what's better, should I try to resolve this at the manager 
level overriding count? I feel like this might cause issues if the 
annotation is actually legit (ie with an aggregate) and it needs the 
subquery after all.
The other option is to subclass the paginator class with a special one that 
does this annotation clearing before running count.

Even with these cases, if the annotated value is used later with a filter 
query I can't really simply removed, but the sub queries and extra function 
calls really doesn't make sense to be there when doing a count, so it seems 
that all the options are quite bad and hackish.

Any other options?


El viernes, 24 de noviembre de 2017, 1:12:07 (UTC-3), Simon Charette 
escribió:
>
> Hello Cristiano,
>
> > Isn't there a way (even if it's hackish) to simply clear the annotations 
> (and order by)? I know querysets are smart enough to not include the order 
> by clause if there's a count.
>
> The ordering is cleared on `count()` because it shouldn't interfere with 
> the result in any way. You can clear annotations using 
> `queryset.query.annotations.clear()` but be aware that it is a private API 
> that could change under your feet. Make sure to make a copy of the queryset 
> (e.g. copy = queryset.all()) before performing this change as it will alter 
> the queryset in place.
>
> Best,
> Simon
>  
> Le jeudi 23 novembre 2017 22:41:41 UTC-5, Cristiano Coelho a écrit :
>>
>> Hello Simon, thanks for the response.
>>
>> The above code is just an example, the reason behind the annotate because 
>> there's some complicated code that builds a queryset and annotates it so it 
>> can easily be reused. It works fine 99% of the time except when there's a 
>> count involved and it ends up being redundant. The solution would be to not 
>> annotate anything and replace the code in multiple places to add the 
>> annotate call (or similar using a custom queryset or manager I guess), but 
>> that's quite painful and will end up with a lot of duplicated code since 
>> there's also an order_by that follows the annotate that needs to be moved 
>> over as well
>>
>> Isn't there a way (even if it's hackish) to simply clear the annotations 
>> (and order by)? I know querysets are smart enough to not include the order 
>> by clause if there's a count.
>>
>> You could also suggest using two separate calls or a flag to pass down to 
>> the internal code so it doesn't include the additional stuff, but that 
>> wouldn't work since paginators accept only one query set for example and 
>> internall uses it for both count and results.
>>
>>
>>
>> El viernes, 24 de noviembre de 2017, 0:05:29 (UTC-3), Simon Charette 
>> escribió:
>>>
>>> Hello Cristiano,
>>>
>>> I understand your frustration but please avoid using the developer 
>>> mailing list
>>> as a second tier support channel. I suggest you try the IRC #django 
>>> channel if
>>> you need to want to get faster support.
>>>
>>> What's happening here is that annotate() really means "select this 
>>> field" while
>>> in your other case you use a lookup (summary__icontains) which are only 
>>> going to
>>> be added to the WHERE clause of your query.
>>>
>>> I'm not sure why you are annotating your queryset without referring to 
>>> it in
>>> a filter clause later on but the ORM cannot simply ignore it when you are
>>> performing your `count()` because some annotations could interfere with 
>>> grouping
>>> somehow.
>>>
>>> There is an open ticket[0] to add support for an `alias()` method that 
>>> would
>>> allow the ORM to clear/ignore the specified expressions if it's not 
>>> referenced
>>> in the query.
>>>
>>> In the mean time I think the best approach would be to avoid annotating 
>>> the
>>> queryset if your don't need to reference the score.
>>>
>>> Cheers,
>>> Simon
>>>
>>> [0] https://code.djangoproject.com/ticket/27719
>>>
>>> Le mardi 21 novembre 2017 08:46:21 UTC-5, Cristiano Coelho a écrit :
>>>>
>>>> Hmm, should I try with the dev mailing list? Guess it's something no 
>

Re: Strange query when using annotate and count

2017-11-23 Thread Simon Charette
Hello Cristiano,

> Isn't there a way (even if it's hackish) to simply clear the annotations 
(and order by)? I know querysets are smart enough to not include the order 
by clause if there's a count.

The ordering is cleared on `count()` because it shouldn't interfere with 
the result in any way. You can clear annotations using 
`queryset.query.annotations.clear()` but be aware that it is a private API 
that could change under your feet. Make sure to make a copy of the queryset 
(e.g. copy = queryset.all()) before performing this change as it will alter 
the queryset in place.

Best,
Simon
 
Le jeudi 23 novembre 2017 22:41:41 UTC-5, Cristiano Coelho a écrit :
>
> Hello Simon, thanks for the response.
>
> The above code is just an example, the reason behind the annotate because 
> there's some complicated code that builds a queryset and annotates it so it 
> can easily be reused. It works fine 99% of the time except when there's a 
> count involved and it ends up being redundant. The solution would be to not 
> annotate anything and replace the code in multiple places to add the 
> annotate call (or similar using a custom queryset or manager I guess), but 
> that's quite painful and will end up with a lot of duplicated code since 
> there's also an order_by that follows the annotate that needs to be moved 
> over as well
>
> Isn't there a way (even if it's hackish) to simply clear the annotations 
> (and order by)? I know querysets are smart enough to not include the order 
> by clause if there's a count.
>
> You could also suggest using two separate calls or a flag to pass down to 
> the internal code so it doesn't include the additional stuff, but that 
> wouldn't work since paginators accept only one query set for example and 
> internall uses it for both count and results.
>
>
>
> El viernes, 24 de noviembre de 2017, 0:05:29 (UTC-3), Simon Charette 
> escribió:
>>
>> Hello Cristiano,
>>
>> I understand your frustration but please avoid using the developer 
>> mailing list
>> as a second tier support channel. I suggest you try the IRC #django 
>> channel if
>> you need to want to get faster support.
>>
>> What's happening here is that annotate() really means "select this field" 
>> while
>> in your other case you use a lookup (summary__icontains) which are only 
>> going to
>> be added to the WHERE clause of your query.
>>
>> I'm not sure why you are annotating your queryset without referring to it 
>> in
>> a filter clause later on but the ORM cannot simply ignore it when you are
>> performing your `count()` because some annotations could interfere with 
>> grouping
>> somehow.
>>
>> There is an open ticket[0] to add support for an `alias()` method that 
>> would
>> allow the ORM to clear/ignore the specified expressions if it's not 
>> referenced
>> in the query.
>>
>> In the mean time I think the best approach would be to avoid annotating 
>> the
>> queryset if your don't need to reference the score.
>>
>> Cheers,
>> Simon
>>
>> [0] https://code.djangoproject.com/ticket/27719
>>
>> Le mardi 21 novembre 2017 08:46:21 UTC-5, Cristiano Coelho a écrit :
>>>
>>> Hmm, should I try with the dev mailing list? Guess it's something no one 
>>> faced before?
>>>
>>> El martes, 14 de noviembre de 2017, 22:54:23 (UTC-3), Cristiano Coelho 
>>> escribió:
>>>>
>>>> I'm getting some very odd query when combining annotate with count. See 
>>>> the following:
>>>>
>>>> >>> q = 
>>>>> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
>>>>> >>> q.count()
>>>>> 3094
>>>>> >>> print connection.queries[-1]
>>>>> 'SELECT COUNT(*) 
>>>>> FROM (
>>>>> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
>>>>> custom_word_similarity(\'test\', 
>>>>> "vulnerabilities_vulnerability"."summary") 
>>>>> AS "score" 
>>>>> FROM "vulnerabilities_vulnerability" 
>>>>> GROUP BY "vulnerabilities_vulnerability"."id", 
>>>>> custom_word_similarity(\'test\', 
>>>>> "vulnerabilities_vulnerability"."summary")
>>>>> ) subquery
>>>>> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
>>>>> >>> q2.count()
>>>>> 33
>>>>> >>> print

Re: Strange query when using annotate and count

2017-11-23 Thread Cristiano Coelho
Hello Simon, thanks for the response.

The above code is just an example, the reason behind the annotate because 
there's some complicated code that builds a queryset and annotates it so it 
can easily be reused. It works fine 99% of the time except when there's a 
count involved and it ends up being redundant. The solution would be to not 
annotate anything and replace the code in multiple places to add the 
annotate call (or similar using a custom queryset or manager I guess), but 
that's quite painful and will end up with a lot of duplicated code since 
there's also an order_by that follows the annotate that needs to be moved 
over as well

Isn't there a way (even if it's hackish) to simply clear the annotations 
(and order by)? I know querysets are smart enough to not include the order 
by clause if there's a count.

You could also suggest using two separate calls or a flag to pass down to 
the internal code so it doesn't include the additional stuff, but that 
wouldn't work since paginators accept only one query set for example and 
internall uses it for both count and results.



El viernes, 24 de noviembre de 2017, 0:05:29 (UTC-3), Simon Charette 
escribió:
>
> Hello Cristiano,
>
> I understand your frustration but please avoid using the developer mailing 
> list
> as a second tier support channel. I suggest you try the IRC #django 
> channel if
> you need to want to get faster support.
>
> What's happening here is that annotate() really means "select this field" 
> while
> in your other case you use a lookup (summary__icontains) which are only 
> going to
> be added to the WHERE clause of your query.
>
> I'm not sure why you are annotating your queryset without referring to it 
> in
> a filter clause later on but the ORM cannot simply ignore it when you are
> performing your `count()` because some annotations could interfere with 
> grouping
> somehow.
>
> There is an open ticket[0] to add support for an `alias()` method that 
> would
> allow the ORM to clear/ignore the specified expressions if it's not 
> referenced
> in the query.
>
> In the mean time I think the best approach would be to avoid annotating the
> queryset if your don't need to reference the score.
>
> Cheers,
> Simon
>
> [0] https://code.djangoproject.com/ticket/27719
>
> Le mardi 21 novembre 2017 08:46:21 UTC-5, Cristiano Coelho a écrit :
>>
>> Hmm, should I try with the dev mailing list? Guess it's something no one 
>> faced before?
>>
>> El martes, 14 de noviembre de 2017, 22:54:23 (UTC-3), Cristiano Coelho 
>> escribió:
>>>
>>> I'm getting some very odd query when combining annotate with count. See 
>>> the following:
>>>
>>> >>> q = 
>>>> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
>>>> >>> q.count()
>>>> 3094
>>>> >>> print connection.queries[-1]
>>>> 'SELECT COUNT(*) 
>>>> FROM (
>>>> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
>>>> custom_word_similarity(\'test\', 
>>>> "vulnerabilities_vulnerability"."summary") 
>>>> AS "score" 
>>>> FROM "vulnerabilities_vulnerability" 
>>>> GROUP BY "vulnerabilities_vulnerability"."id", 
>>>> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary")
>>>> ) subquery
>>>> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
>>>> >>> q2.count()
>>>> 33
>>>> >>> print connection.queries[-1]
>>>> 'SELECT COUNT(*) AS "__count" 
>>>> FROM "vulnerabilities_vulnerability" 
>>>> WHERE UPPER("vulnerabilities_vulnerability"."summary"::text) LIKE 
>>>> UPPER(\'%test%\')
>>>
>>>
>>>
>>> Custom function code, is this what's causing the odd count behavior? Did 
>>> I miss anything?
>>>
>>> class WordTrigramCustomSimilarity(Func):
>>>> function = 'custom_word_similarity' 
>>>> def __init__(self, string, expression, **extra):
>>>> if not hasattr(string, 'resolve_expression'):
>>>> string = Value(string)
>>>> super(WordTrigramCustomSimilarity, self).__init__(string, 
>>>> expression, output_field=FloatField(), **extra)
>>>
>>>
>>> I would expect for the query to be a simple count, rather than a nested 
>>> query with a useless group by (correct me if I'm wrong).

Re: Strange query when using annotate and count

2017-11-23 Thread Simon Charette
Hello Cristiano,

I understand your frustration but please avoid using the developer mailing 
list
as a second tier support channel. I suggest you try the IRC #django channel 
if
you need to want to get faster support.

What's happening here is that annotate() really means "select this field" 
while
in your other case you use a lookup (summary__icontains) which are only 
going to
be added to the WHERE clause of your query.

I'm not sure why you are annotating your queryset without referring to it in
a filter clause later on but the ORM cannot simply ignore it when you are
performing your `count()` because some annotations could interfere with 
grouping
somehow.

There is an open ticket[0] to add support for an `alias()` method that would
allow the ORM to clear/ignore the specified expressions if it's not 
referenced
in the query.

In the mean time I think the best approach would be to avoid annotating the
queryset if your don't need to reference the score.

Cheers,
Simon

[0] https://code.djangoproject.com/ticket/27719

Le mardi 21 novembre 2017 08:46:21 UTC-5, Cristiano Coelho a écrit :
>
> Hmm, should I try with the dev mailing list? Guess it's something no one 
> faced before?
>
> El martes, 14 de noviembre de 2017, 22:54:23 (UTC-3), Cristiano Coelho 
> escribió:
>>
>> I'm getting some very odd query when combining annotate with count. See 
>> the following:
>>
>> >>> q = 
>>> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
>>> >>> q.count()
>>> 3094
>>> >>> print connection.queries[-1]
>>> 'SELECT COUNT(*) 
>>> FROM (
>>> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
>>> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary") 
>>> AS "score" 
>>> FROM "vulnerabilities_vulnerability" 
>>> GROUP BY "vulnerabilities_vulnerability"."id", 
>>> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary")
>>> ) subquery
>>> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
>>> >>> q2.count()
>>> 33
>>> >>> print connection.queries[-1]
>>> 'SELECT COUNT(*) AS "__count" 
>>> FROM "vulnerabilities_vulnerability" 
>>> WHERE UPPER("vulnerabilities_vulnerability"."summary"::text) LIKE 
>>> UPPER(\'%test%\')
>>
>>
>>
>> Custom function code, is this what's causing the odd count behavior? Did 
>> I miss anything?
>>
>> class WordTrigramCustomSimilarity(Func):
>>> function = 'custom_word_similarity' 
>>> def __init__(self, string, expression, **extra):
>>> if not hasattr(string, 'resolve_expression'):
>>> string = Value(string)
>>> super(WordTrigramCustomSimilarity, self).__init__(string, 
>>> expression, output_field=FloatField(), **extra)
>>
>>
>> I would expect for the query to be a simple count, rather than a nested 
>> query with a useless group by (correct me if I'm wrong).
>> The issue gets even worse if the function is expensive, since it gets 
>> called when it's not needed at all, more than once.
>> Also the issue behaves pretty much the same if the queryset includes 
>> filtering and ordering but I didn't include it here for simplicity.
>>
>> Using Django 1.11.7 + postgres (psycopg) backend.
>>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8348886-0a8b-46e0-8bd5-46597ba87408%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange query when using annotate and count

2017-11-21 Thread Cristiano Coelho
Hmm, should I try with the dev mailing list? Guess it's something no one 
faced before?

El martes, 14 de noviembre de 2017, 22:54:23 (UTC-3), Cristiano Coelho 
escribió:
>
> I'm getting some very odd query when combining annotate with count. See 
> the following:
>
> >>> q = 
>> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
>> >>> q.count()
>> 3094
>> >>> print connection.queries[-1]
>> 'SELECT COUNT(*) 
>> FROM (
>> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
>> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary") 
>> AS "score" 
>> FROM "vulnerabilities_vulnerability" 
>> GROUP BY "vulnerabilities_vulnerability"."id", 
>> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary")
>> ) subquery
>> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
>> >>> q2.count()
>> 33
>> >>> print connection.queries[-1]
>> 'SELECT COUNT(*) AS "__count" 
>> FROM "vulnerabilities_vulnerability" 
>> WHERE UPPER("vulnerabilities_vulnerability"."summary"::text) LIKE 
>> UPPER(\'%test%\')
>
>
>
> Custom function code, is this what's causing the odd count behavior? Did I 
> miss anything?
>
> class WordTrigramCustomSimilarity(Func):
>>     function = 'custom_word_similarity' 
>> def __init__(self, string, expression, **extra):
>> if not hasattr(string, 'resolve_expression'):
>> string = Value(string)
>> super(WordTrigramCustomSimilarity, self).__init__(string, 
>> expression, output_field=FloatField(), **extra)
>
>
> I would expect for the query to be a simple count, rather than a nested 
> query with a useless group by (correct me if I'm wrong).
> The issue gets even worse if the function is expensive, since it gets 
> called when it's not needed at all, more than once.
> Also the issue behaves pretty much the same if the queryset includes 
> filtering and ordering but I didn't include it here for simplicity.
>
> Using Django 1.11.7 + postgres (psycopg) backend.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b6e37c84-c09d-4486-af8a-e23c399cf975%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Strange query when using annotate and count

2017-11-14 Thread Cristiano Coelho
I'm getting some very odd query when combining annotate with count. See the 
following:

>>> q = 
> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
> >>> q.count()
> 3094
> >>> print connection.queries[-1]
> 'SELECT COUNT(*) 
> FROM (
> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary") 
> AS "score" 
> FROM "vulnerabilities_vulnerability" 
> GROUP BY "vulnerabilities_vulnerability"."id", 
> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary")
> ) subquery
> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
> >>> q2.count()
> 33
> >>> print connection.queries[-1]
> 'SELECT COUNT(*) AS "__count" 
> FROM "vulnerabilities_vulnerability" 
> WHERE UPPER("vulnerabilities_vulnerability"."summary"::text) LIKE 
> UPPER(\'%test%\')



Custom function code, is this what's causing the odd count behavior? Did I 
miss anything?

class WordTrigramCustomSimilarity(Func):
> function = 'custom_word_similarity' 
> def __init__(self, string, expression, **extra):
> if not hasattr(string, 'resolve_expression'):
> string = Value(string)
> super(WordTrigramCustomSimilarity, self).__init__(string, 
> expression, output_field=FloatField(), **extra)


I would expect for the query to be a simple count, rather than a nested 
query with a useless group by (correct me if I'm wrong).
The issue gets even worse if the function is expensive, since it gets 
called when it's not needed at all, more than once.
Also the issue behaves pretty much the same if the queryset includes 
filtering and ordering but I didn't include it here for simplicity.

Using Django 1.11.7 + postgres (psycopg) backend.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a8ef80d5-26a5-40b4-b2b1-5cbf3bfa8c64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Server side paging..How to sent the count of items??

2017-09-26 Thread Rakhee Menon
Hi ,

I was trying to do server side paging and wanted to send the totalcount of 
items along with itemPerPage..I have attached my code.Can anyone suggest 
how to do it??

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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e44fbb8-b4c7-47f5-b853-642608995e56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: count the selected chechboxes in multipleselectfield

2017-07-05 Thread elloy


On Wednesday, July 5, 2017 at 3:59:41 PM UTC+3, bob gailer wrote:
>
> On Jul 5, 2017 6:55 AM, "elloy" <eleni...@gmail.com > wrote:
> >
> > I need your help with a problem I'm trying to solve
> > I'm making a questionnaire and I have to count the selected choices that 
> the user have checked in a certain question with 5 possible answers(choices)
> > The model I'm using is:
> >
> > class Reuse(models.Model):
> > REUSE_OPTIONS = (
> > ('1', 'first choice'),
> > ('2', 'second choice'),
> > ('3', 'third choice'),
> > ('4', 'fourth choice'),
> > ('5', 'none of the above'),
> > )
> > 
> > user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, 
> blank=True)
> > reuse = MultiSelectField(max_length=250, choices= REUSE_OPTIONS, 
> max_choices=4, null=True)
> > m = models.DecimalField(max_digits=5, decimal_places=3, default=0) 
> > numchoices = models.IntegerField()
> I am not an expert in Django, but I will point out some problems. You just 
> made an assignment to numchoices, then you redefine numchoices in the next 
> line.
> > def numchoices(self):   (I tried 
> this but it didn't work)
> Telling us it didn't work is not helpful. You need to be much more 
> explicit. What led you to say this didn't work?
> > self.choices_count = self.choice_set.count()
> What are choices_count any choice_set?
> > self.save()
> >
> > I wrote this view: 
> > def reuse (request):
> > if request.method == "POST":
> > form = ReuseForm(request.POST)
> > if form.is_valid():
> > reuse = form.save(commit=False)
> ># if reuse.get_choices.count() == 1 : reuse.m=0.075
> (this doesn't work either)
> >   #  elif reuse.get_choices.count() == 2 : reuse.m=0.15
> ># elif reuse.get_choices.count() == 3 : reuse.m=0.225
> >  #   elif reuse.get_choices.count() == 4 : reuse.m=0.3 
> Rather than calling the method so many times it's better to call it once 
> and assign the result to a variable. Also in this case you can compute m 
> from the count
> > reuse.save()
> > return redirect('../22')
> > else:
> > form = ReuseForm()
> > return render(request, 'questionnaire/reuse.html', {'form':form})
> >
> > And the form I'm using is:
> >
> > class ReuseForm(forms.ModelForm):
> >
> > class Meta:
> > model = Reuse
> > fields = ('reuse',)
> >  
> > Please, have you got any suggestions; 
> By the way I don't know what the effect is of defining a function in a 
> model. Someone else will have to deal with that. I suggest you fix problems 
> I've pointed out run the program tell us exactly what goes wrong and where
> >
>
I tried to make the changes you suggested like this:
models.py:
class Reuse(models.Model):
REUSE_OPTIONS = (
 ('1', 'first choice'),
 ('2', 'second choice'),
 ('3', 'third choice'),
 ('4', 'fourth choice'),
 ('5', 'none of the above'),
 )
   
 user = models.ForeignKey(settings.

AUTH_USER_MODEL, null=True, blank=True)
 reuse = MultiSelectField(max_length=250, choices= REUSE_OPTIONS, 
max_choices=4, null=True)
 m = models.DecimalField(max_digits=5, decimal_places=3, default=0) 


views.py:

def reuse (request):
if request.method == "POST":
form = ReuseForm(request.POST)
if form.is_valid():
reuse = form.save(commit=False)
q = reuse.get_choices.count() 
if q == 1 : reuse.m=0.075
elif q == 2 : reuse.m=0.15
elif q == 3 : reuse.m=0.225
elif q == 4 : reuse.m=0.3 
reuse.save()
return redirect('../22')
else:
form = ReuseForm()
return render(request, '../reuse.html', {'form':form})

 The error I get is the following:

>
>
> Exception Type: AttributeError 
> Exception Value: 
>
> 'Reuse' object has no attribute 'get_choices'
>
>
I' m trying to find an attribute of the multiselectfield or a  filter that 
will return the number of the selected checkboxes, every time a user answer 
the question.
Thank you very much for your support

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45f343ee-5d2a-4f1b-8bbf-582d60df0911%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: count the selected chechboxes in multipleselectfield

2017-07-05 Thread Bob Gailer
On Jul 5, 2017 6:55 AM, "elloy" <elenilou...@gmail.com> wrote:
>
> I need your help with a problem I'm trying to solve
> I'm making a questionnaire and I have to count the selected choices that
the user have checked in a certain question with 5 possible answers(choices)
> The model I'm using is:
>
> class Reuse(models.Model):
> REUSE_OPTIONS = (
> ('1', 'first choice'),
> ('2', 'second choice'),
> ('3', 'third choice'),
> ('4', 'fourth choice'),
> ('5', 'none of the above'),
> )
>
> user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True,
blank=True)
> reuse = MultiSelectField(max_length=250, choices= REUSE_OPTIONS,
max_choices=4, null=True)
> m = models.DecimalField(max_digits=5, decimal_places=3, default=0)
> numchoices = models.IntegerField()
I am not an expert in Django, but I will point out some problems. You just
made an assignment to numchoices, then you redefine numchoices in the next
line.
> def numchoices(self):   (I tried
this but it didn't work)
Telling us it didn't work is not helpful. You need to be much more
explicit. What led you to say this didn't work?
> self.choices_count = self.choice_set.count()
What are choices_count any choice_set?
> self.save()
>
> I wrote this view:
> def reuse (request):
> if request.method == "POST":
> form = ReuseForm(request.POST)
> if form.is_valid():
> reuse = form.save(commit=False)
># if reuse.get_choices.count() == 1 : reuse.m=0.075
(this doesn't work either)
>   #  elif reuse.get_choices.count() == 2 : reuse.m=0.15
># elif reuse.get_choices.count() == 3 : reuse.m=0.225
>  #   elif reuse.get_choices.count() == 4 : reuse.m=0.3
Rather than calling the method so many times it's better to call it once
and assign the result to a variable. Also in this case you can compute m
from the count
> reuse.save()
> return redirect('../22')
> else:
> form = ReuseForm()
> return render(request, 'questionnaire/reuse.html', {'form':form})
>
> And the form I'm using is:
>
> class ReuseForm(forms.ModelForm):
>
> class Meta:
> model = Reuse
> fields = ('reuse',)
>
> Please, have you got any suggestions;
By the way I don't know what the effect is of defining a function in a
model. Someone else will have to deal with that. I suggest you fix problems
I've pointed out run the program tell us exactly what goes wrong and where
>
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/ca1f528d-903a-428f-b781-6506dff69e0f%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP1rxO4koSXY--T3eCjmTMtNrHDLkxsoXYS-3hCm-znovwAeWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


count the selected chechboxes in multipleselectfield

2017-07-05 Thread elloy
I need your help with a problem I'm trying to solve
I'm making a questionnaire and I have to count the selected choices that 
the user have checked in a certain question with 5 possible answers(choices)
The model I'm using is:

class Reuse(models.Model):
REUSE_OPTIONS = (
('1', 'first choice'),
('2', 'second choice'),
('3', 'third choice'),
('4', 'fourth choice'),
('5', 'none of the above'),
)

user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, 
blank=True)
reuse = MultiSelectField(max_length=250, choices= REUSE_OPTIONS, 
max_choices=4, null=True)
m = models.DecimalField(max_digits=5, decimal_places=3, default=0) 
numchoices = models.IntegerField()
def numchoices(self):   (I tried 
this but it didn't work)
self.choices_count = self.choice_set.count()
self.save()

I wrote this view: 
def reuse (request):
if request.method == "POST":
form = ReuseForm(request.POST)
if form.is_valid():
reuse = form.save(commit=False)
   # if reuse.get_choices.count() == 1 : reuse.m=0.075(this 
doesn't work either)
  #  elif reuse.get_choices.count() == 2 : reuse.m=0.15
   # elif reuse.get_choices.count() == 3 : reuse.m=0.225
 #   elif reuse.get_choices.count() == 4 : reuse.m=0.3 
reuse.save()
return redirect('../22')
else:
form = ReuseForm()
return render(request, 'questionnaire/reuse.html', {'form':form})

And the form I'm using is:

class ReuseForm(forms.ModelForm):

class Meta:
model = Reuse
fields = ('reuse',)
 
Please, have you got any suggestions; 



-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca1f528d-903a-428f-b781-6506dff69e0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


count the selected checkboxes in a multipleselectfield

2017-07-05 Thread elloy
Please, I need your help because I'm trying to solve a problem
I'm making a questionnaire and I want to count the number of the selected 
choices in a certain question 
The model I'm using is:

class Reuse(models.Model):
REUSE_OPTIONS = (
('1', 'first choice'),
('2', 'second choice'),
('3', 'third choice'),
('4', 'fourth choice'),
('5', 'none of the above'),
)

user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, 
blank=True)
reuse = MultiSelectField(max_length=250, choices= REUSE_OPTIONS, 
max_choices=4, null=True)
m = models.DecimalField(max_digits=5, decimal_places=3, default=0)
numchoices = models.IntegerField()
def numchoices(self):   (I 
tried this but it didn't work)
self.choices_count = self.choice_set.count()
self.save()

 I wrote this view:


def reuse (request):
if request.method == "POST":
form = ReuseForm(request.POST)
if form.is_valid():
reuse = form.save(commit=False)
   # if reuse.get_choices.count() == 1 : reuse.m=0.075  
(this doesn't work either)
  #  elif reuse.get_choices.count() == 2 : reuse.m=0.15
   # elif reuse.get_choices.count() == 3 : reuse.m=0.225
 #   elif reuse.get_choices.count() == 4 : reuse.m=0.3 
reuse.save()
return redirect('../22')
else:
form = ReuseForm()
return render(request, '../reuse.html', {'form':form})

And the form I'm using is:

class ReuseForm(forms.ModelForm):

class Meta:
model = Reuse
fields = ('reuse',)

 Please, have you got any suggestions;
Thank you 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f33f6258-9479-4da1-8c3c-402792da921d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: count from multiple tables in a single query?

2017-06-01 Thread Melvyn Sopacua
On Wednesday 31 May 2017 12:13:48 'Abraham Varricatt' via Django users 
wrote:

> If I want to get the total count from both tables it can be done like
> this,
> 
> author_count = Author.objects.count()
> publisher_count = Publisher.objects.count()
> 
> My concern is that this results in two different queries to the
> database. Can it be done with a single query call?

Why is that a concern? This isn't the kind of thing to optimize. Query 
optimization is about loops and relations. Not about getting information 
you need - it comes at a price. Have you timed what you could save?
-- 
Melvyn Sopacua

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3906536.yyyTSluoAH%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: count from multiple tables in a single query?

2017-05-31 Thread James Schneider
On Wed, May 31, 2017 at 3:01 PM, Alceu Rodrigues de Freitas Junior <
alceu.freitas...@gmail.com> wrote:

> Hi James,
>
> I'm curious... why dropping down from the ORM and doing a single query
> wouldn't be portable?
>
> I understand that it would happen if you use some kind of stored procedure
> in the DB, but I guess a single ANSI SQL would do it.
>
> Thanks!
>
> - Alceu
>

I might have painted that statement with too broad of a brush, but the
underlying intention is correct. Sticking with the ORM ensures consistent
behavior across all supported database backends. In the case of a simple
COUNT(*) query, even with multiple tables involved, the SQL statement is
likely portable across any of the included backends.

My intention was to say that using the ORM will better guarantee that the
call is portable, not necessarily saying that raw SQL cannot or would not
be. Of course, many queries can be made that would work in any
SQL-compliant RDBMS.

At any rate, a quick Google showed that the OP is likely stuck with two
queries anyway. The SO posts, etc. show sub-SELECT statements in use in
order to get the result returned as a single data set.

-James

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVGXcWG65%2BGz3%3DoVP4c6YeZM8rPcorFjhe-S_xOGMytZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: count from multiple tables in a single query?

2017-05-31 Thread Alceu Rodrigues de Freitas Junior

Hi James,

I'm curious... why dropping down from the ORM and doing a single query 
wouldn't be portable?


I understand that it would happen if you use some kind of stored 
procedure in the DB, but I guess a single ANSI SQL would do it.


Thanks!

- Alceu


Em 31/05/2017 17:29, James Schneider escreveu:



If I want to get the total count from both tables it can be done
like this,

|
author_count =Author.objects.count()
publisher_count =Publisher.objects.count()
|

My concern is that this results in two different queries to the
database. Can it be done with a single query call?



Probably not with the standard ORM and the model setup you provided 
with no relation between the tables. You'll likely have to drop down 
to raw SQL. I'd do testing. I doubt you'll have much of a performance 
gain by combining the two queries in to one since you are just doing a 
count and both tables have unique indexes, aside from saving the 
overhead of one SQL call (not the actual query itself). Two calls 
would keep the code simple and portable, which to me is more important 
than a marginal gain in performance.


-James
--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVxVrzLuF7ASWiC34A2MenWvJd3P1GXsP%2Bi-mYQ9FuVvg%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVxVrzLuF7ASWiC34A2MenWvJd3P1GXsP%2Bi-mYQ9FuVvg%40mail.gmail.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/657e58a2-411c-8e8b-0475-4537417d3488%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: count from multiple tables in a single query?

2017-05-31 Thread 'Abraham Varricatt' via Django users
Hello James/Matthew,

I was afraid to hear that. The models are unrelated and I do not want to 
take the trouble of dropping out of the ORM. Since it's a web-service I'm 
building, a work-around is to cache results, but I was challenged to find a 
single DB call solution and wanted to be sure that it wouldn't be possible 
with the ORM. 

Thanks for replying!

Looking into caches,
Abraham V.


On Wednesday, 31 May 2017 16:31:04 UTC-4, Matthew Pava wrote:
>
> Hi Abraham,
>
> If the models are related, you can use double underscore notation with the 
> Count aggregate function.
>
> If the models are unrelated, then I’m fairly certain that you can only use 
> separate queries to get your results.
>
>  
>
>  
>
> *From:* 'Abraham Varricatt' via Django users [mailto:
> django...@googlegroups.com ] 
> *Sent:* Wednesday, May 31, 2017 2:14 PM
> *To:* Django users
> *Subject:* count from multiple tables in a single query?
>
>  
>
> Hello,
>
> Is it possible to get the count of entries from multiple tables in a 
> single query call? I'm looking at the official docs on aggregation and I 
> can't find anything. For example assume I have the following 2 tables,
>
> *class* *Author*(models.Model):
> name = models.CharField(max_length=100)
> age = models.IntegerField()
>
> *class* *Publisher*(models.Model):
> name = models.CharField(max_length=300)
> num_awards = models.IntegerField()
>
>
> If I want to get the total count from both tables it can be done like this,
>
> author_count = Author.objects.count()
> publisher_count = Publisher.objects.count()
>
>
> My concern is that this results in two different queries to the database. 
> Can it be done with a single query call?
>
>
> Yours,
> Abraham V.
>
> -- 
> 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 post to this group, send email to djang...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b99f473-0ea3-4d0a-acd2-08b05c96d687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: count from multiple tables in a single query?

2017-05-31 Thread Matthew Pava
Hi Abraham,
If the models are related, you can use double underscore notation with the 
Count aggregate function.
If the models are unrelated, then I’m fairly certain that you can only use 
separate queries to get your results.


From: 'Abraham Varricatt' via Django users 
[mailto:django-users@googlegroups.com]
Sent: Wednesday, May 31, 2017 2:14 PM
To: Django users
Subject: count from multiple tables in a single query?

Hello,

Is it possible to get the count of entries from multiple tables in a single 
query call? I'm looking at the official docs on aggregation and I can't find 
anything. For example assume I have the following 2 tables,

class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()

class Publisher(models.Model):
name = models.CharField(max_length=300)
num_awards = models.IntegerField()

If I want to get the total count from both tables it can be done like this,
author_count = Author.objects.count()
publisher_count = Publisher.objects.count()

My concern is that this results in two different queries to the database. Can 
it be done with a single query call?


Yours,
Abraham V.
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com<https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/313a8f9ff1f64f12929ff6368a6fa190%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: count from multiple tables in a single query?

2017-05-31 Thread James Schneider
>
>
> If I want to get the total count from both tables it can be done like this,
>
> author_count = Author.objects.count()
> publisher_count = Publisher.objects.count()
>
> My concern is that this results in two different queries to the database.
> Can it be done with a single query call?
>
>

Probably not with the standard ORM and the model setup you provided with no
relation between the tables. You'll likely have to drop down to raw SQL.
I'd do testing. I doubt you'll have much of a performance gain by combining
the two queries in to one since you are just doing a count and both tables
have unique indexes, aside from saving the overhead of one SQL call (not
the actual query itself). Two calls would keep the code simple and
portable, which to me is more important than a marginal gain in performance.

-James

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVxVrzLuF7ASWiC34A2MenWvJd3P1GXsP%2Bi-mYQ9FuVvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


count from multiple tables in a single query?

2017-05-31 Thread 'Abraham Varricatt' via Django users
Hello,

Is it possible to get the count of entries from multiple tables in a single 
query call? I'm looking at the official docs on aggregation and I can't 
find anything. For example assume I have the following 2 tables,

class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()

class Publisher(models.Model):
name = models.CharField(max_length=300)
num_awards = models.IntegerField()


If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count = Publisher.objects.count()

My concern is that this results in two different queries to the database. 
Can it be done with a single query call?


Yours,
Abraham V.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice: count hits/pageview for high traffic website

2017-03-08 Thread carlos
ludovic and Vijay i need put in index page sidebar the most visits or
popular page that people saw, you understand me?

Thank ludovic I'm going to read about piwik maybe help me.

Cheers

On Wed, Mar 8, 2017 at 6:38 AM, Vijay Khemlani <vkhem...@gmail.com> wrote:

> Maybe I'm missing something, but why not Google Analytics?
>
> On 3/8/17, ludovic coues <cou...@gmail.com> wrote:
> > Have you looked at an analytics solution like piwik ?
> >
> > 2017-03-08 6:40 GMT+01:00 carlos <crocha09...@gmail.com>:
> >> Daniel, no i say i used django for a website with high traffic maybe 70k
> >> per
> >> days, but i need count visit page like
> >> django-hitocunts but the problems like django-hitcount is not for a
> >> website
> >> high traffic, the database is very slow ans the website down
> >>
> >> my question is exist any method, third party app like django-hitcount
> but
> >> for site very high traffic Or some idea to do that?
> >>
> >> cheers
> >>
> >> On Tue, Mar 7, 2017 at 6:04 PM, Daniel Bess <db...@endocrypt.com>
> wrote:
> >>>
> >>> Hi Carlos,
> >>>
> >>> You email is a little unclear.  Are you suggesting I should not use
> >>> Django
> >>> for a web backend?
> >>>
> >>> Let me know!
> >>>
> >>> Thanks,
> >>>
> >>> Daniel
> >>>
> >>> On Mar 7, 2017, at 3:38 PM, carlos <crocha09...@gmail.com> wrote:
> >>>
> >>> Hi,
> >>> i try used django-hitcount but really not for website high traffic
> >>> any advice for count visits/hits page for 60k or 100k  traffic for day
> >>>
> >>> thank any idea, link or whatever helps
> >>>
> >>> --
> >>> 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 post to this group, send email to django-users@googlegroups.com.
> >>> Visit this group at https://groups.google.com/group/django-users.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/django-users/CAM-
> 7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com.
> >>> For more options, visit https://groups.google.com/d/optout.
> >>>
> >>>
> >>> --
> >>> 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 post to this group, send email to django-users@googlegroups.com.
> >>> Visit this group at https://groups.google.com/group/django-users.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/django-users/C1AB7BB4-
> BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com.
> >>>
> >>> For more options, visit https://groups.google.com/d/optout.
> >>
> >>
> >>
> >>
> >> --
> >> 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 post to this group, send email to django-users@googlegroups.com.
> >> Visit this group at https://groups.google.com/group/django-users.
> >> To view this discussion on the web visit
> >> https://groups.google.com/d/msgid/django-users/CAM-7rO27%
> 2B8aWAwrAstsvffPBFk%3DTcq29VURG_%2BbX4HdUerOTcQ%40mail.gmail.com.
> >>
> >> For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> >
> > Cordialement, Coues Ludovic
> > +336 148 743 42
> >
> > --
> > 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-us

Re: Advice: count hits/pageview for high traffic website

2017-03-08 Thread Vijay Khemlani
Maybe I'm missing something, but why not Google Analytics?

On 3/8/17, ludovic coues <cou...@gmail.com> wrote:
> Have you looked at an analytics solution like piwik ?
>
> 2017-03-08 6:40 GMT+01:00 carlos <crocha09...@gmail.com>:
>> Daniel, no i say i used django for a website with high traffic maybe 70k
>> per
>> days, but i need count visit page like
>> django-hitocunts but the problems like django-hitcount is not for a
>> website
>> high traffic, the database is very slow ans the website down
>>
>> my question is exist any method, third party app like django-hitcount but
>> for site very high traffic Or some idea to do that?
>>
>> cheers
>>
>> On Tue, Mar 7, 2017 at 6:04 PM, Daniel Bess <db...@endocrypt.com> wrote:
>>>
>>> Hi Carlos,
>>>
>>> You email is a little unclear.  Are you suggesting I should not use
>>> Django
>>> for a web backend?
>>>
>>> Let me know!
>>>
>>> Thanks,
>>>
>>> Daniel
>>>
>>> On Mar 7, 2017, at 3:38 PM, carlos <crocha09...@gmail.com> wrote:
>>>
>>> Hi,
>>> i try used django-hitcount but really not for website high traffic
>>> any advice for count visits/hits page for 60k or 100k  traffic for day
>>>
>>> thank any idea, link or whatever helps
>>>
>>> --
>>> 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 post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> 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 post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/C1AB7BB4-BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAM-7rO27%2B8aWAwrAstsvffPBFk%3DTcq29VURG_%2BbX4HdUerOTcQ%40mail.gmail.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEuG%2BTY4vp5A14t2nH3VwoOf_sOB8d3CFUTQEtB1kwi1p0a5Fw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei358ivGswC1%3DWx%3D_VmSCjjbMvadR6GLiTnZt_%3DaBiu3EA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice: count hits/pageview for high traffic website

2017-03-08 Thread ludovic coues
Have you looked at an analytics solution like piwik ?

2017-03-08 6:40 GMT+01:00 carlos <crocha09...@gmail.com>:
> Daniel, no i say i used django for a website with high traffic maybe 70k per
> days, but i need count visit page like
> django-hitocunts but the problems like django-hitcount is not for a website
> high traffic, the database is very slow ans the website down
>
> my question is exist any method, third party app like django-hitcount but
> for site very high traffic Or some idea to do that?
>
> cheers
>
> On Tue, Mar 7, 2017 at 6:04 PM, Daniel Bess <db...@endocrypt.com> wrote:
>>
>> Hi Carlos,
>>
>> You email is a little unclear.  Are you suggesting I should not use Django
>> for a web backend?
>>
>> Let me know!
>>
>> Thanks,
>>
>> Daniel
>>
>> On Mar 7, 2017, at 3:38 PM, carlos <crocha09...@gmail.com> wrote:
>>
>> Hi,
>> i try used django-hitcount but really not for website high traffic
>> any advice for count visits/hits page for 60k or 100k  traffic for day
>>
>> thank any idea, link or whatever helps
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/C1AB7BB4-BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAM-7rO27%2B8aWAwrAstsvffPBFk%3DTcq29VURG_%2BbX4HdUerOTcQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTY4vp5A14t2nH3VwoOf_sOB8d3CFUTQEtB1kwi1p0a5Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice: count hits/pageview for high traffic website

2017-03-07 Thread carlos
Daniel, no i say i used django for a website with high traffic maybe 70k
per days, but i need count visit page like
django-hitocunts but the problems like django-hitcount is not for a website
high traffic, the database is very slow ans the website down

my question is exist any method, third party app like django-hitcount but
for site very high traffic Or some idea to do that?

cheers

On Tue, Mar 7, 2017 at 6:04 PM, Daniel Bess <db...@endocrypt.com> wrote:

> Hi Carlos,
>
> You email is a little unclear.  Are you suggesting I should not use Django
> for a web backend?
>
> Let me know!
>
> Thanks,
>
> Daniel
>
> On Mar 7, 2017, at 3:38 PM, carlos <crocha09...@gmail.com> wrote:
>
> Hi,
> i try used django-hitcount but really not for website high traffic
> any advice for count visits/hits page for 60k or 100k  traffic for day
>
> thank any idea, link or whatever helps
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp
> 3i2YtnFO5U-oGgbLQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/C1AB7BB4-BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com
> <https://groups.google.com/d/msgid/django-users/C1AB7BB4-BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO27%2B8aWAwrAstsvffPBFk%3DTcq29VURG_%2BbX4HdUerOTcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice: count hits/pageview for high traffic website

2017-03-07 Thread Daniel Bess
Hi Carlos,

You email is a little unclear.  Are you suggesting I should not use Django for 
a web backend?

Let me know!

Thanks,

Daniel

> On Mar 7, 2017, at 3:38 PM, carlos <crocha09...@gmail.com> wrote:
> 
> Hi,
> i try used django-hitcount but really not for website high traffic
> any advice for count visits/hits page for 60k or 100k  traffic for day
> 
> thank any idea, link or whatever helps
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com?utm_medium=email_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C1AB7BB4-BBA6-4156-9826-6C68EE71DF1F%40endocrypt.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice: count hits/pageview for high traffic website

2017-03-07 Thread Shawn Milochik
On Tue, Mar 7, 2017 at 6:38 PM, carlos <crocha09...@gmail.com> wrote:

> Hi,
> i try used django-hitcount but really not for website high traffic
> any advice for count visits/hits page for 60k or 100k  traffic for day
>
> thank any idea, link or whatever helps
>
>
My vote would be for something that uses Redis, or something written in Go.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOzwKwFiaxKa6U1p0G_hA8qDynA3Eib53MgCH0jOdip%2BPTTMBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Advice: count hits/pageview for high traffic website

2017-03-07 Thread carlos
Hi,
i try used django-hitcount but really not for website high traffic
any advice for count visits/hits page for 60k or 100k  traffic for day

thank any idea, link or whatever helps

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO1eRU8kNrbq1J9fmO1yTvEnqbhKp3i2YtnFO5U-oGgbLQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

2017-01-11 Thread Vijay Khemlani
gt; >  'dashboard.users',
>> >  'dashboard.vouchers',
>> >  'purl')
>> > Installed Middleware:
>> > ('django.contrib.sessions.middleware.SessionMiddleware',
>> >  'django.middleware.common.CommonMiddleware',
>> >  'django.middleware.csrf.CsrfViewMiddleware',
>> >  'django.contrib.auth.middleware.AuthenticationMiddleware',
>> >  'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
>> >  'django.contrib.messages.middleware.MessageMiddleware',
>> >  'django.middleware.clickjacking.XFrameOptionsMiddleware',
>> >  'django.middleware.security.SecurityMiddleware',
>> >  'basket.middleware.BasketMiddleware',
>> >  'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')
>> >
>> > Traceback:
>> > File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
>> > get_response
>> >   132. response = wrapped_callback(request,
>> > *callback_args, **callback_kwargs)
>> > File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py"
>> in
>> > _wrapped_view
>> >   22. return view_func(request, *args, **kwargs)
>> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in
>> view
>> >   71. return self.dispatch(request, *args, **kwargs)
>> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in
>> > dispatch
>> >   89. return handler(request, *args, **kwargs)
>> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in
>> get
>> >   158. context = self.get_context_data(**kwargs)
>> > File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py"
>> in
>> > get_context_data
>> >   77. ctx = super(ProductListView,
>> self).get_context_data(**kwargs)
>> > File "C:\Python27\lib\site-packages\django_tables2\views.py" in
>> > get_context_data
>> >   107. table = self.get_table(**self.get_table_kwargs())
>> > File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py"
>> in
>> > get_table
>> >   91. table = super(ProductListView, self).get_table(**kwargs)
>> > File "C:\Python27\lib\site-packages\django_tables2\views.py" in
>> get_table
>> >   82. table = table_class(self.get_table_data(), **kwargs)
>> > File "C:\Python27\lib\site-packages\django_tables2\tables.py" in
>> __init__
>> >   348. self.data = self.TableDataClass(data=data, table=self)
>> > File "C:\Python27\lib\site-packages\django_tables2\tables.py" in
>> __init__
>> >   45. ' list(data) -- {} has
>> > neither'.format(type(data).__name__)
>> > Exception Type: ValueError at /dashboard/catalogue/
>> > Exception Value: data must be QuerySet-like (have count() and
>> order_by())
>> > or support list(data) -- NoneType has neither
>> >
>> > --
>> > 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 post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/django-users/CAAXvsYkWokyB
>> pF2rzGThJeKFN2%3DZR2ezM0rSbDXnjyQr0tu_ug%40mail.gmail.com.
>> > For more options, visit https://groups.google.com/d/optout.
>> >
>>
>> --
>> 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 post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CALn3ei2AehSe77Mr3cmuAiB6KXM3%2BQjHkg%
>> 3D2f9ZO_jsPT18eTQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAAXvsYmo5hNeQN3Pj5%3Dx6ULamJYOkthLosYKwjaEMxtsAFr
> b9A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAAXvsYmo5hNeQN3Pj5%3Dx6ULamJYOkthLosYKwjaEMxtsAFrb9A%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei15szDb%2BJ64HwKTkANY2p59AFyYZvz9uio7rU9bH_Ah7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

2017-01-10 Thread Ali khan
.middleware.FlatpageFallbackMiddleware')
> >
> > Traceback:
> > File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   132. response = wrapped_callback(request,
> > *callback_args, **callback_kwargs)
> > File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py"
> in
> > _wrapped_view
> >   22. return view_func(request, *args, **kwargs)
> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in
> view
> >   71. return self.dispatch(request, *args, **kwargs)
> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in
> > dispatch
> >   89. return handler(request, *args, **kwargs)
> > File "C:\Python27\lib\site-packages\django\views\generic\base.py" in get
> >   158. context = self.get_context_data(**kwargs)
> > File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py"
> in
> > get_context_data
> >   77. ctx = super(ProductListView, self).get_context_data(**
> kwargs)
> > File "C:\Python27\lib\site-packages\django_tables2\views.py" in
> > get_context_data
> >   107. table = self.get_table(**self.get_table_kwargs())
> > File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py"
> in
> > get_table
> >   91. table = super(ProductListView, self).get_table(**kwargs)
> > File "C:\Python27\lib\site-packages\django_tables2\views.py" in
> get_table
> >   82. table = table_class(self.get_table_data(), **kwargs)
> > File "C:\Python27\lib\site-packages\django_tables2\tables.py" in
> __init__
> >   348. self.data = self.TableDataClass(data=data, table=self)
> > File "C:\Python27\lib\site-packages\django_tables2\tables.py" in
> __init__
> >   45. ' list(data) -- {} has
> > neither'.format(type(data).__name__)
> > Exception Type: ValueError at /dashboard/catalogue/
> > Exception Value: data must be QuerySet-like (have count() and order_by())
> > or support list(data) -- NoneType has neither
> >
> > --
> > 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 post to this group, send email to django-users@googlegroups.com.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/django-users/
> CAAXvsYkWokyBpF2rzGThJeKFN2%3DZR2ezM0rSbDXnjyQr0tu_ug%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CALn3ei2AehSe77Mr3cmuAiB6KXM3%
> 2BQjHkg%3D2f9ZO_jsPT18eTQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAXvsYmo5hNeQN3Pj5%3Dx6ULamJYOkthLosYKwjaEMxtsAFrb9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

2017-01-08 Thread Vijay Khemlani
rgs)
> File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py" in
> get_context_data
>   77. ctx = super(ProductListView, self).get_context_data(**kwargs)
> File "C:\Python27\lib\site-packages\django_tables2\views.py" in
> get_context_data
>   107. table = self.get_table(**self.get_table_kwargs())
> File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py" in
> get_table
>   91. table = super(ProductListView, self).get_table(**kwargs)
> File "C:\Python27\lib\site-packages\django_tables2\views.py" in get_table
>   82. table = table_class(self.get_table_data(), **kwargs)
> File "C:\Python27\lib\site-packages\django_tables2\tables.py" in __init__
>   348. self.data = self.TableDataClass(data=data, table=self)
> File "C:\Python27\lib\site-packages\django_tables2\tables.py" in __init__
>   45. ' list(data) -- {} has
> neither'.format(type(data).__name__)
> Exception Type: ValueError at /dashboard/catalogue/
> Exception Value: data must be QuerySet-like (have count() and order_by())
> or support list(data) -- NoneType has neither
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAXvsYkWokyBpF2rzGThJeKFN2%3DZR2ezM0rSbDXnjyQr0tu_ug%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2AehSe77Mr3cmuAiB6KXM3%2BQjHkg%3D2f9ZO_jsPT18eTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

2017-01-07 Thread Ali khan
ype(data).__name__)
Exception Type: ValueError at /dashboard/catalogue/
Exception Value: data must be QuerySet-like (have count() and order_by())
or support list(data) -- NoneType has neither

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAXvsYkWokyBpF2rzGThJeKFN2%3DZR2ezM0rSbDXnjyQr0tu_ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-20 Thread Luis Zárate
Hi
You can override the admin login page overwriting the URLs, you can put
your own login view in admin/account/login after admin include in URLs


El domingo, 20 de noviembre de 2016, Reza Shalbafzadeh <
rezashal...@gmail.com> escribió:
> Hi
> you still can use Django axes as described in Django axes  documentation:
>
> django-axes requires a supported Django version. The application is
intended to work around the Django admin and the regular
django.contrib.auth login-powered pages.
>
> Also you can manually register urls for Django axes
>
http://django-axes.readthedocs.io/en/latest/issues.html#not-being-locked-out-after-failed-attempts
> add watch_login to your admin url
>
> On Friday, November 4, 2016 at 8:16:20 PM UTC+3:30, Daniel Grace wrote:
>>
>> Hello, I have a REST API which is not publicly accessible as it is
behind a proxy.  However the admin site is publicly available through an
NGINX server.  The REST API already has functionality to count failed login
attempts and I would like to duplicate that functionality on the admin
login page.  How do I hook into the admin login page and add the
appropriate code?  Can I still use Django Axes or should I create my own
login form as a replacement?
>> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1d87fca9-1d1d-4a6f-ba10-30c47152917b%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyOrAyKEJNux3%3DRjFQ2sonWEzJKmQmFXGOSoO5k4AOrtxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-20 Thread Reza Shalbafzadeh
Hi
you still can use Django axes as described in Django axes  documentation 
<http://django-axes.readthedocs.io/en/latest/requirements.html?highlight=django%20admin>
:

django-axes requires a supported Django version. The application is 
intended to work around the Django admin and the regular django.contrib.auth 
login-powered pages. 

Also you can manually register urls for Django axes
http://django-axes.readthedocs.io/en/latest/issues.html#not-being-locked-out-after-failed-attempts
add watch_login to your admin url 

On Friday, November 4, 2016 at 8:16:20 PM UTC+3:30, Daniel Grace wrote:
>
> Hello, I have a REST API which is not publicly accessible as it is behind 
> a proxy.  However the admin site is publicly available through an NGINX 
> server.  The REST API already has functionality to count failed login 
> attempts and I would like to duplicate that functionality on the admin 
> login page.  How do I hook into the admin login page and add the 
> appropriate code?  Can I still use Django Axes or should I create my own 
> login form as a replacement?
> 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d87fca9-1d1d-4a6f-ba10-30c47152917b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-17 Thread T Thomas


Hi Daniel,

 

Hope this email finds you well! We are App Innovation Technologies 
<http://www.aitechindia.com/> expertise in Microsoft SharePoint, with the 
latest .NET Framework 3.5, 4.0 and 4.5 and sound knowledge in developing 
WPF based window and web applications. We use PHP, Word-Press and other 
open source technologies for website development and on mobile we work on 
iOS, Android and Windows applications. 

 

 Our lab is equipped with dedicated TFS 2012, MS SQL server 2012, MS 
SharePoint 2010 Enterprise servers in the base of Windows Server 2012 and 
Windows Server 2012 R2. We offer good quality work on a reasonable cost.

 

If you have any project, Please let me know.

 

Our work:

1. ASP.Net / .Net <http://www.aitechindia.com/experdocs/>

2. Website <http://www.aitechindia.com/unique/>

3. iOS Application <http://www.aitechindia.com/goamormobile/>

 

 Thanks & Regards,

Thomas Russell

+1-224-636-9884 

App Innovation Technologies <http://www.aitechindia.com/>




On Friday, November 4, 2016 at 10:16:20 PM UTC+5:30, Daniel Grace wrote:
>
> Hello, I have a REST API which is not publicly accessible as it is behind 
> a proxy.  However the admin site is publicly available through an NGINX 
> server.  The REST API already has functionality to count failed login 
> attempts and I would like to duplicate that functionality on the admin 
> login page.  How do I hook into the admin login page and add the 
> appropriate code?  Can I still use Django Axes or should I create my own 
> login form as a replacement?
> 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abd37173-59f6-45b9-8574-5419cf9400e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-04 Thread Daniel Grace
Hello, I have a REST API which is not publicly accessible as it is behind a 
proxy.  However the admin site is publicly available through an NGINX 
server.  The REST API already has functionality to count failed login 
attempts and I would like to duplicate that functionality on the admin 
login page.  How do I hook into the admin login page and add the 
appropriate code?  Can I still use Django Axes or should I create my own 
login form as a replacement?
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69ea593b-4c5e-4eb6-ab9f-fa4639d17445%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How in Django, made count objects in through model by condition, for using in the admin as sortable field?

2016-04-30 Thread Seti Volkylany
I need will create two sortable fields in Django admin by values in 
Though-Model.

-
My models.py



from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.conf import settings

from autoslug import AutoSlugField

from mylabour.models import TimeStampedModel
from mylabour.utils import CHOICES_LEXERS


class Snippet(TimeStampedModel):
"""

"""

title = models.CharField(_('Title'), max_length=200)
slug_title = AutoSlugField(populate_from='title', 
unique_with='author', always_update=True, sep='__')
description = models.TextField(_('Decription'))
code = models.TextField(_('Code'))
# tags
lexer = models.CharField(_('Lexer of code'), max_length=50, 
choices=CHOICES_LEXERS)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
verbose_name=_('Author'),
related_name='snippets',
on_delete=models.DO_NOTHING,
)
voted_users = models.ManyToManyField(
settings.AUTH_USER_MODEL,
verbose_name=_('Voted users'),
related_name='voted_users',
through='VoteUserInSnippet',
through_fields=('snippet', 'user'),
)

class Meta:
db_table = 'snippet'
verbose_name = _("Snippet")
verbose_name_plural = _("Snippets")
get_latest_by = 'date_created'
ordering = ['date_created']

def __str__(self):
return '{0.title}'.format(self)

def get_absolute_url(self):
return reverse('app_snippets:snippet', kwargs={'slug_title': 
self.slug_title})


class VoteUserInSnippet(models.Model):

user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
verbose_name='User',
limit_choices_to={'is_active': True},
)
snippet = models.ForeignKey('Snippet', on_delete=models.CASCADE, 
verbose_name='Snippet')
is_useful = models.BooleanField(_('Is useful'))
date_voting = models.DateTimeField(_('Date voting'), 
auto_now_add=True)

def __str__(self):
return _('User "{0.user}" found this snippet as 
{0.is_useful}').format(self)


class SnippetComment(TimeStampedModel):

text_comment = models.TextField(_('Text comment'))
snippet = models.ForeignKey('Snippet', related_name='comments', 
verbose_name=_('Snippet'), on_delete=models.CASCADE)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name='comments_snippet',
verbose_name=_('Author'),
on_delete=models.DO_NOTHING,
)

class Meta:
db_table = 'snippet_comment'
verbose_name = "Comment of snippet"
verbose_name_plural = "Comments of snippet"
get_latest_by = 'date_created'
ordering = ['snippet', 'date_created']

def __str__(self):
return _('Comment from "{0.author}" on snippet 
"{0.snippet}"').format(self)

---
My admin.py
---


from django.db.models import Count
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin

from .models import *


class SnippetCommentInline(admin.StackedInline):
'''
Stacked Inline View for SnippetComment
'''

model = SnippetComment
min_num = 0
max_num = None
extra = 1
fk_name = 'snippet'


class VoteUserInSnippetInline(admin.TabularInline):
'''
Stacked Inline View for VoteUserInSnippet
'''

model = VoteUserInSnippet
min_num = 0
max_num = None
extra = 1


class SnippetAdmin(admin.ModelAdmin):
'''
Admin View for Snippet
'''

list_display = (
'title',
'author',
'lexer',
'get_count_good_reply',
'get_count_bad_reply',
'get_count_replies',
'is_new',
'date_modified',
'date_created',
)
list_filter = (
('author', admin.RelatedOnlyFieldListFilter),
'lexer',
'date_modified',
'date_created',
)
inlines = [
SnippetCommentInline,
VoteUserInSnippetInline,
]
search_fields = ('title',)

def get_queryset(self, request):
qs = super(SnippetAdmin, self).get_queryset(request)
qs = qs.annotate(
count_comments=Co

What python package is accurate to detect languages and count words?

2016-02-08 Thread Allison
I am trying to detect languages, so far I have used langdetect, langid. I 
heard goslate is blocked by Google, is there any package as good as 
goslate? It was simple and direct? Or would you recommend a python package 
for detecting languages and counting words? 

Thanks in advance, 

Allison

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a1729c4-4164-4967-aaee-931108c92347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implement page view count without using database for Hit

2016-02-08 Thread sonu kumar
Thanks James,
We have consider database and updated sites using django-visits. Building 
such a full proof system will take longer time.

Regars,
Sonu

On Monday, February 8, 2016 at 2:29:46 PM UTC+5:30, James Schneider wrote:
>
>
> On Feb 7, 2016 7:03 PM, "sonu kumar" <sonun...@gmail.com > 
> wrote:
> >
> > Hi all,
> > We have develop a site where we need to maintain page view count like 
> SO, Quora,YouTube etc. Current approach is based on  number of retrieval 
> using view this leads to problem to user that they are seeing that when a 
> page is reloaded then count get's incremented see here 
> http://www.job360.io/question-answer/cse/how-to-add-two-large-numbers. 
> >
> > How to tackle this problem, is there any exist which can do the work 
> without managing database ?
> >
>
> I'm a bit confused as to why you would be averse to managing a database, 
> assuming that you have an existing database for your users and other 
> content.
>
> If you don't want to manage the page hits yourself, you may look at 
> something like Google Analytics to track it for you.
>
> As far as the refresh question, I haven't researched this in detail, but 
> as far as I'm aware, there is no standard method for requesting refreshes 
> that all browsers follow, and it is difficult to determine whether a 
> request is an initial content load request, or a refresh request without 
> either the browser signaling the server with some type of request header, 
> or some extensive tracking of requests with timers and other heuristics on 
> the server side, and then of course your code has to catch all of those 
> scenarios.
>
> You're trying to merge the concept of a session with a request cycle. 
> Unfortunately, humans think of web access more in terms of sessions, where 
> the HTML, images, stylesheets, authentication, etc. are a single unit 
> carried through while a user browsers a site, but HTTP is built to use a 
> single content request cycle for each resource, independent of any other 
> content request cycle. There are many tricks involved to provide the 
> 'human' experience, like storing/retrieving session data for each HTTP 
> request (which is why your web server process should provide images and 
> stylesheets directly, not Django, so that those tricks are not invoked).
>
> There's no easy answer to your question. It's possible that Analytics our 
> a similar service will perform those database gymnastics for you in their 
> optimized environments to try and remove refreshes from your counts, but 
> you'd have to check with them.
>
> You should also consider the guidelines for what you are counting as a 
> 'hit' for your counter. Perhaps a refresh after 3 seconds shouldn't be 
> counted, but what about a refresh after 45 minutes? What if the same user 
> has multiple browsers open to the same site? What if robot crawlers access 
> your page? Maybe you can filter those out via the reported user agent, but 
> what if they spoof a real browser signature and request 10K hits? What if 
> you have an SPA that polls the server for updates data?
>
> Honestly, unless analytics takes care of this for you, it probably is not 
> worth the extra effort of saving a couple dozen refresh requests. As your 
> page reaches up into tens of thousands of hits, they'll probably become 
> statistically insignificant anyway. 
>
> -James
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/01c4807a-9506-42ad-8ab7-a62a73ea3640%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implement page view count without using database for Hit

2016-02-08 Thread James Schneider
On Feb 7, 2016 7:03 PM, "sonu kumar" <sonunit...@gmail.com> wrote:
>
> Hi all,
> We have develop a site where we need to maintain page view count like SO,
Quora,YouTube etc. Current approach is based on  number of retrieval using
view this leads to problem to user that they are seeing that when a page is
reloaded then count get's incremented see here
http://www.job360.io/question-answer/cse/how-to-add-two-large-numbers.
>
> How to tackle this problem, is there any exist which can do the work
without managing database ?
>

I'm a bit confused as to why you would be averse to managing a database,
assuming that you have an existing database for your users and other
content.

If you don't want to manage the page hits yourself, you may look at
something like Google Analytics to track it for you.

As far as the refresh question, I haven't researched this in detail, but as
far as I'm aware, there is no standard method for requesting refreshes that
all browsers follow, and it is difficult to determine whether a request is
an initial content load request, or a refresh request without either the
browser signaling the server with some type of request header, or some
extensive tracking of requests with timers and other heuristics on the
server side, and then of course your code has to catch all of those
scenarios.

You're trying to merge the concept of a session with a request cycle.
Unfortunately, humans think of web access more in terms of sessions, where
the HTML, images, stylesheets, authentication, etc. are a single unit
carried through while a user browsers a site, but HTTP is built to use a
single content request cycle for each resource, independent of any other
content request cycle. There are many tricks involved to provide the
'human' experience, like storing/retrieving session data for each HTTP
request (which is why your web server process should provide images and
stylesheets directly, not Django, so that those tricks are not invoked).

There's no easy answer to your question. It's possible that Analytics our a
similar service will perform those database gymnastics for you in their
optimized environments to try and remove refreshes from your counts, but
you'd have to check with them.

You should also consider the guidelines for what you are counting as a
'hit' for your counter. Perhaps a refresh after 3 seconds shouldn't be
counted, but what about a refresh after 45 minutes? What if the same user
has multiple browsers open to the same site? What if robot crawlers access
your page? Maybe you can filter those out via the reported user agent, but
what if they spoof a real browser signature and request 10K hits? What if
you have an SPA that polls the server for updates data?

Honestly, unless analytics takes care of this for you, it probably is not
worth the extra effort of saving a couple dozen refresh requests. As your
page reaches up into tens of thousands of hits, they'll probably become
statistically insignificant anyway.

-James

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWRWGGjyBqMbtuApuRfO4Hr%3D9MNGQhcVNBSLWAqKL%3Dw6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Implement page view count without using database for Hit

2016-02-07 Thread sonu kumar
Hi all,
We have develop a site where we need to maintain page view count like SO, 
Quora,YouTube etc. Current approach is based on  number of retrieval using 
view this leads to problem to user that they are seeing that when a page is 
reloaded then count get's incremented see here 
http://www.job360.io/question-answer/cse/how-to-add-two-large-numbers. 

How to tackle this problem, is there any exist which can do the work 
without managing database ?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5bf873d-9edb-4a20-bd6a-0d27e058aa71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: count

2016-01-28 Thread sum abiut
Thanks heaps works perfectly well.

Cheers

On Fri, Jan 29, 2016 at 4:09 PM, <aspel...@gmail.com> wrote:

> from django.http import HttpResponse
> from django.template import loader, RequestContext
>
> def foreginexchange_view(request):
> t = loader.get_template("template.html")
> test=ball.objects.filter(request="checked").count()
> c = RequestContext(request, {'test': test})
> return HttpResponse(t.render(c))
>
>
> On Wednesday, January 27, 2016 at 11:12:19 PM UTC+2, suabiut wrote:
>>
>> Version 1.7
>>
>> On Wed, Jan 27, 2016 at 10:42 PM, <aspe...@gmail.com> wrote:
>>
>>> Which version of Django do you using?
>>>
>>> вторник, 26 января 2016 г., 23:14:03 UTC+2 пользователь suabiut написал:
>>>>
>>>> When i did that i got the error:
>>>>
>>>> 'dict' object has no attribute 'render_context'
>>>>
>>>>
>>>>
>>>> On Tue, Jan 26, 2016 at 7:25 PM, <aspe...@gmail.com> wrote:
>>>>
>>>>> Try this
>>>>> def foreginexchange_view(request):
>>>>> t = loader.get_template("template.html")
>>>>> test=ball.objects.filter(request="checked").count()
>>>>> return HttpResponse(t.render({'test': test}))
>>>>>
>>>>> On Tuesday, January 26, 2016 at 4:45:52 AM UTC+2, suabiut wrote:
>>>>>>
>>>>>> Thanks James,
>>>>>> here is my view.py
>>>>>>
>>>>>> def foreginexchange_view(request):
>>>>>> test=ball.objects.filter(request="checked").count()
>>>>>> return render(request,'template.html',locals())
>>>>>>
>>>>>>
>>>>>>
>>>>>> Cheers
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Jan 26, 2016 at 1:30 PM, James Schneider <jrschn...@gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>>
>>>>>>> On Jan 25, 2016 6:07 PM, "sum abiut" <sua...@gmail.com> wrote:
>>>>>>> >
>>>>>>> > Hi,
>>>>>>> > i am trying to count the number of fields that has request field
>>>>>>> begin checked and then display the value of count in a template.html 
>>>>>>> but i
>>>>>>> am not sure how to go about doing that.
>>>>>>> >
>>>>>>> > For example i want to do something like
>>>>>>> >
>>>>>>> > test=ball.object.filter(request="checked").count()
>>>>>>> >
>>>>>>> > then on a template.html i want to out put the value of test
>>>>>>> >
>>>>>>> > {{test}}
>>>>>>> >
>>>>>>> > i have try that but i am not getting any value from the output.
>>>>>>> >
>>>>>>>
>>>>>>> Can you post your view? You would run that query in your view and
>>>>>>> then pass it to your template through the context.
>>>>>>>
>>>>>>> -James
>>>>>>>
>>>>>>> --
>>>>>>> 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 post to this group, send email to django...@googlegroups.com.
>>>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgThuMtZvUj3QHxLKFHiRu67oTZuvfoLT3K9EpNt08Dg%40mail.gmail.com
>>>>>>> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgThuMtZvUj3QHxLKFHiRu67oTZuvfoLT3K9EpNt08Dg%40mail.gmail.com?utm_medium=email_source=footer>
>>>>>>> .
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>> You received this messa

Re: count

2016-01-28 Thread aspellip
from django.http import HttpResponse
from django.template import loader, RequestContext

def foreginexchange_view(request):
t = loader.get_template("template.html")
test=ball.objects.filter(request="checked").count() 
c = RequestContext(request, {'test': test})
return HttpResponse(t.render(c))


On Wednesday, January 27, 2016 at 11:12:19 PM UTC+2, suabiut wrote:
>
> Version 1.7
>
> On Wed, Jan 27, 2016 at 10:42 PM, <aspe...@gmail.com > wrote:
>
>> Which version of Django do you using?
>>
>> вторник, 26 января 2016 г., 23:14:03 UTC+2 пользователь suabiut написал:
>>>
>>> When i did that i got the error:
>>>
>>> 'dict' object has no attribute 'render_context'
>>>
>>>
>>>
>>> On Tue, Jan 26, 2016 at 7:25 PM, <aspe...@gmail.com> wrote:
>>>
>>>> Try this
>>>> def foreginexchange_view(request):
>>>> t = loader.get_template("template.html")
>>>> test=ball.objects.filter(request="checked").count()
>>>> return HttpResponse(t.render({'test': test}))
>>>>
>>>> On Tuesday, January 26, 2016 at 4:45:52 AM UTC+2, suabiut wrote:
>>>>>
>>>>> Thanks James,
>>>>> here is my view.py
>>>>>
>>>>> def foreginexchange_view(request):
>>>>> test=ball.objects.filter(request="checked").count()
>>>>> return render(request,'template.html',locals())
>>>>>
>>>>>
>>>>>
>>>>> Cheers
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Jan 26, 2016 at 1:30 PM, James Schneider <jrschn...@gmail.com> 
>>>>> wrote:
>>>>>
>>>>>>
>>>>>> On Jan 25, 2016 6:07 PM, "sum abiut" <sua...@gmail.com> wrote:
>>>>>> >
>>>>>> > Hi,
>>>>>> > i am trying to count the number of fields that has request field 
>>>>>> begin checked and then display the value of count in a template.html but 
>>>>>> i 
>>>>>> am not sure how to go about doing that.
>>>>>> >
>>>>>> > For example i want to do something like
>>>>>> >
>>>>>> > test=ball.object.filter(request="checked").count()
>>>>>> >
>>>>>> > then on a template.html i want to out put the value of test
>>>>>> >
>>>>>> > {{test}}
>>>>>> >
>>>>>> > i have try that but i am not getting any value from the output.
>>>>>> >
>>>>>>
>>>>>> Can you post your view? You would run that query in your view and 
>>>>>> then pass it to your template through the context.
>>>>>>
>>>>>> -James
>>>>>>
>>>>>> -- 
>>>>>> 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 post to this group, send email to django...@googlegroups.com.
>>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgThuMtZvUj3QHxLKFHiRu67oTZuvfoLT3K9EpNt08Dg%40mail.gmail.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgThuMtZvUj3QHxLKFHiRu67oTZuvfoLT3K9EpNt08Dg%40mail.gmail.com?utm_medium=email_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>> 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 post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on t

  1   2   3   4   >