AttributeError: 'TemplateResponse' object has no attribute '_reason_phrase'

2017-11-22 Thread Web Architect
Hi,

We recently migrated from Django 1.8 to Django 1.11.7. We have an 
ecommerece site running on Django. When we are trying to access a page, 
following exception is occuring:

Traceback (most recent call last):

  File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 85, in run

self.result = application(self.environ, self.start_response)

  File 
"/virenv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", 
line 63, in __call__

return self.application(environ, start_response)

  File "/virenv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", 
line 161, in __call__

status = '%d %s' % (response.status_code, response.reason_phrase)

  File "/virenv/lib/python2.7/site-packages/django/http/response.py", line 
69, in reason_phrase

if self._reason_phrase is not None:

AttributeError: 'TemplateResponse' object has no attribute '_reason_phrase'


I am completely clueless why the above exception is occurring. I do not 
have any other data or logs for the above exception


Could anyone help me in providing a way to debug the above?


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/1089b578-3a8e-4eed-8ff2-becdc8bf3de9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: AttributeError: 'TemplateResponse' object has no attribute '_reason_phrase'

2017-11-24 Thread Web Architect
Figured out why the issue was occurring. I had written a cache decorator to 
cache based on per user:

def cache_per_user_method(ttl=None, prefix=None, cache_post=False):

'''

Decorator which caches the view for each User

* ttl - the cache lifetime, do not send this parameter means that the 
cache

  will last until the restart server or decide to remove it

* prefix - Prefix to use to store the response in the cache. If not 
informed,

  it will be used 'view_cache _' + function.__ name__

* cache_post - Determine whether to make requests cache POST

* The caching for anonymous users is shared with everyone


How to use it:

@cache_per_user_method(ttl=3600, cache_post=False)

def get(self, request):

...

'''

def decorator(view_method):

def apply_cache(obj, request, *args, **kwargs):


CACHE_KEY = cache_key(request, prefix)


logger.debug("cache key %s",CACHE_KEY)


# Verifica se pode fazer o cache do request

if not cache_post and request.method == 'POST':

can_cache = False

else:

can_cache = True


if can_cache:

response = core_cache.get(CACHE_KEY, None)

else:

response = None


if not response:

response = view_method(obj, request, *args, **kwargs)

logger.debug("cache not found in decorator")

if can_cache and hasattr(response, 'render'):

logger.debug("cache set in decorator")

core_cache.set(CACHE_KEY, response.render(), ttl)

return response

return apply_cache


The above code was causing the error to happen but couldn't figure out 
where the issue was in the above. 


Thanks,

On Wednesday, November 22, 2017 at 9:44:59 PM UTC+5:30, Tim Graham wrote:
>
> I tried a Google search for the last line of the error message and came to 
> https://code.djangoproject.com/ticket/25964. Conclusion: try clearing 
> your cache.
>
> On Wednesday, November 22, 2017 at 3:29:42 AM UTC-5, Web Architect wrote:
>>
>> Hi,
>>
>> We recently migrated from Django 1.8 to Django 1.11.7. We have an 
>> ecommerece site running on Django. When we are trying to access a page, 
>> following exception is occuring:
>>
>> Traceback (most recent call last):
>>
>>   File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 85, in run
>>
>> self.result = application(self.environ, self.start_response)
>>
>>   File 
>> "/virenv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py",
>>  
>> line 63, in __call__
>>
>> return self.application(environ, start_response)
>>
>>   File 
>> "/virenv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
>> 161, in __call__
>>
>> status = '%d %s' % (response.status_code, response.reason_phrase)
>>
>>   File "/virenv/lib/python2.7/site-packages/django/http/response.py", 
>> line 69, in reason_phrase
>>
>> if self._reason_phrase is not None:
>>
>> AttributeError: 'TemplateResponse' object has no attribute 
>> '_reason_phrase'
>>
>>
>> I am completely clueless why the above exception is occurring. I do not 
>> have any other data or logs for the above exception
>>
>>
>> Could anyone help me in providing a way to debug the above?
>>
>>
>> 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/27d1281c-2d9f-44f3-a6a3-d2e6672310c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi,

I am trying to optimise Django queries on my ecommerce website. One of the 
fundamental query is where I have no clue how to make efficient. It could 
be trivial and probably been known long time back. But I am new to Django 
and would appreciate any help. This is primarily for one to many or many to 
many relations.

Following is an example scenario:
(Please pardon my syntax as I want to put across the concept and not the 
exact django code unless it's really needed):

Model A:

class A(models.Model):
# Fields of model A

Model B (which is related to A with foreign key):

class B(models.Model):
a = models.ForeignKey('A', related_name='bs')

Now I would like to find out all As for which there is atleast one b. The 
only way I know is as follows:

A.objects.filter(bs__isnull=False)

But the above isn't an optimal way as with large of records in A and B, the 
above takes lot of time. It gets more inefficient if it's a many to many 
relationship.

Could anyone please let me know the most efficient way to use django 
queryset for the above scenario?

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/4817c6c7-987b-4b71-aef3-3ed910e1be5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Andy,

Thanks for your response. I was pondering on option a before posting this 
query thinking there could be better ways in django/SQL to handle this. But 
now I would probably go with a.

Thanks.

On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>
> a) Maybe its an option to put the foreign key to the other model? This way 
> you dont need to make a join to find out if there is a relation.
>
> b) Save the existing ralation status to model A
>
> c) cache the A.objects.filter(bs__isnull=False) query
>
> But apart from that i fear you cannot do much more, since this is just a 
> DB and not a Django ORM question.
>
>
> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect:
>>
>> Hi,
>>
>> I am trying to optimise Django queries on my ecommerce website. One of 
>> the fundamental query is where I have no clue how to make efficient. It 
>> could be trivial and probably been known long time back. But I am new to 
>> Django and would appreciate any help. This is primarily for one to many or 
>> many to many relations.
>>
>> Following is an example scenario:
>> (Please pardon my syntax as I want to put across the concept and not the 
>> exact django code unless it's really needed):
>>
>> Model A:
>>
>> class A(models.Model):
>> # Fields of model A
>>
>> Model B (which is related to A with foreign key):
>>
>> class B(models.Model):
>> a = models.ForeignKey('A', related_name='bs')
>>
>> Now I would like to find out all As for which there is atleast one b. The 
>> only way I know is as follows:
>>
>> A.objects.filter(bs__isnull=False)
>>
>> But the above isn't an optimal way as with large of records in A and B, 
>> the above takes lot of time. It gets more inefficient if it's a many to 
>> many relationship.
>>
>> Could anyone please let me know the most efficient way to use django 
>> queryset for the above scenario?
>>
>> 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/a7522736-166e-4d6d-8b8a-a6f88b0d6f47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Vijay,

Thanks for your response.

In my scenario, there is also another model with manytomany relation with A:

class C(models.Model):
a = manytomany('A', related_name='cs', through='D')

so, for around 25K records in A, 45K records in D and 18K records in B, 
following query takes more than 300ms and sometimes more than 500ms:

A.objects.filter(bs__isnull=False, cs__isnull=False).

Thanks.

On Saturday, February 3, 2018 at 12:28:38 AM UTC+5:30, Vijay Khemlani wrote:
>
> "with large of records in A and B, the above takes lot of time"
>
> How long? At first glance it doesn't look like a complex query or 
> something particularly inefficient for a DB.
>
> On Fri, Feb 2, 2018 at 11:31 AM, Andy > 
> wrote:
>
>> not that i know of
>>
>>
>> Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect:
>>>
>>> Hi Andy,
>>>
>>> Thanks for your response. I was pondering on option a before posting 
>>> this query thinking there could be better ways in django/SQL to handle 
>>> this. But now I would probably go with a.
>>>
>>> Thanks.
>>>
>>> On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>>>>
>>>> a) Maybe its an option to put the foreign key to the other model? This 
>>>> way you dont need to make a join to find out if there is a relation.
>>>>
>>>> b) Save the existing ralation status to model A
>>>>
>>>> c) cache the A.objects.filter(bs__isnull=False) query
>>>>
>>>> But apart from that i fear you cannot do much more, since this is just 
>>>> a DB and not a Django ORM question.
>>>>
>>>>
>>>> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am trying to optimise Django queries on my ecommerce website. One of 
>>>>> the fundamental query is where I have no clue how to make efficient. It 
>>>>> could be trivial and probably been known long time back. But I am new to 
>>>>> Django and would appreciate any help. This is primarily for one to many 
>>>>> or 
>>>>> many to many relations.
>>>>>
>>>>> Following is an example scenario:
>>>>> (Please pardon my syntax as I want to put across the concept and not 
>>>>> the exact django code unless it's really needed):
>>>>>
>>>>> Model A:
>>>>>
>>>>> class A(models.Model):
>>>>> # Fields of model A
>>>>>
>>>>> Model B (which is related to A with foreign key):
>>>>>
>>>>> class B(models.Model):
>>>>> a = models.ForeignKey('A', related_name='bs')
>>>>>
>>>>> Now I would like to find out all As for which there is atleast one b. 
>>>>> The only way I know is as follows:
>>>>>
>>>>> A.objects.filter(bs__isnull=False)
>>>>>
>>>>> But the above isn't an optimal way as with large of records in A and 
>>>>> B, the above takes lot of time. It gets more inefficient if it's a many 
>>>>> to 
>>>>> many relationship.
>>>>>
>>>>> Could anyone please let me know the most efficient way to use django 
>>>>> queryset for the above scenario?
>>>>>
>>>>> 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...@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/73ed5ff7-d4db-4057-a812-01c82bf08cf3%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/73ed5ff7-d4db-4057-a812-01c82bf08cf3%40googlegroups.com?utm_medium=email&utm_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/e8097811-a1de-44c2-9d9a-0457f1ead77f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-02 Thread Web Architect
Hi Furbee,

Thanks for your response. 

With my experience I have always noticed that a query within query kills 
the mysql and Mysqld CPU usage hits the ceiling. I would still check your 
alternate. 

I have mentioned the size of A and B in response to Vijay's reply. 

On Saturday, February 3, 2018 at 1:06:48 AM UTC+5:30, Furbee wrote:
>
> There are a couple options you could try to see which is the best fit for 
> your data. With DEBUG=True in settings.py you can check the actual queries 
> and process time. It depends on the sizes of A and B. Another query you can 
> run is:
>
> A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat=True))
>
> When I tried, it seemed to be about the same speed with my test data as 
> the one you had A.objects.filter(bs__isnull=True).
>
> To see what queries are generated and the query time with DEBUG=True:
> Open your Django Python Shell
> >>> A.objects.exclude(id__in=B.objects.all().values_list('a_id', 
> flat=True))
> >>> A.objects.filter(bs__isnull=True)
> >>> from django.db import connection
> >>> for q in connection.queries:
> >>> print("{0}: {1}".format(q['sql'], q['time']))
>
> This will show you both queries generated and how long it took to get a 
> response from your DB.
>
> You can also write raw SQL, if you can make one more efficiently.
>
> Furbee
>
> On Fri, Feb 2, 2018 at 10:56 AM, Vijay Khemlani  > wrote:
>
>> "with large of records in A and B, the above takes lot of time"
>>
>> How long? At first glance it doesn't look like a complex query or 
>> something particularly inefficient for a DB.
>>
>> On Fri, Feb 2, 2018 at 11:31 AM, Andy > 
>> wrote:
>>
>>> not that i know of
>>>
>>>
>>> Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect:
>>>>
>>>> Hi Andy,
>>>>
>>>> Thanks for your response. I was pondering on option a before posting 
>>>> this query thinking there could be better ways in django/SQL to handle 
>>>> this. But now I would probably go with a.
>>>>
>>>> Thanks.
>>>>
>>>> On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>>>>>
>>>>> a) Maybe its an option to put the foreign key to the other model? This 
>>>>> way you dont need to make a join to find out if there is a relation.
>>>>>
>>>>> b) Save the existing ralation status to model A
>>>>>
>>>>> c) cache the A.objects.filter(bs__isnull=False) query
>>>>>
>>>>> But apart from that i fear you cannot do much more, since this is just 
>>>>> a DB and not a Django ORM question.
>>>>>
>>>>>
>>>>> Am Freitag, 2. Februar 2018 14:47:45 UTC+1 schrieb Web Architect:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am trying to optimise Django queries on my ecommerce website. One 
>>>>>> of the fundamental query is where I have no clue how to make efficient. 
>>>>>> It 
>>>>>> could be trivial and probably been known long time back. But I am new to 
>>>>>> Django and would appreciate any help. This is primarily for one to many 
>>>>>> or 
>>>>>> many to many relations.
>>>>>>
>>>>>> Following is an example scenario:
>>>>>> (Please pardon my syntax as I want to put across the concept and not 
>>>>>> the exact django code unless it's really needed):
>>>>>>
>>>>>> Model A:
>>>>>>
>>>>>> class A(models.Model):
>>>>>> # Fields of model A
>>>>>>
>>>>>> Model B (which is related to A with foreign key):
>>>>>>
>>>>>> class B(models.Model):
>>>>>> a = models.ForeignKey('A', related_name='bs')
>>>>>>
>>>>>> Now I would like to find out all As for which there is atleast one b. 
>>>>>> The only way I know is as follows:
>>>>>>
>>>>>> A.objects.filter(bs__isnull=False)
>>>>>>
>>>>>> But the above isn't an optimal way as with large of records in A and 
>>>>>> B, the above takes lot of time. It gets more inefficient if it's a many 
>>>>>> to 
>>>>

Re: Optimal query for related names in onetomany or manytomany using Django Queryset

2018-02-06 Thread Web Architect
Hi Furbee,

Thanks for the suggestion. Would look into it. 

Thanks. 

On Sunday, February 4, 2018 at 10:32:20 AM UTC+5:30, Furbee wrote:
>
> You can set up an index on multiple field, as well, so if you’re searching 
> for As without a reference from B or C, using the index_together operative 
> in the class Meta for that model. I’m not completely sure, but I think this 
> may speed up you query time.
>
> Thanks,
>
> Furbee
>
> On Saturday, February 3, 2018, Vijay Khemlani  > wrote:
>
>> Well, you should've said that in the first post.
>>
>> First I would try with a saner DB (Postgres)
>>
>> Also I don't think 300 ms is particularly bad, but in that case start 
>> looking into caching alternatives (e.g. memcached) or a search index (e.g. 
>> ElasticSearch) 
>>
>> On Sat, Feb 3, 2018 at 3:14 AM, Web Architect > > wrote:
>>
>>> Hi Furbee,
>>>
>>> Thanks for your response. 
>>>
>>> With my experience I have always noticed that a query within query kills 
>>> the mysql and Mysqld CPU usage hits the ceiling. I would still check your 
>>> alternate. 
>>>
>>> I have mentioned the size of A and B in response to Vijay's reply. 
>>>
>>> On Saturday, February 3, 2018 at 1:06:48 AM UTC+5:30, Furbee wrote:
>>>>
>>>> There are a couple options you could try to see which is the best fit 
>>>> for your data. With DEBUG=True in settings.py you can check the actual 
>>>> queries and process time. It depends on the sizes of A and B. Another 
>>>> query 
>>>> you can run is:
>>>>
>>>> A.objects.exclude(id__in=B.objects.all().values_list('a_id', flat=True))
>>>>
>>>> When I tried, it seemed to be about the same speed with my test data as 
>>>> the one you had A.objects.filter(bs__isnull=True).
>>>>
>>>> To see what queries are generated and the query time with DEBUG=True:
>>>> Open your Django Python Shell
>>>> >>> A.objects.exclude(id__in=B.objects.all().values_list('a_id', 
>>>> flat=True))
>>>> >>> A.objects.filter(bs__isnull=True)
>>>> >>> from django.db import connection
>>>> >>> for q in connection.queries:
>>>> >>> print("{0}: {1}".format(q['sql'], q['time']))
>>>>
>>>> This will show you both queries generated and how long it took to get a 
>>>> response from your DB.
>>>>
>>>> You can also write raw SQL, if you can make one more efficiently.
>>>>
>>>> Furbee
>>>>
>>>> On Fri, Feb 2, 2018 at 10:56 AM, Vijay Khemlani  
>>>> wrote:
>>>>
>>>>> "with large of records in A and B, the above takes lot of time"
>>>>>
>>>>> How long? At first glance it doesn't look like a complex query or 
>>>>> something particularly inefficient for a DB.
>>>>>
>>>>> On Fri, Feb 2, 2018 at 11:31 AM, Andy  wrote:
>>>>>
>>>>>> not that i know of
>>>>>>
>>>>>>
>>>>>> Am Freitag, 2. Februar 2018 15:28:26 UTC+1 schrieb Web Architect:
>>>>>>>
>>>>>>> Hi Andy,
>>>>>>>
>>>>>>> Thanks for your response. I was pondering on option a before posting 
>>>>>>> this query thinking there could be better ways in django/SQL to handle 
>>>>>>> this. But now I would probably go with a.
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> On Friday, February 2, 2018 at 7:50:53 PM UTC+5:30, Andy wrote:
>>>>>>>>
>>>>>>>> a) Maybe its an option to put the foreign key to the other model? 
>>>>>>>> This way you dont need to make a join to find out if there is a 
>>>>>>>> relation.
>>>>>>>>
>>>>>>>> b) Save the existing ralation status to model A
>>>>>>>>
>>>>>>>> c) cache the A.objects.filter(bs__isnull=False) query
>>>>>>>>
>>>>>>>> But apart from that i fear you cannot do much more, since this is 
>>>>>>>> just a DB and not a Django ORM question.
>>>>>>>>
>>>>>>>>
>>>>>>>> Am F

A tricky query in one to many relationship - atleast for me:)

2016-08-29 Thread Web Architect
Hi,

I am looking for an elegant and efficient mechanism to have a query filter 
or a solution for the following one to many relationship model. Please note 
the following is just an illustration of the models - hope it should 
provide what I am looking for:

class A(models.Model):

name = models.CharField(_("Name"), max_length=255, unique=True)


class B(models.Model):

text = models.CharField(_("Text"), max_length=255, unique=True)

date_created = models.DateTimeField(_("Date Created"), auto_now_add=True) 

 a = models.ForeignKey(A, related_name='b')


To get all the instances of B associated with a specific instance of A (say 
'a'), I could do the following : a.b.all()

The latest instance of B associated with 'a' would be : 
a.b.latest('date_created')

Now I would like to have a list of all instances of A where the latest 
instance of B associated with each instance of A will have the 'text' field 
as 'ABCD'. 

A.objects.filter(b__text='ABCD') will give all instances of A where each 
instance of A will have atleast one instance of B with 'text' = 'ABCD'.

There could be a brute force way of getting a solution for the above where 
in I can do A.objects.filter(b__text='ABCD')  and then go through each 
instance  of A in a for loop over the queryset and check for the latest 
instance of B for text='ABCD'.

As mentioned earlier, I am looking for an elegant and optimal way (if any 
in Django) for the above query.

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/a9ea312a-578e-4a2f-a739-a38e87a4b15b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Hi Mike,

Thanks for your response. 

I am aware of chaining filters.

The latest() API in django queryset returns an object and not a queryset. 
Hence, I cannot add a filter to it. 

I had thought about using chaining filters but couldn't find a way.

On Tuesday, August 30, 2016 at 12:18:56 PM UTC+5:30, Mike Dewhirst wrote:
>
> On 30/08/2016 4:33 PM, Web Architect wrote: 
> > Hi, 
> > 
> > I am looking for an elegant and efficient mechanism to have a query 
> > filter or a solution for the following one to many relationship model. 
> > Please note the following is just an illustration of the models - hope 
> > it should provide what I am looking for: 
> > 
> > class A(models.Model): 
> > 
> > name = models.CharField(_("Name"), max_length=255, unique=True) 
> > 
> > 
> > class B(models.Model): 
> > 
> > text = models.CharField(_("Text"), max_length=255, unique=True) 
> > 
> > date_created = models.DateTimeField(_("Date Created"), 
> > auto_now_add=True)Â 
> > 
> > Â a =Â models.ForeignKey(A, related_name='b') 
> > 
> > 
> > To get all the instances of B associated with a specific instance of A 
> > (say 'a'), I could do the following : a.b.all() 
> > 
> > The latest instance of B associated with 'a' would be : 
> > a.b.latest('date_created') 
> > 
> > Now I would like to have a list of all instances of A where the latest 
> > instance of B associated with each instance of A will have the 'text' 
> > field as 'ABCD'. 
> > 
> > A.objects.filter(b__text='ABCD') will give all instances of A where 
> > each instance of A will have atleast one instance of B with 'text' = 
> > 'ABCD'. 
> > 
> > There could be a brute force way of getting a solution for the above 
> > where in I can do A.objects.filter(b__text='ABCD') Â and then go 
> > through each instance  of A in a for loop over the queryset and check 
> > for the latest instance of B for text='ABCD'. 
>
> HAve you looked at ... 
>
> https://docs.djangoproject.com/en/1.8/topics/db/queries/#chaining-filters 
>
>
> > 
> > As mentioned earlier, I am looking for an elegant and optimal way (if 
> > any in Django) for the above query. 
> > 
> > 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...@googlegroups.com  
> > <mailto:django-users+unsubscr...@googlegroups.com >. 
> > To post to this group, send email to django...@googlegroups.com 
>  
> > <mailto: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/a9ea312a-578e-4a2f-a739-a38e87a4b15b%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/a9ea312a-578e-4a2f-a739-a38e87a4b15b%40googlegroups.com?utm_medium=email&utm_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/508c9991-7d21-4583-82e5-1abea0584511%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Hi Erik,

Thanks for the solution.

So, I understand we get all instances of B which are max (date created)  or 
latest (date created) for each instance of A and then we check b.text == 
'ABCD' and select the corresponding instance of A. 
Can't we add additional filter to check if text='ABCD' instead of running 
it through the for loop? I am still yet to catch up with all the concepts 
of Django ORM hence, not sure about it.

Also, if we use Max('a__b__date_created') , do we need the following 
condition still in the for loop? :
if b.date_created != b.date_created__max: 
continue 

Thanks.


On Tuesday, August 30, 2016 at 3:03:44 PM UTC+5:30, Erik Cederstrand wrote:
>
> > for b in 
> B.objects.all().select_related('a').annotate(Max('date_created')): 
>
> That should probably be: Max('a__b__date_created') instead. 
>
> Erik 
>

-- 
You received this message because you are subscribed to the Google 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/49ab42be-053d-442d-a9b9-51d5123529fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Thanks Erik. Will try out the solution you mentioned.

On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30, Erik Cederstrand wrote:
>
>
> > Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand <
> erik+...@cederstrand.dk >: 
> > 
> > I'm not even sure that's possible to express in SQL, but it would 
> probably be quite convoluted if it is. Here's an easier-to-understand 
> solution: 
> > 
> > res = set() 
> > for b in 
> B.objects.all().select_related('a').annotate(Max('date_created')): 
> >if b.date_created != b.date_created__max: 
> >continue 
> >if b.text != 'ABCD': 
> >continue 
> >res.add(a) 
>
> I did some more experimenting. I think this actually does what you want: 
>
> res = [ 
> b.a for b in B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> .select_related('a') 
> ] 
>
> which you can rewrite as: 
>
> A.objects.filter( 
> b__in=B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> ) 
>
> Erik

-- 
You received this message because you are subscribed to the Google 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/2dc0eaa1-1c80-454d-9e3d-9ba4cbcb8140%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Hi Erik,

I tried your solution but there are some issues:

.filter(date_created=Max('a__b__date_created'))  - this is throwing error 
saying not proper use of group function.

If I remove the above, the result isn't correct where when I go through 
each 'a' in the result, associated latest B.text isn't always 'ABCD' - if 
there are multiple instances of B associated with an instance of A and one 
of the instances of B has text='ABCD' (might not be the latest 
date_created), that instance of B is also there in the query result.

Thanks.

On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30, Erik Cederstrand wrote:
>
>
> > Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand <
> erik+...@cederstrand.dk >: 
> > 
> > I'm not even sure that's possible to express in SQL, but it would 
> probably be quite convoluted if it is. Here's an easier-to-understand 
> solution: 
> > 
> > res = set() 
> > for b in 
> B.objects.all().select_related('a').annotate(Max('date_created')): 
> >if b.date_created != b.date_created__max: 
> >continue 
> >if b.text != 'ABCD': 
> >continue 
> >res.add(a) 
>
> I did some more experimenting. I think this actually does what you want: 
>
> res = [ 
> b.a for b in B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> .select_related('a') 
> ] 
>
> which you can rewrite as: 
>
> A.objects.filter( 
> b__in=B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> ) 
>
> Erik

-- 
You received this message because you are subscribed to the Google 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/13a40885-4cce-46af-ba50-368942608c37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Web Architect
Hi Michal,

Thanks for the solution. I tried the solution in a different way:

A.objects.annotate( 
max_date_created=Max('b__date_created')).filter(b__date_created=F('max_date_created'),
 
b__text='ABCD') 

Hope the above amounts to the same thing as you have suggested.

Thanks.


On Wednesday, August 31, 2016 at 1:48:38 PM UTC+5:30, Michal Petrucha wrote:
>
> On Tue, Aug 30, 2016 at 11:46:14PM -0700, Web Architect wrote: 
> > Hi Erik, 
> > 
> > I tried your solution but there are some issues: 
> > 
> > .filter(date_created=Max('a__b__date_created'))  - this is throwing 
> error 
> > saying not proper use of group function. 
> > 
> > If I remove the above, the result isn't correct where when I go through 
> > each 'a' in the result, associated latest B.text isn't always 'ABCD' - 
> if 
> > there are multiple instances of B associated with an instance of A and 
> one 
> > of the instances of B has text='ABCD' (might not be the latest 
> > date_created), that instance of B is also there in the query result. 
>
> Hmm, I haven't actually tried to run any code, but I'd try reordering 
> some of the method calls, and using an explcit field alias for the 
> annotation, which should let you then use an F() expression in 
> subsequent filters; something like this: 
>
> A.objects.filter( 
> b__in=B.objects 
> .annotate(max_date_created=Max('a__b__date_created')) 
> .filter(date_created=F('max_date_created'), text='ABCD') 
> ) 
>
> Good luck, 
>
> Michal 
>

-- 
You received this message because you are subscribed to the Google 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/88d20adc-6375-425c-88a5-870d0244471f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Cache-Control header for Flat Pages

2016-09-28 Thread Web Architect
Hi,

We are using Django Flat pages for some static pages like About us, privacy 
policy etc. We are using Web Accelerator (like Varnish) in front of Django. 
Hence, would like to set the Cache-Control Header to cache the flat pages. 
I am not able to figure how to do that for flat pages.

Tried using the middleware UpdateCacheMiddleware but it's not working. 
Would really appreciate if someone could throw some light.

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/38b38234-21bf-487a-9497-8120f7699513%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cache-Control header for Flat Pages

2016-09-29 Thread Web Architect
Hi Serge,

Thanks for your response.

We do not have any Views implemented for flatpages. I think they are Django 
internal stuff for static html content (something like a CMS):

https://docs.djangoproject.com/en/1.10/ref/contrib/flatpages/

Have used the url pattern as in the example mentioned in the link above:

from django.contrib.flatpages import views
urlpatterns += [
url(r'^about-us/$', views.flatpage, {'url': '/about-us/'}, name='about'),
url(r'^license/$', views.flatpage, {'url': '/license/'}, name='license'),]


Thanks.


On Thursday, September 29, 2016 at 1:05:02 PM UTC+5:30, Sergiy Khohlov 
wrote:
>
> could you please example your view.py   of those  flat pages. In case of 
> CBV syntax is little different  but it is possible to add any  response 
> header using view. 
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Thu, Sep 29, 2016 at 7:30 AM, Web Architect  > wrote:
>
>> Hi,
>>
>> We are using Django Flat pages for some static pages like About us, 
>> privacy policy etc. We are using Web Accelerator (like Varnish) in front of 
>> Django. Hence, would like to set the Cache-Control Header to cache the flat 
>> pages. I am not able to figure how to do that for flat pages.
>>
>> Tried using the middleware UpdateCacheMiddleware but it's not working. 
>> Would really appreciate if someone could throw some light.
>>
>> 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...@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/38b38234-21bf-487a-9497-8120f7699513%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/38b38234-21bf-487a-9497-8120f7699513%40googlegroups.com?utm_medium=email&utm_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/be7ce1a3-96fe-444d-bdb2-8a99a81e72ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cache-Control header for Flat Pages

2016-09-29 Thread Web Architect
Hi Michal,

Thanks for your response. My mistake that I should have mentioned that we 
are using Django 1.8. The decorator cache_control I think was introduced in 
1.9. Would there be something similar in 1.8?

Thanks.

On Thursday, September 29, 2016 at 5:08:08 PM UTC+5:30, Michal Petrucha 
wrote:
>
> On Thu, Sep 29, 2016 at 03:47:11AM -0700, Web Architect wrote: 
> > Hi Serge, 
> > 
> > Thanks for your response. 
> > 
> > We do not have any Views implemented for flatpages. I think they are 
> Django 
> > internal stuff for static html content (something like a CMS): 
> > 
> > https://docs.djangoproject.com/en/1.10/ref/contrib/flatpages/ 
> > 
> > Have used the url pattern as in the example mentioned in the link above: 
> > 
> > from django.contrib.flatpages import views 
> > urlpatterns += [ 
> > url(r'^about-us/$', views.flatpage, {'url': '/about-us/'}, 
> name='about'), 
> > url(r'^license/$', views.flatpage, {'url': '/license/'}, 
> name='license'),] 
>
> You can use the cache_control view decorator to wrap the flatpage view 
> before you plug it into your urlpatterns:: 
>
> from django.contrib.flatpages import views 
> from django.views.decorators.cache import cache_control 
>
> cached_flatpage = cache_control(max_age=4700)(views.flatpage) 
>
> urlpatterns += [ 
> url(r'^about-us/$', cached_flatpage, {'url': '/about-us/'}, 
> name='about'), 
> url(r'^license/$', cached_flatpage, {'url': '/license/'}, 
> name='license'),] 
>
> Cheers, 
>
> Michal 
>

-- 
You received this message because you are subscribed to the Google 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/6d9d04ee-1bce-4031-89ea-823c52e8438d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Minify HTML in Django

2016-10-31 Thread Web Architect
Hi,

Is there an optimal and efficient way to minify HTML in Django?

I tried using django-htmlmin but it's affecting the performance. 

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/f7886579-ff7f-4be2-8f25-c12e3e010899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Minify HTML in Django

2016-11-03 Thread Web Architect
Will go through Django Compressor. 

On Tuesday, November 1, 2016 at 3:22:56 PM UTC+5:30, somecallitblues wrote:
>
> Take a look at Django Compressor. 
>
> On Tuesday, 1 November 2016, Web Architect  > wrote:
>
>> Hi,
>>
>> Is there an optimal and efficient way to minify HTML in Django?
>>
>> I tried using django-htmlmin but it's affecting the performance. 
>>
>> 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/f7886579-ff7f-4be2-8f25-c12e3e010899%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/f7886579-ff7f-4be2-8f25-c12e3e010899%40googlegroups.com?utm_medium=email&utm_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/9f374395-23c4-43e2-b5bc-eb6c98196297%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Minify HTML in Django

2016-11-03 Thread Web Architect
Will go through Django Compressor.

Thanks.

On Tuesday, November 1, 2016 at 3:22:56 PM UTC+5:30, somecallitblues wrote:
>
> Take a look at Django Compressor. 
>
> On Tuesday, 1 November 2016, Web Architect  > wrote:
>
>> Hi,
>>
>> Is there an optimal and efficient way to minify HTML in Django?
>>
>> I tried using django-htmlmin but it's affecting the performance. 
>>
>> 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/f7886579-ff7f-4be2-8f25-c12e3e010899%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/f7886579-ff7f-4be2-8f25-c12e3e010899%40googlegroups.com?utm_medium=email&utm_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/6e4d2f57-9f71-4b74-9ecd-cffe26d24eeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Local variable dump on exception in production environment (DEBUG=False)

2019-02-01 Thread Web Architect
Hi,

In our production environment, we receive mail whenever an exception 
happens in our django application. But it contains only the function 
traces. The log will be helpful it also contains data dump or the local 
variable dump for each function trace. 
The exception trace on the browser in our development environment 
(DEBUG=True) contains the local variable dump. 

Hence, could anyone let me know if it's possible to get the local variable 
dump during exceptions in our django application? 

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/5b32c8ae-eb93-425d-88dc-d2c2a775a487%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable dump on exception in production environment (DEBUG=False)

2019-02-01 Thread Web Architect
Hi Vineeth,

Thanks for the info. Sentry sounds interesting and we will have a look at 
Sentry as it might need integration. 

Django does report function trace via mails but we are looking for the 
local variable trace also . Was hoping a small tweak in django should help. 

Thanks.

On Friday, February 1, 2019 at 4:00:13 PM UTC+5:30, vineeth sagar wrote:
>
> Hi, 
>
> I am not sure about django, but you can have a look at sentry, we use it 
> in production and it gives everything you ask for. I am sure Django also 
> does it but I find sentry better for error reporting.
>
> regards
> Vineeth
>
> On Feb 1, 2019 3:41 PM, "Web Architect" > 
> wrote:
>
>> Hi,
>>
>> In our production environment, we receive mail whenever an exception 
>> happens in our django application. But it contains only the function 
>> traces. The log will be helpful it also contains data dump or the local 
>> variable dump for each function trace. 
>> The exception trace on the browser in our development environment 
>> (DEBUG=True) contains the local variable dump. 
>>
>> Hence, could anyone let me know if it's possible to get the local 
>> variable dump during exceptions in our django application? 
>>
>> 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...@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/5b32c8ae-eb93-425d-88dc-d2c2a775a487%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/5b32c8ae-eb93-425d-88dc-d2c2a775a487%40googlegroups.com?utm_medium=email&utm_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/c6a39e60-5385-41df-a444-ab4fa5c4f614%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable dump on exception in production environment (DEBUG=False)

2019-02-03 Thread Web Architect
Hi Simon,

Thanks for your response. 

include_html was what I needed and the stack trace in mail contained the 
variable dump.

Thanks a lot. 

On Friday, February 1, 2019 at 10:15:53 PM UTC+5:30, Simon Charette wrote:
>
> Hello there,
>
> I haven't tried it myself but you could try subclassing 
> django.utils.log.AdminEmailHandler
> to rely on the better-exceptions[0] package to _better_ format exceptions 
> sent in text
> emails or simply set the include_html option[1] to True in your LOGGING 
> configuration to
> get report similar to when DEBUG=True is enabled in development 
> environment.
>
> Cheers,
> Simon
>
> [0] https://github.com/Qix-/better-exceptions
> [1] 
> https://docs.djangoproject.com/en/2.1/topics/logging/#django.utils.log.AdminEmailHandler
>
> Le vendredi 1 février 2019 05:11:47 UTC-5, Web Architect a écrit :
>>
>> Hi,
>>
>> In our production environment, we receive mail whenever an exception 
>> happens in our django application. But it contains only the function 
>> traces. The log will be helpful it also contains data dump or the local 
>> variable dump for each function trace. 
>> The exception trace on the browser in our development environment 
>> (DEBUG=True) contains the local variable dump. 
>>
>> Hence, could anyone let me know if it's possible to get the local 
>> variable dump during exceptions in our django application? 
>>
>> 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/3a13c1b1-1b52-4af4-9aa7-0dbeeaf4bb81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


DB queries in django scripts

2019-04-09 Thread Web Architect
Hi,

We have a Django 1.11 based ecommerce web site. 

We use django management scripts and django extension of runscript heavily 
for DB operations - running under cron. 

There's a tool - django-debugtoolbar to check the DB queries on the web. 
But is there a tool to monitor/check the DB queries for scripts? This would 
be really helpful in our script optimisation.

Looking forward to the info.

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/904bf95e-4fff-40e1-88af-19c62994e1b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DB queries in django scripts

2019-04-15 Thread Web Architect
Hi Derek,

Thanks for your response. We are using MySQL. Could you suggest something 
similar for the same?

Thanks.

On Thursday, April 11, 2019 at 1:27:02 PM UTC+5:30, Derek wrote:
>
> If you are using PostggeQL you may want to look at the query analysis 
> produced by:
> https://www.postgresql.org/docs/current/pgstatstatements.html
>
> There are various third-party tools to gather output from the 
> pg_stat_statements and make it available e.g.
> https://github.com/pganalyze/collector
> https://www.mni.de/using-grafana-with-pg_stat_statements/ 
> https://grafana.com/docs/features/datasources/postgres/
>
>
> On Wednesday, 10 April 2019 07:57:51 UTC+2, Web Architect wrote:
>>
>> Hi,
>>
>> We have a Django 1.11 based ecommerce web site. 
>>
>> We use django management scripts and django extension of runscript 
>> heavily for DB operations - running under cron. 
>>
>> There's a tool - django-debugtoolbar to check the DB queries on the web. 
>> But is there a tool to monitor/check the DB queries for scripts? This would 
>> be really helpful in our script optimisation.
>>
>> Looking forward to the info.
>>
>> 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/b56b59a5-e296-47f3-9c20-07f24e2c4060%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Logging CSRF errors and other HTTP errors by Django

2017-03-08 Thread Web Architect
Hi,

Is there a way to log CSRF errors? Like whenever an user visits my site and 
faces a CSRF error, I would like Django to log it in a file. I would like 
to know if my users are facing CSRF errors. 
Also, Can Django log HTTP error codes like 4xx or 5xx in a file? 

We are using Django 1.8.3 with uWsgi.

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/5b550f68-70ee-4da2-be05-3303d6550ae5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Logging CSRF errors and other HTTP errors by Django

2017-03-08 Thread Web Architect
Thanks for your response. We do use logging but missed the part of 
django.request. Thanks for pointing it. 

On Wednesday, March 8, 2017 at 9:31:21 PM UTC+5:30, Melvyn Sopacua wrote:
>
> On Wednesday 08 March 2017 06:15:42 Web Architect wrote:
>
>  
>
> > Is there a way to log CSRF errors? Like whenever an user visits my
>
> > site and faces a CSRF error, I would like Django to log it in a file.
>
>  
>
> Did you read the logging documentation 
> <https://docs.djangoproject.com/en/1.10/topics/logging/>?
>
>  
>
> -- 
>
> 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/da591e49-3bbb-4825-8edf-4836505e8885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django queryset High CPU Usage

2017-03-09 Thread Web Architect
Hi,

I am a bit perplexed by this and not sure what the solution is. Following 
is the scenario:

There is a Model A with 1 records. Just a simple queryset - 
A.objects.all() is resulting in CPU hitting almost 100%. Is there a way to 
optimize this? But why would such a query result in high CPU Usage?

Would appreciate if anyone could throw some light on the above.

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/0c5f0c9f-4f7a-446e-b0bd-fa8815382382%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-09 Thread Web Architect
Would like to further add - the python CPU Usage is hitting almost 100 %. 
When I run  a Select * query on Mysql, its quite fast and CPU is normal. I 
am not sure if anything more needs to be done in Django. 

On Friday, March 10, 2017 at 10:55:51 AM UTC+5:30, Web Architect wrote:
>
> Hi,
>
> I am a bit perplexed by this and not sure what the solution is. Following 
> is the scenario:
>
> There is a Model A with 1 records. Just a simple queryset - 
> A.objects.all() is resulting in CPU hitting almost 100%. Is there a way to 
> optimize this? But why would such a query result in high CPU Usage?
>
> Would appreciate if anyone could throw some light on the above.
>
> 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/e0cc58b8-f44b-4745-be46-fe7b52503b74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi James,

Thanks for your response. Melvyn also posed a similar point of not loading 
the whole records. 

But all the records are needed for reporting purposes - where the data is 
read from the DB and a csv report is created. I am not quite an expert on 
Django but I am not sure if there is a better way to do it. 

The scenario is as follows to make it clearer:

Ours is an ecommerce site built on Django. Our admin/accounting team needs 
to download reports now and then. We have a Django model for the line items 
purchased. Now there could be 10k line items sold and each line items are 
associated with other models like payments, shipments etc which is a 
complex set of relations. 

We do not yet have a sophisticated reporting mechanism but was working on 
building a simplistic reporting system on Django. But I am finding issues 
with scaling up - as reported with CPU Usage and the amount of time taken. 
If there is a way to optimise this - would be great otherwise we might not 
have to look for standard methods of reporting tools. 

Would appreciate suggestions/advices on the above.

Thanks,

On Friday, March 10, 2017 at 2:52:50 PM UTC+5:30, James Schneider wrote:
>
>
>
> On Mar 9, 2017 9:37 PM, "Web Architect" > 
> wrote:
>
> Would like to further add - the python CPU Usage is hitting almost 100 %. 
> When I run  a Select * query on Mysql, its quite fast and CPU is normal. I 
> am not sure if anything more needs to be done in Django. 
>
>
> Ironically, things being done in Django is the reason for your CPU 
> utilization issue in the first place.
>
> Calling a qs.all() is NOT the same as a SELECT * statement, even more so 
> when speaking to the scale of query that you mention.
>
> Your SQL query is simply listing data in a table. A very easy thing to do, 
> hence the reason it runs quickly.
>
> The qs.all() call is also running the same query (probably). However, in 
> addition to pulling all of the data, it is performing a transformation of 
> that data in to Django model objects. If you are pulling 10K items, then 
> Django is creating 10K objects, which is easily more intensive than a raw 
> SQL query, even for simple model objects. 
>
> In general, there's usually no practical reason to ever pull that many 
> objects from a DB for display on a page. Filter down to a reasonable number 
> (<100 for almost all sane cases) or implement a paging system to limit 
> returned results. It's also probably using a ton of RAM only to be 
> immediately thrown away at the end of the request. Browsers will 
> disintegrate trying to render that many HTML elements simultaneously.
>
> Look at implementing a paging system, possibly through Django's built-in 
> mechanism, or something like Datatables and the infinite scroll plugin.
>
> https://docs.djangoproject.com/en/dev/topics/pagination/
>
> https://datatables.net/extensions/scroller/
>
> -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/566cf05e-babf-456c-91fa-a698f7c7537d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi James,

Thanks for the clarification. Much appreciated. Will follow your points for 
the reporting part considering the overheads in ORM. 

Thanks,

On Friday, March 10, 2017 at 4:55:35 PM UTC+5:30, James Bennett wrote:
>
> If all you need is to export data from your database (with or without 
> transforming it along the way) to a CSV, using the normal QuerySet methods 
> is probably the wrong approach; you don't need model objects to do that. 
> Some options include:
>
> * Use raw SQL to query for the data and push it to CSV (also, some 
> databases natively understand how to export query results to CSV)
> * Use the values() or values_list() methods to use lighter-weight basic 
> Python data structures (dictionaries and lists) instead of model objects
> * If you *must* instantiate model objects, use the iterator() method to 
> avoid keeping them around in-memory, and look at server-side cursors as an 
> option
> * If you're fetching related data, make sure you're eager-loading the 
> relations to avoid N+1 problems.
>
>
> On Fri, Mar 10, 2017 at 3:06 AM, Web Architect  > wrote:
>
>> Hi James,
>>
>> Thanks for your response. Melvyn also posed a similar point of not 
>> loading the whole records. 
>>
>> But all the records are needed for reporting purposes - where the data is 
>> read from the DB and a csv report is created. I am not quite an expert on 
>> Django but I am not sure if there is a better way to do it. 
>>
>> The scenario is as follows to make it clearer:
>>
>> Ours is an ecommerce site built on Django. Our admin/accounting team 
>> needs to download reports now and then. We have a Django model for the line 
>> items purchased. Now there could be 10k line items sold and each line items 
>> are associated with other models like payments, shipments etc which is a 
>> complex set of relations. 
>>
>> We do not yet have a sophisticated reporting mechanism but was working on 
>> building a simplistic reporting system on Django. But I am finding issues 
>> with scaling up - as reported with CPU Usage and the amount of time taken. 
>> If there is a way to optimise this - would be great otherwise we might not 
>> have to look for standard methods of reporting tools. 
>>
>> Would appreciate suggestions/advices on the above.
>>
>> Thanks,
>>
>> On Friday, March 10, 2017 at 2:52:50 PM UTC+5:30, James Schneider wrote:
>>>
>>>
>>>
>>> On Mar 9, 2017 9:37 PM, "Web Architect"  wrote:
>>>
>>> Would like to further add - the python CPU Usage is hitting almost 100 
>>> %. When I run  a Select * query on Mysql, its quite fast and CPU is normal. 
>>> I am not sure if anything more needs to be done in Django. 
>>>
>>>
>>> Ironically, things being done in Django is the reason for your CPU 
>>> utilization issue in the first place.
>>>
>>> Calling a qs.all() is NOT the same as a SELECT * statement, even more so 
>>> when speaking to the scale of query that you mention.
>>>
>>> Your SQL query is simply listing data in a table. A very easy thing to 
>>> do, hence the reason it runs quickly.
>>>
>>> The qs.all() call is also running the same query (probably). However, in 
>>> addition to pulling all of the data, it is performing a transformation of 
>>> that data in to Django model objects. If you are pulling 10K items, then 
>>> Django is creating 10K objects, which is easily more intensive than a raw 
>>> SQL query, even for simple model objects. 
>>>
>>> In general, there's usually no practical reason to ever pull that many 
>>> objects from a DB for display on a page. Filter down to a reasonable number 
>>> (<100 for almost all sane cases) or implement a paging system to limit 
>>> returned results. It's also probably using a ton of RAM only to be 
>>> immediately thrown away at the end of the request. Browsers will 
>>> disintegrate trying to render that many HTML elements simultaneously.
>>>
>>> Look at implementing a paging system, possibly through Django's built-in 
>>> mechanism, or something like Datatables and the infinite scroll plugin.
>>>
>>> https://docs.djangoproject.com/en/dev/topics/pagination/
>>>
>>> https://datatables.net/extensions/scroller/
>>>
>>> -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 fro

Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi Melvyn,

Thanks for your response.

We are using the Celery for all tasks which could be done offline or 
separately. Report generation is one of it. We trigger the task from 
Browser but the report creation is run via Celery which when completed 
sends the csv filepath to the browser to be downloaded. 

But the CPU usage and time taken are high. Though right now we are using a 
single multicore HW. Since I am not quite adept in Django, hence, I raised 
the query if there is a way to optimise. I have used defer, only etc to 
lighten the query but still its taking time and CPU. But seems like ORM is 
a bottle-neck. 

I agree it's prudent to have the reporting on a separate HW. Would consider 
it.

Thanks.

On Friday, March 10, 2017 at 5:25:39 PM UTC+5:30, Melvyn Sopacua wrote:
>
> On Friday 10 March 2017 03:06:12 Web Architect wrote:
>
> > Hi James,
>
> > 
>
> > Thanks for your response. Melvyn also posed a similar point of not
>
> > loading the whole records.
>
> > 
>
> > But all the records are needed for reporting purposes - where the data
>
> > is read from the DB and a csv report is created. I am not quite an
>
> > expert on Django but I am not sure if there is a better way to do it.
>
> > 
>
> > The scenario is as follows to make it clearer:
>
> > 
>
> > Ours is an ecommerce site built on Django. Our admin/accounting team
>
> > needs to download reports now and then. We have a Django model for
>
> > the line items purchased. Now there could be 10k line items sold and
>
> > each line items are associated with other models like payments,
>
> > shipments etc which is a complex set of relations.
>
>  
>
> The most scalable solution is to not send the CSV to the browser and not 
> do it at the webserver.
>
> Use some tasking system like Celery to generate the report at a different 
> server. Use a management command to do it. Then mail the report or make it 
> available as static file via rsync/ssh/whathavyou.
>
>  
>
> You get bonus points for setting up the report generating server with a 
> read-only slave of the database.
>
>  
>
> This scales much better and doesn't tie up webserver resources.
>
> -- 
>
> 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/a9efcf50-7638-47fd-a4a8-cd04192c6af3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-10 Thread Web Architect
Hi,

Thanks for your response. 

Well, its not just the queryset but when the query triggered by an if 
condition or a for loop - thats what I meant. I was doing some basic 
performance check as well while working on the report generation - I 
observed the issue. There's no manager other than the default one. The CPU 
usage spikes and it takes some time before the Objects are created. 

But when you say not all objects are created at one go, you mean they can 
be deferred? You mean the query results are stored in the memory till each 
record is accessed or something using the objects? Could you please clarify?

Thanks. 

On Friday, March 10, 2017 at 5:31:14 PM UTC+5:30, Vijay Khemlani wrote:
>
> There is something wrong in your setup 
>
> I can query a 400.000 item table in less than a second with the 
> typical "Model.objects.all()". Django does not convert all of the 
> entries into objects just by that query. 
>
> You don't have any managers, or anything that can result in a 
> side-effect beyond the query itself? 
>
>
>
> On 3/10/17, James Bennett > wrote: 
> > If all you need is to export data from your database (with or without 
> > transforming it along the way) to a CSV, using the normal QuerySet 
> methods 
> > is probably the wrong approach; you don't need model objects to do that. 
> > Some options include: 
> > 
> > * Use raw SQL to query for the data and push it to CSV (also, some 
> > databases natively understand how to export query results to CSV) 
> > * Use the values() or values_list() methods to use lighter-weight basic 
> > Python data structures (dictionaries and lists) instead of model objects 
> > * If you *must* instantiate model objects, use the iterator() method to 
> > avoid keeping them around in-memory, and look at server-side cursors as 
> an 
> > option 
> > * If you're fetching related data, make sure you're eager-loading the 
> > relations to avoid N+1 problems. 
> > 
> > 
> > On Fri, Mar 10, 2017 at 3:06 AM, Web Architect  > wrote: 
> > 
> >> Hi James, 
> >> 
> >> Thanks for your response. Melvyn also posed a similar point of not 
> >> loading 
> >> the whole records. 
> >> 
> >> But all the records are needed for reporting purposes - where the data 
> is 
> >> read from the DB and a csv report is created. I am not quite an expert 
> on 
> >> Django but I am not sure if there is a better way to do it. 
> >> 
> >> The scenario is as follows to make it clearer: 
> >> 
> >> Ours is an ecommerce site built on Django. Our admin/accounting team 
> >> needs 
> >> to download reports now and then. We have a Django model for the line 
> >> items 
> >> purchased. Now there could be 10k line items sold and each line items 
> are 
> >> associated with other models like payments, shipments etc which is a 
> >> complex set of relations. 
> >> 
> >> We do not yet have a sophisticated reporting mechanism but was working 
> on 
> >> building a simplistic reporting system on Django. But I am finding 
> issues 
> >> with scaling up - as reported with CPU Usage and the amount of time 
> >> taken. 
> >> If there is a way to optimise this - would be great otherwise we might 
> >> not 
> >> have to look for standard methods of reporting tools. 
> >> 
> >> Would appreciate suggestions/advices on the above. 
> >> 
> >> Thanks, 
> >> 
> >> On Friday, March 10, 2017 at 2:52:50 PM UTC+5:30, James Schneider 
> wrote: 
> >>> 
> >>> 
> >>> 
> >>> On Mar 9, 2017 9:37 PM, "Web Architect"  wrote: 
> >>> 
> >>> Would like to further add - the python CPU Usage is hitting almost 100 
> >>> %. 
> >>> When I run  a Select * query on Mysql, its quite fast and CPU is 
> normal. 
> >>> I 
> >>> am not sure if anything more needs to be done in Django. 
> >>> 
> >>> 
> >>> Ironically, things being done in Django is the reason for your CPU 
> >>> utilization issue in the first place. 
> >>> 
> >>> Calling a qs.all() is NOT the same as a SELECT * statement, even more 
> so 
> >>> when speaking to the scale of query that you mention. 
> >>> 
> >>> Your SQL query is simply listing data in a table. A very easy thing to 
> >>> do, hence the reason it runs quickly. 
> >>> 
> >>> The qs.all() call is also running the same query (probably). However,

Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Vjiay,

My apologies if the scenario is not clear. Following are the details:

Lets say there is a Model A (with fields, foreignkeys and ManyToMany 
relationships with other models). There are 10k records for A. Lets say 
following is the pseudo code for the report:

As = A.objects.all()

for a in As:
 retrieve other related data from associated models.
 Write Data in a csv report file

There's no CPU intensive work above - its just fetching data. I had used 
select_related and prefetch_related to reduce DB queries - otherwise MySQL 
CPU usage was going up.

The above was run in Celery as separate task. The Python CPU was hitting 
almost 100% and it was taking time to generate the report - more than 300s.

To debug the issue, I broke the above code and made it simple to narrow 
down the issue.

So, I just did the following:

As = A.objects.all()

if As:
 print "hello"

In the above, the CPU was hitting almost 100% and was taking almost a 
second or  more before Hello was printed. I also did select_related and 
prefetch_related to check further.

Hence, the conclusion that the query was creating the CPU spike. 

Hope I am clear.

Thanks,


On Sunday, March 12, 2017 at 6:00:00 AM UTC+5:30, Vijay Khemlani wrote:
>
> "But the CPU usage and time taken are high" <- I'm assuming high 
> enough to be problematic for OP. 
>
> I'm seriously not following. Why are people suggesting reporting and 
> export software when OP hasn't even described the problem in detail. 
> It's not even clear whether the high cpu and time taken are due to the 
> basic query ("Model.objects.all()") or the further processing of the 
> report. 
>
> It could easily be a missing "select_related" which causes thousands 
> of joins inside a for loop. 
>
> On 3/11/17, James Schneider > wrote: 
> > On Mar 11, 2017 12:01 PM, "Vijay Khemlani"  > wrote: 
> > 
> > Am I the only one who thinks that generating a report over a set of 
> > just 10.000 records could be done in 10 - 20 secs unless there are 
> > some serious computations going on with that data? 
> > 
> > For a report I have to query around 200.000 records, with 
> > aggregations, and it takes less than a minute using the ORM. 
> > 
> > 
> > The OP never mentioned a time interval that I can find in this thread, 
> only 
> > CPU utilization. I can only imagine that the query is taking long enough 
> to 
> > notice the CPU utilization, which would be at least a few seconds. 
> > 
> > Querying and aggregating 200K records within the DB is not comparable to 
> > pulling 10K individual records and performing processing on each one. An 
> > ORM call with aggregation will perform a large majority of the work in 
> the 
> > DB, and the ORM simply wraps the response accordingly. 
> > 
> > -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%2BciWZFoHQD%3D9UpSQzmpzO70_7MXuw6J01myYrAQ4ZN-uX4g%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/4f3b29f5-b800-4bbc-bdb4-9b3e41ad2656%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect


On Sunday, March 12, 2017 at 4:53:25 AM UTC+5:30, James Schneider wrote:
>
>
>
> On Mar 11, 2017 12:01 PM, "Vijay Khemlani"  > wrote:
>
> Am I the only one who thinks that generating a report over a set of
> just 10.000 records could be done in 10 - 20 secs unless there are
> some serious computations going on with that data?
>
> For a report I have to query around 200.000 records, with
> aggregations, and it takes less than a minute using the ORM.
>
>
> The OP never mentioned a time interval that I can find in this thread, 
> only CPU utilization. I can only imagine that the query is taking long 
> enough to notice the CPU utilization, which would be at least a few seconds.
>
> Querying and aggregating 200K records within the DB is not comparable to 
> pulling 10K individual records and performing processing on each one. An 
> ORM call with aggregation will perform a large majority of the work in the 
> DB, and the ORM simply wraps the response accordingly. 
>

I agree. The task was mostly to pull data from DB and generate the CSV. The 
 model structure was as follows:

Main Model A

A has foreignkey to model D
A has foriegnkey to model E
F has foreignkey to model D

Model B having manyTomany relationship with A through B1
Model C having manyTomany relationship with A through C1

It was mostly DB fetches which was the complex part. Something like fetch 
the latest of B related to each record of A. Fetch the latest of F related 
to the record of D which is related to each record of A. 

There were no CPU intensive calculations done. Though the overall DB 
fetches were complex, as mentioned in my response to Vijay, I just broke 
down the issue and tried the single queryset with select_related and 
prefetch_related and also "defer" and "only" to make the query lighter. But 
weren't helping. In fact the prefetch related on B and C were making the 
overall query heavier and hence, increasing the response time further.

Please note the above example was just the subset of the overall DB 
relations and models.


> -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/b169cc33-8120-441c-847d-6977d0e0712a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Camilo,

Thanks for your suggestion. Would certainly look for solutions outside 
Django if Django cannot suffice. But was trying to find something with 
Django since the web part was in Django and for easy of development.

We are already using Celery Extensively but then high Resource Usage is not 
desirable. If there is no alternative then we would have to live with it 
and probably add more HW or do some distributed processing. 

Thanks.

On Saturday, March 11, 2017 at 6:08:11 PM UTC+5:30, Camilo Torres wrote:
>
> Hi.
>
> You can probably use another web framework for that report, or even 
> rethink your architecture and put the report creation outside Django and 
> the web server without Django ORM.
>
> You may be interested in evaluating Celery and Django Celery. You can 
> create a separate task outside Django to create such report, call the task 
> from within Django with Celery, create the report and email to the user.
>
> Regards.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/978b671f-23c9-4438-a667-5ac27472f000%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset High CPU Usage

2017-03-13 Thread Web Architect
Hi Daniel,

Thanks for the suggestion. Would look into django-import-export.

Thanks.

On Saturday, March 11, 2017 at 6:29:57 PM UTC+5:30, Daniel Hepper wrote:
>
> In additions to the suggestions you already received from others, have a 
> look at django-import-export. It allows you to easily export data in 
> various formats.
>
> Hope that helps,
> Daniel Hepper
> https://consideratecode.com
>
> On Friday, March 10, 2017 at 12:06:13 PM UTC+1, Web Architect wrote:
>>
>> Hi James,
>>
>> Thanks for your response. Melvyn also posed a similar point of not 
>> loading the whole records. 
>>
>> But all the records are needed for reporting purposes - where the data is 
>> read from the DB and a csv report is created. I am not quite an expert on 
>> Django but I am not sure if there is a better way to do it. 
>>
>> The scenario is as follows to make it clearer:
>>
>> Ours is an ecommerce site built on Django. Our admin/accounting team 
>> needs to download reports now and then. We have a Django model for the line 
>> items purchased. Now there could be 10k line items sold and each line items 
>> are associated with other models like payments, shipments etc which is a 
>> complex set of relations. 
>>
>> We do not yet have a sophisticated reporting mechanism but was working on 
>> building a simplistic reporting system on Django. But I am finding issues 
>> with scaling up - as reported with CPU Usage and the amount of time taken. 
>> If there is a way to optimise this - would be great otherwise we might not 
>> have to look for standard methods of reporting tools. 
>>
>> Would appreciate suggestions/advices on the above.
>>
>> Thanks,
>>
>> On Friday, March 10, 2017 at 2:52:50 PM UTC+5:30, James Schneider wrote:
>>>
>>>
>>>
>>> On Mar 9, 2017 9:37 PM, "Web Architect"  wrote:
>>>
>>> Would like to further add - the python CPU Usage is hitting almost 100 
>>> %. When I run  a Select * query on Mysql, its quite fast and CPU is normal. 
>>> I am not sure if anything more needs to be done in Django. 
>>>
>>>
>>> Ironically, things being done in Django is the reason for your CPU 
>>> utilization issue in the first place.
>>>
>>> Calling a qs.all() is NOT the same as a SELECT * statement, even more so 
>>> when speaking to the scale of query that you mention.
>>>
>>> Your SQL query is simply listing data in a table. A very easy thing to 
>>> do, hence the reason it runs quickly.
>>>
>>> The qs.all() call is also running the same query (probably). However, in 
>>> addition to pulling all of the data, it is performing a transformation of 
>>> that data in to Django model objects. If you are pulling 10K items, then 
>>> Django is creating 10K objects, which is easily more intensive than a raw 
>>> SQL query, even for simple model objects. 
>>>
>>> In general, there's usually no practical reason to ever pull that many 
>>> objects from a DB for display on a page. Filter down to a reasonable number 
>>> (<100 for almost all sane cases) or implement a paging system to limit 
>>> returned results. It's also probably using a ton of RAM only to be 
>>> immediately thrown away at the end of the request. Browsers will 
>>> disintegrate trying to render that many HTML elements simultaneously.
>>>
>>> Look at implementing a paging system, possibly through Django's built-in 
>>> mechanism, or something like Datatables and the infinite scroll plugin.
>>>
>>> https://docs.djangoproject.com/en/dev/topics/pagination/
>>>
>>> https://datatables.net/extensions/scroller/
>>>
>>> -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/29c0528f-57a7-4f73-be77-3158fe6e61dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-16 Thread Web Architect
Hi,

Could someone please let me know what the implications of Django queryset 
iterator on select_related and prefetch_related? 

Also, I am still not quite clear on the concept of iterator which I 
understand returns a Generator. Whenever a for loop is run on the 
Generator, the DB is queried for each element in the for loop - if my 
understanding is correct. The result of the Query is not stored in the 
memory. So, for some model A,

qs = A.objects.all() which probably does 'Select "all columns/fields'" from 
A in some order". This would probably fetch the results in one go. I am not 
sure how the iterator() changes this. 

BTW I observed that the iterator doesn't work like a typical Generator. 
Repeated call with next() on the Generator produces the same value. 

Would appreciate if someone could explain the above or provide any 
reference.

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/252d11a2-6e49-4c5a-b466-e186cf7254af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Questions on Django queryset iterator - wrt select_related and prefetch_related and how it works

2017-03-17 Thread Web Architect
Hi,

Thanks for your response. But I have observed the following:

Without Iterator: It takes a bit of a time before the for loop is executed 
and also the CPU spikes up during that period and so does the Memory - 
which implies the DB is accessed to fetch all the results.

With iterator: The for loop execution starts immediately and the memory 
usage is also low. This probably implies that not all the results are 
fetched with a single query. 

Based on what you have mentioned, I am not sure how to understand the above 
behaviour. 

Thanks,

On Friday, March 17, 2017 at 11:27:52 AM UTC+5:30, Shawn Milochik wrote:
>
> I think the benefit of using the iterator is best explained by an example:
>
> Without iterator:
>
> You loop through the queryset, using each item for  whatever you're doing. 
> As you do this, all the items are now in your local scope, using up RAM. 
> If, after the loop, you should want to loop through the data again, you 
> can. Upside: Can re-use the data. Downside: memory usage.
>
> With iterator:
>
> You loop through the queryset, using each item for  whatever you're doing. 
> As you do this, read items are garbage-collected. If you want to loop 
> through the data again, you'll have to hit the database again. Upside: 
> Memory usage.
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google 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/aa3da7de-a700-48fc-bf30-1c41d11b1d56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Strange issue in CSRF

2017-04-09 Thread Web Architect
Hi,

We are seeing a strange issue with CSRF in Django. We are using Django 
1.8.4. 

Ours is an ecommerce site which has been up since an year. We have been 
observing 403 CSRF errors now and then for form posts. But the issue is 
intermittent and suddenly pops up. I mean the form posts work fine for 
days/weeks but then suddenly the CSRF error starts showing up. On digging 
further, when we check the POST request in inspect element, the CSRF shows 
in the post and cookie:
Cookie:QGUserId=%220319088571507253%22; mailer_popup=no; 
sessionid=si11ft0y1w6fr1ostgd9yd0yi88xpyo9; ga=GA1.3.133645024.1488272511; 
jivaana_country=IN; 
jivaana_last_visited_page=/product/traditional-maharastrian-earrings-green-12629/;
 
jivaana_last_visited_product=Traditional Maharastrian Earrings - Green; 
jivaana_last_visited_image=undefined; last_session_reminder=1; 
jivaana_last_visited_catalogue=/footwear/juttis/; oscar_history="[6251\054 
11144\054 8724\054 17749\054 7849\054 11402]"; 
jivaana_product_list=[{"page":"/product/electric-daisy-11402/","name":"Blue 
Juttis - Electric Daisy","image":"
http://www.jivaana.com/cache/74/d0/electric-daisy_juttis_red-pink-black-green-yellow_147937470755-74d09c587f73dc8135e005422b9e6b59.jpg"}];
 
cart_prod_title=Blue Juttis - Electric Daisy; cart_prod_image=
http://www.jivaana.com/cache/74/d0/electric-daisy_juttis_red-pink-black-green-yellow_147937470755-74d09c587f73dc8135e005422b9e6b59.jpg;
 
cart_session_reminder=1; 
messages="03d4207b1d9610be355acf1ee7667642dbace557$[[\"__json_message\"\0541\05425\054\"\\n\\n\\n
 
   \\nBlue Juttis - Electric Daisy has been added to 
your cart.\\n\\n\\n\"\054\"safe 
noicon\"]\054[\"__json_message\"\0541\05420\054\"\\n\\n\\n\\n\\n 
   \\n\\nYour cart total is now 
\\u00a0\\u20b94\054020\\n\\n\\n   
 \\n\\n\\n\"\054\"safe noicon\"]]"; gat_tw=1; qg_identified=true; 
csrftoken=NnjVnLA5tUW8DEQhuUx3wtZJxbIYx1ex; gat=1; 
_ga=GA1.2.133645024.1488272511

view URL encoded
csrfmiddlewaretoken:NnjVnLA5tUW8DEQhuUx3wtZJxbIYx1ex
form-TOTAL_FORMS:2
form-INITIAL_FORMS:2
form-MIN_NUM_FORMS:0
form-MAX_NUM_FORMS:1000
form-0-quantity:2
form-0-id:46476
form-1-quantity:1
form-1-id:49589

But when I dump the request log in the Django server, the csrftoken cookie 
is missing:
csrfmiddlewaretoken=NnjVnLA5tUW8DEQhuUx3wtZJxbIYx1ex&form-TOTAL_FORMS=2&form-INITIAL_FORMS=2&form-MIN_NUM_FORMS=0&form-MAX_NUM_FORMS=1000&form-0-quantity=2&form-0-id=46476&form-1-quantity=1&form-1-id=49589
 [0m
{'jivaana_last_visited_page': 
'/product/traditional-maharastrian-earrings-green-12629/', 
'jivaana_last_visited_image': 'undefined', 'jivaana_country': 'IN', 
'last_session_reminder': '1', '_ga': 'GA1.3.133645024.1488272511', 
'mailer_popup': 'no', 'sessionid': 'si11ft0y1w6fr1ostgd9yd0yi88xpyo9', 
'QGUserId': '%220319088571507253%22', 'jivaana_last_visited_product': 
'Traditional', 'oscar_history': '[6251, 11144, 8724, 17749, 7849, 11402]', 
'jivaana_last_visited_catalogue': '/footwear/juttis/'}

The log is getting dumped in Django Middleware, hence, not sure if Django 
Strips off the csrftoken cookie from request. If Django is not stripping 
off the CSRF cookie, then this is  an issue with CSRF and the missing 
csrftoken cookie explains the 403 forbidden error. 
On clearing browser cache, the form POST starts working again. 

I am not sure why the above is happening and hence, was wondering if anyone 
has faced similar issue and have an answer/solution to the above. The above 
issue occurs only for few users (not all) but its affecting our business.

Also, when the 403 CSRF occurs, Django throws a DEBUG page with following 
content:

CSRF Verification failed. Request aborted...You are seeing this page 
because you have DEBUG=TRUE. 

The above error page should not occur as in our production DEBUG is set to 
False.

Would appreciate if someone could throw some light on the above issues.

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/93d8e49a-782a-4b14-8977-f2be9c2685a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django queryset returning corrupted value

2017-10-06 Thread Web Architect
Hi,

We have running an ecommerce site using Django 1.8.13. It has been running 
fine for a year. But suddenly the django querysets are returning corrupted 
values. I am completely clueless why this is happening. Like a model field 
is of type SlugField but queryset is returning long. 

Would really appreciate if anyone could throw some light on how to fix the 
above issue. When I check the values in MySQL DB using PhpMyAdmin and 
everything is fine. 

Thanks,
Pinakee

-- 
You received this message because you are subscribed to the Google 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/31e38550-5759-47fb-8aac-634222f538e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset returning corrupted value

2017-10-07 Thread Web Architect
Hi Antonis,

Thanks for your response:

Following is the model:

from treebeard.mp_tree import MP_Node

@python_2_unicode_compatible
[docs] 
<http://django-oscar.readthedocs.io/en/releases-1.1/ref/apps/catalogue.html#oscar.apps.catalogue.abstract_models.AbstractCategory>class
 AbstractCategory(MP_Node):
"""A product category. Merely used for navigational purposes; has no
effects on business logic.
Uses django-treebeard."""
name = models.CharField(_('Name'), max_length=255, db_index=True)
description = models.TextField(_('Description'), blank=True)
image = models.ImageField(_('Image'), upload_to='categories', blank=True,
  null=True, max_length=255)
slug = models.SlugField(_('Slug'), max_length=255, db_index=True)

Following is the queryset:

 >>>cat=category.objects.get(pk=11)

>>> cat

Traceback (most recent call last):

  File "", line 1, in 

  File 
"/home/pinakee/oscar_v1/lib/python2.7/site-packages/django/db/models/base.py", 
line 496, in __repr__

u = six.text_type(self)

  File 
"/home/pinakee/oscar_v1/lib/python2.7/site-packages/oscar/apps/catalogue/abstract_models.py",
 line 102, in __str__

return self.full_name

  File "/home/waltzz/jivaana/jivaana_custom/catalogue/models.py", line 61, in 
full_name

cache_key = self.slug + '_full_name'

TypeError: unsupported operand type(s) for +: 'long' and 'str'

>>> cat.slug

3L


The reason above exception is coming because cat.slug is long and not string as 
it is supposed to be.

MySQL Version:

mysql -V

mysql  Ver 14.14 Distrib 5.5.48, for Linux (x86_64) using readline 5.1


OS:

2.6.32-504.30.3.el6.x86_64


Thanks.


On Friday, October 6, 2017 at 11:49:04 PM UTC+5:30, Antonis Christofides 
wrote:
>
> Hi,
>
> could you show the code that defines the slugfield, the queryset that is 
> returning the wrong value, full error message and traceback (if available), 
> and the version of your OS and RDBMS?
>
> It doesn't matter if the problem is more general; let's focus on one 
> specific manifestation of it.
>
> Regards,
>
> Antonis
>
> On October 6, 2017 8:16:20 PM GMT+03:00, Web Architect  > wrote:
>>
>> Hi,
>>
>> We have running an ecommerce site using Django 1.8.13. It has been 
>> running fine for a year. But suddenly the django querysets are returning 
>> corrupted values. I am completely clueless why this is happening. Like a 
>> model field is of type SlugField but queryset is returning long. 
>>
>> Would really appreciate if anyone could throw some light on how to fix 
>> the above issue. When I check the values in MySQL DB using PhpMyAdmin and 
>> everything is fine. 
>>
>> Thanks,
>> Pinakee
>>
>>

-- 
You received this message because you are subscribed to the Google 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/0fb7769f-409a-4951-9e2d-4807f0873c16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django queryset returning corrupted value

2017-10-09 Thread Web Architect
Hi Antonis,

Thanks for your response. You are right, The issue wasn't in MySQL or even 
Django ORM. We were using Cachalot 
(http://django-cachalot.readthedocs.io/en/latest/) for query caching which 
was causing the issue. Disabling cachalot fixed the issue. Would need to 
look more into query caching  to use it properly without issues.

Thanks.

On Monday, October 9, 2017 at 1:54:20 AM UTC+5:30, Antonis Christofides 
wrote:
>
> Hi,
>
> this is very strange of course. I doubt it has anything to do with MySQL, 
> because even if MySQL had done something wrong and had returned a long in 
> place of a string, the Django ORM should have caught that and raised an 
> error earlier. So the problem must be in Django. (But of course with such a 
> strange problem anything is possible).
>
> I'd first try to clean up the Python compiled files (remove them), remove 
> and recreate the virtualenv, and restart Django. Also check the disk space 
> in the machine.
>
> Regards,
>
> Antonis
>
> Antonis Christofideshttp://djangodeployment.com
>
> On 2017-10-07 11:40, Web Architect wrote:
>
> Hi Antonis, 
>
> Thanks for your response:
>
> Following is the model:
>
> from treebeard.mp_tree import MP_Node
>
> @python_2_unicode_compatible
> [docs] 
> <http://django-oscar.readthedocs.io/en/releases-1.1/ref/apps/catalogue.html#oscar.apps.catalogue.abstract_models.AbstractCategory>class
>  AbstractCategory(MP_Node):
> """A product category. Merely used for navigational purposes; has no  
>   effects on business logic.
> Uses django-treebeard."""
> name = models.CharField(_('Name'), max_length=255, db_index=True)
> description = models.TextField(_('Description'), blank=True)
> image = models.ImageField(_('Image'), upload_to='categories', blank=True,
>   null=True, max_length=255)
> slug = models.SlugField(_('Slug'), max_length=255, db_index=True)
> Following is the queryset:
>
>  >>>cat=category.objects.get(pk=11)
>
> >>> cat
>
> Traceback (most recent call last):
>
>   File "", line 1, in 
>
>   File 
> "/home/pinakee/oscar_v1/lib/python2.7/site-packages/django/db/models/base.py",
>  line 496, in __repr__
>
> u = six.text_type(self)
>
>   File 
> "/home/pinakee/oscar_v1/lib/python2.7/site-packages/oscar/apps/catalogue/abstract_models.py",
>  line 102, in __str__
>
> return self.full_name
>
>   File "/home/waltzz/jivaana/jivaana_custom/catalogue/models.py", line 61, in 
> full_name
>
> cache_key = self.slug + '_full_name'
>
> TypeError: unsupported operand type(s) for +: 'long' and 'str'
>
> >>> cat.slug
>
> 3L
>
>
> The reason above exception is coming because cat.slug is long and not string 
> as it is supposed to be.
> MySQL Version:
>
> mysql -V
>
> mysql  Ver 14.14 Distrib 5.5.48, for Linux (x86_64) using readline 5.1
>
>
> OS:
>
> 2.6.32-504.30.3.el6.x86_64
>
>
> Thanks.
>
>
> On Friday, October 6, 2017 at 11:49:04 PM UTC+5:30, Antonis Christofides 
> wrote: 
>>
>> Hi,
>>
>> could you show the code that defines the slugfield, the queryset that is 
>> returning the wrong value, full error message and traceback (if available), 
>> and the version of your OS and RDBMS?
>>
>> It doesn't matter if the problem is more general; let's focus on one 
>> specific manifestation of it.
>>
>> Regards,
>>
>> Antonis
>>
>> On October 6, 2017 8:16:20 PM GMT+03:00, Web Architect  
>> wrote: 
>>>
>>> Hi, 
>>>
>>> We have running an ecommerce site using Django 1.8.13. It has been 
>>> running fine for a year. But suddenly the django querysets are returning 
>>> corrupted values. I am completely clueless why this is happening. Like a 
>>> model field is of type SlugField but queryset is returning long. 
>>> Would really appreciate if anyone could throw some light on how to fix 
>>> the above issue. When I check the values in MySQL DB using PhpMyAdmin and 
>>> everything is fine. 
>>> Thanks,
>>> Pinakee
>>>
>> -- 
> You received this message because you are subscribed 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/

Error while customising Django User

2015-12-18 Thread Web Architect
Hi,

I am new to Django and still under the process of learning. We are using an 
open source ecommerce platform - Oscar - for our online store. Oscar is 
based on Django.

I was trying to customise the Django User model by extending with some few 
extra fields/columns:

# file: your-project/apps/user/models.pyfrom django.db import models

from django.contrib.auth.models import AbstractUser

class User(AbstractUser): user_type = models.IntegerField()

# use our own user model in settings.pyAUTH_USER_MODEL = "user.User"

With the above changes, when I run 'makemigration' followed by 'migrate', I am 
getting the following errors:

*Running migrations:*

  Rendering model states...Traceback (most recent call last):

  File "./manage.py", line 10, in 

execute_from_command_line(sys.argv)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 338, in execute_from_command_line

utility.execute()

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 330, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
 line 393, in run_from_argv

self.execute(*args, **cmd_options)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
 line 444, in execute

output = self.handle(*args, **options)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
 line 222, in handle

executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/executor.py",
 line 100, in migrate

state.apps  # Render all real_apps -- performance critical

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/utils/functional.py",
 line 60, in __get__

res = instance.__dict__[self.name] = self.func(instance)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
 line 166, in apps

return StateApps(self.real_apps, self.models)

  File 
"/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
 line 248, in __init__

raise ValueError(msg.format(field=operations[0][1], model=lookup_model))

ValueError: Lookup failed for model referenced by field basket.Basket.owner: 
customer.User


I am not sure what's causing the above error. Certainly there could be 
models which would be dependent on the User model but I thought the 
makemigrations and migrate should be able to resolve those.

Would appreciate if someone could help me with resolving the above errors.

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/d9f452f6-d770-4af2-90a1-9d43d2aace66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while customising Django User

2015-12-19 Thread Web Architect
Hi Tim,

Thanks for your response and the details.

In that case, what would be the best approach to have additional 
credentials for the user? Do I need to create another model/table and link 
it to User? In that case, how will that get included in the User object? Do 
I need to create a middleware?

I am sorry if some queries seem out of the way as I am new to Django. 

Thanks.

On Friday, December 18, 2015 at 8:24:57 PM UTC+5:30, Tim Graham wrote:
>
> If you didn't start your project with a custom user, it's non-trivial to 
> start using one. Please see https://code.djangoproject.com/ticket/25313.
>
> On Friday, December 18, 2015 at 6:55:16 AM UTC-5, Web Architect wrote:
>>
>> Hi,
>>
>> I am new to Django and still under the process of learning. We are using 
>> an open source ecommerce platform - Oscar - for our online store. Oscar is 
>> based on Django.
>>
>> I was trying to customise the Django User model by extending with some 
>> few extra fields/columns:
>>
>> # file: your-project/apps/user/models.pyfrom django.db import models
>>
>> from django.contrib.auth.models import AbstractUser
>>
>> class User(AbstractUser): user_type = models.IntegerField()
>>
>> # use our own user model in settings.pyAUTH_USER_MODEL = "user.User"
>>
>> With the above changes, when I run 'makemigration' followed by 'migrate', I 
>> am getting the following errors:
>>
>> *Running migrations:*
>>
>>   Rendering model states...Traceback (most recent call last):
>>
>>   File "./manage.py", line 10, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  line 338, in execute_from_command_line
>>
>> utility.execute()
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  line 330, in execute
>>
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>  line 393, in run_from_argv
>>
>> self.execute(*args, **cmd_options)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>  line 444, in execute
>>
>> output = self.handle(*args, **options)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>>  line 222, in handle
>>
>> executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/executor.py",
>>  line 100, in migrate
>>
>> state.apps  # Render all real_apps -- performance critical
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/utils/functional.py",
>>  line 60, in __get__
>>
>> res = instance.__dict__[self.name] = self.func(instance)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>  line 166, in apps
>>
>> return StateApps(self.real_apps, self.models)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>  line 248, in __init__
>>
>> raise ValueError(msg.format(field=operations[0][1], model=lookup_model))
>>
>> ValueError: Lookup failed for model referenced by field basket.Basket.owner: 
>> customer.User
>>
>>
>> I am not sure what's causing the above error. Certainly there could be 
>> models which would be dependent on the User model but I thought the 
>> makemigrations and migrate should be able to resolve those.
>>
>> Would appreciate if someone could help me with resolving the above errors.
>>
>> 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/a32d3029-8e78-477e-ae64-3df5ad8358a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while customising Django User

2015-12-21 Thread Web Architect
Hi Tim,

Thanks for your suggestion. Will go through the documentation and will try 
it out.

Thanks.

On Saturday, December 19, 2015 at 9:26:37 PM UTC+5:30, Tim Graham wrote:
>
> You could use a OneToOneField as described at 
> https://docs.djangoproject.com/en/stable/topics/auth/customizing/#extending-the-existing-user-model
>
> On Saturday, December 19, 2015 at 5:12:52 AM UTC-5, Web Architect wrote:
>>
>> Hi Tim,
>>
>> Thanks for your response and the details.
>>
>> In that case, what would be the best approach to have additional 
>> credentials for the user? Do I need to create another model/table and link 
>> it to User? In that case, how will that get included in the User object? Do 
>> I need to create a middleware?
>>
>> I am sorry if some queries seem out of the way as I am new to Django. 
>>
>> Thanks.
>>
>> On Friday, December 18, 2015 at 8:24:57 PM UTC+5:30, Tim Graham wrote:
>>>
>>> If you didn't start your project with a custom user, it's non-trivial to 
>>> start using one. Please see https://code.djangoproject.com/ticket/25313.
>>>
>>> On Friday, December 18, 2015 at 6:55:16 AM UTC-5, Web Architect wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am new to Django and still under the process of learning. We are 
>>>> using an open source ecommerce platform - Oscar - for our online store. 
>>>> Oscar is based on Django.
>>>>
>>>> I was trying to customise the Django User model by extending with some 
>>>> few extra fields/columns:
>>>>
>>>> # file: your-project/apps/user/models.pyfrom django.db import models
>>>>
>>>> from django.contrib.auth.models import AbstractUser
>>>>
>>>> class User(AbstractUser): user_type = models.IntegerField()
>>>>
>>>> # use our own user model in settings.pyAUTH_USER_MODEL = "user.User"
>>>>
>>>> With the above changes, when I run 'makemigration' followed by 'migrate', 
>>>> I am getting the following errors:
>>>>
>>>> *Running migrations:*
>>>>
>>>>   Rendering model states...Traceback (most recent call last):
>>>>
>>>>   File "./manage.py", line 10, in 
>>>>
>>>> execute_from_command_line(sys.argv)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>>>  line 338, in execute_from_command_line
>>>>
>>>> utility.execute()
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>>>  line 330, in execute
>>>>
>>>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>>>  line 393, in run_from_argv
>>>>
>>>> self.execute(*args, **cmd_options)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>>>  line 444, in execute
>>>>
>>>> output = self.handle(*args, **options)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>>>>  line 222, in handle
>>>>
>>>> executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/executor.py",
>>>>  line 100, in migrate
>>>>
>>>> state.apps  # Render all real_apps -- performance critical
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/utils/functional.py",
>>>>  line 60, in __get__
>>>>
>>>> res = instance.__dict__[self.name] = self.func(instance)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>>>  line 166, in apps
>>>>
>>>> return StateApps(self.real_apps, self.models)
>>>>
>>>>   File 
>>>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>>>  line 248, in __init__
>>>>
>>>> raise ValueError(msg.format(field=operations[0][1], 
>>>> model=lookup_model))
>>>>
>>>> ValueError: Lookup failed for model referenced by field 
>>>> basket.Basket.owner: customer.User
>>>>
>>>>
>>>> I am not sure what's causing the above error. Certainly there could be 
>>>> models which would be dependent on the User model but I thought the 
>>>> makemigrations and migrate should be able to resolve those.
>>>>
>>>> Would appreciate if someone could help me with resolving the above errors.
>>>>
>>>> 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/47f352cb-2b08-4164-9320-7c7ebd09d81d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while customising Django User

2015-12-21 Thread Web Architect
Hi,

Thanks for your suggestion. Will try it out.

Thanks.

On Saturday, December 19, 2015 at 10:11:48 PM UTC+5:30, Abdoul Aziz 
Abdoulaye wrote:
>
> Hello, 
> You can use django monkey patching for adding additional fields to User 
> model 
>
> for your case it will look like this. 
>
> User.add_to_class('user_type', model.IntergerField())
>
> Le vendredi 18 décembre 2015 11:55:16 UTC, Web Architect a écrit :
>>
>> Hi,
>>
>> I am new to Django and still under the process of learning. We are using 
>> an open source ecommerce platform - Oscar - for our online store. Oscar is 
>> based on Django.
>>
>> I was trying to customise the Django User model by extending with some 
>> few extra fields/columns:
>>
>> # file: your-project/apps/user/models.pyfrom django.db import models
>>
>> from django.contrib.auth.models import AbstractUser
>>
>> class User(AbstractUser): user_type = models.IntegerField()
>>
>> # use our own user model in settings.pyAUTH_USER_MODEL = "user.User"
>>
>> With the above changes, when I run 'makemigration' followed by 'migrate', I 
>> am getting the following errors:
>>
>> *Running migrations:*
>>
>>   Rendering model states...Traceback (most recent call last):
>>
>>   File "./manage.py", line 10, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  line 338, in execute_from_command_line
>>
>> utility.execute()
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  line 330, in execute
>>
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>  line 393, in run_from_argv
>>
>> self.execute(*args, **cmd_options)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py",
>>  line 444, in execute
>>
>> output = self.handle(*args, **options)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>>  line 222, in handle
>>
>> executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/executor.py",
>>  line 100, in migrate
>>
>> state.apps  # Render all real_apps -- performance critical
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/utils/functional.py",
>>  line 60, in __get__
>>
>> res = instance.__dict__[self.name] = self.func(instance)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>  line 166, in apps
>>
>> return StateApps(self.real_apps, self.models)
>>
>>   File 
>> "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py",
>>  line 248, in __init__
>>
>> raise ValueError(msg.format(field=operations[0][1], model=lookup_model))
>>
>> ValueError: Lookup failed for model referenced by field basket.Basket.owner: 
>> customer.User
>>
>>
>> I am not sure what's causing the above error. Certainly there could be 
>> models which would be dependent on the User model but I thought the 
>> makemigrations and migrate should be able to resolve those.
>>
>> Would appreciate if someone could help me with resolving the above errors.
>>
>> 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/5b275610-c3af-40e2-9db7-f6ae36175e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django debug= false throwing 503 error

2015-12-28 Thread Web Architect
Hi,

I have set the following in settings.py for our production system:

DEBUG=False

ALLOWED_HOSTS = ['*'] (in fact any value is not working)

The server is throwing "HTTPError = 503". 

There are no logs and I am clueless about the reason for the error. I tried 
searching the net and looking into DJango documents but couldn't find the 
possible reason.

Django version is 1.8.3. 

Would really appreciate if anyone could help with the above.

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/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django debug= false throwing 503 error

2015-12-28 Thread Web Architect
Thanks for your message.

On Production, I am running the server behind Nginx. Its run using uwsgi. 
The server works fine with "DEBUG=True" but when it's set to false, it 
throws http 503 error. I saw it in uwsgi logs. Also, when I ran the server 
locally with ./manage.py runserver, its on the console.

Thanks.

On Monday, December 28, 2015 at 3:01:39 PM UTC+5:30, aRkadeFR wrote:
>
> Hello,
>
> How do you run your server in production?
> Where do you see the server throwing the 503 error?
>
> Thanks,
>
> On 12/28/2015 09:46 AM, Web Architect wrote:
>
> Hi, 
>
> I have set the following in settings.py for our production system:
>
> DEBUG=False
>
> ALLOWED_HOSTS = ['*'] (in fact any value is not working)
>
> The server is throwing "HTTPError = 503". 
>
> There are no logs and I am clueless about the reason for the error. I 
> tried searching the net and looking into DJango documents but couldn't find 
> the possible reason.
>
> Django version is 1.8.3. 
>
> Would really appreciate if anyone could help with the above.
>
> 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...@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/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com?utm_medium=email&utm_source=footer>
> https://groups.google.com/d/msgid/django-users/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> aRkadeFR
>
>

-- 
You received this message because you are subscribed to the Google 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/ccd569ad-e8a4-4670-a0b9-47d494f5847e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django debug= false throwing 503 error

2015-12-28 Thread Web Architect
I had run the server locally using ./manage.py runserver and it threw the 
error on the console:

December 28, 2015 - 08:57:30

Django version 1.8.4, using settings 'jivaana.settings'

Starting development server at http://0.0.0.0:8600/

Quit the server with CONTROL-C.

HTTPError = 503

*[28/Dec/2015 08:57:31] "GET /catalogue/ HTTP/1.1" 500 2990*

HTTPError = 503

*[28/Dec/2015 08:57:37] "GET /accounts/login/ HTTP/1.1" 500 2990*

HTTPError = 503

*[28/Dec/2015 09:01:55] "GET /catalogue/ HTTP/1.1" 500 2990*


*I do not have any other logs which I could share. If any more info is 
needed, I could try to gather.*


*Thanks.*

On Monday, December 28, 2015 at 3:08:01 PM UTC+5:30, monoBOT monoBOT wrote:
>
> ​Your server is not working, the first thing to do always is see what is 
> the error message:
>
> 503 Service Unavailable
>
> The server is currently unable to handle the request due to a temporary 
> overloading or maintenance of the server. The implication is that this is a 
> temporary condition which will be alleviated after some delay. If known, 
> the length of the delay MAY be indicated in a Retry-After header. If no 
> Retry-After is given, the client SHOULD handle the response as it would for 
> a 500 response.
>
> Note: The existence of the 503 status code does not imply that a server 
> must use it when becoming overloaded. Some servers may wish to simply 
> refuse the connection.
>
> When you face similar things you should test them locally (with manage.py 
> runserver) with the exact same configuration for django to show you the 
> error message.​ 
> You have not explained too much so we can not help you more.
>
>
> 2015-12-28 8:46 GMT+00:00 Web Architect >:
>
>> Hi,
>>
>> I have set the following in settings.py for our production system:
>>
>> DEBUG=False
>>
>> ALLOWED_HOSTS = ['*'] (in fact any value is not working)
>>
>> The server is throwing "HTTPError = 503". 
>>
>> There are no logs and I am clueless about the reason for the error. I 
>> tried searching the net and looking into DJango documents but couldn't find 
>> the possible reason.
>>
>> Django version is 1.8.3. 
>>
>> Would really appreciate if anyone could help with the above.
>>
>> 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...@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/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>

-- 
You received this message because you are subscribed to the Google 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/060a429d-06a1-4232-a316-b2fcfaea922f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django debug= false throwing 503 error

2015-12-28 Thread Web Architect
Hi,

Thanks for your response.

I had run the server using runserver and it threw the same error:

December 28, 2015 - 08:57:30

Django version 1.8.4, using settings 'jivaana.settings'

Starting development server at http://0.0.0.0:8600/

Quit the server with CONTROL-C.

HTTPError = 503

*[28/Dec/2015 08:57:31] "GET /catalogue/ HTTP/1.1" 500 2990*

HTTPError = 503

*[28/Dec/2015 08:57:37] "GET /accounts/login/ HTTP/1.1" 500 2990*

HTTPError = 503

*[28/Dec/2015 09:01:55] "GET /catalogue/ HTTP/1.1" 500 2990*


*I am sorry I should have mentioned. After all the above debugging, I was 
clueless what was going wrong.*


The DEBUG and ALLOWED_HOSTS was set as per documentation. Not sure if 
anything more was needed.


Thanks.

On Monday, December 28, 2015 at 3:40:24 PM UTC+5:30, esauro wrote:
>
> Hi,
> I assume the development server is working. If that is the case it could 
> be that you have a problem with your production stack. I remember a 
> situation long time ago (like Django 1.1 or so) a project I run with apache 
> + mod_wsgi and we have a problem like this (I don't remember the error 
> code) because there were a "print" in the code.
>
> So please confirm you can use "runserver"
> * If so, try to put more data on your production stack (web server, 
> wsgi gateway, etc.)
> * If no you'll probably have much more data to fix the problem.
>
> Regards,
> Esau.
>
>
>
> On Mon, Dec 28, 2015 at 8:46 AM, Web Architect  > wrote:
>
>> Hi,
>>
>> I have set the following in settings.py for our production system:
>>
>> DEBUG=False
>>
>> ALLOWED_HOSTS = ['*'] (in fact any value is not working)
>>
>> The server is throwing "HTTPError = 503". 
>>
>> There are no logs and I am clueless about the reason for the error. I 
>> tried searching the net and looking into DJango documents but couldn't find 
>> the possible reason.
>>
>> Django version is 1.8.3. 
>>
>> Would really appreciate if anyone could help with the above.
>>
>> 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...@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/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/a3a76d7c-438c-442d-a68b-3d31859b4708%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Esaú Rodríguez
> esa...@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 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/284d41eb-fbba-469c-b9e0-148b65daf38c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Debugging Django with Debug set to False

2016-01-04 Thread Web Architect
Hi,

Is there a way to debug Django when DEBUG is set to False in settings.py 
(for example on production)? 

The reason for asking the above is if we face any issue with DEBUG set to 
False and if we need to debug. 

We are new to Django and we are building an ecommerce platform based on 
Django. 

Would appreciate if anyone could help with the above?

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/c4f16aba-f0e0-4aae-a6c0-1513571c7a97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging Django with Debug set to False

2016-01-05 Thread Web Architect
Thanks all for the responses and I would certainly consider them for 
production level debugging. I understand that application level debugging 
could be achieved by various logging mechanisms or tools.

But one of my main concern is the platform level debugging where in if 
anything goes wrong with any package. For example, recently when I had set 
DEBUG=False, the backend was throwing HTTP 500. I was completely clueless 
what was happening. After deep debugging in the code, I figured out that 
'compress js' that was being used in templates - it seemed was not being 
supported when DEBUG=False. It took some time to figure this out. Had there 
been a log or some mechanism, debugging would have been lot easier and 
quicker.

On Monday, January 4, 2016 at 11:03:26 PM UTC+5:30, Web Architect wrote:
>
> Hi,
>
> Is there a way to debug Django when DEBUG is set to False in settings.py 
> (for example on production)? 
>
> The reason for asking the above is if we face any issue with DEBUG set to 
> False and if we need to debug. 
>
> We are new to Django and we are building an ecommerce platform based on 
> Django. 
>
> Would appreciate if anyone could help with the above?
>
> 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/1550f31d-bcf7-430a-849f-f219e5ba3077%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Debugging DJango app on production for High CPU Usage

2016-02-23 Thread Web Architect
Hi,

We have an ecommerce platform based on Django. We are using uwsgi to run 
the app. The issue the CPU usage is hitting the roof (sometimes going 
beyond 100%) for some scenarios. I would like to debug the platform on 
Production to see where the CPU consumption is happening. We have used 
Cache all over the place (including templates) as well - hence, the DB 
queries would be quite limited. 

I would refrain from using Django-debug toolbar as it slows down the 
platform further, increases the CPU usage and also need to turn the DEBUG 
on. Is there any other tool or way to debug the platform? Would appreciate 
any recommendations/suggestions. 

Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
Would appreciate if anyone could throw some light on this.

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/c2699791-6de9-4b94-975b-fd1d4f8bbd3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-24 Thread Web Architect
Hi Asif,

The OS is CentOS 6 Linux - HW is a dual core processor. Running Django with 
uwsgi. uwsgi is configured with 4 processes and 2 threads (no logic behind 
the numbers but trying to find the optimal combination). I just ran top and 
was checking the CPU usage. Mostly two instances of uwsgi is running and 
one is spiking beyond 100% cpu usage. 

Thanks,
Pinakee

On Wednesday, February 24, 2016 at 5:48:17 PM UTC+5:30, Asif Saifuddin 
wrote:
>
> What is your server configuration and system usage statistics?
>
> On Wednesday, February 24, 2016 at 10:59:28 AM UTC+6, Web Architect wrote:
>>
>> Hi,
>>
>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>> beyond 100%) for some scenarios. I would like to debug the platform on 
>> Production to see where the CPU consumption is happening. We have used 
>> Cache all over the place (including templates) as well - hence, the DB 
>> queries would be quite limited. 
>>
>> I would refrain from using Django-debug toolbar as it slows down the 
>> platform further, increases the CPU usage and also need to turn the DEBUG 
>> on. Is there any other tool or way to debug the platform? Would appreciate 
>> any recommendations/suggestions. 
>>
>> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>> Would appreciate if anyone could throw some light on this.
>>
>> 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/ca866790-5ece-44f1-b8cb-37865689a818%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-24 Thread Web Architect
Hi Avraham,

Please find my comments inline.

On Wednesday, February 24, 2016 at 6:49:29 PM UTC+5:30, Avraham Serour 
wrote:
>
> > sometimes going beyond 100%
>
> how??
>
> That's what I am trying to figure out :)
 

> You can use django-debug-toolbar on your development machine, check the 
> logs for the pages that take the longest to process and the one that are 
> the most requested and start with those, of course your CPU won't be high 
> but you should check and compare if there were improvements after changes.
>

I have done that on our development machine. There aren't much heavy 
calculation being done in any of the views. Only thing is MySQL access. But 
we have template based caching which is obviously reducing the DB queries 
for the cached period.

>
> Do you know already if the CPU usage spike is caused by django and not 
> another software? do you have other stuff in the same server? database? 
> elasticsearch? mongodb? celery workers?
>
We are using Solr but with top, won't that show as CPU consumption by java? 
We do not have celery. Since it's ecommerce platform, its image intensive 
where we are using sorl thumbnail to generate thumbnails dynamically. But 
 Sorl caches the thumbnails. Hence Image processing could have been CPU 
intensive but thats also being cached.


> were specifically are you using cache? I'm not familiar with the technical 
> term "all over the place"
>

Mostly in templates. I think that should help (won't be needed in views I 
presume).  Also, caching the DB results.  

>
> > does the Django ORM increase the CPU usage?
>
> using the ORM increase the CPU usage if you compare to not using it, the 
> fastest code is the one that does't run
>
> Avraham
>
>
> On Wed, Feb 24, 2016 at 9:10 AM, Asif Saifuddin  > wrote:
>
>> What is your server configuration and system usage statistics?
>>
>> On Wednesday, February 24, 2016 at 10:59:28 AM UTC+6, Web Architect wrote:
>>>
>>> Hi,
>>>
>>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>>> beyond 100%) for some scenarios. I would like to debug the platform on 
>>> Production to see where the CPU consumption is happening. We have used 
>>> Cache all over the place (including templates) as well - hence, the DB 
>>> queries would be quite limited. 
>>>
>>> I would refrain from using Django-debug toolbar as it slows down the 
>>> platform further, increases the CPU usage and also need to turn the DEBUG 
>>> on. Is there any other tool or way to debug the platform? Would appreciate 
>>> any recommendations/suggestions. 
>>>
>>> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>>> Would appreciate if anyone could throw some light on this.
>>>
>>> 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...@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/69176a56-5604-4b3e-9887-9ebedf55dbb4%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/69176a56-5604-4b3e-9887-9ebedf55dbb4%40googlegroups.com?utm_medium=email&utm_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/a28fe32c-b0d2-4ff7-8fa8-580d19e4eafe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-24 Thread Web Architect
Hi Javier, 

I am new to uwsgi. The CPU usage is what top is reporting. Is there a way 
to optimise uwsgi?

Thanks.

On Wednesday, February 24, 2016 at 7:06:34 PM UTC+5:30, Javier Guerra wrote:
>
> On 24 February 2016 at 13:18, Avraham Serour  > wrote: 
> >> sometimes going beyond 100% 
> > 
> > how?? 
>
>
> if it's what top reports, 100% refers to a whole core.  a multiforking 
> server (like uWSGI) can easily go well beyond that. 
>
> and that's not a bad thing 
>
> -- 
> Javier 
>

-- 
You received this message because you are subscribed to the Google 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/276a9765-fd6d-45ec-8f2e-b04efc118316%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-24 Thread Web Architect
Hi Will,

In fact thats what I am doing currently. Also, trying to run the load as 
per the production (similar RPS etc based on reports from ngxtop). But 
unfortunately not able to generate the CPU usage spike on development 
(similar to production).

Thanks.

On Wednesday, February 24, 2016 at 7:10:22 PM UTC+5:30, Will Harris wrote:
>
> Hey Web Architect, I guess you never got that DB dump running in 
> development? ;-)
>
> Why don't you run some profiling middleware to see if you can some traces 
> of the production system? Or how about New Relic or some such? That's 
> pretty good at helping to identify problems spots in your stack.
>
> Finally, you will really need to get your production setup running in a 
> development environment if you are ever to have a hope of experimenting 
> with different solutions. You need to understand what user actions are 
> causing the load to spike, and reproduce that on similar infrastructure in 
> a controlled environment where you can instrument your code to see exactly 
> what's going on.
>
> On Wednesday, February 24, 2016 at 5:59:28 AM UTC+1, Web Architect wrote:
>>
>> Hi,
>>
>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>> beyond 100%) for some scenarios. I would like to debug the platform on 
>> Production to see where the CPU consumption is happening. We have used 
>> Cache all over the place (including templates) as well - hence, the DB 
>> queries would be quite limited. 
>>
>> I would refrain from using Django-debug toolbar as it slows down the 
>> platform further, increases the CPU usage and also need to turn the DEBUG 
>> on. Is there any other tool or way to debug the platform? Would appreciate 
>> any recommendations/suggestions. 
>>
>> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>> Would appreciate if anyone could throw some light on this.
>>
>> 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/c8704db5-24af-4622-b944-2472acd90e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-24 Thread Web Architect
Hi Nikolas,

I am new to uwsgi. Top is showing CPU consumption by uwsgi. Following is my 
uwsgi configuration:

master=True

socket=:7090

max-requests=5000

processes = 4

threads = 2

enable-threads = true

#harakiri = 30 (not sure if using this would be a good idea)

stats = 127.0.0.1:9191

HW is a dual core processor with CentOS 6 linux. I am not sure if there is 
a better way to configure uwsgi. uwsgitop is showing only one worker 
process being heavily used and that is the one spiking to 100% + cpu usage. 

Thanks.


On Thursday, February 25, 2016 at 1:47:43 AM UTC+5:30, Nikolas 
Stevenson-Molnar wrote:
>
> Just to be clear: is is the uwsgi process(es) consuming the CPU? I ask 
> because you mention DB queries, which wouldn't impact the CPU of uwsgi 
> (you'd see that reflected in the database process).
>
> On Tuesday, February 23, 2016 at 8:59:28 PM UTC-8, Web Architect wrote:
>>
>> Hi,
>>
>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>> beyond 100%) for some scenarios. I would like to debug the platform on 
>> Production to see where the CPU consumption is happening. We have used 
>> Cache all over the place (including templates) as well - hence, the DB 
>> queries would be quite limited. 
>>
>> I would refrain from using Django-debug toolbar as it slows down the 
>> platform further, increases the CPU usage and also need to turn the DEBUG 
>> on. Is there any other tool or way to debug the platform? Would appreciate 
>> any recommendations/suggestions. 
>>
>> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>> Would appreciate if anyone could throw some light on this.
>>
>> 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/f3ddf458-1b3c-4e3f-8726-2ed494ace71d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-25 Thread Web Architect
Hi Nikolas,

Cache backend is Redis. The CPU usage is directly proportional to the load 
(increases with the increase in load). Memory usage seems to be fine.

Thanks.

On Friday, February 26, 2016 at 3:32:23 AM UTC+5:30, Nikolas 
Stevenson-Molnar wrote:
>
> Which cache backend are you using? Also, how's your memory usage? Do the 
> spikes in CPU correlate with load? I.e., does the CPU use increase/decrease 
> consistently with the number of users?
>
> On Wednesday, February 24, 2016 at 10:17:24 PM UTC-8, Web Architect wrote:
>>
>> Hi Nikolas,
>>
>> I am new to uwsgi. Top is showing CPU consumption by uwsgi. Following is 
>> my uwsgi configuration:
>>
>> master=True
>>
>> socket=:7090
>>
>> max-requests=5000
>>
>> processes = 4
>>
>> threads = 2
>>
>> enable-threads = true
>>
>> #harakiri = 30 (not sure if using this would be a good idea)
>>
>> stats = 127.0.0.1:9191
>>
>> HW is a dual core processor with CentOS 6 linux. I am not sure if there 
>> is a better way to configure uwsgi. uwsgitop is showing only one worker 
>> process being heavily used and that is the one spiking to 100% + cpu usage. 
>>
>> Thanks.
>>
>>
>> On Thursday, February 25, 2016 at 1:47:43 AM UTC+5:30, Nikolas 
>> Stevenson-Molnar wrote:
>>>
>>> Just to be clear: is is the uwsgi process(es) consuming the CPU? I ask 
>>> because you mention DB queries, which wouldn't impact the CPU of uwsgi 
>>> (you'd see that reflected in the database process).
>>>
>>> On Tuesday, February 23, 2016 at 8:59:28 PM UTC-8, Web Architect wrote:
>>>>
>>>> Hi,
>>>>
>>>> We have an ecommerce platform based on Django. We are using uwsgi to 
>>>> run the app. The issue the CPU usage is hitting the roof (sometimes going 
>>>> beyond 100%) for some scenarios. I would like to debug the platform on 
>>>> Production to see where the CPU consumption is happening. We have used 
>>>> Cache all over the place (including templates) as well - hence, the DB 
>>>> queries would be quite limited. 
>>>>
>>>> I would refrain from using Django-debug toolbar as it slows down the 
>>>> platform further, increases the CPU usage and also need to turn the DEBUG 
>>>> on. Is there any other tool or way to debug the platform? Would appreciate 
>>>> any recommendations/suggestions. 
>>>>
>>>> Also, does the Django ORM increase the CPU usage? Does it block the 
>>>> CPU? Would appreciate if anyone could throw some light on this.
>>>>
>>>> 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/7f9520e2-b346-4b91-80e2-6b4f281d6bb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-02-29 Thread Web Architect
The load is low - around 4-5 rps. I don't think that should effect the CPU 
usage so much.



On Friday, February 26, 2016 at 9:57:42 PM UTC+5:30, Nikolas 
Stevenson-Molnar wrote:
>
> What sort of load are you experiencing in production? Is it possible that 
> you're simply running into a hardware limitation and need to scale?
>
> On Thursday, February 25, 2016 at 9:29:22 PM UTC-8, Web Architect wrote:
>>
>> Hi Nikolas,
>>
>> Cache backend is Redis. The CPU usage is directly proportional to the 
>> load (increases with the increase in load). Memory usage seems to be fine.
>>
>> Thanks.
>>
>> On Friday, February 26, 2016 at 3:32:23 AM UTC+5:30, Nikolas 
>> Stevenson-Molnar wrote:
>>>
>>> Which cache backend are you using? Also, how's your memory usage? Do the 
>>> spikes in CPU correlate with load? I.e., does the CPU use increase/decrease 
>>> consistently with the number of users?
>>>
>>> On Wednesday, February 24, 2016 at 10:17:24 PM UTC-8, Web Architect 
>>> wrote:
>>>>
>>>> Hi Nikolas,
>>>>
>>>> I am new to uwsgi. Top is showing CPU consumption by uwsgi. Following 
>>>> is my uwsgi configuration:
>>>>
>>>> master=True
>>>>
>>>> socket=:7090
>>>>
>>>> max-requests=5000
>>>>
>>>> processes = 4
>>>>
>>>> threads = 2
>>>>
>>>> enable-threads = true
>>>>
>>>> #harakiri = 30 (not sure if using this would be a good idea)
>>>>
>>>> stats = 127.0.0.1:9191
>>>>
>>>> HW is a dual core processor with CentOS 6 linux. I am not sure if there 
>>>> is a better way to configure uwsgi. uwsgitop is showing only one worker 
>>>> process being heavily used and that is the one spiking to 100% + cpu 
>>>> usage. 
>>>>
>>>> Thanks.
>>>>
>>>>
>>>> On Thursday, February 25, 2016 at 1:47:43 AM UTC+5:30, Nikolas 
>>>> Stevenson-Molnar wrote:
>>>>>
>>>>> Just to be clear: is is the uwsgi process(es) consuming the CPU? I ask 
>>>>> because you mention DB queries, which wouldn't impact the CPU of uwsgi 
>>>>> (you'd see that reflected in the database process).
>>>>>
>>>>> On Tuesday, February 23, 2016 at 8:59:28 PM UTC-8, Web Architect wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> We have an ecommerce platform based on Django. We are using uwsgi to 
>>>>>> run the app. The issue the CPU usage is hitting the roof (sometimes 
>>>>>> going 
>>>>>> beyond 100%) for some scenarios. I would like to debug the platform on 
>>>>>> Production to see where the CPU consumption is happening. We have used 
>>>>>> Cache all over the place (including templates) as well - hence, the DB 
>>>>>> queries would be quite limited. 
>>>>>>
>>>>>> I would refrain from using Django-debug toolbar as it slows down the 
>>>>>> platform further, increases the CPU usage and also need to turn the 
>>>>>> DEBUG 
>>>>>> on. Is there any other tool or way to debug the platform? Would 
>>>>>> appreciate 
>>>>>> any recommendations/suggestions. 
>>>>>>
>>>>>> Also, does the Django ORM increase the CPU usage? Does it block the 
>>>>>> CPU? Would appreciate if anyone could throw some light on this.
>>>>>>
>>>>>> 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/5f751bd7-a679-4ab8-b4a8-0ec9f503259a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-03-02 Thread Web Architect
Hi James,

Thanks for the detailed explanation. Certainly helps and I would embed 
logging to debug the CPU usage. 

Please find my comments inline:

On Monday, February 29, 2016 at 2:45:41 PM UTC+5:30, James Schneider wrote:
>
>
> On Tue, Feb 23, 2016 at 8:59 PM, Web Architect  > wrote:
>
>> Hi,
>>
>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>> beyond 100%) for some scenarios. I would like to debug the platform on 
>> Production to see where the CPU consumption is happening. We have used 
>> Cache all over the place (including templates) as well - hence, the DB 
>> queries would be quite limited. 
>>
>
> Have you validated that your cache is actually being used, and not just 
> populated? I've seen that before.
>

Cache is being and has been validated. But one thing I have observed is - 
while I was storing ORM objects (DB results) in cache to avoid DB queries, 
it proved to be expensive due to the object related operations 
(manipulating and copying the objects in cache). We are using Redis and 
Redis only handles strings I think. Hence, I reverted back to DB. 

I am personally in favour of async based frameworks like Tornado - in fact 
have used it for a high capacity Pinterest like platform where the 
performance has been excellent. But Tornado is quite lightweight and lot of 
services need to be built by us - hence, chose Django for ecommerce. This 
was the first experience with a complex service (ecommerce) on a platform 
like Django. Since Django is Sync, I was wondering if the threads getting 
stuck waiting for DB responses. 

>
>  
>
>> I would refrain from using Django-debug toolbar as it slows down the 
>> platform further, increases the CPU usage and also need to turn the DEBUG 
>> on. Is there any other tool or way to debug the platform? Would appreciate 
>> any recommendations/suggestions. 
>>
>
>
> Have you looked into profiling the code or adding logging statements 
> throughout your code to determine when/where particular segments are being 
> run? I would definitely start with logging. I'm assuming you have 
> suspicions on where your pain points might be:
>
> https://docs.djangoproject.com/en/1.9/topics/logging/
>
> I would put them in places that may be part of large loops (in terms of 
> number of objects queried or depth of relationships traversed), or 
> sprinkled within complex views. You have to start narrowing down which 
> page/pages are causing your angst. 
>
>
> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>> Would appreciate if anyone could throw some light on this.
>>
>
> I'm not sure about blocking, but if deployed correctly, the ORM should 
> have a negligible (and acceptable) hit to the CPU in most cases, if you 
> notice one at all. I've seen spikes from bad M2M relationships where 
> prefetch_related() was needed (>200 queries down to 3 with 
> prefetch_related, and ~1-2s total response down to <80ms if I recall 
> correctly). The most common case I run into is as part of nested {% for %} 
> loops within a template that dig down through relationships.
>

We have 'for loops' in templates where DB queries are being made.  Would 
look into those. 

>
> I would also consider increasing the logging levels of your cache and DB 
> to see if you are getting repetitive queries. The ORM does cause those from 
> time to time since it has non-intuitive behavior in some edge cases. You 
> can try that during low activity periods to keep the extra logging from 
> overwhelming the system. Sometimes you can still catch the issue with a 
> single end-user for something like repetitive/multiple queries, and are 
> actually much easier to diagnose on a low usage server.
>
> Do you have any other jobs that run against the system (session cleanup, 
> expired inventory removal, mass mailing, etc.)? Would it be possible for 
> those to be the culprit?
>
We do not have any other bulk tasks right now. If possible, we try to do 
those separately with crons.  

>
> Have you figured out any reproducible trigger?
>

I have done some load testing with locust.io and know there are few views 
which are the culprits - specifically the ones where we show bunch of 
products. But  wanted to make sure if Django is not a bottleneck. 

 

>
> -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/dd47a604-26ab-46ed-83f7-3328f6d4fc8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging DJango app on production for High CPU Usage

2016-03-02 Thread Web Architect
Integrated new Relic and seems to be good. Thanks for the suggestion. 

On Monday, February 29, 2016 at 3:20:43 PM UTC+5:30, Lloyd Dube wrote:
>
> New Relic.
>
> On Wed, Feb 24, 2016 at 6:59 AM, Web Architect  > wrote:
>
>> Hi,
>>
>> We have an ecommerce platform based on Django. We are using uwsgi to run 
>> the app. The issue the CPU usage is hitting the roof (sometimes going 
>> beyond 100%) for some scenarios. I would like to debug the platform on 
>> Production to see where the CPU consumption is happening. We have used 
>> Cache all over the place (including templates) as well - hence, the DB 
>> queries would be quite limited. 
>>
>> I would refrain from using Django-debug toolbar as it slows down the 
>> platform further, increases the CPU usage and also need to turn the DEBUG 
>> on. Is there any other tool or way to debug the platform? Would appreciate 
>> any recommendations/suggestions. 
>>
>> Also, does the Django ORM increase the CPU usage? Does it block the CPU? 
>> Would appreciate if anyone could throw some light on this.
>>
>> 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...@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/c2699791-6de9-4b94-975b-fd1d4f8bbd3c%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/c2699791-6de9-4b94-975b-fd1d4f8bbd3c%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Regards,
> Sithembewena
>

-- 
You received this message because you are subscribed to the Google 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/c7e7f373-902f-4cc9-9e93-9063fa138a27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django, uwsgi, gevent, Pymongo

2016-03-24 Thread Web Architect
Hi,

We have a live site running on Django and uwsgi. Pymongo is being used in 
the application for MonogoDB. uwsgi is being used to run the Django 
application.

As per Pymongo docs, it has been suggested to use Gevent monkey patching:

https://api.mongodb.org/python/current/examples/gevent.html

Being new to Django and uwsgi, would appreciate if anyone could suggest - 
if to call Gevents monkey.patch_all() in wsgi.py or manager.py.

Also, as per the Pymongo documentation, only threads and sockets are being 
used and are to be replaced. Hence, can I just call monkey.patch_thread() 
and monkey.patch_socket()?

Also, would there be any potential issues that could arise due to the above?

uwsgi version is 2.0.12 and django version is 1.8.4.

Looking forward to clarifications...

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/08e89144-8eba-4a0e-b424-a6d05c2ff730%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to delete least recently used not expired django sessions?

2018-08-17 Thread Web Architect
Hi,

We are using persistent django sessions for our website where in the 
session information is stored in MySQL. Over last couple of years, the 
session data has grown to a huge number and we were planning to clean it up.
I know that there is a django management command 'clearsessions' and we are 
using the same as a daily cronjob.
But our challenge is we have long expiry timelines of like 100 years so 
that our users are never logged out (unless they clear their cookies etc). 
Hence, the clearsessions won't help. 

The solution we are looking for are removing the sessions which are never 
used for a long period. Let's say a user never came to our site for 3 
months after last logging in. We would like to purge those sessions. Would 
really appreciate if anyone could suggest any such solution - be it in 
Django or if we need to custom build it.

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/57001ae7-1361-43ed-98e3-a9ec072444fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete least recently used not expired django sessions?

2018-08-18 Thread Web Architect
Hi Mike,

Thanks for your response. 

Ours is an ecommerce site and forcing logouts especially for our regular 
users, might not be desirable from business point of view . 

Hence, ideally we would like to keep sessions where users's last activity 
should be within a given time period like 3 months. We can force out the 
users who aren't active since last 3 months. 

Is there a way to do that in django?

Thanks.

On Saturday, August 18, 2018 at 5:11:23 AM UTC+5:30, Mike Dewhirst wrote:
>
> On 17/08/2018 10:44 PM, Web Architect wrote: 
> > Hi, 
> > 
> > We are using persistent django sessions for our website where in the 
> > session information is stored in MySQL. Over last couple of years, the 
> > session data has grown to a huge number and we were planning to clean 
> > it up. 
> > I know that there is a django management command 'clearsessions' and 
> > we are using the same as a daily cronjob. 
> > But our challenge is we have long expiry timelines of like 100 years 
> > so that our users are never logged out (unless they clear their 
> > cookies etc). Hence, the clearsessions won't help. 
> > 
> > The solution we are looking for are removing the sessions which are 
> > never used for a long period. Let's say a user never came to our site 
> > for 3 months after last logging in. We would like to purge those 
> > sessions. Would really appreciate if anyone could suggest any such 
> > solution - be it in Django or if we need to custom build it. 
>
> What are the consequences of deleting all sessions and forcing a new 
> login for everyone? 
>
>
> > 
> > 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...@googlegroups.com  
> > <mailto:django-users+unsubscr...@googlegroups.com >. 
> > To post to this group, send email to django...@googlegroups.com 
>  
> > <mailto: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/57001ae7-1361-43ed-98e3-a9ec072444fe%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/57001ae7-1361-43ed-98e3-a9ec072444fe%40googlegroups.com?utm_medium=email&utm_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/a5867de1-730e-4d8c-93a1-0df41c65f595%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete least recently used not expired django sessions?

2018-08-19 Thread Web Architect
Hi Hemendra, 

Thanks for the workaround. Would look at it's feasibility in our existing 
scenario. 

Thanks.

On Saturday, August 18, 2018 at 3:58:10 PM UTC+5:30, HEMENDRA SINGH HADA 
wrote:
>
> Hi,
>
> I can suggest one thing it might be useful for you. For this you need to 
> create one more attribute in session table like *last activity,* which 
> will update every time when user is logged in and perform some action. 
> Write one middle-ware which will check the activity of each user and update 
> *last 
> activity *field in request repose cycle.
>
> I am not sure will this approach is acceptable for your current scenario.
>
> Thanks,
> Hemendra Singh
>
>
>

-- 
You received this message because you are subscribed to the Google 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/1c0d5eb4-cd3a-48ca-b2c8-23570c214537%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete least recently used not expired django sessions?

2018-08-19 Thread Web Architect
Hi Jason,

Thanks for your response.

As mentioned in my earlier post...I have a long expiry date for the 
sessions (and hence, the cookies)  as we want our users to be always logged 
in or in session (till they clear their cookies). And that's what is 
causing the issue. 

The goal is to keep the regular users logged in whereas flush out the non 
active users (even if their sessions haven't expired). Hence, was looking 
for a solution for the same. 

Thanks.

On Saturday, August 18, 2018 at 5:39:19 PM UTC+5:30, Jason wrote:
>
> With database sessions out of the box, no.
>
>
> https://github.com/django/django/blob/master/django/contrib/sessions/base_session.py
>
> You can see there are three attributes for a session model: key, data and 
> expire_date
>
> That said, since sessions are backed by browser cookies, django's default 
> is two weeks for session cookies as you can see at 
> https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-SESSION_COOKIE_AGE,
>  
> which are used here:  
> https://github.com/django/django/blob/master/django/contrib/sessions/backends/base.py#L225-L244
>
> So if you haven't altered that, all sessions expire in two weeks, and you 
> can just delete those expired sessions by using the clearsessions 
> management command 
> 
> .
>
> if you have changed that, then what Hemendra suggested above seems like a 
> reasonable approach, but one that is not backwards compatible if you don't 
> have a timestamp field for last access 
>
>
>

-- 
You received this message because you are subscribed to the Google 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/4794450f-ad83-4a00-96e3-f354745b322b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete least recently used not expired django sessions?

2018-08-22 Thread Web Architect
Hi Avraham,

Thanks for the recommendation. Will take a look at the package. 

Thanks.

On Monday, August 20, 2018 at 1:00:03 PM UTC+5:30, Avraham Serour wrote:
>
> maybe something like this could be useful for your use case:
> https://pypi.org/project/django-session-timeout/
> it has an option for SESSION_EXPIRE_AFTER_LAST_ACTIVITY
>
>
> maybe this could also be useful for you: 
> https://django-session-security.readthedocs.io/en/latest/
>
>
>
> On Mon, Aug 20, 2018 at 8:34 AM Web Architect  > wrote:
>
>> Hi Jason,
>>
>> Thanks for your response.
>>
>> As mentioned in my earlier post...I have a long expiry date for the 
>> sessions (and hence, the cookies)  as we want our users to be always logged 
>> in or in session (till they clear their cookies). And that's what is 
>> causing the issue. 
>>
>> The goal is to keep the regular users logged in whereas flush out the non 
>> active users (even if their sessions haven't expired). Hence, was looking 
>> for a solution for the same. 
>>
>> Thanks.
>>
>> On Saturday, August 18, 2018 at 5:39:19 PM UTC+5:30, Jason wrote:
>>>
>>> With database sessions out of the box, no.
>>>
>>>
>>> https://github.com/django/django/blob/master/django/contrib/sessions/base_session.py
>>>
>>> You can see there are three attributes for a session model: key, data 
>>> and expire_date
>>>
>>> That said, since sessions are backed by browser cookies, django's 
>>> default is two weeks for session cookies as you can see at 
>>> https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-SESSION_COOKIE_AGE,
>>>  
>>> which are used here:  
>>> https://github.com/django/django/blob/master/django/contrib/sessions/backends/base.py#L225-L244
>>>
>>> So if you haven't altered that, all sessions expire in two weeks, and 
>>> you can just delete those expired sessions by using the clearsessions 
>>> management command 
>>> <https://github.com/django/django/blob/master/django/contrib/sessions/management/commands/clearsessions.py>
>>> .
>>>
>>> if you have changed that, then what Hemendra suggested above seems like 
>>> a reasonable approach, but one that is not backwards compatible if you 
>>> don't have a timestamp field for last access 
>>>
>>>
>>> -- 
>> You received this message because you are subscribed 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/4794450f-ad83-4a00-96e3-f354745b322b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/4794450f-ad83-4a00-96e3-f354745b322b%40googlegroups.com?utm_medium=email&utm_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/c8c48fbf-e381-4867-ba7b-94e62c7dce1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete least recently used not expired django sessions?

2018-08-22 Thread Web Architect
Hi,

Thanks for the approach. On our site, customers have option to do guest 
checkout wherein users can make a purchase without getting 
registered/signing up. We are still using session information for such 
users. Hence, the session is kind of combined for logged in and not logged 
in users. The challenge is to figured out the sessions for logged in users 
(atleast I am not aware of how to do that in Django).  
Typically in businesses, users (specifically the masses and who aren't that 
tech savvy) prefer a flow that's smooth and hassle free though security 
definitely becomes an important aspect. Hence, the challenge is to combine 
the both.

I would certainly look into the approach you have suggested. 

Thanks. 

On Monday, August 20, 2018 at 2:08:30 PM UTC+5:30, Michal Petrucha wrote:
>
> -BEGIN PGP SIGNED MESSAGE- 
> Hash: SHA512 
>
> On Fri, Aug 17, 2018 at 05:44:22AM -0700, Web Architect wrote: 
> > Hi, 
> > 
> > We are using persistent django sessions for our website where in the 
> > session information is stored in MySQL. Over last couple of years, the 
> > session data has grown to a huge number and we were planning to clean it 
> up. 
> > I know that there is a django management command 'clearsessions' and we 
> are 
> > using the same as a daily cronjob. 
> > But our challenge is we have long expiry timelines of like 100 years so 
> > that our users are never logged out (unless they clear their cookies 
> etc). 
> > Hence, the clearsessions won't help. 
> > 
> > The solution we are looking for are removing the sessions which are 
> never 
> > used for a long period. Let's say a user never came to our site for 3 
> > months after last logging in. We would like to purge those sessions. 
> Would 
> > really appreciate if anyone could suggest any such solution - be it in 
> > Django or if we need to custom build it. 
> > 
> > Thanks. 
>
> There is another de-facto standard solution to this problem, which 
> does not involve setting the session expiry to years – it's usually 
> referred to as “persistent authentication cookie”. That way, sessions 
> would expire after the usual short period of time, and it also makes 
> the persistent login feature optional for your users. 
>
> I haven't found a maintained package that would implement this for 
> Django applications, but you can find a bunch of material on this 
> topic. For example, this article seems to consider a lot of potential 
> attack vectors: 
>
> https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title.2
>  
>
> Michal 
> -BEGIN PGP SIGNATURE- 
> Version: GnuPG v1 
>
> iQIcBAEBCgAGBQJben3lAAoJEHA7T/IPM/klRiMQAKnoqOWIrbQDiDcaARde9jl+ 
> SuPfHZP/H44t7z610+CC2D03C4hps+7acQWslH2S+WFL/+VUJPqytGTWsAJbs12A 
> /R+UaIlwDGFMeRBw2xdDusZtbE4t+atGS5PPgr8hEW89/op9/DruSed1cVxoUiBp 
> pwNwBst+cieNhtBYpXBUCe8mRxRegc8xCz/pKRw9ZycszYgB4rTpDVwOFMmxPWuS 
> rKDRgMsXhYQskiGWi5oSHQ8xEgxBeGXdv3HnlwCm9TenXs1gfVQwbRhG4btivCUD 
> nzhpUTtHx3PP5/uDK0GM87MqB6ufuf7H/7QXgFKTWBZxSeOXwaxICsxYaG54DMld 
> hYxFk36RtjufWgcffQooBfw3eavtzAnPdjlZzEI3ZYj5fPx9agGJf177JAVSCovS 
> bppF1QbipuIfQlLyv7gee8bR6a6uLEQZ4vp9NHrfqWjXYqmIDxubnVB5B1/d6yvG 
> S9liRlkoGAWC9tTS5ig03QV1b4nBlJIonKIRBecrfJXHw3G2WojY8HAiSyyz9A4P 
> S/XcvOzK7dWsw/NUmx84GkR3SGfFeQor3bVWUeBhG6BBOjZq6cj+MHa2gZswIIYa 
> d6dHRCa4hyDwBLZDaEbI4EDbIkrY82L87PD9KW+0xbBYojwysQz8pL/3WHc8F1NL 
> 0VXYCCnD/4/LdzywjR21 
> =njLP 
> -END PGP SIGNATURE- 
>

-- 
You received this message because you are subscribed to the Google 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/fbcb5b75-de8b-43fb-a47e-5232b1c95212%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Customise Session Engine to distribute session data storage

2018-08-27 Thread Web Architect
Hi,

Right now we are using the Django cache_db session engine for persistent 
sessions and also for some speed. Is it possible to customise this where I 
can store some session data in cache and some in DB? For example, I want to 
store all login sessions in DB and rest like some user specific data - 
basket etc in cache .

Looking forward to your support

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/cfd7fc04-6102-4c01-904e-d7939bbada5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customise Session Engine to distribute session data storage

2018-08-27 Thread Web Architect
Hi Jason,

Thanks for the response. Why not use Django's cache backend and setting 
cache alias to be redis?

Thanks. 

On Monday, August 27, 2018 at 5:01:08 PM UTC+5:30, Jason wrote:
>
> there's an option to use redis as a session backend, which would be faster 
> than using a regular db, even a well tuned mysql/postgres instance
>
> https://github.com/martinrusev/django-redis-sessions
>
> On Monday, August 27, 2018 at 3:52:06 AM UTC-4, Web Architect wrote:
>>
>> Hi,
>>
>> Right now we are using the Django cache_db session engine for persistent 
>> sessions and also for some speed. Is it possible to customise this where I 
>> can store some session data in cache and some in DB? For example, I want to 
>> store all login sessions in DB and rest like some user specific data - 
>> basket etc in cache .
>>
>> Looking forward to your support
>>
>> 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/cecb2b48-e036-4bfb-8cde-75d1214149af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customise Session Engine to distribute session data storage

2018-08-30 Thread Web Architect
We were actually cache_db but the sessions were consuming too much of DB. 
Hence, we want some sessions to be persistent in DB and some to be volatile 
and not stored in DB. Hence, I was looking for some way to achieve that. 
Like I want all login sessions to be stored in DB whereas rest in cache. 

On Tuesday, August 28, 2018 at 4:37:46 PM UTC+5:30, Jason wrote:
>
> Actually, there's nothing stopping you from using redis for cache and 
> session cache.  
>
> SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
>
> will use your cache to store sessions.  and if you use cached_db instead 
> of cache, that data will persist in redis and survive restarts.
>
> On Tuesday, August 28, 2018 at 1:40:38 AM UTC-4, Web Architect wrote:
>>
>> Hi Jason,
>>
>> Thanks for the response. Why not use Django's cache backend and setting 
>> cache alias to be redis?
>>
>> Thanks. 
>>
>> On Monday, August 27, 2018 at 5:01:08 PM UTC+5:30, Jason wrote:
>>>
>>> there's an option to use redis as a session backend, which would be 
>>> faster than using a regular db, even a well tuned mysql/postgres instance
>>>
>>> https://github.com/martinrusev/django-redis-sessions
>>>
>>> On Monday, August 27, 2018 at 3:52:06 AM UTC-4, Web Architect wrote:
>>>>
>>>> Hi,
>>>>
>>>> Right now we are using the Django cache_db session engine for 
>>>> persistent sessions and also for some speed. Is it possible to customise 
>>>> this where I can store some session data in cache and some in DB? For 
>>>> example, I want to store all login sessions in DB and rest like some user 
>>>> specific data - basket etc in cache .
>>>>
>>>> Looking forward to your support
>>>>
>>>> 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/86d58e15-ff41-48e3-b534-2bf982d59531%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customise Session Engine to distribute session data storage

2018-09-03 Thread Web Architect
Thanks. This seems to be quite helpful. Will look into it. 

On Thursday, August 30, 2018 at 6:23:10 PM UTC+5:30, Jason wrote:
>
> https://github.com/adw0rd/django-multi-sessions
>
> that's a non-working project but might give you some clues how to route 
> sessions to different backends.
>

-- 
You received this message because you are subscribed to the Google 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/b520e4c7-a36c-48ec-97cd-3643dca7e232%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


db_index=True not creating indexes

2018-10-05 Thread Web Architect
Hi,

We are using django for our ecommerce website. 

I am facing a strange issue. I was trying to index a field in a table and 
hence, set db_index=True in the field declaration. I ran migrations but 
when I checked the indexes for the table, the index for the field wasn't 
there. There were also few foreign key fields but no indexes for them as 
well. The migration didn't throw any error. Hence, I am a bit perplexed. 

Would appreciate if anyone could help me with the above. 

Also, can I create indexes directly in the database (not via django)? Will 
that have any issue in Django. 

I am using Django 1.11. MySQL is 5.6. 

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/2b5b6f3d-a704-46f6-9506-c0a47cdead26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: db_index=True not creating indexes

2018-10-05 Thread Web Architect
Hi Mathew,

Thanks for your response. 

I did run makemigrations before running migration. There were no issues 
with those. But somehow the indexes were not showing on the tables when I 
ran SHOW INDEX from tablename;. That's the reason I was thinking of 
creating the indexes manually. 

I will look into RunSQL.

Thanks.

On Friday, October 5, 2018 at 7:12:18 PM UTC+5:30, Matthew Pava wrote:
>
> Hi,
>
> I’m using Django 2.0 and PostgreSQL 9.something, but my tables do have 
> indexes.  Did you run the makemigrations command before running the migrate 
> command?
>
>  
>
> Also, you can modify the database that Django uses however you want with 
> some caveats.  Anyway, you can add views and modify columns and add 
> constraints in the database.  I do have a suggestion that if you do that, 
> you create your own migration files with the RunSQL command so that you can 
> be able to recreate the database structure and keep track of your 
> modifications.
>
>  
>
> So, in your case, if you really want to add an index manually, create a 
> blank migration file, and add this operation:
>
> migrations.RunSQL(“CREATE INDEX my_cool_looking_index USING BTREE ON 
> appname_modelname (my_cool_looking_field)”)
>
>  
>
>
> https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-makemigrations
>
>  
>
> https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runsql
>
>  
>
> Good luck!
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Web Architect
> *Sent:* Friday, October 5, 2018 7:14 AM
> *To:* Django users
> *Subject:* db_index=True not creating indexes
>
>  
>
> Hi,
>
>  
>
> We are using django for our ecommerce website. 
>
>  
>
> I am facing a strange issue. I was trying to index a field in a table and 
> hence, set db_index=True in the field declaration. I ran migrations but 
> when I checked the indexes for the table, the index for the field wasn't 
> there. There were also few foreign key fields but no indexes for them as 
> well. The migration didn't throw any error. Hence, I am a bit perplexed. 
>
>  
>
> Would appreciate if anyone could help me with the above. 
>
>  
>
> Also, can I create indexes directly in the database (not via django)? Will 
> that have any issue in Django. 
>
>  
>
> I am using Django 1.11. MySQL is 5.6. 
>
>  
>
> 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...@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/2b5b6f3d-a704-46f6-9506-c0a47cdead26%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/2b5b6f3d-a704-46f6-9506-c0a47cdead26%40googlegroups.com?utm_medium=email&utm_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/23c805c9-27c1-41f5-bc8e-1706dc4f038e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Form Code getting executed during django project startup

2018-10-12 Thread Web Architect
Hi,

We are using Django for our ecommerce site. 

I have some confusion on when the code gets executed in Django. I have a 
django form with a choice field in module m1.py:

class SomeForm(forms.Form):
field = forms.ChoiceField(choices=get_choices())


def get_choices():
return some choices


In views.py, I have imported SomeForm:

from app.m1 import SomeForm

class SomeFormView(Formview):
form = SomeForm
...rest of the view code


When I run the django project using ./manage.py runserver, I am surprised 
to see that get_choices gets executed. This is undesirable as I can have a 
Django queryset in get_choices and I do not want unnecessary DB access. 

It would be really helpful if someone can shed some light on the above and 
tell me what exactly is happening. How can I avoid get_choices getting 
executed during django start  or running? get_choices should only get 
executed when SomeFormView is accessed.

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/419b19a4-6ba1-4a27-8c27-f0d65b34a8bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Form Code getting executed during django project startup

2018-10-12 Thread Web Architect
Hi Michal,

Thanks a lot. That was an eye-opener and a big help :)

Thanks.

On Friday, October 12, 2018 at 1:39:38 PM UTC+5:30, Michal Petrucha wrote:
>
> -BEGIN PGP SIGNED MESSAGE- 
> Hash: SHA512 
>
> On Fri, Oct 12, 2018 at 12:52:31AM -0700, Web Architect wrote: 
> > Hi, 
> > 
> > We are using Django for our ecommerce site. 
> > 
> > I have some confusion on when the code gets executed in Django. I have a 
> > django form with a choice field in module m1.py: 
> > 
> > class SomeForm(forms.Form): 
> > field = forms.ChoiceField(choices=get_choices()) 
>
> The problem is here – you're calling get_choices, and passing the 
> result to the ChoiceField as a static list. If you pass get_choices as 
> a function, it will be called at runtime, whenever the form is 
> instantiated: 
>
> class SomeForm(forms.Form): 
> field = forms.ChoiceField(choices=get_choices) 
>
> Good luck, 
>
> Michal 
>
> > 
> > 
> > def get_choices(): 
> > return some choices 
> > 
> > 
> > In views.py, I have imported SomeForm: 
> > 
> > from app.m1 import SomeForm 
> > 
> > class SomeFormView(Formview): 
> > form = SomeForm 
> > ...rest of the view code 
> > 
> > 
> > When I run the django project using ./manage.py runserver, I am 
> surprised 
> > to see that get_choices gets executed. This is undesirable as I can have 
> a 
> > Django queryset in get_choices and I do not want unnecessary DB access. 
> > 
> > It would be really helpful if someone can shed some light on the above 
> and 
> > tell me what exactly is happening. How can I avoid get_choices getting 
> > executed during django start  or running? get_choices should only get 
> > executed when SomeFormView is accessed. 
> > 
> > Thanks. 
> -BEGIN PGP SIGNATURE- 
> Version: GnuPG v1 
>
> iQIcBAEBCgAGBQJbwFaVAAoJEHA7T/IPM/klm44QAJMjeGXjs7fzHaCpi7Sn16Ib 
> bHAyoluqmS5+Pw9yYsg3FaYJwx1JC6r/vB6Hv9WfBAI5cIzJa+k0e8T7PkuUg3Nc 
> ioG4izJWYC8F4MSXXynRVrt8UR4OfQrDw2tmXPXI++nf9GgMmN1Q/VJwVyWKUK8h 
> MD6L8ap0IIhhjOr3Nwvc1lsT68Hx4eEBmPcGa88FsHMUpox6ktIYmIeCq9WDIVQz 
> GKxMdRr+SUjcq7NeqqLL1davlL2YIKAaSdy1tNaxQ890u436MUkQ0L5FK2FtpKIh 
> ViqraEi/BaHWzZ6Dr6l6oG5QlrIHiG89VjYvYYo6qAtB67Yl5A6QnLY1YkMpiNkv 
> jZJt+u3ad4+qP5JQ0/SDYruyN2cjt6SVowQmAAxyGYbzFYMhWEz/NDopPXB/8q01 
> nr7o+N4azH696Ryr9bH5KEilrZvoxxxt9Zb+IGaJU5tfHs4A2Pzmw6aNmwMkRAVg 
> Mo0eaQuOu4zG6ix5X2wX7z+2MrGfBw0OJisOH3BzPOQ9CdHOaB0HuaveKQ39aVCL 
> vmGgPy+NnBr+EL/r1PC+sD9JjSFM6sD8+7fB1rvEtYsILj+DHHICYOZGaBGU34zm 
> TJjCHDSTp5Dx/p5mrt8Y9UJLf5U7C2Sz562R2ez3wKkrCqxGKN7fY7cq0oB01Cph 
> geJsa6+RNjRHpCbM1U/U 
> =7eA9 
> -END PGP SIGNATURE- 
>

-- 
You received this message because you are subscribed to the Google 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/242ffbae-150e-45ec-877f-0a983044258d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Hi,

We are using django 1.11 for our ecommerce site. 

We are facing an issue with modelform and many to many field in it as 
follows:

Lets say there are two models:

class A(models.Model):
   c = models.CharField()

class B(models.Model):
  a = models.ManyToManyField('A')

Now if I define a modelform:

class MF(models.ModelForm):
  class Meta:
  model = B
  fields = [a,]

We are using django widget tweaks to render the fields in MF. Now if there 
are tens of thousands of records in A, the MF form rendering causes the 
page to hang as the widget will try to show the whole set of tens of 
thousands of records option for field a. 

Hence, would appreciate if anyone could suggest a smart solution wherein 
the above issue is taken care of. 

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/2b3be3a1-e0a6-4c73-8c69-d7a314885ab3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Would also add that the server CPU usage was hitting 100% due to the 
template loading issue. 

On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote:
>
> Hi,
>
> We are using django 1.11 for our ecommerce site. 
>
> We are facing an issue with modelform and many to many field in it as 
> follows:
>
> Lets say there are two models:
>
> class A(models.Model):
>c = models.CharField()
>
> class B(models.Model):
>   a = models.ManyToManyField('A')
>
> Now if I define a modelform:
>
> class MF(models.ModelForm):
>   class Meta:
>   model = B
>   fields = [a,]
>
> We are using django widget tweaks to render the fields in MF. Now if there 
> are tens of thousands of records in A, the MF form rendering causes the 
> page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
>
> Hence, would appreciate if anyone could suggest a smart solution wherein 
> the above issue is taken care of. 
>
> 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/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Hi Sanjay,

Thanks for the prompt response and the approach. 

That seems to be an efficient approach - would look into auto-complete.

Thanks.

On Monday, October 29, 2018 at 5:09:50 PM UTC+5:30, Sanjay Bhangar wrote:
>
> My recommendation would be to use a bit of Javascript to implement an 
> "autocomplete" to fetch records via AJAX as the user types (with 
> perhaps a minimum of 3 characters or so), so you only ever fetch a 
> subset of records and don't overload your template. 
>
> You can find quite a few 3rd party libraries that should be able to 
> aid in setting up this behaviour, see: 
> https://djangopackages.org/grids/g/auto-complete/ - unfortunately, I 
> can't recommend a particular one right now - but most should have 
> integrations for the django admin / django forms with Many2Many or 
> ForeignKey fields. 
>
> Hope that helps, 
> Sanjay 
> On Mon, Oct 29, 2018 at 5:01 PM Web Architect  > wrote: 
> > 
> > Would also add that the server CPU usage was hitting 100% due to the 
> template loading issue. 
> > 
> > On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote: 
> >> 
> >> Hi, 
> >> 
> >> We are using django 1.11 for our ecommerce site. 
> >> 
> >> We are facing an issue with modelform and many to many field in it as 
> follows: 
> >> 
> >> Lets say there are two models: 
> >> 
> >> class A(models.Model): 
> >>c = models.CharField() 
> >> 
> >> class B(models.Model): 
> >>   a = models.ManyToManyField('A') 
> >> 
> >> Now if I define a modelform: 
> >> 
> >> class MF(models.ModelForm): 
> >>   class Meta: 
> >>   model = B 
> >>   fields = [a,] 
> >> 
> >> We are using django widget tweaks to render the fields in MF. Now if 
> there are tens of thousands of records in A, the MF form rendering causes 
> the page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
> >> 
> >> Hence, would appreciate if anyone could suggest a smart solution 
> wherein the above issue is taken care of. 
> >> 
> >> 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...@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/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%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/e7590f4d-2658-4c8a-bfba-02a5d64cbb12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django unit test - response context is None

2018-10-31 Thread Web Architect
Hi,

We are using django 1.11 for our ecommerce site.

We are developing unit tests for our views using django testing framework. 
We are facing issue with a simple implementation:

import unittest


from django.urls import reverse

from django.test import Client


class ViewTests(unittest.TestCase):

def setUp(self):

self.client = Client()


def test_View(self):

url = '/some-url/'



response = self.client.get(url)

products = response.context['products']


In the above test case, response.context is coming out to be None and 
hence, response.context['products'] is throwing exception. Whereas when I 
run the same on django admin shell, response.context has context object 
dict. 


I am quite confused why this is happening. I couldn't find any reason in 
the django documents.


Would really appreciate if someone could help me with the above.  


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/8e487599-2179-4de6-9a4a-32e108778991%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django unit test - response context is None

2018-10-31 Thread Web Architect
Hi Jason,

Thanks for your prompt response. 

I was using Django TestCase but it wasn't working then. Hence, I resorted 
to unittest as shown in Django 1.11 documentation. Also, the attribute was 
working fine in django shell. 

Please refer to the documentation here:
https://docs.djangoproject.com/en/1.11/topics/testing/tools/#overriding-settings

I will check the link you have provided for the solution.

Thanks.

On Wednesday, October 31, 2018 at 6:19:40 PM UTC+5:30, Jason wrote:
>
> Two things I can see:
>
> you should be inheriting from TestCase in django.test, not unittest.  
> Second, you should find your answer at 
> https://stackoverflow.com/questions/27136048/django-unit-test-response-context-is-none
>  . 
> I believe the attribute you're trying to access was deprecated in django 
> 1.8 and was probably removed in 1.11
>

-- 
You received this message because you are subscribed to the Google 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/9dfbf9e5-c4e3-480b-bb47-201949005190%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.