Freelancer

2007-11-02 Thread chetan

Hi,


I Am A Freelancer.I Am A Web Designer And A 3d Animator.I Am Doing Job
In Ahmadabad In India.http://www.ewebarea.com Is The Name OF My
Site.If You Have Any Project related To Web Please Contact Me On
[EMAIL PROTECTED]


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to make django sqlite database connection readonly.

2017-01-30 Thread Chetan Gupta
Hi,

I am new to django.
My requirement is django application i have 3 db connection.
I want 2 db connection is readonly.

Please let me know how to do that.

Regards
Chetan

-- 
You received this message because you are subscribed to the Google Groups 
"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/4f683ab6-e423-4ac0-a476-f0d2698b90ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for Django Python Developers to build Strong Application

2014-11-12 Thread Chetan Salvi
 Hi Ankit,

 I will refer our own company Lotus Intelligent Systems which is 
progressing as start up Indian based company.

We had developed many web applications in python using django.

You can visit our website www.lotusintelligentsystems.com.

Thanks

Regards
chetan salvi

-- 
You received this message because you are subscribed to the Google Groups 
"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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd9e6542-15fa-4d7b-83b5-2d2204961fbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Dynamic choices

2006-02-08 Thread Chetan Vaity
Hi all,

I have a model which looks somethng like:

class MyModel(meta.Model):
    id = meta.AutoField(primary_key = True)
    name = meta.CharField(maxlength=20, unique=True)
    location = meta.CharField(maxlength=100, choices=getLocationChoices())

and getLocationChoices() is a function defined in the same file which
returns a list of tuples. This function reads a dynamic store (LDAP) to
get the list.

What I notice is that whenever an entry is added to LDAP, it is not
reflected in the SelectField drop-down on the create form for the
model. But if I simply restart the Apache httpd server, the drop-down
is correctly populated.

Can someone tell me why this is so?

Thanks,
- Chetan



Re: Dynamic choices

2006-02-14 Thread Chetan Vaity
Thanks Amit and Adrian,I think I'll do something like what Amit said or write a custom manipulator.- ChetanOn 2/8/06, Adrian Holovaty <
[EMAIL PROTECTED]> wrote:On 2/8/06, Amit Upadhyay <
[EMAIL PROTECTED]> wrote:> > What I notice is that whenever an entry is added to LDAP, it is not> reflected in the SelectField drop-down on the create form for the model. But
> if I simply restart the Apache httpd server, the drop-down is correctly> populated.> >> > Can someone tell me why this is so?>> This is so because getLocationChoices() is calculated when model is being
> created. To solve your problem you can do the following:You could do what Amit suggested, but I would suggest creating aseparate Location model  to avoid this problem entirely. The "choices"
parameter is intended for a finite list of choices that never change.When you're dealing with data that needs to be dynamic, use thedatabase.Adrian--Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Multi-page forms

2006-02-23 Thread Chetan Vaity
Hi,I want to build a two-page form for creating an object. As I see it there are two options:1. Store values in hidden fields2. Use the session to store the variables from the first formAny Django best practices?
- Chetan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---


How does one access the human readble names given in the model

2006-03-01 Thread Chetan Vaity
Example model:class Vegetable(meta.Model):   name = CharField("Name of the vegetable", maxlength=10)   freshness = PositiveIntegerField("How fresh is it", maxlength=2)With the django API:
from django.models.vegetable import *v = vegetables.get_object(pk=1)Now, how can I get the human readble name of the member "freshness" for the object "v"I tried exploring v.__class__, v._meta, etc. but no luck.
I think it is possible because, the admin interface does do it for the in-built "users" model.Thanks,Chetan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---


Template tags for sorting based on table headers

2006-03-02 Thread Chetan Vaity
Hi all,Here is a first cut implementation for a custom template tag which makes providing sorting on table headers easy.Assume that your model is something like:class Vegetable(meta.Model):    name = meta.CharField
()    wt = meta.PositiveIntegerField()    You will need to do the following things to provide sorting in the list view:1. Make a "templatetags" directory inside your app directory and copy the 2 attached files there (
corder.py and support.py). Also create an empty __init__.py there.2. In your view function for displaying the list of objects:from wherever.yourapp.templatetags.support import *...def displaylist(request):
 orderobj = getoo(request)    # getoo() is defined in templatetags/support.py. # orderobj contains data which needs to go to the template from the view. ... object_list = vegetables.get_list
()   # You will be doing this somehwe in the view function ... return render_to_response('vegetable_list', {'object_list': object_list, 'orderobj': orderobj, ...})3. In your template file (vegetable_list.html):
{% load corder %} ...{% block content %} # I don't know why but the corderlist tag must be inside the content block{% corderlist object_list orderobj %} # This tag sorts the object_list...
{% corderheader name Name orderobj %}{% corderheader wt Weight orderobj %}
{% for object in object_list %}{{ object.name }}{{ object.weight }}{% endfor %}
...{% endblock %}The "corderlist" tag takes 2 arguments: an object_list and the orderobj object (which is passed to the template from the view)This tag sorts the object_list according to options in orderobj (You need not worry what's in that object. It should do the correct thing).
This tag generates no output.The "corderheader" tag generates the  tag with the appropriate query string in the  tag.The 3 parameters are: membername - the member variable of the model, verbosename - what you want to appear on the table, and the orderobj object.
Let me know if you have any problems in trying it out.Thanks,- Chetanps: I work on the 0.90 release

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django users" group.  To post to this group, send email to django-users@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/django-users  -~--~~~~--~~--~--~---
from django.core.template import register_tag, TemplateSyntaxError, Node

#
# For the tag {% corderlist objectlist orderobj %}
# This should sort the objectlist based on orderobj['orderby'] and
# orderobj['ordertype']
#
def do_corderlist(parser, token):
try:
tag_name, objlistvar, orderobjvar = token.contents.split(None, 2)
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires 2 arguments" % token.contents.split()[0]

return COrderListNode(objlistvar, orderobjvar)


class COrderListNode(Node):
def __init__(self, objlistvar, orderobjvar):
self.objlistvar = objlistvar
self.orderobjvar = orderobjvar
def render(self, context):
orderobj = context[self.orderobjvar]

# If orderobj is not set, don't sort, return immediately
if orderobj['orderby'] == None:
return ''

def cmpfunc_asc(a, b):
var = orderobj['orderby']
a_var = getattr(a, var)
b_var = getattr(b, var)
if a_var < b_var:
return -1
if a_var == b_var:
return 0
return 1

def cmpfunc_desc(a, b):
var = orderobj['orderby']
a_var = getattr(a, var)
b_var = getattr(b, var)
if b_var < a_var:
return -1
if b_var == a_var:
return 0
return 1

if orderobj['ordertype'] == 'asc':
context[self.objlistvar].sort(cmpfunc_asc) # In place sort
else:
context[self.objlistvar].sort(cmpfunc_desc)
return ''

#
# For the tag   {% corderheader membername verbosename orderobj %}
# For example:  {% corderheader name Room orderobj %}
# This should render something like:
# Room
# The class attribute in the should be decided based on whether the current tag
# is being ordered on
#
def do_corderheader(parser, token):
try:
tag_name, membervar, verbosename, orderobjvar = token.contents.split(None, 3)
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires 3 arguments" % token.contents.split()[0]
return COrderHeaderNode(membervar, verbosename, orderobjvar)


class COrderHeaderNode(Node):
def __init__(self, membervar, verbosename, orderobjvar):
self.membervar = membervar
self.verbosename = verbosename
self.orderobjvar = orderobjvar

def render(self, context):
orderobj = context[s

Re: Django csv file

2019-03-12 Thread Chetan Ganji
I would suggest you use transactions for inserting those many documents.
https://www.mongodb.com/transactions

Django ORM does not support MongoDB. So, you can't use models/ORM/Class
Based Views of Django with mongo.
Only way I know to use Mongo with Django is function based views. There are
some third party MONGO ORMS for django, but I never used them so far, so
can't comment on how good they are or are not. Do your R&D and find it out
;-)

I hope this helps you. Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 12:42 AM Ryan Nowakowski 
wrote:

> If I were you, I'd work through the Django tutorial first. Then ask
> specific questions if you have any.
>
> On March 12, 2019 5:32:08 AM CDT, Cigi Sebastine 
> wrote:
>>
>>
>> Hi all
>>
>> I am trying to insert data from csv file to mongodb4 using python3.7
>> (Bulk data insertion 47lakhs records)
>> i need to implement in django
>> Can please anyone share ur idea
>>
>> import pandas as pd
>> import json
>>
>> mng_client = MongoClient('localhost', 27017)
>> mng_db = mng_client['testcsv']
>> collection_name = mng_db['datastore']
>> db_cm = mng_db['datastore']
>>
>> df = pd.read_csv('filepath',encoding = 'ISO-8859-1') # loading csv file
>> #dfstr = df.to_json('testjson1.json')
>> data_json = json.loads( df.to_json())
>> db_cm.insert_many(data_json)
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "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/89E98305-6AEC-4A82-9839-E86760DC3AB2%40fattuba.com
> <https://groups.google.com/d/msgid/django-users/89E98305-6AEC-4A82-9839-E86760DC3AB2%40fattuba.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/CAMKMUjv%3DrU%3DNJxhd%2BHwpz40RrFB_Z2qP9Mq7q2SoXFys4HSO2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django csv file

2019-03-13 Thread Chetan Ganji
Welcme CIGI

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 5:13 PM Cigi Sebastine 
wrote:

> Thank you Chetan.
>
>
> On Wed, Mar 13, 2019 at 3:41 AM Chetan Ganji 
> wrote:
>
>> I would suggest you use transactions for inserting those many documents.
>> https://www.mongodb.com/transactions
>>
>> Django ORM does not support MongoDB. So, you can't use models/ORM/Class
>> Based Views of Django with mongo.
>> Only way I know to use Mongo with Django is function based views. There
>> are some third party MONGO ORMS for django, but I never used them so far,
>> so can't comment on how good they are or are not. Do your R&D and find it
>> out ;-)
>>
>> I hope this helps you. Cheers!
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Wed, Mar 13, 2019 at 12:42 AM Ryan Nowakowski 
>> wrote:
>>
>>> If I were you, I'd work through the Django tutorial first. Then ask
>>> specific questions if you have any.
>>>
>>> On March 12, 2019 5:32:08 AM CDT, Cigi Sebastine <
>>> cigisebast...@gmail.com> wrote:
>>>>
>>>>
>>>> Hi all
>>>>
>>>> I am trying to insert data from csv file to mongodb4 using python3.7
>>>> (Bulk data insertion 47lakhs records)
>>>> i need to implement in django
>>>> Can please anyone share ur idea
>>>>
>>>> import pandas as pd
>>>> import json
>>>>
>>>> mng_client = MongoClient('localhost', 27017)
>>>> mng_db = mng_client['testcsv']
>>>> collection_name = mng_db['datastore']
>>>> db_cm = mng_db['datastore']
>>>>
>>>> df = pd.read_csv('filepath',encoding = 'ISO-8859-1') # loading csv file
>>>> #dfstr = df.to_json('testjson1.json')
>>>> data_json = json.loads( df.to_json())
>>>> db_cm.insert_many(data_json)
>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "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/89E98305-6AEC-4A82-9839-E86760DC3AB2%40fattuba.com
>>> <https://groups.google.com/d/msgid/django-users/89E98305-6AEC-4A82-9839-E86760DC3AB2%40fattuba.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/CAMKMUjv%3DrU%3DNJxhd%2BHwpz40RrFB_Z2qP9Mq7q2SoXFys4HSO2Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMKMUjv%3DrU%3DNJxhd%2BHwpz40RrFB_Z2qP9Mq7q2SoXFys4HSO2Q%40mail.gmail.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/CAAaRqFM-NALvhVJgcDXvRZoa7M-cgSURTbPMAQRcSUVxtH8THw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAAaRqFM-NALvhVJgcDXvRZoa7M-cgSURTbPMAQRcSUVxtH8THw%40mail.gmail.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/CAMKMUjsNd0BVch1zpjDU859DoGWiFTOGZ17e873C_vNwD9SfiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Queryset for Multiple set

2019-03-13 Thread Chetan Ganji
Hi Vaibhav,

I think this would do what you want. Make sure too call the objects on the
model name (  Modelname  ) ;-)


systems = ['windows', 'unix']
variable = Modelname.objects.filter(clientname=cname, clienttype__in=systems,
errorcode='20')



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 5:17 PM Krishnasagar Subhedarpage <
pagesa...@gmail.com> wrote:

> You could do using django ORM query expressions. Refer below link:
> https://docs.djangoproject.com/en/2.1/ref/models/expressions/
>
>
> Regards,
> Krishnasagar Subhedarpage
>
>
>
> On Wed, 13 Mar 2019 at 17:14, Vaibhav Mishra  wrote:
>
>> Hi All,
>>
>> I am trying to achieve below ,
>>
>> variable = object.filter(clientname =cname , clienttype='windows' and
>> clienttype='unix', errorcode='20')
>>
>>
>>
>>  Notice that I want to filter by two or more values in second parameter..
>> How can we do this ?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/54464687-7fd0-4103-b74f-5de566ae9e89%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/54464687-7fd0-4103-b74f-5de566ae9e89%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/CAChYJc8NwTG5LDBmjBbFav3b125dOsNCTwtHN%3DJrMbhrZ9T0rw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAChYJc8NwTG5LDBmjBbFav3b125dOsNCTwtHN%3DJrMbhrZ9T0rw%40mail.gmail.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/CAMKMUjt2mw0mfbHHqD2p7_PPD2%3DGFgJM0QadR%3Di_bb5HpG7ORA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need to Store All Model data in RAM

2019-03-13 Thread Chetan Ganji
Hi Vaibhav,

Andréas is right. You need to evaluate the queryset first as the orm
queries are lazy.
So the solution would be something like below example.


another_list = []
getdata = data.objects.all() # this is a queryset

# apply filters if you need to

getdata = list(getdata) # this would be a list in python

for item in getdata: # won't hit database again
if item in another_list:
# do something
pass



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 7:27 PM Andréas Kühne 
wrote:

> Hi,
>
> You can't. The way that you are working - it would always go back to the
> database - because you are using the filter methods.
>
> You would need to create a list from the items, then do the comparison in
> python - which probably will be slower (but not necessarily).
>
> Regards,
>
> Andréas
>
>
> Den ons 13 mars 2019 kl 12:44 skrev Vaibhav Mishra :
>
>> Hi All,
>>
>> I have a table of over 100,000 rows which I need to compare with another
>> list to find if the entry matching a rows is in there or not
>>
>> The following does not work
>>
>> getdata = data.objects.all()
>>
>>
>> mydata= getdata.filter(mycriteria)
>>
>>
>>
>>
>> Process information and comparision from 'mydata'
>>
>>
>>
>> .The code .should fetch all data and should no longer go to Database. ,
>> but it still seem to hit database
>> .
>> Whenever I am running code, I see that for each comparision , the Code is
>> Hitting the database resulting in over thousands of queries and lot of
>> delay in finishing Processing data.
>>
>> How can I force All Data to be stored in RAM so that its no longer needed
>> to access database. ?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/a120e643-936e-4f6a-9662-7811808fa8cf%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/a120e643-936e-4f6a-9662-7811808fa8cf%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/CAK4qSCevkAVGFf%3DMrS8VVsv2BgPuDkRUqW_tSFwk1dfrzb7pvg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCevkAVGFf%3DMrS8VVsv2BgPuDkRUqW_tSFwk1dfrzb7pvg%40mail.gmail.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/CAMKMUjs%3DxtJPN-gmnfmg7M%3DSGsP0jg5qru6o%3DcQGJmuqabckkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need to Store All Model data in RAM

2019-03-13 Thread Chetan Ganji
Bhai, read your original question

*"I have a table of over 100,000 rows which I need to compare with another
list to find if the entry matching a rows is in there or not "*

Which another list were you talking about?

so the another_list could be a pre-populated list of python or another list
made of queryset.

e.g.
another_list = [1, 2, 3, 4] OR
another_list = list(Modelname.objects.all())

I hope this clears your confusion.



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 9:32 PM Vaibhav Mishra  wrote:

> Thanks Andreas, Will try out the list Method.
>
> On Wednesday, March 13, 2019 at 9:58:16 AM UTC-4, Andréas Kühne wrote:
>>
>> Hi,
>>
>> You can't. The way that you are working - it would always go back to the
>> database - because you are using the filter methods.
>>
>> You would need to create a list from the items, then do the comparison in
>> python - which probably will be slower (but not necessarily).
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den ons 13 mars 2019 kl 12:44 skrev Vaibhav Mishra :
>>
>>> Hi All,
>>>
>>> I have a table of over 100,000 rows which I need to compare with another
>>> list to find if the entry matching a rows is in there or not
>>>
>>> The following does not work
>>>
>>> getdata = data.objects.all()
>>>
>>>
>>> mydata= getdata.filter(mycriteria)
>>>
>>>
>>>
>>>
>>> Process information and comparision from 'mydata'
>>>
>>>
>>>
>>> .The code .should fetch all data and should no longer go to Database. ,
>>> but it still seem to hit database
>>> .
>>> Whenever I am running code, I see that for each comparision , the Code
>>> is Hitting the database resulting in over thousands of queries and lot of
>>> delay in finishing Processing data.
>>>
>>> How can I force All Data to be stored in RAM so that its no longer
>>> needed to access database. ?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@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/a120e643-936e-4f6a-9662-7811808fa8cf%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/a120e643-936e-4f6a-9662-7811808fa8cf%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/5b0499d9-073f-4d3e-8f38-4160e4b50f65%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5b0499d9-073f-4d3e-8f38-4160e4b50f65%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/CAMKMUjv6Z-tSmmqD9CP1wGchSPvtTieqi_Ga8Yf7sSJgO-6dyA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: image didn't upload

2019-03-14 Thread Chetan Ganji
Did you setup MEDIA-ROOT location in your settings.py
For reference -
https://docs.djangoproject.com/en/2.1/ref/settings/#media-root

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#m_4678954581711788864_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 5:43 PM omar ahmed  wrote:

> this is my model
> class LeagueNews(models.Model):
> ...
> news_image = models.ImageField(upload_to='core/media/core',max_length=255,
> null=True,blank=True)
>
>
> and this is my template
>
>
> {% block content %}
>
> {{ article.news_title }}
>
> {{ article.publication_date }}
>
> {{ article.news_text }}
>
> 
>
> {% endblock %}
> the view
>
> def newsdetail(request, news_id):
> article = get_object_or_404(LeagueNews,pk=news_id)
> return render(request, 'core/newsdetail.html',{'article':article})
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/1d4123b8-c5bc-4bed--51bb142f21b0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/1d4123b8-c5bc-4bed--51bb142f21b0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#m_4678954581711788864_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

-- 
You received this message because you are subscribed to the Google Groups 
"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/CAMKMUjvxSdyNqJan2MjVcsR%2BigpMsj-%2BxZonEUTLt8HKoXBnKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Very much begineer

2019-03-14 Thread Chetan Ganji
Look no further codingforentrepreneurs
Start with trydjango 1.8 project. See his youtube channel.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 6:29 PM AhenTheBegineer 
wrote:

> Hello,
> I'm very new to the software and pretty much know about python(less than
> basics) so I want to explore django.
> And want to know how it works, what software are needed for it and how do
> I start with the softwae to be handy with it.
> Thank you
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/5fda8787-9841-4b9f-885d-f43e4e0e5d41%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5fda8787-9841-4b9f-885d-f43e4e0e5d41%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/CAMKMUjvfuF88sDq39PL8tk8CY73MGp%3DGzJnfyoRXjeiiO3mL_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: on_delete not getting called when ForeignKey is a property

2019-03-14 Thread Chetan Ganji
Why do you need to do any calculations in the model code?

I would do any calculations in the views and store them using models. That
will remove the getters and setters from model.
Everything should work fine then.

Hope it helps.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 8:31 PM mccc  wrote:

> Hello,
>
> I have set up this nice model:
> class CustomGroup(models.Model):
>
> name = models.CharField(max_length=255)
> _parent = models.ForeignKey(
> "self", on_delete=models.CASCADE, null=True,
> related_name="descendants", db_column="parent"
> )
> _depth = models.IntegerField(default=1)
>
> @property
> def parent(self):
> return self._parent
>
> @property
> def depth(self):
> return self._depth
>
> @parent.setter
> def parent(self, value):
> if self == value:
> raise ValueError("parent must be different from self")
> p = value
> while value is not None:
> if self == value.parent:
> raise ValueError("parent cannot be a descendant")
> value = value.parent
> self._parent = p
> self.depth = (p.depth + 1) if p is not None else 1
>
> @depth.setter
> def depth(self, value):
> if value > MAX_GROUPS_DEPTH:
> raise ValueError("Too many nested groups")
>
> for descendant in self.descendants.all():
> descendant.depth = value + 1
> descendant.save()
> self._depth = value
>
>
> and the CASCADE function is not getting fired when the parent gets deleted;
> I tried adding another field without the property modifiers, and that
> worked as expected.
>
> Is there any way I can have both my custom getter and setter, and the
> on_delete behaviour?
>
> 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/292cfb9d-c605-46ef-bb4a-5d69a8ecbb6b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/292cfb9d-c605-46ef-bb4a-5d69a8ecbb6b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

-- 
You received this message because you are subscribed to the Google Groups 
"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/CAMKMUjuRrwxkKGtNEKDibHMaMm4pUEP_YX2rvxZcCGJzPfDxng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: on_delete not getting called when ForeignKey is a property

2019-03-14 Thread Chetan Ganji
That approach is not working for the original poster. So I gave him a
solution that solves the problem.

I meant, its my opinion to keep models slim and write utils to make the
controllers slim.
You don't have to follow it ;-)  Follow what makes sense to you. I prefer
it that way.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 9:01 PM Sithembewena L. Dube 
wrote:

> There is nothing wrong with having logic in models.
>
> This is the principle of object orientation - encapsulating methods and
> properties in a class definition to group related behaviours and attributes
> of a specified type of entity.
>
> See the section titled "Make ‘em Fat" here:
> https://django-best-practices.readthedocs.io/en/latest/applications.html
>
>
> Kind regards,
> Sithembewena
>
>
> *Sent with Shift
> <https://tryshift.com/?utm_source=SentWithShift&utm_campaign=Sent%20with%20Shift%20Signature&utm_medium=Email%20Signature&utm_content=General%20Email%20Group>*
>
> On Thu, Mar 14, 2019 at 5:21 PM Chetan Ganji 
> wrote:
>
>> Why do you need to do any calculations in the model code?
>>
>> I would do any calculations in the views and store them using models.
>> That will remove the getters and setters from model.
>> Everything should work fine then.
>>
>> Hope it helps.
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>>
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>>  I’m
>> protected online with Avast Free Antivirus. Get it here — it’s free
>> forever.
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>> <#m_3800371179043208066_m_7932060366693994324_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Thu, Mar 14, 2019 at 8:31 PM mccc  wrote:
>>
>>> Hello,
>>>
>>> I have set up this nice model:
>>> class CustomGroup(models.Model):
>>>
>>> name = models.CharField(max_length=255)
>>> _parent = models.ForeignKey(
>>> "self", on_delete=models.CASCADE, null=True,
>>> related_name="descendants", db_column="parent"
>>> )
>>> _depth = models.IntegerField(default=1)
>>>
>>> @property
>>> def parent(self):
>>> return self._parent
>>>
>>> @property
>>> def depth(self):
>>> return self._depth
>>>
>>> @parent.setter
>>> def parent(self, value):
>>> if self == value:
>>> raise ValueError("parent must be different from self")
>>> p = value
>>> while value is not None:
>>> if self == value.parent:
>>> raise ValueError("parent cannot be a descendant")
>>> value = value.parent
>>> self._parent = p
>>> self.depth = (p.depth + 1) if p is not None else 1
>>>
>>> @depth.setter
>>> def depth(self, value):
>>> if value > MAX_GROUPS_DEPTH:
>>> raise ValueError("Too many nested groups")
>>>
>>> for descendant in self.descendants.all():
>>> descendant.depth = value + 1
>>> descendant.save()
>>> self._depth = value
>>>
>>>
>>> and the CASCADE function is not getting fired when the parent gets
>>> deleted;
>>> I tried adding another field without the property modifiers, and that
>>> worked as expected.
>>>
>>> Is there any way I can have both my custom getter and setter, and the
>>> on_delete behaviour?
>>>
>>> Thanks
>>&g

Re: image didn't upload

2019-03-14 Thread Chetan Ganji
See this works or not.


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]

MEDIAFILES_DIRS = [
os.path.join(BASE_DIR, 'media'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static-root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media-root')




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 9:16 PM omar ahmed  wrote:

> thanks but it doesn't work
> MEDIA_URL = '/media/'
> MEDIA_ROOT = 'media'
>
> On Thursday, March 14, 2019 at 2:36:35 PM UTC+2, Chetan Ganji wrote:
>>
>> Did you setup MEDIA-ROOT location in your settings.py
>> For reference -
>> https://docs.djangoproject.com/en/2.1/ref/settings/#media-root
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji@gmail.com
>> http://ryucoder.in
>>
>>
>>
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>>  I’m
>> protected online with Avast Free Antivirus. Get it here — it’s free
>> forever.
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>> <#m_7758653622765414323_CAMKMUjvxSdyNqJan2MjVcsR+igpMsj-+xZonEUTLt8HKoXBnKA@mail.gmail.com_m_4678954581711788864_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Thu, Mar 14, 2019 at 5:43 PM omar ahmed  wrote:
>>
>>> this is my model
>>> class LeagueNews(models.Model):
>>> ...
>>> news_image = models.ImageField(upload_to='core/media/core',max_length=
>>> 255, null=True,blank=True)
>>>
>>>
>>> and this is my template
>>>
>>>
>>> {% block content %}
>>>
>>> {{ article.news_title }}
>>>
>>> {{ article.publication_date }}
>>>
>>> {{ article.news_text }}
>>>
>>> 
>>>
>>> {% endblock %}
>>> the view
>>>
>>> def newsdetail(request, news_id):
>>> article = get_object_or_404(LeagueNews,pk=news_id)
>>> return render(request, 'core/newsdetail.html',{'article':article})
>>>
>>> --
>>> You received this message because you are subscribed 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/1d4123b8-c5bc-4bed--51bb142f21b0%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/1d4123b8-c5bc-4bed--51bb142f21b0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>>  I’m
>> protected online with Avast Free Antivirus. Get it here — it’s free
>> forever.
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>> <#m_7758653622765414323_CAMKMUjvxSdyNqJan2MjVcsR+igpMsj-+xZonEUTLt8HKoXBnKA@mail.gmail.com_m_4678954581711788864_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubsc

Re: on_delete not getting called when ForeignKey is a property

2019-03-14 Thread Chetan Ganji
OK.

One work around could be to fire the signal manually just after you
set/delete the value? I have not checked it yet :P

Do one thing, implement pre_delete and post_delete signals and check the
values of  instance, sender and using. It might give you more information
about what is happening.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 9:15 PM mccc  wrote:

>
>
> On Thursday, March 14, 2019 at 4:22:15 PM UTC+1, Chetan Ganji wrote:
>>
>> Why do you need to do any calculations in the model code?
>>
>> I would do any calculations in the views and store them using models.
>> That will remove the getters and setters from model.
>> Everything should work fine then.
>>
>> Hope it helps.
>>
>
> No, nothing would work fine: in that case I would need to remember
> constantly to either copy the code to handle the behaviour or make a call
> to *a view* each time and in any place that handles those fields.
> Plus the tests would need to check over and over for the same behaviour
> every time the field was involved.
>
> I'm sorry, but it really doesn't help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/ed1853bb-402a-4688-9061-63054c44ce63%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ed1853bb-402a-4688-9061-63054c44ce63%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/CAMKMUjuXZaAQXtM0ac%3DX7icsk76-eTcWnKSCgYp9iR_crQP%3D6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic CBV DeleteView GET csrf_token

2019-03-14 Thread Chetan Ganji
https://www.django-rest-framework.org/topics/ajax-csrf-cors/
https://docs.djangoproject.com/en/2.1/ref/csrf/#ajax

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Fri, Mar 15, 2019 at 12:34 AM B  wrote:

> I'm implementing a DeleteView, and for completion I would like to provide
> the functionality indicated here:
>
>
> https://docs.djangoproject.com/en/2.1/ref/class-based-views/generic-editing/#deleteview
>
> *If this view is fetched via GET, it will display a confirmation page that
> should contain a form that POSTs to the same URL.*
>
> However, by default a GET will not include the required context to the
> template for {% csrf_token %}. How do I include the appropriate context
> information for a plain DeleteView CBV?
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/213ca896-0973-4b64-9345-50de5cd9e5d7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/213ca896-0973-4b64-9345-50de5cd9e5d7%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/CAMKMUjuRMSAqgVxdtNPHEt%2BRpSzM-VAx9rTgJf7CBqZ91UFtrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic CBV DeleteView GET csrf_token

2019-03-14 Thread Chetan Ganji
Frameworks dont work as we want them too :P
We have to understand how the defaults are implemented then make the
changes as necessary ;-)
If it can be customized, great! otherwise learn and use a different
framework, LOLZ ;-)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Fri, Mar 15, 2019 at 1:02 AM B  wrote:

> Thanks. I have things working fine under Ajax. This particular scenario is
> an "odd one" since performing a GET on a delete view isn't common, but it
> is implemented by Django. It is helpful for testing, but perhaps the right
> approach is to "disable" get for the DeleteView and be done with it. My
> main concern was for Django to behave "out of box" as intended without
> overrides.
>
> On Thursday, March 14, 2019 at 3:24:46 PM UTC-4, Chetan Ganji wrote:
>>
>> https://www.django-rest-framework.org/topics/ajax-csrf-cors/
>> https://docs.djangoproject.com/en/2.1/ref/csrf/#ajax
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji@gmail.com
>> http://ryucoder.in
>>
>>
>>
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>>  I’m
>> protected online with Avast Free Antivirus. Get it here — it’s free
>> forever.
>> <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
>> <#m_8157490019364007879_CAMKMUjuRMSAqgVxdtNPHEt+RpSzM-VAx9rTgJf7CBqZ91UFtrg@mail.gmail.com_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Fri, Mar 15, 2019 at 12:34 AM B  wrote:
>>
>>> I'm implementing a DeleteView, and for completion I would like to
>>> provide the functionality indicated here:
>>>
>>>
>>> https://docs.djangoproject.com/en/2.1/ref/class-based-views/generic-editing/#deleteview
>>>
>>> *If this view is fetched via GET, it will display a confirmation page
>>> that should contain a form that POSTs to the same URL.*
>>>
>>> However, by default a GET will not include the required context to the
>>> template for {% csrf_token %}. How do I include the appropriate context
>>> information for a plain DeleteView CBV?
>>>
>>> --
>>> You received this message because you are subscribed 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/213ca896-0973-4b64-9345-50de5cd9e5d7%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/213ca896-0973-4b64-9345-50de5cd9e5d7%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/98106b93-47ac-4cbb-8c89-d3291d52b2a5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/98106b93-47ac-4cbb-8c89-d3291d52b2a5%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/CAMKMUjvEymdFUtQ0qeaPHsie0PsjeuvwkdQC_kkHuHdoeMi8zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What I am doing wrong

2019-03-15 Thread Chetan Ganji
In the admin.py file that import statement seems to be wrong.  "*from
website.module import website*"
I cant help you more as I dont know the directory structure.

Check for the location of the module named website relative to the admin.py
file.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 15, 2019 at 5:36 PM Harish Chaudhary 
wrote:

> --
> You received this message because you are subscribed to the Google Groups
> "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/CALxqzK4w7v7pg8XuAX7ZUDhWP-5aejpxMT802AYSfHNi7uRfmA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALxqzK4w7v7pg8XuAX7ZUDhWP-5aejpxMT802AYSfHNi7uRfmA%40mail.gmail.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/CAMKMUjtTiQJ04gQ-TuOzw0MTFJgGXz5Ag_1jnmvRDNwaEByV4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What I am doing wrong

2019-03-15 Thread Chetan Ganji
Sure. please make sure to mention which class or function from which file
needs to be imported in which file


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 15, 2019 at 6:14 PM Harish Chaudhary 
wrote:

> Hello Chetan can I send you my project can you please look into it
>
> On Fri, 15 Mar, 2019, 5:53 PM Chetan Ganji, 
> wrote:
>
>> In the admin.py file that import statement seems to be wrong.  "*from
>> website.module import website*"
>> I cant help you more as I dont know the directory structure.
>>
>> Check for the location of the module named website relative to the
>> admin.py file.
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Fri, Mar 15, 2019 at 5:36 PM Harish Chaudhary 
>> wrote:
>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "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/CALxqzK4w7v7pg8XuAX7ZUDhWP-5aejpxMT802AYSfHNi7uRfmA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CALxqzK4w7v7pg8XuAX7ZUDhWP-5aejpxMT802AYSfHNi7uRfmA%40mail.gmail.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/CAMKMUjtTiQJ04gQ-TuOzw0MTFJgGXz5Ag_1jnmvRDNwaEByV4A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMKMUjtTiQJ04gQ-TuOzw0MTFJgGXz5Ag_1jnmvRDNwaEByV4A%40mail.gmail.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/CALxqzK6PkgXvLS%3DMnT4RAYmTqHvuM39cA0LKBSPEj9gT1G38yw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALxqzK6PkgXvLS%3DMnT4RAYmTqHvuM39cA0LKBSPEj9gT1G38yw%40mail.gmail.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/CAMKMUjvH3q4B1UCph5UQJ_oT0Y86%2BiQokYi8cNLm64QDhTO8-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there any inline editing the data and delete data in table in Django?

2019-03-20 Thread Chetan Ganji
Hi Sankar,

Derek is right, we can only give you suggestions as we are far away from
you. How is really upto YOU.
What you are trying to achieve is basically a front end task. You only have
knowledge of django which is a backend technology.

You have many options to make choice from -
1. You have to learn to use jquery to do it the way you want it.
2. Use the default UpdateView from django where EDIT/UPDATE view will be
shown separately. i.e. let go of inline editing feature.
3. Find someone who will code it for you.
4. Any other that you can think of.

Happy Coding :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 20, 2019 at 11:58 AM VeeraNagaRaja Sankar 
wrote:

> hi,
>
> means, i am only aware of Django so i need any code reference to do that
>  thank you,
>
> Best Regards,
> Inti VeeraNagaRaja Sankar,M.Tech(IT)
> M: 9985864383
> intisank...@gmail.com 
> https://about.me/veeranagarajasankar
>
>
> On Wed, Mar 20, 2019 at 11:55 AM Derek  wrote:
>
>> That is not an answerable question.  We have given you suggestions - the
>> "how" is up to you.
>>
>> On Tuesday, 19 March 2019 09:36:27 UTC+2, veera nagaraja sankar Inti
>> wrote:
>>>
>>>
>>> how ?
>>>
>>> On Monday, March 4, 2019 at 12:40:03 PM UTC+5:30, Derek wrote:
>>>>
>>>> Grid / tabular editing outside of the admin is tricky; I have not been
>>>> able to manage it and have not found a good app for it.
>>>>
>>>> Here are some suggested reading:
>>>>
>>>> * https://www.ibm.com/developerworks/library/wa-django/index.html
>>>> * https://bossanova.uk/jexcel
>>>> *
>>>> https://medium.com/ag-grid/building-a-crud-application-with-ag-grid-part-4-3189034df922
>>>>
>>>> You'd also need an app like Django REST Framework to handle GET/POST of
>>>> JSON data to populate your grid.
>>>>
>>>> On Wednesday, 27 February 2019 20:39:04 UTC+2, veera nagaraja sankar
>>>> Inti wrote:
>>>>>
>>>>> need help friends ?..
>>>>>
>>>>> thq..
>>>>>
>>>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/562202e8-53a3-44d2-b0aa-ba710e180787%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/562202e8-53a3-44d2-b0aa-ba710e180787%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/CAJFTHQa_6OGseZ8TwrniWrUNDM%2BkN8a%3DChBFrF7j4XRysARaLw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJFTHQa_6OGseZ8TwrniWrUNDM%2BkN8a%3DChBFrF7j4XRysARaLw%40mail.gmail.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/CAMKMUjuhQ56%3DEurstUPVqxOXv3u%2Bj3VSaggTOkOAx_u95CJ3%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: custom registration form

2019-03-25 Thread Chetan Ganji
There is a better way in django.

Django provides admin panel for the admins, you just have to create one
account for the admin as superuser. Email needs to be sent manually which
can be done immediately after the form is validated.
User model has "*is_active*" flag that can be used to limit access before
the user is authorised by the admin. You will have to create an additional
page to accept or discard the registered user.

If you dont want to use default admin panel, you will end up writing CRUD
for the admin panel. Workflow will still be the same as above.



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, Mar 25, 2019 at 6:22 PM Shubham Joshi  wrote:

> How can I create sign up form in such a way that..once a form has been
> filled and submitted by user (teacher / student) . The form should be sent
> to the Admins email id , once s/he verified the sign up form , the user
> should able log in
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/67df728c-e165-4390-8fd8-9c5bc4ae1103%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/67df728c-e165-4390-8fd8-9c5bc4ae1103%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/CAMKMUjsnb%3D48VXQGhCOc-HoQ2END9n_zL0TrJ_9uQ7PZmdxtDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit-Testing Django Views

2019-03-28 Thread Chetan Ganji
I would prefer to just check the status code of the response object.
This is what I have done. You have to check if it works for forms with
csrf_token or not.


class TestReverseUrls(TestCase):

def setUp(self):
self.client = Client()
self.reverseUrls = ['index', 'login', 'register']
self.response = {url:self.client.get(reverse(url)) for url in self
.reverseUrls}

def test_reverse_urls(self):
for url in self.reverseUrls:
self.assertEqual(self.response[url].status_code, 200)



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 29, 2019 at 12:57 AM Aldian Fazrihady  wrote:

> There are several things you can try:
> 1. Mocking csrf token functions
> 2. Passing the csrf token context from first HTML generation to the second
> HTML generation
> 3. Wiping out the csrf token parts from both HTML before comparing them.
>
> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>
>> This is effectively failing because of a mechanism added in 1.10 to
>> protect
>> against BREACH attacks[0] by salting the CSRF token.
>>
>> I'm not aware of any way to disable this mechanism but testing against the
>> exact HTML returned from a view seems fragile.
>>
>> I suggest you use assertContains[1] (with or without html=True) and
>> assertTemplateUsed[2] instead.
>>
>> Cheers,
>> Simon
>>
>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>> [1]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>> [2]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>
>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>
>>> Hi people,
>>>
>>> I am following the book Test-Driven Development with Python
>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>  by
>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>> outdated as of now so I started with version 2.1.
>>>
>>> I am trying to unit test my index view. One unit-test that I have
>>> written is testing whether the index view returns correct HTML or not by
>>> comparing the input received through
>>> django.template.loader.render_to_string
>>> the unit-test fail with the following traceback
>>> python manage.py test
>>> Creating test database for alias 'default'...
>>> .System check identified no issues (0 silenced).
>>> F.
>>> ==
>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>> --
>>> Traceback (most recent call last):
>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>> self.assertEqual(expected_html, actual_html)
>>> AssertionError: '>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>> '>> chars]l>\n'
>>>
>>> --
>>> Ran 3 tests in 0.006s
>>>
>>> FAILED (failures=1)
>>> Destroying test database for alias 'default'...
>>>
>>> Process finished with exit code 1
>>>
>>>
>>> It was clear that the csrf token is causing the test to fail. Is there
>>> any way to test it, or should it be tested? I ask this as when I changed my
>>> Django version to 1.7, the tests were passing, even after giving the csrf
>>> token field in the form. I tried going through the changelogs but 1.7 is
>>> far behind (beginner here). Please find the code snippets, directory
>>> structure provided below.
>>>
>>>
>>> *lists/views.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *from django.http import HttpResponsefrom django.shortcuts import render# 
>>> Create your views here.def index(request):if request.method == 'POST':  
>>>   return HttpResponse(request.POST['item_text'])return 
>>> render(request, 'index.html')*
>>>
>>>
>>> *lists/test.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>

Re: Unit-Testing Django Views

2019-03-28 Thread Chetan Ganji
There is one more way you could do it


class TestIndexPageLoad(TestCase):

def setUp(self):
self.client = Client()
self.response = self.client.get('/')

def test_check_response(self):
self.assertTemplateUsed(self.response, 'index.html')



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 29, 2019 at 1:56 AM Chetan Ganji  wrote:

> I would prefer to just check the status code of the response object.
> This is what I have done. You have to check if it works for forms with
> csrf_token or not.
>
>
> class TestReverseUrls(TestCase):
>
> def setUp(self):
> self.client = Client()
> self.reverseUrls = ['index', 'login', 'register']
> self.response = {url:self.client.get(reverse(url)) for url in self
> .reverseUrls}
>
> def test_reverse_urls(self):
> for url in self.reverseUrls:
> self.assertEqual(self.response[url].status_code, 200)
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Fri, Mar 29, 2019 at 12:57 AM Aldian Fazrihady 
> wrote:
>
>> There are several things you can try:
>> 1. Mocking csrf token functions
>> 2. Passing the csrf token context from first HTML generation to the
>> second HTML generation
>> 3. Wiping out the csrf token parts from both HTML before comparing them.
>>
>> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>>
>>> This is effectively failing because of a mechanism added in 1.10 to
>>> protect
>>> against BREACH attacks[0] by salting the CSRF token.
>>>
>>> I'm not aware of any way to disable this mechanism but testing against
>>> the
>>> exact HTML returned from a view seems fragile.
>>>
>>> I suggest you use assertContains[1] (with or without html=True) and
>>> assertTemplateUsed[2] instead.
>>>
>>> Cheers,
>>> Simon
>>>
>>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>>> [1]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>>> [2]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>>
>>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>>
>>>> Hi people,
>>>>
>>>> I am following the book Test-Driven Development with Python
>>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>>  by
>>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>>> outdated as of now so I started with version 2.1.
>>>>
>>>> I am trying to unit test my index view. One unit-test that I have
>>>> written is testing whether the index view returns correct HTML or not by
>>>> comparing the input received through
>>>> django.template.loader.render_to_string
>>>> the unit-test fail with the following traceback
>>>> python manage.py test
>>>> Creating test database for alias 'default'...
>>>> .System check identified no issues (0 silenced).
>>>> F.
>>>> ==
>>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>>> --
>>>> Traceback (most recent call last):
>>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>>> self.assertEqual(expected_html, actual_html)
>>>> AssertionError: '>>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>>> '>>> chars]l>\n'
>>>>
>>>> --
>>>> Ran 3 tests in 0.006s
>>>>
>>>> FAILED (failures=1)
>>>> Destroying test database for alias 'default'...
>>>>
>>>> Process finished with exit code 1
>>>>
>>>>
>>>> It was clear that the csrf token is causing the test to fail. Is there
>>>> any way to test it, or should it be tested? I ask this as when I changed my
>>>> Django version to 1.7, the tests were passing, even after giving the csrf
>>>> token field in the form. I tried going through the changelogs but 1.7 is
>>>> far behind (beginner here). Please find the code sn

Re: I am on a e-commerce website on a video from youtube and I am having problems with stripe

2019-03-29 Thread Chetan Ganji
 I am not sure about this.

But the issue seems to be that the user in question has a stripe account
and that stripe account does not have any cards associated with the
account. Maybe try adding a card to the account, if it does not have any.
If it has, delete it and create a new one. See if it helps.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Fri, Mar 29, 2019 at 6:16 PM Patrice Chaula  wrote:

> I am using Stripe to process payments from my website. Yesterday it was
> working ok. That was before I changed code my code so It can process
> payments using a customer_id. I am using test keys
>
>  My code below. Help I'm still a beginner in django. I'm sorry my English
> is bad.
>
> from django.shortcuts import render
> from django.contrib.auth.decorators import login_required
> from django.conf import settings
> import stripe
>
>
> stripe.api_key =  settings.STRIPE_SECRET_KEY
> # Create your views here.
> @login_required
> def checkout(request):
>  publishKey = settings.STRIPE_PUBLISHABLE_KEY
>customer_id = request.user.userstripe.stripe_id
> print(customer_id)
>  if request.method == 'POST':
>customer = stripe.Customer.retrieve(customer_id)
>token = request.POST['stripeToken']
> charge = stripe.Charge.create(
>  amount = 1000,
>  currency = 'usd',
>   customer = customer,
>description = 'Example Charge',
> )
>   context = {'publishKey':publishKey}
> template = 'checkout.html'
>  return render(request, template, context)
>
>
> The error I am getting is below
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\django\core\handlers\exception.py" in
> inner
>   34. response = get_response(request)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\django\core\handlers\base.py" in
> _get_response
>   126. response = self.process_exception_by_middleware(e,
> request)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\django\core\handlers\base.py" in
> _get_response
>   124. response = wrapped_callback(request,
> *callback_args, **callback_kwargs)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\django\contrib\auth\decorators.py" in
> _wrapped_view
>   21. return view_func(request, *args, **kwargs)
>
> File "C:\Users\Patrice\Desktop\ecommerce web\ecommerce\checkout\views.py"
> in checkout
>   22. description = 'Example Charge',
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\stripe\api_resources\abstract\createable_api_resource.py"
> in create
>   22. response, api_key = requestor.request("post", url, params,
> headers)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in request
>   121. resp = self.interpret_response(rbody, rcode, rheaders)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in
> interpret_response
>   372. self.handle_error_response(rbody, rcode, resp.data,
> rheaders)
>
> File "C:\Program
> Files\Python37-32\lib\site-packages\stripe\api_requestor.py" in
> handle_error_response
>   151. raise err
>
> Exception Type: CardError at /checkout/
> Exception Value: Request req_En9Ipi3bygWUWY: Cannot charge a customer that
> has no active card
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/04423272-5bf9-4b26-9963-c180b926c909%40googlegroups.com
> <https://groups.google.co

Re: ModelForm for model that includes multiple items of one kind

2019-03-30 Thread Chetan Ganji
I think, you will need to implement something like below.

Profile:
first_name
middle_name
last_name
birthday
address  (primary/default)
email (primary/default)
phone (primary/default)


Address

address_line1
address_line2
City
state
zip

Email

email

Phone

phone


As one profile can have multiple entries of addresses, email and phone
numbers, you could use concept of formset to deal with them.
Also, as there are multiple entries, you could store one of them as default
or primary.

I hope this helps :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Sun, Mar 31, 2019 at 3:56 AM Dean Karres  wrote:

> Hi
>
> I am looking for some advice.  I have a basic Profile model.  It looks
> something like:
>
> Profile:
> first_name
> middle_name
> last_name
> birthday
> address_line1
> address_line2
> city
> state
> zip
> email
> phone
>
> I have a ModelForm that goes with this.
>
> This is sufficient for nearly all the cases I am trying to deal with.
> However, there are a few special cases in which a person needs to list two
> or more addresses; two or more email addrs; two or more phone numbers; or,
> combinations.
>
> I know just enough about database normalization to think that I need the
> Profile model plus Address, Email and Phone models and have the Profile
> have a ForeignKey relation to each of the others.  A la:
>
> Profile:
> first_name
> middle_name
> last_name
> birthday
> 
> 
> 
>
> Address
> address_line1
> address_line2
> City
> state
> zip
>
> Email
> email
>
> Phone
> phone
>
> My question is more about the associated ModelForm(s).  First, I currently
> have a ModelForm for the first Profile model without the foreign keys.  If
> I break out the address, email and phone portions into separate models do I
> need to create separate model forms for each new model?  If so would the
> new Profile ModelFOrm just inherit the ModelForms of the other components.
> Something like:
>
> class ProfileForm(ModelForm, AddressForm, EmailForm, PhoneForm):
> ...
>
> The current ModelForm has "clean_" "clean" methods.  Do I keep that
> in the new Profile form?  Do I put the various "clean" methods in their own
> model forms and hope that inheritance will pull them in?
>
> Next, how does a ModelForm deal with more than one of the same item --
> like more then one address?
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/a8954cd8-e3c6-4d6f-8780-1f88a9874a3b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a8954cd8-e3c6-4d6f-8780-1f88a9874a3b%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/CAMKMUjuXoHKh9CwOe%3DG78mJhQUvw19Uva2hUORKxgCtbReuXNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re:

2019-03-30 Thread Chetan Ganji
Best way to learn coding n framework is to build a project. I have taken
courses from various vendors, best ones are the one from Coding For
Entrepreneurs. He also has a youtube channel. Start with try django 1.8

On Sun, Mar 31, 2019, 6:20 AM Makori Breens  wrote:

> http://track.haatm.com/aff_c?offer_id=919&aff_id=29710
>
> On 3/30/19, Victor H. Velasquez Rizo  wrote:
> > Hello Carol.
> >
> > Try this
> > https://tutorial.djangogirls.org/en/
> >
> > On Sat, Mar 30, 2019 at 9:12 AM carol caro 
> wrote:
> >
> >> Hello. I am a new or beginner django developer. Where do I start
> from
> >> I have installed python and integrated with Django framework but I don't
> >> know what to do next
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "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/CAN%2Bowc-S7n3OX0jc_fLjro6unDSNZJU4yGbYsxTLGeh55%3DFQvA%40mail.gmail.com
> >> <
> https://groups.google.com/d/msgid/django-users/CAN%2Bowc-S7n3OX0jc_fLjro6unDSNZJU4yGbYsxTLGeh55%3DFQvA%40mail.gmail.com?utm_medium=email&utm_source=footer
> >
> >> .
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
> >
> > --
> >
> >
> >
> > Atte...,.
> > Vìctor Hugo Velàsquez Rizo
> > Cali - Colombia
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "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/CAFCXTzjxXSzeP8KQEWeV%2BCnVOZEHPinh08iCN1a1jYWpNcf4Xw%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/CAOz9w2Ei8LWhTorQ5Lmw-O4vBK683v%3D-nwLnWZDGQgs0uJrejA%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/CAMKMUjspjMOPeuUCCnsCsrU-_D3LWjx68F1VxasEGm8beEOX0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Static image not getting displayed.

2019-04-02 Thread Chetan Ganji
{% load static %} in the first link of your template.

You have below code


The line should be



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Apr 3, 2019 at 1:13 AM Ing.Daniel Bojorge 
wrote:

> See the development tools and look what path is it?
>
> So, put STATIC_URL = '/static/' in your settings.py and
> {% load static %} in the first link of your template.
>
>
> Dios L@s Bendiga
>
> Saludos,
>
>
>
> [image: --]
>
> daniel.bojorge
> [image: http://]about.me/daniel.bojorge
> <http://about.me/daniel.bojorge?promo=email_sig>
>  *Curso Desarrollo Web con Python usando Django 2.1 Para Principiantes*
> <https://goo.gl/oeT5Sx>
> *WebService RestFul API con Python usando Django RestFrameWork*
> <https://goo.gl/j8i34C>
> *Fácil Replicación de Cualquier Base de Datos y/o Sistema Operativo*
> <https://goo.gl/HjtExs>
> *Programación en Capas (Web y Escritorio)* <https://goo.gl/zGZpSD>
> Mi Blog <http://debsconsultores.blogspot.com>
> Nicaragua
>
> "Si ustedes permanecen unidos a mí, y si permanecen fieles a mis
> enseñanzas, pidan lo que quieran y se les dará.
> (Juan 15:7 DHH)
> Bendito el varón que se fía en el SEÑOR, y cuya confianza es el SEÑOR.
> (Jeremías 17:7 RV2000)
>
>
>
> El mar., 2 abr. 2019 a las 12:36, Agbonxoft Prince ()
> escribió:
>
>> Try loading static , if it's not loaded
>> *{% load static %}* in the HTML page
>>
>>
>> On Tue, Apr 2, 2019, 19:01 Sandip Nath  wrote:
>>
>>> Downloaded an image of Django Reinhardt and saved it in static/images
>>> folder as django.jpeg. In the settings.py file created a variable
>>> STATIC_DIR and assigned it os.path.join(BASE_DIR, 'static') and again
>>> assign this variable to STATICFILES_DIR and kept the STATIC_URL as
>>> "/static/". In the index.html written that:
>>> 
>>>
>>> But after doing all this I am getting only the text of alt and no image.
>>> Where I am wrong? Please help.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To 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/bbaac132-6d24-43a3-8278-fe5878c0b694%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/bbaac132-6d24-43a3-8278-fe5878c0b694%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/CAKbA5VTtt0Gbjn-TPtxhpgDbf1T5EwAUhnPr%2BT%3DqmMmNU%3DsO5A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAKbA5VTtt0Gbjn-TPtxhpgDbf1T5EwAUhnPr%2BT%3DqmMmNU%3DsO5A%40mail.gmail.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/CAMQeQjb-%3D5vCMYUsZG-RgmPTMxft1mxDWW0w9fErqzYmEbNZMg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMQeQjb-%3D5vCMYUsZG-RgmPTMxft1mxDWW0w9fErqzYmEbNZMg%40mail.gmail.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/CAMKMUjsZHGjrkdE77YTNBXNcwbqg-bqMJvhxRsOx5%3D1-FehtWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Changing Admin Interface in Django

2019-04-11 Thread Chetan Ganji
Django CMS has a different admin site i.e. Layout and CSS is different.
There are many admin site available from third party. Maybe you might like
some of them.
https://djangopackages.org/grids/g/admin-styling/

Other way to do is, list all the templates in the admin site app. Find out
their css files and change them manually.
That's a very tedious task.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Apr 11, 2019 at 10:54 PM Aayush Bhattarai 
wrote:

> Yes I want to change everything.
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/309a5372-abb7-4525-8b95-f6e4528bd6f2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/309a5372-abb7-4525-8b95-f6e4528bd6f2%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/CAMKMUjt8niG-paSaO0y%3DWzDu3KOCCErozg-ZoXeB3iZYn%2BwZZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help, I need to convert my python code into Secure API using Django

2019-04-29 Thread Chetan Ganji
Hi Vamsi,

For No 1 - You can create a REST API using django or (django + django rest
framework).
For No 2,3,4 - For production you have to user Apache + modwsgi or nginx +
gunicorn (or other wsgi compliant server for python).

I dont suggest windows for production. If you plan to use it on linux,
below is the tutorial. I have used it many times for deployments.
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, Apr 29, 2019 at 9:46 PM Vamsi tangutoori <
vamsidhar.tanguto...@gmail.com> wrote:

> Hi Everyone,
> I am new to django and python programming. I developed a facial
> recognition module in python using boto3 library. Currently I sued flask to
> create an API and test in my development environment but to move it to
> production i need to use django. Can you please help or point me in the
> right direction as to how do i do the below.
>
> 1. Take my facialrecognition.py file and convert it into an API,
> preferably using django.
> 2. Make this API to be pointing to a specific URL(locally on a windows
> machine).
> 3. Deploy this code into a production machine(windows).
> 4. Make sure that the API starts every time the windows machine starts to
> avoid loosing service.
>
> Things i researched so far are:
> 1. How to create a django project with its REST library.
> 2. From the articles and tutorials i found out that this is only
> development version, to deploy in production i need a production server
> like Apache etc. is this necessary?
>
> Thanks in Advance for your help.
> Vamsi.
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/17aa8268-0fd8-4095-a5bb-82e68eecf186%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/17aa8268-0fd8-4095-a5bb-82e68eecf186%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/CAMKMUjvsqqRLp-6btfhV951gqwq5t1AehKsCgsER2UFuFfhMbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help, I need to convert my python code into Secure API using Django

2019-04-29 Thread Chetan Ganji
Linux is very easy to get started, as a web developer, all the code that
you write will end up on a linux server eventually.
It would be very good idea to start learning linux immediately. You will
require that skill in the near future.
None would want to pay the price of windows server when Linux is FREE ;-)

However, for the time being, please dabble with apache + modwsgi for
windows. I dont remember exact resources I used to deploy on window.
Simplest alternative is given below.
https://bitnami.com/stack/django/installer

One thing I remember is modwsgi is dependant on the python version i.e.
different python versions require modwsgi to be built for that specific
version.
Try some the ones listed in below link, if they don't work, you have to
search online for that.
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

Some tuts from youtube. I havent checked them yet so do your R&D. Follow
the steps that they have shown i the video to see if it works.
https://www.youtube.com/watch?v=s0RX_YU9eJM
https://www.youtube.com/watch?v=VnR5O4IjmOs

Hope it helps.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, Apr 30, 2019 at 12:05 AM Vamsi 
wrote:

> Hi Chetan,
> Thanks for the quick reply. Linux is not an option for me as I am not well
> versed in it. Is it possible for you to give me some resource for windows.
>
> Thanks and regards,
> Vamsi
>
> Sent from my iPhone
>
> On Apr 29, 2019, at 1:06 PM, Chetan Ganji  wrote:
>
> Hi Vamsi,
>
> For No 1 - You can create a REST API using django or (django + django rest
> framework).
> For No 2,3,4 - For production you have to user Apache + modwsgi or nginx +
> gunicorn (or other wsgi compliant server for python).
>
> I dont suggest windows for production. If you plan to use it on linux,
> below is the tutorial. I have used it many times for deployments.
>
> https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
>
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Mon, Apr 29, 2019 at 9:46 PM Vamsi tangutoori <
> vamsidhar.tanguto...@gmail.com> wrote:
>
>> Hi Everyone,
>> I am new to django and python programming. I developed a facial
>> recognition module in python using boto3 library. Currently I sued flask to
>> create an API and test in my development environment but to move it to
>> production i need to use django. Can you please help or point me in the
>> right direction as to how do i do the below.
>>
>> 1. Take my facialrecognition.py file and convert it into an API,
>> preferably using django.
>> 2. Make this API to be pointing to a specific URL(locally on a windows
>> machine).
>> 3. Deploy this code into a production machine(windows).
>> 4. Make sure that the API starts every time the windows machine starts to
>> avoid loosing service.
>>
>> Things i researched so far are:
>> 1. How to create a django project with its REST library.
>> 2. From the articles and tutorials i found out that this is only
>> development version, to deploy in production i need a production server
>> like Apache etc. is this necessary?
>>
>> Thanks in Advance for your help.
>> Vamsi.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/17aa8268-0fd8-4095-a5bb-82e68eecf186%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/17aa8268-0fd8-4095-a5bb-82e68eecf186%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/CAMKMUjvsqqRLp-6btfhV951gqwq5t1AehKsCgsER2UFuFfhMbA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMKMUjvsqqRLp-6btfhV951gqwq5

Re: More controls on createsuperuser

2019-04-30 Thread Chetan Ganji
RE :"*someone could still run createsuperuser *"

How do you suppose this is going to happen unless they have access to your
system?

If you are really concerned about that?? django is basically a package.
Just find the source code for the creatsuperuser admin command and delete
that file if its the only command in that file ;-)
if not just delete that function only :) Its that simple.

But How will you create a superuser after deleting the command from the
django package??

One way to solve is write your own custom management command, create
superuser at the time of deployment and delete that custom command also.

I hope this solves your problemo :)
Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, Apr 30, 2019 at 6:09 PM Lipika Chandel 
wrote:

> Hey,
> I am using Django 2.2 and I am stuck with the image upload functionality
> from admin site. I am not able to get the image on my template.
> Please help.
>
> Thanks & Regards
> LIPIKA CHANDEL
>
> On Tue, Apr 30, 2019 at 11:57 AM Jani Tiainen  wrote:
>
>> I've have to agree that any attempt to limit superuser creation through
>> manage.py is wrong solution to wrong problem.
>>
>> Even it's possible to attempt it it is as easy to circumvent.
>>
>> So do not give an access to manage.py to users that are not supposed to.
>> Problem solved for good.
>>
>> ma 29. huhtik. 2019 klo 21.04  kirjoitti:
>>
>>> Anyone capable of running the createsuperuser command on your project
>>> most probably has access to all and any of the project's files, specially
>>> your config file.
>>>
>>> Actually this user is either a valid su or you are in serious trouble
>>> because the security of your server sucks or you gave access to your
>>> project to the wrong person.
>>>
>>> So, no I don't think there is any point in doing so. Not because it
>>> can't be done but because it is both trivially useless.and uselessly
>>> trivial.
>>>
>>>
>>>
>>> On Sunday, April 28, 2019 at 11:24:57 PM UTC-4, JJ Zolper wrote:
>>>>
>>>> All,
>>>>
>>>> Curious what people think about more thought and control going into who
>>>> can run the createsuperuser method?
>>>>
>>>> For example say there's models that I don't want anyone to touch except
>>>> myself as a superuser. Is it not plausible that even if I make a Django
>>>> Group around that model that someone could still run createsuperuser and
>>>> give themselves the ability to have full control?
>>>>
>>>> Wouldn't it make sense if some random developer were to run
>>>> createsuperuser using django settings with any of the databases (as an
>>>> example) that it prevent them if say that email isn't on say an internal
>>>> list in the django admin of approved potential users?
>>>>
>>>> I see something like this being a good idea to prevent just anyone from
>>>> getting full control over the site without it being specifically provided.
>>>>
>>>> Maybe there's something I'm missing something but been reading about
>>>> third party options and more about what's there and I just feel there's a
>>>> hole when it comes to who can create a super user account. Obviously you
>>>> could have a script that you run to initialize who is a super user, what
>>>> the groups are etc, but then you're basically recording personal
>>>> information somewhere when that should only be typed in.
>>>>
>>>> Open to ideas and thoughts, mostly just curious what could be a good
>>>> answer.
>>>>
>>>> Best,
>>>>
>>>> JJ
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "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/f85e2d9b-ec2d-4814-b4d5-df137bf8a883%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/f85e2d9b-ec2d-4814-b4d5-df137bf8a883%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For 

Re: Website slowed down drasticaly

2019-05-02 Thread Chetan Ganji
Not sure about whats the issue. You could do couple of things to understand
whats the root cause of the problem.
I know they are generic guidelines. Anyone couldnt be more specific than
this.


   1. Benchmark the time required to process each request. You could write
   a middleware to track this time.
   Attach starttime to each request object and read that at the time of
   returning the response.

   2. Try using the django debug toolbar to see how much time it is taking
   to execute the sql queries.
   There might be some room for improvement as most developers dont
   practice sql regularly.
   https://django-debug-toolbar.readthedocs.io/en/latest/

   3. Maybe try using a different database - PostgreSQL, MySQL, etc.

   4. But if you have time for R&D, you could try using the different
   python implementation, it is said to be faster in many cases than cpython.
   It's not 100% compliant i.e. some packages might not work with pypy. So
   please do your research before walking down this road.
   https://pypy.org/

   5. Try using a different web server. If you are using Apache, try using
   nginx. Also use a different wsgi server. If you are using gunicorn, try
   with waitress or others.



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 2, 2019 at 5:09 PM Saurabh Adhikary 
wrote:

> Hello ,
>
> I'm using Django version 1.8.1  and Python version 2.7.12 . Suddenly since
> Feb '19 there has been a drastic decrease in my website's response rate.
> For sure , there has been some minor increase in the no of hits, but the
> performance is too bad.
>
> Initially , the thought came that the hardware of the server was old , so
> a new server with high configuration was bought.
> We have done the new indexing also on it.
> Still the sought for a higher performance is awaited.
>
>
> Is it that the Django support for 1.8.1 or Python support for 2.7.12 has
> reduced and that is casing the website to slow down or I am missing out on
> something ?
> Kindly help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/238a6da2-8f34-4b8b-939c-e20d4306545b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/238a6da2-8f34-4b8b-939c-e20d4306545b%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/CAMKMUjt8bqgOOns%3DuAsVbtR3yz17VypX3766zCMN5zVtbbRX4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: help with URLS.PY

2019-05-02 Thread Chetan Ganji
The line
path('', HomeView.as_view(), name='home'),

Change it to below and try again.
path(''", HomeView.as_view(), name='home'),


On May 3, 2019 2:52 AM,  wrote:

new to django. so i have an app that displays an html page. i also have a
menu on that page that will load up other html pages.
however, when i add the path to urls.py and then the class def in views, it
fails. i know it's something simple, what am i missing.

As I said, the dashboard.html works, i just want another menu option to
load the other html file. i have commented this out as it causes my app to
break.



urls.py

from django.conf.urls import url
from django.contrib import admin
from django.urls import path

from vr_reporting_app.views import HomeView
from vr_reporting_app.views import Map

urlpatterns = [
path('', HomeView.as_view(), name='home'),#points to the view in
views.py
#path('map/', Map.as_view(), name='map'),

path('admin/', admin.site.urls),
]


views.py

from django.shortcuts import render
from django.views.generic.base import TemplateView

class HomeView(TemplateView):
template_name = 'dashboard.html'

class Map(TemplateView):
template_name = 'map.html'

-- 
You received this message because you are subscribed to the Google Groups
"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/8ef3e2d9-799e-4803-bd20-199300b373af%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/CAMKMUjv3M2J8by9hAcikBS4snG88R0mijmSeG-ms28p%2BRbOKnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Website slowed down drasticaly

2019-05-03 Thread Chetan Ganji
Hi Saurabh,

You are welcome :)

No 1 will give you insights about which endpoints are taking the most time
to load. Then, you can drill down the specific endpoints for bottlenecks.

Two more things you could try.

1. Remove unused/unnecessary middlewares from the middlewares list in the
settings.py of the project.
As they are executed before and after every single request, they could add
hugh unnecessary overhead easily.

2. Normally requests are processed in synchronous manner. Gunicorn has
aysnc worker types.
I did not have a need to look into it yet, but they could help speed up
things.
I would not suggest it for payment gateway endpoints. If your project is a
ERP/CRM type project, it could help you a little to look into it.
https://www.spirulasystems.com/blog/2015/01/20/gunicorn-worker-types/

Nginx already handles requests async manner. Try combining Nginx + Async
worker in gunicorn.
You could get some boost.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, May 3, 2019 at 11:00 AM Saurabh Adhikary 
wrote:

> Hi Chetan,
>
> 1)  Yes . We are infact trying this. Thank You.
> 2) *Taken*
> 3) We are on MySql , migration will cost a lot of man hours, which can be
> invested only if the result is concrete.
> 4) Up-gradation, that's our last resort.
> 5) Tried almost all. All in vain.
>
> Thanks for your inputs. :)
>
> On Thursday, 2 May 2019 17:52:11 UTC+5:30, Chetan Ganji wrote:
>>
>> Not sure about whats the issue. You could do couple of things to
>> understand whats the root cause of the problem.
>> I know they are generic guidelines. Anyone couldnt be more specific than
>> this.
>>
>>
>>1. Benchmark the time required to process each request. You could
>>write a middleware to track this time.
>>Attach starttime to each request object and read that at the time of
>>returning the response.
>>
>>2. Try using the django debug toolbar to see how much time it is
>>taking to execute the sql queries.
>>There might be some room for improvement as most developers dont
>>practice sql regularly.
>>https://django-debug-toolbar.readthedocs.io/en/latest/
>>
>>3. Maybe try using a different database - PostgreSQL, MySQL, etc.
>>
>>4. But if you have time for R&D, you could try using the different
>>python implementation, it is said to be faster in many cases than cpython.
>>It's not 100% compliant i.e. some packages might not work with pypy.
>>So please do your research before walking down this road.
>>https://pypy.org/
>>
>>    5. Try using a different web server. If you are using Apache, try
>>using nginx. Also use a different wsgi server. If you are using gunicorn,
>>try with waitress or others.
>>
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Thu, May 2, 2019 at 5:09 PM Saurabh Adhikary 
>> wrote:
>>
>>> Hello ,
>>>
>>> I'm using Django version 1.8.1  and Python version 2.7.12 . Suddenly
>>> since Feb '19 there has been a drastic decrease in my website's response
>>> rate.
>>> For sure , there has been some minor increase in the no of hits, but the
>>> performance is too bad.
>>>
>>> Initially , the thought came that the hardware of the server was old ,
>>> so a new server with high configuration was bought.
>>> We have done the new indexing also on it.
>>> Still the sought for a higher performance is awaited.
>>>
>>>
>>> Is it that the Django support for 1.8.1 or Python support for 2.7.12 has
>>> reduced and that is casing the website to slow down or I am missing out on
>>> something ?
>>> Kindly help.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@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/238a6da2-8f34-4b8b-939c-e20d4306545b%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/238a6da2-8f34-4b8b-939c-e20d4306545b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/opto

Re: Website slowed down drasticaly

2019-05-03 Thread Chetan Ganji
One more thing -

All the third party resources i.e. js and css files e.g. bootstrap, jquery,
etc;  don't fetch them from your server.
Use CDN for those. This will help the load times a lot.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, May 3, 2019 at 2:47 PM Chetan Ganji  wrote:

> Hi Saurabh,
>
> You are welcome :)
>
> No 1 will give you insights about which endpoints are taking the most time
> to load. Then, you can drill down the specific endpoints for bottlenecks.
>
> Two more things you could try.
>
> 1. Remove unused/unnecessary middlewares from the middlewares list in the
> settings.py of the project.
> As they are executed before and after every single request, they could add
> hugh unnecessary overhead easily.
>
> 2. Normally requests are processed in synchronous manner. Gunicorn has
> aysnc worker types.
> I did not have a need to look into it yet, but they could help speed up
> things.
> I would not suggest it for payment gateway endpoints. If your project is a
> ERP/CRM type project, it could help you a little to look into it.
> https://www.spirulasystems.com/blog/2015/01/20/gunicorn-worker-types/
>
> Nginx already handles requests async manner. Try combining Nginx + Async
> worker in gunicorn.
> You could get some boost.
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Fri, May 3, 2019 at 11:00 AM Saurabh Adhikary <
> adhikarysaur...@gmail.com> wrote:
>
>> Hi Chetan,
>>
>> 1)  Yes . We are infact trying this. Thank You.
>> 2) *Taken*
>> 3) We are on MySql , migration will cost a lot of man hours, which can be
>> invested only if the result is concrete.
>> 4) Up-gradation, that's our last resort.
>> 5) Tried almost all. All in vain.
>>
>> Thanks for your inputs. :)
>>
>> On Thursday, 2 May 2019 17:52:11 UTC+5:30, Chetan Ganji wrote:
>>>
>>> Not sure about whats the issue. You could do couple of things to
>>> understand whats the root cause of the problem.
>>> I know they are generic guidelines. Anyone couldnt be more specific than
>>> this.
>>>
>>>
>>>1. Benchmark the time required to process each request. You could
>>>write a middleware to track this time.
>>>Attach starttime to each request object and read that at the time of
>>>returning the response.
>>>
>>>2. Try using the django debug toolbar to see how much time it is
>>>taking to execute the sql queries.
>>>There might be some room for improvement as most developers dont
>>>practice sql regularly.
>>>https://django-debug-toolbar.readthedocs.io/en/latest/
>>>
>>>3. Maybe try using a different database - PostgreSQL, MySQL, etc.
>>>
>>>4. But if you have time for R&D, you could try using the different
>>>python implementation, it is said to be faster in many cases than 
>>> cpython.
>>>It's not 100% compliant i.e. some packages might not work with pypy.
>>>So please do your research before walking down this road.
>>>https://pypy.org/
>>>
>>>5. Try using a different web server. If you are using Apache, try
>>>using nginx. Also use a different wsgi server. If you are using gunicorn,
>>>try with waitress or others.
>>>
>>>
>>>
>>> Regards,
>>> Chetan Ganji
>>> +91-900-483-4183
>>> ganji...@gmail.com
>>> http://ryucoder.in
>>>
>>>
>>> On Thu, May 2, 2019 at 5:09 PM Saurabh Adhikary 
>>> wrote:
>>>
>>>> Hello ,
>>>>
>>>> I'm using Django version 1.8.1  and Python version 2.7.12 . Suddenly
>>>> since Feb '19 there has been a drastic decrease in my website's response
>>>> rate.
>>>> For sure , there has been some minor increase in the no of hits, but
>>>> the performance is too bad.
>>>>
>>>> Initially , the thought came that the hardware of the server was old ,
>>>> so a new server with high configuration was bought.
>>>> We have done the new indexing also on it.
>>>> Still the sought for a higher performance is awaited.
>>>>
>>>>
>>>> Is it that the Django support for 1.8.1 or Python support for 2.7.12
>>>> has reduced and that is casing the website to slow down or I am missing out
>>>> on something ?
>>>> Kindly help.
>>>>
>>>> --
&

Re: Need Help

2019-05-07 Thread Chetan Ganji
As far as I know, there are only two dependency for the django, that is
pytz and sqlparse. Rest of the code for django is written from scratch.

You can confirm this by creating a new virtualenv and install django inside
it. Command will install django as well as other 2 libraries.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, May 7, 2019 at 5:15 PM Manoj Kumar Singh 
wrote:

> Many of the  interviewer asked me how many libraries and frameworks are
> used in django project.
> Please let me know the correct answer.
>
> --
>
>
> *Regards:-*Manoj Kumar 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/CAKfuDkW7XDhaYYNBB2gWRXJ35o6AnJvX4b3b5WPrVWW7HrruzA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAKfuDkW7XDhaYYNBB2gWRXJ35o6AnJvX4b3b5WPrVWW7HrruzA%40mail.gmail.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/CAMKMUjtjgSVosmRaaxi%2BLoSF1qYm3YH7TDNw6FTnT%3DJs9ir5Lw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: form submission

2019-05-09 Thread Chetan Ganji
Hi Ganesh,

This guy is total nerd. He teaches in a very easy to understand way ;-)
https://www.youtube.com/watch?v=KsLHt3D_jsE&list=PLEsfXFp6DpzRcd-q4vR5qAgOZUuz8041S

Start with Try Django 1.8.

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 9, 2019 at 6:44 PM Lutalo Bbosa joseph 
wrote:

> please specify what type of forms. coz in django u can create forms in
> forms.py using the models, and then this can be invoked in html as {{ forrm
> }} so am not understanding what u want specifically
>
> On Thu, May 9, 2019 at 3:39 PM Ganesh Babu  wrote:
>
>> Recently i was started Pyhon with Django.  Installation has been
>> succeeded in ubuntu and projects creation is also succeeded.
>>
>> Please help me,  how to create  form submission using pycharm
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/24114dd0-1699-4459-905e-49904371dc73%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/24114dd0-1699-4459-905e-49904371dc73%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/CAMz%3Dh%3DTkAdQ-wTZoxAqjt7HbTp2tHvskAs5pf296d_kb4ybkbA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMz%3Dh%3DTkAdQ-wTZoxAqjt7HbTp2tHvskAs5pf296d_kb4ybkbA%40mail.gmail.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/CAMKMUjtAdF8Dh_HYOjxtHC89Y6MmeaD6VAMVwkJNZdROFO78-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: form submission

2019-05-09 Thread Chetan Ganji
He sure does have it .

https://www.youtube.com/watch?v=-oQvMHpKkms&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=49

But in try django 1.8 he teaches the very basic stuff that everyone needs
to know about django. I just wish I started with this project instead of
others.
As I only found one project that teaches the basic stuff in simple and
effective manner. I have taken courses from many different people.
Most of them went out of my head as they never fully explained what the
heck was happening. That's not the case with Justin Mitchell ;-)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 9, 2019 at 9:56 PM Robert Wahoo  wrote:

> That’s for 1.8, does he have an updated set of videos for 2.x?
>
>
>
> *From: *"django-users@googlegroups.com" 
> on behalf of Chetan Ganji 
> *Reply-To: *"django-users@googlegroups.com"  >
> *Date: *Thursday, May 9, 2019 at 12:05 PM
> *To: *"django-users@googlegroups.com" 
> *Subject: *Re: form submission
>
>
>
> Hi Ganesh,
>
> This guy is total nerd. He teaches in a very easy to understand way ;-)
>
>
> https://www.youtube.com/watch?v=KsLHt3D_jsE&list=PLEsfXFp6DpzRcd-q4vR5qAgOZUuz8041S
>
>
>
> Start with Try Django 1.8.
>
>
> Cheers!
>
>
>
>
> Regards,
>
> Chetan Ganji
>
> +91-900-483-4183
>
> ganji.che...@gmail.com
>
> http://ryucoder.in
>
>
>
>
>
> On Thu, May 9, 2019 at 6:44 PM Lutalo Bbosa joseph 
> wrote:
>
> please specify what type of forms. coz in django u can create forms in
> forms.py using the models, and then this can be invoked in html as {{ forrm
> }} so am not understanding what u want specifically
>
>
>
> On Thu, May 9, 2019 at 3:39 PM Ganesh Babu  wrote:
>
> Recently i was started Pyhon with Django.  Installation has been succeeded
> in ubuntu and projects creation is also succeeded.
>
>
>
> Please help me,  how to create  form submission using pycharm
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/24114dd0-1699-4459-905e-49904371dc73%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/24114dd0-1699-4459-905e-49904371dc73%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/CAMz%3Dh%3DTkAdQ-wTZoxAqjt7HbTp2tHvskAs5pf296d_kb4ybkbA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMz%3Dh%3DTkAdQ-wTZoxAqjt7HbTp2tHvskAs5pf296d_kb4ybkbA%40mail.gmail.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/CAMKMUjtAdF8Dh_HYOjxtHC89Y6MmeaD6VAMVwkJNZdROFO78-A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMKMUjtAdF8Dh_HYOjxtHC89Y6MmeaD6VAMVwkJNZdROFO78-A%40mail.gmail.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 vis

Re: Different database types use in a single Django project

2019-05-10 Thread Chetan Ganji
Hi Bbake,

Django Class Based Views and Models are wired for relational databases
only. If you want to use MongoDB with django you have to say bye bye to CBV
and Django ORM. There are some third party libraries to map django models
to mongo, but IDK how good they are for production use.

One way to solve this problem is use Function Based Views for views where
MongoDB will be used.
You will have to access mongo db using a database driver like pymongo.

If you just need to store the json data, another way to solve this problem
is to use django and postgres database.
PostgreSQL has JSON field, django also supports that. Check the official
documents for more info.
https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/

If you find any more solutions, please let me know, as I also want to
explore the options of using mongo with django.
Thanks in advance.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, May 10, 2019 at 5:27 PM Bbake Waikhom  wrote:

> Is there any way that I can use different database type in a single Django
> project like some model A will use SQL and some model B will use MongoDB?
> Because in my project some data are better to store in a relational
> database and some are better to store in a NoSQL database. I've been
> searching for a while to achieve this but I couldn't find any solution.
> Please let me know if there is a way. Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/b3776d83-18c9-47a0-9a8a-e3e7cb2e849a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b3776d83-18c9-47a0-9a8a-e3e7cb2e849a%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/CAMKMUjvwPcizHF%3DRrdJai9j8C2BakWj7XpMMK_O%2BbntuByHrTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help on architecture of User layout configuration system

2019-05-13 Thread Chetan Ganji
My 2 cents -

You will have to store the user preferences in a settings file on the
server. I would suggest to use a JSONField for the same if you are using
the PostgrSQL. Otherwise you will have to create a separate model. Saving
settings in model will take more efforts. Using JSON for this would be
perfect. Store this JSON on the User Model in the django, so you are
basically adding an extra JSONField to the user model in django. If you
store this data on a different model, you will end up writing one extra
sql/orm query to fetch the settings. So, save yourself that trouble and
store the settings on the user model.

Whatever user can configure, create respective key value pairs for the
same.

Then in every template where these settings would be required, access them
using the variable *request.user.settings* (assuming you named it
settings).
In the templates, wherever the user can customize his view, you would write
the if blocks to check if the current user has selected the respective
settings or not.
Accordingly they would be rendered *DYNAMICALLY*.

I hope it helps :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, May 13, 2019 at 3:58 PM Devender Kumar  wrote:

> Hi,
> I want to make a web app in which user has rights to configure his
> layout.Means each user can configure his layout according to his choice and
> work
> Like how many fields can his form have how many field he want to see in
> table view of individual record view . configure theme color of his own
> choice .
> all these type of settings he can do for his own use.
> Can any one help me with this type of architecture.
> Thank you
> Devender
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/b9332431-bb74-416d-b5e6-a54db73c1b56%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b9332431-bb74-416d-b5e6-a54db73c1b56%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/CAMKMUjtvZ6JngGhGxgVkg%2BjNVm2J4-CgdJRcuUdzpW1aj3p2vA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't save to Postgres db locally - Fresher

2019-05-15 Thread Chetan Ganji
*Problem - *
def *contact*(request):
  ..
  c = *contact*(email='email',subject='subject',message='message')
  ..

The two methods that should be doing two separate things have the same
name. So, the python interpreter is confused.

*Solution - *
Rename anyone of the above methods.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 15, 2019 at 3:50 PM Emmanuel klutse  wrote:

> Hello Team,
> I need help please, I’m try to save to my db from a FORM using the command
> below.
> I’ve all I could but the process keeps failing and I’m stack.
>
> File
> "/Users/emmanuelklutse/Documents/djangodev/myPortfolio/emmanuel/views.py", l
> ine 17, in contact
> c = contact(email='email',subject='subject',message='message')
> TypeError: contact() got an unexpected keyword argument ‘email'
>
>
> def contact(request):
> if request.method == 'POST':
> email = request.POST.get('email')
> subject = request.POST.get('subject')
> message = request.POST.get('message')
>
> c = contact(email='email',subject='subject',message='message')
> c.save()
>
> return render (request,'emmanuel/contact.html')
> else:
> return render (request,'emmanuel/contact.html’)
>
>
> Thanks,
> Emmanuel klutse. Best 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/D5902281-068C-448D-8C3B-4661EC37473A%40gmail.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/CAMKMUjv5c7WoQ8aZzZWgm%3DZxoEs0zX3nVeQC_yiTzKKiHGUVkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help on architecture of User layout configuration system

2019-05-15 Thread Chetan Ganji
This one is interesting. I was also looking for the solution of the same
problem.

If I understand correctly, the problem with forms is -
User can choose the name of the field and the type of the fields e.g.
IntegerField(). FloatField(), etc. Kind of a form that is generated using a
form :P
More like a Form Builder App which will help users create DYNAMIC FORMS.
Am I correct?

We could create a form for that with 2 inputs elements.
One input to enter the name of the field.
Second would be a dropdown (select html element) with the type of the model
fields that django models.Model has. We can also add select dropdown for
constraints.
Store the values of these two in a JSONField(). This part is simple and
possible.

The real challenge is -
*How to turn them into models and store the actual data?*

*Solution 1*
That is also simple. We could create a default string that resembles the
source code of a model class of a django model.
and create the code for it by writing the if clauses for diff fields of the
models and create a string for the same. Then write this string to a .py
file.
e.g.

"class BaseModel(models.Model):
created = models.DateTimeField(auto_now=False, auto_now_add=True,)
updated = models.DateTimeField(auto_now=True, auto_now_add=False,)"


The Problem with this approach is app will end up with lots of .py files
that has diff models.
Making migrations and Migrating will also be a pain point.
Making any migrations will require stopping and restarting the server
(nginx+gunicorn), that is not possible in a production environment.
Will have to restart the server for every new form created and migrated.

*Not a good idea to do this.*

*Solution 2*
As each form/model would have a separate schema, using a JSONField() makes
sense here.
As we are storing forms in JSONField(), store the data also in the
JSONField().
This wont require making any models/migrations and migrating the database.
Also server restarts are not required at all.

This is more feasible solution and will be easier approach than the earlier
one.

However, making the forms populate/reder dynamically from the stored json
field and validating them dynamically according to their schema *NEEDS SOME
R&D*.
Give it a try and share the results with me.

I hope it was worth your time :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, May 13, 2019 at 4:38 PM Devender Kumar  wrote:

> Thank you for your suggestion
> I am using PostgreSQL
> You have successfully saved the layout but I am talking about the dynamics
> forms fields which will be used for form submission how you are looking to
> store the values of 1000's of records entered after that in those fields.
> that's why I was looking for more efficient way (as I know this solution
> already ignore the fact that storing the json of record values too) as it
> might decrease the efficiency of the system.
>
> On Monday, May 13, 2019 at 3:58:47 PM UTC+5:30, Devender Kumar wrote:
>>
>> Hi,
>> I want to make a web app in which user has rights to configure his
>> layout.Means each user can configure his layout according to his choice and
>> work
>> Like how many fields can his form have how many field he want to see in
>> table view of individual record view . configure theme color of his own
>> choice .
>> all these type of settings he can do for his own use.
>> Can any one help me with this type of architecture.
>> Thank you
>> Devender
>>
> --
> You received this message because you are subscribed to the Google Groups
> "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/ec432f98-e6ce-4849-9d8d-46237f451cda%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ec432f98-e6ce-4849-9d8d-46237f451cda%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/CAMKMUjspS2BqJpAyDMyOVHrQK334vNyPopo4wAGCyGMEBT%3DDEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Run django in apache2.4+centos7.5+python2.7

2019-05-15 Thread Chetan Ganji
This might help you.

https://bitnami.com/stack/django/installer


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 15, 2019 at 9:13 PM Kurosh Sol  wrote:

> Hi,
> I would like to ask a question about django setup
> Please if you can help me
> I use dedicate server from inmotion hosting .com
> With apache 2.4 (cpanel)
> I have easy_apach4 in my whm
> I install python 3 and i have python 2.7 in my server  and when i commend
> django in python terminal
> I get
> (1, 11, 20, u’final’ ,0)
> I can run my django project in my port 8000 by run serever
> Also i can run python code in my cgi folder of my website
> But i can not run django from apache server
> I try to install mode_wsgi but i got error in no package found
> Than i read article about can not install from cpanel so i tried to
> download and custom install but new version of easy_apache doesn’t accept
> custom install
> Is there anyway i can use apache
> I would be more than happy if get any help
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/69649cf3-310d-4eba-b6e9-770dff0bf76c%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/CAMKMUjuUJaOnvpPd4Tc2Azya9ckiht2wNm0NKmcS2hJ%3DR0e_WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: multiple database

2020-10-09 Thread Chetan Ganji
https://docs.djangoproject.com/en/3.1/topics/db/multi-db/


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Oct 9, 2020 at 6:41 PM Khaleel Ahmed H. M. Shariff <
khaleelahme...@gmail.com> wrote:

> Hi Suhaib,
> May Peace, Blessings & Mercy of Almighty God be on you!
>
> Kindly throw some light on what database you are using. Are you using
> SQLite (default available with Python) or any other RDBMS like
> MySQL/Oracle???
> Awaiting your reply.
> Thanks in advance.
>
>
> God Bless You!
> God Bless India!!
> --
>
> Love & Regards
> Dr. (h.c.) Khaleel Ahmed H. M.
>
> Managing Director, Tanzanite Realty India Private Limited
>
> ---
>
> Human Life is Precious
> Koran Surah Ma'idah Chapter 5 Verse 32:
> If anyone killed a person, not in retaliation of murder, or (and) to
> spread mischief in the land - it would be as if he killed all mankind, & if
> anyone saved a life, it would be as if he saved the life of all mankind.
>
>
> On Fri, Oct 9, 2020 at 6:05 PM Suhaib Ali  wrote:
>
>> Hello everyone,
>>
>> i have some doubt regarding django database. i want to create multiple
>> database according to the user wish. for example i want to create a company
>> so each and every company needs their own database while creating the
>> company
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/cff6452c-e9fd-4126-9ef7-51ea4083c6f6n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/cff6452c-e9fd-4126-9ef7-51ea4083c6f6n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMjBbiBL91PMWVAmLWZoPSJSiD5v%2B8WzMB9A83UvWOqy5RwAhw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMjBbiBL91PMWVAmLWZoPSJSiD5v%2B8WzMB9A83UvWOqy5RwAhw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: API to stop/resume/terminate a long running task

2020-10-13 Thread Chetan Ganji
Hi Aparna,

I dont know the details of your implementation. As its a bulk upload,
assuming there would be an upload form where user can put multiple files
simultaneously.
One by one, each file would be uploaded to the server.

AFAIK, bulk operations are not supposed to be stopped and resumed in order
to avoid inconsistency issues.
However, after each file upload you could pause and resume later if each
upload is mutually exclusive.
I have an idea, check if it works for you. It can simply be implemented in
the front end by using a boolean variable.
You could stop uploading if the value of boolean is false and resume if
it's true.
Pause button will set it to false and Resume button will set it to true.

Answers to below questions would help anyone who wants to give better
solutions.

What kind of data - csv, xls, audio, videos, etc.
How long would a typical upload operation would take?
What is the stack? frontend and backend
What is the workflow of uploading the files?

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, Oct 12, 2020 at 9:01 PM Arpana Mehta 
wrote:

> Hello everybody,
> I am here looking for a solution to a problem commonly faced maybe.
>
> I have like a huge amount of data that is being uploaded in a go. While I
> can keep these upload tasks under atomic decorators to avoid systemic
> failure but I don't have way to let the user stop the task and resume or
> terminate it later.
>
> I would need suggestions on how to go about this workflow.
>
> Would love details in the flow. I understand the basic mechanism myself
> but I want to write APIs to stop or resume any running bulk write/read task
> in my system.
>
> Thanks and regards,
> Arpana
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGyqUuWfaa0_ME%2BHjQx8b6nKyB0g54F0OtA8DrEvzwpqxJ013g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAGyqUuWfaa0_ME%2BHjQx8b6nKyB0g54F0OtA8DrEvzwpqxJ013g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Trying to trigger a bulkcreation of records using a reverse relationship

2020-11-13 Thread Chetan Ganji
Im not 100% sure about this :P

Instead of this -
def save(self, *args, **kwargs):
if self.records.count() <= 0:
for student in self.klass.students.all():
self.records.create(student=student, status='present')
super(Attendance, self).save(*args, **kwargs)


Try with below code -

def save(self, *args, **kwargs):
super(Attendance, self).save(*args, **kwargs)
if self.records.count() <= 0:
for student in self.klass.students.all():
self.records.create(student=student, status='present') # separate sql query
i guess for each entry created.


There is a diff logic.

1. create attendance object.
2. bulk create AttendanceRecord objects
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#bulk-create

P.S. both of this operations should happen inside a transaction.
https://docs.djangoproject.com/en/3.1/topics/db/transactions/


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Nov 13, 2020 at 4:41 PM DumbaClassics 
wrote:

> Hello Family may you help.
>
> I am trying to create a School Attendance Module and I have a StudentClass
> table, the Student table, Attendance table and the AttendanceRecord table.
> Here is the code
>
> class StudentClass(models.Model):
> name  =   models.CharField(max_length=100)
> # stream   =   models.ForeignKey('Stream', on_delete=models.PROTECT)
> creation_date =   models.DateTimeField(auto_now=False,
> auto_now_add=True)
>
>
> def __str__(self):
> return self.name
>
> class Student(models.Model):
> name = models.CharField(max_length=100)
> klass = models.ForeignKey('StudentClass', models.PROTECT,
> related_name='students')
>
> def __str__(self):
> return self.name
>
> class Attendance(models.Model):
> date = models.DateTimeField(auto_now_add=True)
> klass = models.ForeignKey('StudentClass', models.PROTECT,
> related_name='attendances')
>
> def save(self, *args, **kwargs):
> if self.records.count() <= 0:
> for student in self.klass.students.all():
> self.records.create(student=student, status='present')
> super(Attendance, self).save(*args, **kwargs)
>
> def __str__(self):
> return f"{self.id}, {self.date}"
>
> class AttendanceRecord(models.Model):
> ATTENDANCE_STATUS = [
> ('present', 'PRESENT'),
> ('absent', 'ABSENT')
> ]
> attendance = models.ForeignKey(
> 'Attendance',
> on_delete=models.SET_NULL,
> null=True,
> blank=True,
> related_name='records'
> )
> student = models.ForeignKey('Student', on_delete=models.PROTECT)
> status = models.CharField(max_length=100, choices=ATTENDANCE_STATUS)
>
>
> def __str__(self):
> return f"(STUDENT: {self.student}, STATUS: {self.status})"
>
>
> What am I trying to achieve??
>
> I want to have a situation whereby when I trigger the creation of a
> Attendance instance an Attendance Record linked to that instance is
> generated with the record generating default attendance records for all
> students enrolled in that klass with a default attendance status of present
> which I can get on to edit only for those students who are absent. The
> method I tried for ovveriding the save method didnt work as it generated
> this error '"unsaved related object '%s'." % field.name
> ValueError: save() prohibited to prevent data loss due to unsaved related
> object 'attendance'.'
>
> I wasnt really confident of that solution anyway.
>
> May you assist me on how best one wld solve such a problem
>
> Thank you in Advance
>
> Dumba
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2742a034-586d-44a2-872a-5d0c24dc8d70n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/2742a034-586d-44a2-872a-5d0c24dc8d70n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Trying to trigger a bulkcreation of records using a reverse relationship

2020-11-13 Thread Chetan Ganji
Welcome :)

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Nov 13, 2020 at 9:22 PM Dumba Classics 
wrote:

> thank you @Chetan the solution does work and I am very grateful!!
>
> On Fri, Nov 13, 2020 at 5:35 PM Chetan Ganji 
> wrote:
>
>> Im not 100% sure about this :P
>>
>> Instead of this -
>> def save(self, *args, **kwargs):
>> if self.records.count() <= 0:
>> for student in self.klass.students.all():
>> self.records.create(student=student, status='present')
>> super(Attendance, self).save(*args, **kwargs)
>>
>>
>> Try with below code -
>>
>> def save(self, *args, **kwargs):
>> super(Attendance, self).save(*args, **kwargs)
>> if self.records.count() <= 0:
>> for student in self.klass.students.all():
>> self.records.create(student=student, status='present') # separate sql
>> query i guess for each entry created.
>>
>>
>> There is a diff logic.
>>
>> 1. create attendance object.
>> 2. bulk create AttendanceRecord objects
>> https://docs.djangoproject.com/en/3.1/ref/models/querysets/#bulk-create
>>
>> P.S. both of this operations should happen inside a transaction.
>> https://docs.djangoproject.com/en/3.1/topics/db/transactions/
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Fri, Nov 13, 2020 at 4:41 PM DumbaClassics 
>> wrote:
>>
>>> Hello Family may you help.
>>>
>>> I am trying to create a School Attendance Module and I have a
>>> StudentClass table, the Student table, Attendance table and the
>>> AttendanceRecord table. Here is the code
>>>
>>> class StudentClass(models.Model):
>>> name  =   models.CharField(max_length=100)
>>> # stream   =   models.ForeignKey('Stream', on_delete=models.PROTECT)
>>> creation_date =   models.DateTimeField(auto_now=False,
>>> auto_now_add=True)
>>>
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>> class Student(models.Model):
>>> name = models.CharField(max_length=100)
>>> klass = models.ForeignKey('StudentClass', models.PROTECT,
>>> related_name='students')
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>> class Attendance(models.Model):
>>> date = models.DateTimeField(auto_now_add=True)
>>> klass = models.ForeignKey('StudentClass', models.PROTECT,
>>> related_name='attendances')
>>>
>>> def save(self, *args, **kwargs):
>>> if self.records.count() <= 0:
>>> for student in self.klass.students.all():
>>> self.records.create(student=student, status='present')
>>> super(Attendance, self).save(*args, **kwargs)
>>>
>>> def __str__(self):
>>> return f"{self.id}, {self.date}"
>>>
>>> class AttendanceRecord(models.Model):
>>> ATTENDANCE_STATUS = [
>>> ('present', 'PRESENT'),
>>> ('absent', 'ABSENT')
>>> ]
>>> attendance = models.ForeignKey(
>>> 'Attendance',
>>> on_delete=models.SET_NULL,
>>> null=True,
>>> blank=True,
>>> related_name='records'
>>> )
>>> student = models.ForeignKey('Student', on_delete=models.PROTECT)
>>> status = models.CharField(max_length=100, choices=ATTENDANCE_STATUS)
>>>
>>>
>>> def __str__(self):
>>> return f"(STUDENT: {self.student}, STATUS: {self.status})"
>>>
>>>
>>> What am I trying to achieve??
>>>
>>> I want to have a situation whereby when I trigger the creation of a
>>> Attendance instance an Attendance Record linked to that instance is
>>> generated with the record generating default attendance records for all
>>> students enrolled in that klass with a default attendance status of present
>>> which I can get on to edit only for those students who are absent. The
>>> method I tried for ovveriding the save method didnt work as it generated
>>> this error '"unsaved related object '%s'." % field.name
>>> ValueError: save() prohibited to prevent data loss due to unsaved
>>> related object 'attendance'.'
>>>
>>> I wasnt really confident of that solution anyway.
>>>
>>> May y

Re: deployment error : django + pgsql

2020-12-29 Thread Chetan Ganji
Give the details of not able to migrate and someone might be able to help
you

Meanwhile refer to below doc and try again.
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, Dec 29, 2020 at 10:05 PM Kasper Laudrup 
wrote:

> Hi Govind,
>
> On 29/12/2020 15.43, Govind Kumar Yadav wrote:
> > hi I have been trying to deploy my Django project with pgsql on Linux
> > with over nginx server but i am not able to migrate for my already
> > existing project which works fine in my windows machine.
> > Help me to get over the issues.
>
> No one is able to help you get over your issues, since no one knows
> which issues you are having apart from lack of communication skills.
>
> Try to take the time to write a proper question and then I'm sure
> someone will be happy to take the time and write a proper answer.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1c48e865-75c2-7c0a-5273-86c41f81f850%40stacktrace.dk
> .
>

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


Re: How to get username in django_requestlogging

2021-01-03 Thread Chetan Ganji
Hey,

On that link it is mentioned as below.

If any of this information cannot be extracted from the current request (or
there is no current request), a hyphen '-' is substituted as a placeholder.

Maybe you are trying with anonymous user? 😅




On Sat, Jan 2, 2021, 8:42 PM Shailesh Yadav 
wrote:

> I am using ‘django_requestlogging’ for the log file and I have followed
> django_requestlogging  this
> link and configured it as per the steps given.
>
> I am not getting the username in the log file instead of that I am getting
> “-”.
>
> Please find the code details.
>
>
> *step1*.Installed application
>
> INSTALLED_APPS =
>
>  [ --- --
>
>   'django_requestlogging',
>
>  ]
>
>
> *step2:* Created Middleware
>
>
> from django.utils.deprecation import MiddlewareMixin from
> django_requestlogging.middleware import LogSetupMiddleware as Original
> class LogSetupMiddleware(MiddlewareMixin, Original): pass
>
>
> *step3:* used in settings.py
>
>
> MIDDLEWARE = [ ‘django.middleware.security.SecurityMiddleware’,
> ‘django.contrib.sessions.middleware.SessionMiddleware’,
> ‘django.middleware.common.CommonMiddleware’,
> ‘django.middleware.csrf.CsrfViewMiddleware’,
> ‘django.contrib.auth.middleware.AuthenticationMiddleware’,
> ‘django.contrib.messages.middleware.MessageMiddleware’,
> ‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
> ‘user_visit.middleware.UserVisitMiddleware’, #
> ‘django_requestlogging.middleware.LogSetupMiddleware’,
> ‘apple.middleware1.LogSetupMiddleware’ ]
>
>
>
> *step4:* Configuration
>
>
>
>
> LOGGING = {
> 'version': 1,
> # Version of logging
> 'disable_existing_loggers': False,
> 'filters': {
> # Add an unbound RequestFilter.
> 'request': {
> '()': 'django_requestlogging.logging_filters.RequestFilter',
> },
> },
> 'formatters': {
> 'request_format': {
> 'format': '%(remote_addr)s "%(request_method)s '
> '%(path_info)s %(server_protocol)s" %(http_user_agent)s '
> '%(message)s %(asctime)s',
> },
>
> 'simple': {
> 'format': '[%(asctime)s] - %(levelname)5s -:%(message)3s -" %(username)5s'
> },
>
> },
> 'handlers': {
> 'console': {
> 'level': 'INFO',
> 'class': 'logging.StreamHandler',
> 'filters': ['request'],
> 'formatter': 'simple',
> },
>
> 'file': {
> 'level': 'INFO',
> 'class': 'logging.FileHandler',
> 'filename': 'icici.log',
> 'formatter':'simple'
> },
> },
> 'loggers': {
> 'django': {
> # Add your handlers that have the unbound request filter
> 'handlers': ['console','file'],
> 'level': 'DEBUG',
> 'propagate': True,
> # Optionally, add the unbound request filter to your
> # application.
> 'filters': ['request'],
> },
> },
> }
>
> In the O/p Log file, I am getting.
>
> [2021-01-01 21:53:39,243] - INFO -:"GET /genesysall/ HTTP/1.1" 200 82259
> -" -
>
> Any help or hint on this how to get the username.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f1f1adea-a087-42f6-b5ef-d3847b9bc43bn%40googlegroups.com
> 
> .
>

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


Re: How to get username in django_requestlogging

2021-01-03 Thread Chetan Ganji
However,

use sentry for logging on prod servers, it will make your life easier.

Its free to get started 😉

On Sun, Jan 3, 2021, 11:08 PM Chetan Ganji  wrote:

> Hey,
>
> On that link it is mentioned as below.
>
> If any of this information cannot be extracted from the current request
> (or there is no current request), a hyphen '-' is substituted as a
> placeholder.
>
> Maybe you are trying with anonymous user? 😅
>
>
>
>
> On Sat, Jan 2, 2021, 8:42 PM Shailesh Yadav 
> wrote:
>
>> I am using ‘django_requestlogging’ for the log file and I have followed
>> django_requestlogging <https://pypi.org/project/django-requestlogging/> this
>> link and configured it as per the steps given.
>>
>> I am not getting the username in the log file instead of that I am
>> getting “-”.
>>
>> Please find the code details.
>>
>>
>> *step1*.Installed application
>>
>> INSTALLED_APPS =
>>
>>  [ --- --
>>
>>   'django_requestlogging',
>>
>>  ]
>>
>>
>> *step2:* Created Middleware
>>
>>
>> from django.utils.deprecation import MiddlewareMixin from
>> django_requestlogging.middleware import LogSetupMiddleware as Original
>> class LogSetupMiddleware(MiddlewareMixin, Original): pass
>>
>>
>> *step3:* used in settings.py
>>
>>
>> MIDDLEWARE = [ ‘django.middleware.security.SecurityMiddleware’,
>> ‘django.contrib.sessions.middleware.SessionMiddleware’,
>> ‘django.middleware.common.CommonMiddleware’,
>> ‘django.middleware.csrf.CsrfViewMiddleware’,
>> ‘django.contrib.auth.middleware.AuthenticationMiddleware’,
>> ‘django.contrib.messages.middleware.MessageMiddleware’,
>> ‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
>> ‘user_visit.middleware.UserVisitMiddleware’, #
>> ‘django_requestlogging.middleware.LogSetupMiddleware’,
>> ‘apple.middleware1.LogSetupMiddleware’ ]
>>
>>
>>
>> *step4:* Configuration
>>
>>
>>
>>
>> LOGGING = {
>> 'version': 1,
>> # Version of logging
>> 'disable_existing_loggers': False,
>> 'filters': {
>> # Add an unbound RequestFilter.
>> 'request': {
>> '()': 'django_requestlogging.logging_filters.RequestFilter',
>> },
>> },
>> 'formatters': {
>> 'request_format': {
>> 'format': '%(remote_addr)s "%(request_method)s '
>> '%(path_info)s %(server_protocol)s" %(http_user_agent)s '
>> '%(message)s %(asctime)s',
>> },
>>
>> 'simple': {
>> 'format': '[%(asctime)s] - %(levelname)5s -:%(message)3s -" %(username)5s'
>> },
>>
>> },
>> 'handlers': {
>> 'console': {
>> 'level': 'INFO',
>> 'class': 'logging.StreamHandler',
>> 'filters': ['request'],
>> 'formatter': 'simple',
>> },
>>
>> 'file': {
>> 'level': 'INFO',
>> 'class': 'logging.FileHandler',
>> 'filename': 'icici.log',
>> 'formatter':'simple'
>> },
>> },
>> 'loggers': {
>> 'django': {
>> # Add your handlers that have the unbound request filter
>> 'handlers': ['console','file'],
>> 'level': 'DEBUG',
>> 'propagate': True,
>> # Optionally, add the unbound request filter to your
>> # application.
>> 'filters': ['request'],
>> },
>> },
>> }
>>
>> In the O/p Log file, I am getting.
>>
>> [2021-01-01 21:53:39,243] - INFO -:"GET /genesysall/ HTTP/1.1" 200 82259
>> -" -
>>
>> Any help or hint on this how to get the username.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f1f1adea-a087-42f6-b5ef-d3847b9bc43bn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/f1f1adea-a087-42f6-b5ef-d3847b9bc43bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

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


Angular Material Help Required

2021-01-22 Thread Chetan Ganji
Hi,

I was hoping someone could help me with this. I know this is not
angular group :P

*Requirement:* errors should be displayed just after the mat-label.

*Problem:* mat-error is always displayed below the matInput in angular
material theme. It doesnt matter in which order I write the markup, errors
are always displayed below the input.

*Solution:*
1. mat-errors need to be made inline in the css, I found the css code that
will make this change.
2. mat-error are always subscripted to matInput - I need help with this.
I want to understand how this happens in the framework and how to stop this
default behaviour.
I have looked into the source code, but could not find the code responsible
for this.

This change needs to be done project wide. Please suggest a solution that's
ideal.
One solution would be to extend the default angular/material directives and
make the changes in those and import extended directives instead of the
default directives.
Is there a better way to do this?

Thanks in advance!


My code in theme pages

First name 
 is
required 




I think below code is the markup of errors
https://github.com/angular/components/blob/acb3f33413b92cc326f51a1db8b43e4a8094d745/src/material/form-field/form-field.html#L74




...




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in

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


Re:

2021-01-26 Thread Chetan Ganji
Hi Salima,

Couple of things you can change in the code to make it run faster!
Do these changes and performance will definitely improve.

1.Queryset

Problem:
classifieds =
vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
This will fetch all the entries in the table; if there are million records
in the table,
all of them will be fetched, which is not required at all!

Processing them will consume resources on the server which is unnecessary
calculation!
Avoid it!

Solution:
classifieds =
vk_classifieds.objects.filter(class_status='1').order_by('-added_date')[:page_size]

Only fetch what you need! As your page size is 40 actual query will look
like below.
classifieds =
vk_classifieds.objects.filter(class_status='1').order_by('-added_date')[:40]

2. Calculation on every request

2.1 classifieds_dist
Distance between two zipcodes is not going to be changed! You dont have to
calculate on every request.
Calculate it only once when the new classified is created and store it in a
separate table.
This calculation must be done using a celery task.

Every time zipcode of classified is updated or user updates his zipcode,
this distance has to be updated.
You have to put restrictions on how many times a user can change his
zipcode.
Otherwise you could end up paying hugh money to the api providers!
This updation must be done using a celery task.


2.2 diff_time
I dont know the code and complexity of it.
However as it is going to be required on every request find a way to
calculate it once and store in a separate table.

Let me know if they are helpful or not!
Cheers!


On Thu, Jan 21, 2021, 9:35 AM Salima Begum 
wrote:

> Hi all,
>
> We are building website, Here I have written functionality for classifieds
> page.
> It is loading to slow because of We are prompting distance calculation in
> classifieds page. By using distance API matrix based on logged in user zip
> code and individual Ad zip codes from query set(database).
>
> ```
> def classifieds(request):
> global dict_time
> try:
> dict_time = {}
> email = request.session.get('email')
>
> # Here we are displaying the classified ads "order by date".
> The ads will be sorted by latest date.
> classifieds =
> vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
>
> count =
> vk_classifieds.objects.filter(class_status='1').order_by('-added_date').count()
> for i in classifieds:
> # diff_time is a child method. By passing 'i' as object in
> diff_time.
> difrnc_date = diff_time(i)
> dict_time[i.id] = difrnc_date
>
> # Pagination for classifieds page.
> # classified = random.sample(list(classifieds), k=count)
> # print("classified = ", str(classified))
> # By default first page
> page = request.GET.get('page', 1)
> # print("page = ", str(page))
> # Per page setting 40 objects.
> paginator = Paginator(list(classifieds), 40)
> # print("paginator = ", str(paginator))
> classified_p = paginator.page(page)
> # print(classified_p)
> except PageNotAnInteger:
> classified_p = paginator.page(1)
> except EmptyPage:
> classified_p = paginator.page(paginator.num_pages)
> except Exception as e:
> logging.error(e)
> return render(request, "classifieds.html",
>   {"Classifieds": classified_p,
>  # distance calculation
>"distance": classifieds_dist(email),
>'some_date': dict_time,
>})
> return render(request, "classifieds.html", {"Classifieds":
> classified_p,
> "distance":
> classifieds_dist(email),
> 'some_date': dict_time,
> })
> ```
>
> ```
>
> def classifieds_dist(email):
> global frm, km
> dict_distance = {}
>
> qury = vk_customer.objects.filter(email=email).first()
>
> # From above qury variable we are getting zip of customer.
> frm = qury.Zip
> # importing json package to calculate the distance
> url = "
> https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial";
> headers = {
> 'Authorization': "Bearer somevalue",
> 'User-Agent': "some value",
> 'Accept': "*/*",
> 'Cache-Control': "no-cache",
> 'Postman-Token': "some value",
> 'Host': "maps.googleapis.com",
> 'Accept-Encoding': "gzip, deflate",
> 'Connection': "keep-alive",
> 'cache-control': "no-cache"
> }
> classifieds =
> vk_classifieds.objects.filter(class_status='1').order_by('-added_date')
> for i in classifieds:
> # while a user login th

Re: Django Rest Framework APIView request

2021-02-01 Thread Chetan Ganji
If it needs to be done on specific endpoints, write a custom decorator
method for that endpoint.

If it needs to be done on every request, write custom middleware.

On Mon, Feb 1, 2021, 1:51 PM Ammar Mohammed  wrote:

>
> Hi everyone i have an API View inherited from another class
> i want to create a new app that reciver the current Client requests and
> process it then pass it to the original View
> (all i want to do is to recive the view from the user (the user will use
> the original urls without any edit in the clients) then i want to add some
> value to one of the request variables and redirect it to the original
> APIView)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c8b3c72e-6664-4aff-b427-69d2933b3ec5n%40googlegroups.com
> 
> .
>

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


Re: How to set daily update limit for django model(db)?

2021-02-13 Thread Chetan Ganji
Hi Shailesh,

I am assuming you have created_at and updated_at fields (these or similar)
on the model.
You can write a query like below to get the count of no of rows updated
that day using below code.
Remember to update the filters of the queryset as required e.g. user.


from django.utils import timezone

current_date = timezone.now().date()

edited_count = Model.objects.filter(updated_at__date=current_date).count()


Reference :
https://docs.djangoproject.com/en/3.1/ref/models/querysets/#date

I hope it helps you.

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Feb 5, 2021 at 7:12 AM Shailesh Yadav 
wrote:

> Hi Jaimikp,
>
> I have checked it but no luck. Can we make changes in the resource.py file?
> check the count and store that count into a variable and the next day the
> count value should get reset.
> I have checked *before_import *but not able to implement and also don't
> know if implementing this at resource.py level is good or at views.py logic
> code
>
> Please find the below answer.
>
> https://stackoverflow.com/questions/66042509/how-to-check-perform-field-validation-in-resource-py
>
>
> On Monday, January 25, 2021 at 9:23:50 PM UTC+5:30 jaimikp...@gmail.com
> wrote:
>
>> Hi Shailesh,
>>
>> you can define the function with the use of DateTime module, which
>> changes the value of the variable daily for the count.
>>
>> https://stackoverflow.com/questions/52305294/changing-a-variable-based-on-current-time-of-day
>>
>> and for excel, you can get the number of lines in the file, and you can
>> implement a validator as well.
>>
>> https://stackoverflow.com/questions/13377793/is-it-possible-to-get-an-excel-documents-row-count-without-loading-the-entire-d
>>
>>
>> On Saturday, 23 January 2021 at 02:03:51 UTC+5:30 gabriela...@gmail.com
>> wrote:
>>
>>> Hi Sahilesh:
>>> Try with this:
>>>
>>> https://www.kite.com/python/answers/how-to-count-the-number-of-rows-in-a-pandas-dataframe-in-python
>>>
>>> El viernes, 22 de enero de 2021 a las 14:39:35 UTC-3,
>>> shailesh...@gmail.com escribió:
>>>
>>>> Thanks! but Can you elaborate more?
>>>> *howmany = mytable.count()* = Here How it'll work and how to reset the
>>>> value in 1 day. how I can use it in my code.
>>>>
>>>>
>>>> import xlrd   =
>>>>
>>>> I was trying something like this
>>>> def CTA_upload(request):
>>>> i = 1
>>>> count = (1,)
>>>> print('Counter value at starting :', len(count))
>>>> allcta = CTA.objecta.all()
>>>> allcta7 = len(tuple(allcta)) // 2
>>>> print('Tuple Check:', allcta7)
>>>>
>>>> try:
>>>> if request.method == 'POST':
>>>> movie_resource = CTAResource()
>>>> ##we will get data in movie_resources
>>>> dataset = Dataset()
>>>> new_movie = request.FILES['file']
>>>> if not new_movie.name.endswith('xls'):
>>>> messages.info(request, 'Sorry Wrong File Format.Please Upload valid
>>>> format')
>>>> return render(request, 'apple/uploadcts.html')
>>>> messages.info(request, 'Processing...')
>>>>
>>>> imported_data = dataset.load(new_movie.read(), format='xls')
>>>> for data in imported_data:
>>>> value = CTA(
>>>> data[0],
>>>> data[1],
>>>> data[2],
>>>> data[3],
>>>> data[4],
>>>> data[5],
>>>> data[6],
>>>> data[7],
>>>> data[8],
>>>> )
>>>> if len(count) <= allcta7:
>>>> value.save()
>>>> i+= 1
>>>> count = append(i)
>>>> else:
>>>> messages.info(request, 'Sorry You have uploaded more data than
>>>> specified limit...')
>>>> count.clear()
>>>>
>>>> except:
>>>> messages.info(request,'Same Email ID has been observed more than
>>>> once.Except that other records has been added../nPlease Make sure Email
>>>> field should be unique.')
>>>> print("Problem hai kuch to")
>>>>
>>>> return render(request,'app/uploadcts.html')
>>>>
>>>> On Friday, January 22, 2021 at 10:45:54 PM UTC+5:30
>>>> gabriela...@gmail.com wrote:
>>>>
>>>>> Previous, you can use:
>>>>> howmany = mytabl

Re: Immediately Need Help

2021-02-19 Thread Chetan Ganji
Hi Kritika

Ye chanel mein firangi log bhi hai, unko hinglish kaisa samjhenga? 😂

Teko field pe unique constraint lagana padenga

Teko no wapas 1 se start karneke liye query maarana padenga

last_no = Model.objects.filter(categorycode="blah",
citycode="blah-blah").count()

unique_code ="LM" + categorycode
+ citycode + str(last_no + 1)


Aisa code likkha toh result milenga 😋


On Fri, Feb 19, 2021, 3:31 PM Kritika Paul  wrote:

>  I have to create a unique code for each space saved in dbAb db me save
> krne k lie, wo multiple part me save ho rha hai, multiple models bhi hai
> uske.1st model se mujhe space category ka name uthana hai
> 2nd se city code
> Category alag alg ho skti hai
> To code genrate hoga LM-categorycode-citycode-1Next time jb category,
> B hogi to number 1 se hi start hoga, ni to category same hai to fr se 2
> allot ho jaega
> Eg Category - CW, COM
> City - Noida, DelhiSpace 1 - Cw category
> Code space 1- LMCWNoida1Space2 - CW Category
> CODE SPACE2 - LMCWDelhi2Space 3 - COM category
> CODE SPACE 3- LM-COM-NOIDA0001
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/690debd2-46e0-497f-92a8-3abbc391b97dn%40googlegroups.com
> 
> .
>

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


Re: Immediately Need Help

2021-02-19 Thread Chetan Ganji
Yes kritika show all the models.

How shubham?
If an entry is deleted, unique code will also be deleted. Next time it gets
generated, it might be assigned to different entry, but it still be unique.

As kritika clarified already, so it wont be a problem.

On Fri, Feb 19, 2021, 3:58 PM shubham vashisht  wrote:

> Chetan
> If any row is deleted from the table, then your logic will fail to return
> the unique code
>
> On Fri, 19 Feb 2021, 15:52 Chetan Ganji,  wrote:
>
>> Hi Kritika
>>
>> Ye chanel mein firangi log bhi hai, unko hinglish kaisa samjhenga? 😂
>>
>> Teko field pe unique constraint lagana padenga
>>
>> Teko no wapas 1 se start karneke liye query maarana padenga
>>
>> last_no = Model.objects.filter(categorycode="blah",
>> citycode="blah-blah").count()
>>
>> unique_code ="LM" + categorycode
>> + citycode + str(last_no + 1)
>>
>>
>> Aisa code likkha toh result milenga 😋
>>
>>
>> On Fri, Feb 19, 2021, 3:31 PM Kritika Paul 
>> wrote:
>>
>>>  I have to create a unique code for each space saved in dbAb db me save
>>> krne k lie, wo multiple part me save ho rha hai, multiple models bhi hai
>>> uske.1st model se mujhe space category ka name uthana hai
>>> 2nd se city code
>>> Category alag alg ho skti hai
>>> To code genrate hoga LM-categorycode-citycode-1Next time jb
>>> category, B hogi to number 1 se hi start hoga, ni to category same hai to
>>> fr se 2 allot ho jaega
>>> Eg Category - CW, COM
>>> City - Noida, DelhiSpace 1 - Cw category
>>> Code space 1- LMCWNoida1Space2 - CW Category
>>> CODE SPACE2 - LMCWDelhi2Space 3 - COM category
>>> CODE SPACE 3- LM-COM-NOIDA0001
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/690debd2-46e0-497f-92a8-3abbc391b97dn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/690debd2-46e0-497f-92a8-3abbc391b97dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMKMUjs6q%2B6Xer6-MRu%3DYjhKq5EYNXahEji%2BY5HBerTaNQ1Law%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMKMUjs6q%2B6Xer6-MRu%3DYjhKq5EYNXahEji%2BY5HBerTaNQ1Law%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJW_r64v1-f85ViX%2BnCFdBrupiXi5Ba%3Dzec6xoSvuZnR1jaMEg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJW_r64v1-f85ViX%2BnCFdBrupiXi5Ba%3Dzec6xoSvuZnR1jaMEg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Immediately Need Help

2021-02-19 Thread Chetan Ganji
Show the model where you save Space_code

On Fri, Feb 19, 2021, 4:19 PM Kritika Paul  wrote:

> class SpaceCategory(BaseModel):
> __tablename__ = "space_categories"
>
> name = db.Column(db.String(255))
> description = db.Column(db.Text)
> image_url = db.Column(db.Text)
> code = db.Column(db.String(100))
> space_sub_category = db.relationship('SpaceSubCategory', backref
> =db.backref("space_category", uselist=False))
>
> class Cities(BaseModel):
> __tablename__ = "cities"
> name = db.Column(db.String(255))
> code = db.Column(db.String(100))
> is_deleted = db.Column(db.Boolean,default=False)
> These are the models,
> There is one other model where I have to save Space_code
>
> Now, Space Category is CW,COM,MS
> City Code is NOIDA, DELHI,KOlkata
>
> Space code to be generated such that Numbers should increase Space
> Category Wise
>
>
> On Fri, 19 Feb 2021 at 16:07, Chetan Ganji  wrote:
>
>> Yes kritika show all the models.
>>
>> How shubham?
>> If an entry is deleted, unique code will also be deleted. Next time it
>> gets generated, it might be assigned to different entry, but it still be
>> unique.
>>
>> As kritika clarified already, so it wont be a problem.
>>
>> On Fri, Feb 19, 2021, 3:58 PM shubham vashisht 
>> wrote:
>>
>>> Chetan
>>> If any row is deleted from the table, then your logic will fail to
>>> return the unique code
>>>
>>> On Fri, 19 Feb 2021, 15:52 Chetan Ganji,  wrote:
>>>
>>>> Hi Kritika
>>>>
>>>> Ye chanel mein firangi log bhi hai, unko hinglish kaisa samjhenga? 😂
>>>>
>>>> Teko field pe unique constraint lagana padenga
>>>>
>>>> Teko no wapas 1 se start karneke liye query maarana padenga
>>>>
>>>> last_no = Model.objects.filter(categorycode="blah",
>>>> citycode="blah-blah").count()
>>>>
>>>> unique_code ="LM" + categorycode
>>>> + citycode + str(last_no + 1)
>>>>
>>>>
>>>> Aisa code likkha toh result milenga 😋
>>>>
>>>>
>>>> On Fri, Feb 19, 2021, 3:31 PM Kritika Paul 
>>>> wrote:
>>>>
>>>>>  I have to create a unique code for each space saved in dbAb db me
>>>>> save krne k lie, wo multiple part me save ho rha hai, multiple models bhi
>>>>> hai uske.1st model se mujhe space category ka name uthana hai
>>>>> 2nd se city code
>>>>> Category alag alg ho skti hai
>>>>> To code genrate hoga LM-categorycode-citycode-1Next time jb
>>>>> category, B hogi to number 1 se hi start hoga, ni to category same hai to
>>>>> fr se 2 allot ho jaega
>>>>> Eg Category - CW, COM
>>>>> City - Noida, DelhiSpace 1 - Cw category
>>>>> Code space 1- LMCWNoida1Space2 - CW Category
>>>>> CODE SPACE2 - LMCWDelhi2Space 3 - COM category
>>>>> CODE SPACE 3- LM-COM-NOIDA0001
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/690debd2-46e0-497f-92a8-3abbc391b97dn%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/690debd2-46e0-497f-92a8-3abbc391b97dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAMKMUjs6q%2B6Xer6-MRu%3DYjhKq5EYNXahEji%2BY5HBerTaNQ1Law%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAMKMUjs6q%2B6Xer6-MRu%3DYjhKq5EYNXahEji%2BY5HBerTaNQ1Law%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
&

Re: Immediately Need Help

2021-02-20 Thread Chetan Ganji
 Shubham is right. However, as no row will be deleted.
Also, the code created once will never be assigned to any other space.
It wont matter!

Formula : LM-categorycode-citycode-current_index
e.g. "LM-CW-DELHI-1"
# Remove dashses from the string, they are added only to make it easier to
understand

String after the citycode is called as current_index and it has to be of a
standard length
e.g. 9. We will call this length as Z_FILL_INDEX. You can modify this
Z_FILL_INDEX as required.
Hence, Z_FILL_INDEX = 9. In above example, current_index = "1"

As no row will be deleted, also, the code created once will never be
assigned to any other space
Hence, current_index will be 1 or plus 1 of the latest one
Below code is for django ORM, IDK sqlalchemy version of it :P
I dont see how Space is related to a City, you can figure that part
yourself.
if current_index > 9, code will break. 10 Cr is a big no.
However, if current_index could be bigger than that, pick a bigger no for
Z_FILL_INDEX.

In case you run out of index in the future, you can write a script to add
few extra zeros
to current index part of the code or add pick a bigger no for Z_FILL_INDEX
initially e.g. 12.

MUST DO : ADD UNIQUE CONSTRAINT ON THE name FIELD OF THE Spaces Model.
Z_FILL_INDEX = 9

last_code = Spaces.objects.filter(space_category="blah").order_by(
"-created_at").first()
if last_code is None:
current_index = "1".zfill(Z_FILL_INDEX)
else:
current_index = str(int(last_code[-Z_FILL_INDEX:]) + 1)

unique_code ="LM" + categorycode + citycode + current_index




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Feb 19, 2021 at 6:16 PM shubham vashisht 
wrote:

> If there are 4 rows which have categorycode="blah" and
> citycode="blah-blah", then the space code will be something like this,
> LMblahblah-blah1, LMblahblah-blah2, LMblahblah-blah3, LMblahblah-blah4.
> But if you delete row with spacecode different from LMblahblah-blah4, then
> your code will generate space code LMblahblah-blah4
>
> On Fri, 19 Feb 2021, 16:07 Chetan Ganji,  wrote:
>
>> Yes kritika show all the models.
>>
>> How shubham?
>> If an entry is deleted, unique code will also be deleted. Next time it
>> gets generated, it might be assigned to different entry, but it still be
>> unique.
>>
>> As kritika clarified already, so it wont be a problem.
>>
>> On Fri, Feb 19, 2021, 3:58 PM shubham vashisht 
>> wrote:
>>
>>> Chetan
>>> If any row is deleted from the table, then your logic will fail to
>>> return the unique code
>>>
>>> On Fri, 19 Feb 2021, 15:52 Chetan Ganji,  wrote:
>>>
>>>> Hi Kritika
>>>>
>>>> Ye chanel mein firangi log bhi hai, unko hinglish kaisa samjhenga? 😂
>>>>
>>>> Teko field pe unique constraint lagana padenga
>>>>
>>>> Teko no wapas 1 se start karneke liye query maarana padenga
>>>>
>>>> last_no = Model.objects.filter(categorycode="blah",
>>>> citycode="blah-blah").count()
>>>>
>>>> unique_code ="LM" + categorycode
>>>> + citycode + str(last_no + 1)
>>>>
>>>>
>>>> Aisa code likkha toh result milenga 😋
>>>>
>>>>
>>>> On Fri, Feb 19, 2021, 3:31 PM Kritika Paul 
>>>> wrote:
>>>>
>>>>>  I have to create a unique code for each space saved in dbAb db me
>>>>> save krne k lie, wo multiple part me save ho rha hai, multiple models bhi
>>>>> hai uske.1st model se mujhe space category ka name uthana hai
>>>>> 2nd se city code
>>>>> Category alag alg ho skti hai
>>>>> To code genrate hoga LM-categorycode-citycode-1Next time jb
>>>>> category, B hogi to number 1 se hi start hoga, ni to category same hai to
>>>>> fr se 2 allot ho jaega
>>>>> Eg Category - CW, COM
>>>>> City - Noida, DelhiSpace 1 - Cw category
>>>>> Code space 1- LMCWNoida1Space2 - CW Category
>>>>> CODE SPACE2 - LMCWDelhi2Space 3 - COM category
>>>>> CODE SPACE 3- LM-COM-NOIDA0001
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://gr

Re: Why does my django form with recaptcha send data even empty the recaptcha?

2021-03-12 Thread Chetan Ganji
Remove below line and try again

self.fields['captcha'].widget.attrs['required'] = 'True'


If the problem persists, try some js or jquery validation in frontend





On Thu, Mar 11, 2021, 9:19 PM Gabriel Araya Garcia <
gabrielaraya2...@gmail.com> wrote:

> Camarada Sokov:
> Your code is very difficult to understand at first sight. I did not know
> about ReCaptchaField().
> But, is interesting to learn something new.
>
> Recards,
>
> Gabriel Araya Garcia
> GMI - Desarrollo de Sistemas Informáticos
> from Santiago de Chile
>
>
>
> El jue, 11 mar 2021 a las 12:40, Sergei Sokov ()
> escribió:
>
>> I put the google recaptcha V2 to my django project form. It looks like
>> working, but if I leave empty the recaptcha checkbox my form is sent still.
>>
>> forms.py
>> from django import
>> forms from captcha.fields
>> import ReCaptchaField
>> from django.forms import Textarea
>> from .models import *
>> class CustomerForm(forms.ModelForm):
>> captcha = ReCaptchaField( public_key='key', private_key='key', )
>> class Meta:
>> model = Customer fields = '__all__'
>> def __init__(self, *args, **kwargs):
>> # get 'user' param from kwargs
>> user = kwargs.pop('user', None)
>> super().__init__(*args, **kwargs)
>> self.fields['message'].widget = Textarea(attrs={'rows': 4})
>> self.fields['i_have_read_rules'].widget.attrs['required'] = 'True'
>> self.fields['i_agree'].widget.attrs['required'] = 'True'
>> self.fields['captcha'].widget.attrs['required'] = 'True'
>> for field in self.fields:
>> self.fields[field].widget.attrs['class'] = 'form-control'
>> self.fields['i_have_read_rules'].widget.attrs['class'] =
>> 'form-check'
>> self.fields['i_agree'].widget.attrs['class'] = 'form-check'
>>
>> html
>> 
>> {% csrf_token %}
>> Выберите услугу
>> {{form.choice_services}}
>> {{form.name}}
>> > class="form-group">{{form.telephone_number}}
>> {{form.email}}
>> {{form.message}}
>> {{form.contact_text}}
>>  {{
>> form.captcha }}
>> 
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/e18dcba2-07e2-44d9-ace6-744a2bb69234n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKVvSDD_HZmL%2BUVgsFVZgQCuyuhCs3Ofe2DkOtne-ydp%2B3joyw%40mail.gmail.com
> 
> .
>

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


Re: I cant figure out this error

2021-03-13 Thread Chetan Ganji
Good Read!
Thanks Kasper 😊

On Sat, Mar 13, 2021, 5:58 AM Kasper Laudrup  wrote:

>
> https://betterprogramming.pub/how-to-ask-questions-about-programming-dcd948fcd2bd
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/51f7f7a8-dfa3-0024-3c45-0f4c64f2ee08%40stacktrace.dk
> .
>

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


Re: deployment UI

2021-03-15 Thread Chetan Ganji
Checkout PythonAnywhere if it helps you or not

On Mon, Mar 15, 2021, 8:15 PM waverider  wrote:

> Hi,
>
> Is there some web interface (SaaS or on premises) for initial server setup
> and Django apps deployment?
>
> Are you happily using it?
>
> There are a few SaaS tools for PHP apps, but I haven't seen one for Django.
>
>
> Thanks
>
> PS: I'm not asking about CLI tools like configuration management software,
> just about turn key web interface solutions.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0a9474ab-b5cf-4408-94e0-355355e2e976n%40googlegroups.com
> 
> .
>

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


Re: Admin layout getting too bulky - what to do?

2021-05-03 Thread Chetan Ganji
I am not sure how useful this will be. You can check it out.
https://django-mptt.readthedocs.io/en/latest/index.html


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, May 3, 2021 at 8:13 PM Mike Dewhirst  wrote:

> Derek
>
> My phone doesn't do interspersed responses well, so my apologies for top
> posting.
>
> The record to which I refer is any one of those in any list page.
>
> After clicking one, if that record has any 1:1, 1:n or n:m related
> records, their *verbose_name_plural* names will be displayed as dumb
> headings with related records appearing below with show/hide links as well
> as an 'Add another ...' link.
>
> I'd like to see the sidebar display links to those (currently) dumb
> headings and fetch them to the top.
>
> Hope that clarifies what I meant despite what I said :-)
>
> I'll  have a look at Django suit in the morning. Thanks for the heads up.
>
> Cheers
>
> Mike
>
>
>
> --
> (Unsigned mail from my phone)
>
>
>
>  Original message 
> From: Derek 
> Date: 3/5/21 19:42 (GMT+10:00)
> To: Django users 
> Subject: Re: Admin layout getting too bulky - what to do?
>
> Re "So my need is for a fixed vertical sidebar with the same links which
> take you to the same list pages."
>
> This is what I use Django Suit for -  it can be located at the top or side
> and remains in place across all admin pages.  You can add your own items to
> the menu (and these can point to non-admin pages - for example, I point to
> a page of report URLs which is a non-standard admin page) ; I have never
> added menu items "on the fly" so am not sure this is possible.
>
> I cannot understand your requirement statement "When that page opens for
> the record, the sidebar of links should change to the named headings on
> that page. When a heading is clicked the page should relocate itself so
> that heading is at the top"  at all, sorry. Maybe a follow-up post with a
> picture (== 1000 words)?
>
> Derek
>
>
> On Monday, 3 May 2021 at 08:57:25 UTC+2 Mike Dewhirst wrote:
>
>> OK - I've now looked at some Django Admin templating systems and they
>> all seem to solve a different problem than the one I need to ... which
>> is ...
>>
>> Consider the Admin main menu seen at the /admin url after login. If you
>> click any of the links they take you to a single page with a list of
>> records. So my need is for a fixed vertical sidebar with the same links
>> which take you to the same list pages. The vertical sidebar should
>> remain unchanged and unmoved on the list page in case the user clicked
>> the wrong link.
>>
>> The next step is to select a record from the list. When that page opens
>> for the record, the sidebar of links should change to the named headings
>> on that page. When a heading is clicked the page should relocate itself
>> so that heading is at the top. The sidebar of links should remain
>> unchanged and unmoved in case the user wishes to relocate to a different
>> heading. Much like the Django documentation except the sidebar should
>> stay where it was when clicked!
>>
>> At the moment, those headings don't have urls within the page. And the
>> (Show/Hide) urls are all just a lone hash '#'.
>>
>> Therefore my problem is to understand how to include heading name
>> anchors and construct a list of urls (including 'top' and bottom') for
>> such a sidebar. And of course to understand how to make such a sidebar
>> in the first place.
>>
>> Where might I begin my research?
>>
>> Thanks
>>
>> Mike
>>
>>
>> On 2/05/2021 5:26 pm, Mike Dewhirst wrote:
>> > My project has a central table with many 1:n and n:m sub-tables. I
>> > mean lots of them. It takes forever to keep scrolling up and down the
>> > page to find the section of interest and then maybe scroll through
>> > some records in that section before clicking (SHOW) to reveal data.
>> >
>> > Is there a way I can do a sidebar of links which take the user to
>> > specific sections?
>> >
>> > I have had a look at the contrib layout and it doesn't appear obvious
>> > what to do. Especially since they don't pay me enough to play with js
>> ;-)
>> >
>> > Has this been solved before?
>> >
>> > Thanks for any hints
>> >
>> > Cheers
>> >
>> > Mike
>> >
>>
>>
>> --
>> Signed email is an absolute defence against phishing. This email has
&

Re: Custom User

2021-05-06 Thread Chetan Ganji
https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#django.contrib.auth.hashers.make_password

On Thu, May 6, 2021, 6:46 PM Owen Murithi 
wrote:

> How do I make password for AbstractUser Hashed?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/741b9434-d473-4d15-b343-50b3e37d50d7n%40googlegroups.com
> 
> .
>

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


Re: Newbee help on deploying Django App to Apache2

2021-05-30 Thread Chetan Ganji
I think, you are using the default python version installed on the machine,
not the one of the virtualenv.
You will have to configure the mod_wsgi to use the python of the virtuelanv.

This might help you.
https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html#


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Sun, May 30, 2021 at 4:46 PM Moose Smith <47kanga...@gmail.com> wrote:

> App written in ubuntu virtual environment python 3.8.5. Works well on
> Visual Studio Code development server. Am trying to make it run on Apache2
> development server.  I have been able to install WSGI module on Apache
> Server and ran a test Hello World in Python and it worked. However, the
> django app when ported over does not work.
> The error log confirms that the mod_wsgi has been created using by Python
> 3.8
> [mpm_event:notice] [pid 607786:tid 140700034231360] AH00489: Apache/2.4.41
> (Ubuntu) mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
> The error I am getting indicates that the Apache / WSGI is reading the
> files in the virtual environment I copied over.
>
> mod_wsgi (pid=609049): Exception occurred processing WSGI script '/ File
> "/usr/public/apache/MCE/learn/djpro/wsgi.py", line 12, in 
> from django.core.wsgi import get_wsgi_application
> ModuleNotFoundError: No module named 'django'
>
> My research indicates that this error occurs when the mod--wsgi in being
> interpreted by a different version than what was used to create my virtual
> environment. It also might be permissions/ownership issues with the file
> and directories copied over to the server, or improperly configured module.
>
> My question is this: Does the mod_WSGI module have to be the same as the
> one that created my virtual environment?  My understanding is that WSGI has
> two components, the server side, and the application side. It would not
> make sense that the Server side MUST match the application side because it
> would not be possible to service various apps with different versions of
> Python/Django. I assumed the server side was python version independent and
> that the requirement for Python similarity was only on the application side
> in that the Python used to create the virtual environment and my app must
> match the version used to create the WSGI interface on the application side
> (this side not the server). That said, I have discovered there is a Python
> 2.7 version of the mod_WSGI for the server side which differs from the 3.7
> version.
>
> Can someone clear up the Python version requirement and if it does require
> a match between the server and the app side, how will I be able to run
> future versions of Python/Django apps without having to go back and
> "recomplie"?
>
> Also if someone has any clues on solving my error that would be very much
> appreciated.
>
> Thanks
> Moose
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d3041741-1604-473f-8810-263bb3b16c59n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d3041741-1604-473f-8810-263bb3b16c59n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Customizable model field (such as SRID for geometries) and migrations

2021-06-05 Thread Chetan Ganji
I dont understand your requirements :P

But this will certainly help.
https://docs.djangoproject.com/en/3.2/ref/contrib/gis/tutorial/#geodjango-tutorial
https://docs.djangoproject.com/en/3.2/ref/contrib/gis/model-api/

IN the below link, it says about setting the SRID field :P
https://docs.djangoproject.com/en/3.2/ref/contrib/gis/tutorial/#geographic-data

Note that the models module is imported from django.contrib.gis.db.
The default spatial reference system for geometry fields is WGS84 (meaning
the SRID <https://en.wikipedia.org/wiki/SRID> is 4326) – in other words,
the field coordinates are in longitude, latitude pairs in units of degrees.
To use a different coordinate system, set the SRID of the geometry field
with the srid argument. Use an integer representing the coordinate system’s
EPSG code.


I hope this helps you !!!



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 2, 2021 at 12:26 PM Olivier Dalang 
wrote:

> Dear List,
>
> I'm working on a Django app whose models have geometry fields and that
> will be deployed in several geographic locations.
>
> Using a globally available reference system (WGS84) and reprojecting on
> the fly will not work due to performance and accuracy implications for
> geometric queries. Thus I'd like to make the SRID customizable.
>
> The issue comes with migrations which hard-code the SRID in the
> CreateModel statements. I could import an SRID from a variable in
> settings.py, but don't like that idea, as changing it after creating would
> mess things up (srid mismatch, creating new migrations...). It's actually
> not really a django setting, but more related to the data.
>
> One idea would be to store the default SRID in the DB itself (in a
> dedicated settings model) and retrieve the SRID dynamically from that
> before running the migrations and loading the models. There could even be
> some logic to reproject/adapt all geometries fields if the value changes.
> Sounds nice, but also complicated (models are not available .
>
> I'm probably not the first one with this type of requirement (could also
> happen for other use cases such as language, currencies, etc.). Is there a
> package I could use or some design pattern I could follow ?
>
> Thanks !!
>
> Olivier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAExk7p1s%2B4XozdQOxjZKMbXmG7xq6hhMSiVTsrSyj26VBG%3DFJw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAExk7p1s%2B4XozdQOxjZKMbXmG7xq6hhMSiVTsrSyj26VBG%3DFJw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Absurdly long queries with Postgres 11 during unit tests

2021-06-09 Thread Chetan Ganji
This might help shed more light on the problem.

   1. https://pypi.org/project/pytest-django-queries/
   2. Try cProfile
   https://www.geeksforgeeks.org/profiling-in-python/



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, Jun 8, 2021 at 1:33 AM Rich Rauenzahn  wrote:

> This is heads up in case anyone sees something similar:
>
> I have managed to trigger this degenerate query case in two completely
> different Django 2.2 projects.   In production with a normal sized dataset,
> the query time is fine.  But during unit testing with a small subset of the
> data, the queries took a long time.  A LONG time.
>
> In the most recent case each query took 100x longer.  200+ seconds instead
> of 2 seconds.  The unit test dataset isn't very large because it's a unit
> test.
>
> I think I may have first seen this when I upgraded the project to postgres
> 11.
>
> Manually vacuuming between tests resolves the issue.  (Yes, autovacuum is
> on by default -- and isn't the db created from scratch for each 'manage
> test' invocation?)
>
> This is how I did it:
>
> def _vacuum():
> # Some unit test queries seem to take a much longer time.
> # Let's try vacuuming.
> # https://stackoverflow.com/a/13955271/2077386
> with connection.cursor() as cursor:
> logger.info("Vacuum: begin")
> cursor.execute("VACUUM ANALYZE")
> logger.info("Vacuum: complete")
>
> class VacuumMixin:
> @classmethod
> def setUpClass(cls):
> _vacuum()
> return super().setUpClass()
>
> @classmethod
> def tearDownClass(cls):
> ret = super().tearDownClass()
> _vacuum()
> return ret
>
> If anyone else sees this, please let me know.  Maybe we can further RCA it.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e76b105e-ed53-4031-869c-830f94677ef4n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e76b105e-ed53-4031-869c-830f94677ef4n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: django cron Job Functionality

2021-06-11 Thread Chetan Ganji
This will help you

https://pypi.org/project/django-celery-beat/


On Fri, Jun 11, 2021, 5:34 PM Eugene TUYIZERE 
wrote:

> Dear Team,
>
> In my application, I want a user to set for example a leave plan in the
> system and the system notify the user by email for example one day before
> the start leave date. At the same time the system disables the user in the
> system. Here I have a field *is_active *and I want the system to set it
> to False from the leave date to the end date. And also to set Ongoing
> status on the leave plan user list. I heard somewhere that Django Cron Job
> can do this but I never use it and I do not know how to use it in the
> application.
> If someone has used  it for some time please I need help.
>
> Thank you
>
> --
> *Eugene*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHt2hqPgNU%2BvyDb8Eua%2B6_OMM8H6xsMzTgJ-73-0erfmKw%40mail.gmail.com
> 
> .
>

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


Re: Best way to optimize API requests calls from over 10,000 users simultaneously

2021-06-21 Thread Chetan Ganji
What is the problem you are trying to solve?
What do you want to optimize exactly? 🤔

I hope this helps you -
https://betterprogramming.pub/how-to-ask-questions-about-programming-dcd948fcd2bd


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, Jun 21, 2021 at 6:19 PM Sunday Iyanu Ajayi 
wrote:

> Dear Team,
>
> Please I need help on how to optimize API requests calls for over 10,000
> users simultaneously without any issues and my system spec is 8vCPUs, 16GB
> RAM.
>
> Regards
>
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunnexaj...@gmail.com *
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKYSAw2UTC6zvJoTWO%2BFQFqs9JQYaFbybC8ymp8kdt4cfwn3Nw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAKYSAw2UTC6zvJoTWO%2BFQFqs9JQYaFbybC8ymp8kdt4cfwn3Nw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: DRF | Django | Up votes | Down Votes

2021-06-25 Thread Chetan Ganji
You should have a field on Votes Model diff_vote as integerfield, which
will be updated when a user upvote or downvote.

WHY??
Calculating this value on list view will result in higher latency.
So we can dump that calculation on creating on updating.

What do you mean by calculate the up votes and down votes at the same time?


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Jun 25, 2021 at 12:39 PM DJANGO DEVELOPER 
wrote:

> Oba Thank you so much. and let me try it.
> and one more thing that I want to ask that how can I calculate the up
> votes and down votes at the same time? as Facebook likes and dislikes do.
> can you guide me in this regard?
>
> On Fri, Jun 25, 2021 at 11:15 AM oba stephen 
> wrote:
>
>> Hi,
>>
>> One way would be to create an extra field to track the difference in both
>> fields and then in your meta information on that model set the ordering to
>> that field.
>>
>> Another approach which is better is to do something like this.
>>
>> Votes.objects.extra(select={'diff': 'upvote - downvote'}).order_by('diff')
>>
>>
>> Best regards
>>
>> Stephen Oba
>>
>> On Fri, Jun 25, 2021, 6:03 AM DJANGO DEVELOPER 
>> wrote:
>>
>>> Is there anyone who can help me here?
>>>
>>> On Thu, Jun 24, 2021 at 7:15 PM DJANGO DEVELOPER <
>>> abubakarbr...@gmail.com> wrote:
>>>
>>>> Hi Django experts.
>>>> I am building a Django, DRF based mobile app and I want to have
>>>> functionality of up votes and down votes for posts that user will post.
>>>> So what I want to say here that, if an user upvotes a post then it
>>>> should be get higher ranks as quora questions do. and if there are more
>>>> down votes than up votes then a post should be moved down ward rather than
>>>> going up.
>>>> I have applied a logic already here and shared the screenshots as well.
>>>> but I am sure that there is a better logic or solution for this problem.
>>>> Thanks in advance.
>>>> Mr Mike and Mr Lalit can you guide me here please?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/c72fefe7-58d2-4c43-84b8-0faa3d9747b0n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/c72fefe7-58d2-4c43-84b8-0faa3d9747b0n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAKPY9pkAYcmio_U%2BAUPMcxzxbdT8QM1QPfPDftMgrj2NQvsJRQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAKPY9pkAYcmio_U%2BAUPMcxzxbdT8QM1QPfPDftMgrj2NQvsJRQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAAJsLnras7ETsnRc5yj2F-S%3DMo5xfEMWDbVXPOvm08oQDxoFAg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAAJsLnras7ETsnRc5yj2F-S%3DMo5xfEMWDbVXPOvm08oQDxoFAg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKPY9pkYmP2xvW8FYRxBH8a55kURefFwrJGE59O-g%2Be8ktF%2B0g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAKPY9pkYmP2xvW8FYRxBH8a55kURefFwrJGE59O-g%2Be8ktF%2B0g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: How can i start to learn django?

2021-06-26 Thread Chetan Ganji
https://youtube.com/c/CodingEntrepreneurs


On Wed, Jun 16, 2021, 2:23 AM Sebastian Jung 
wrote:

> At beginnig Django Girls Tutorial ist a good start in my opinon
> https://tutorial.djangogirls.org/en/
>
> anil9...@gmail.com  schrieb am Di., 15. Juni 2021,
> 14:27:
>
>> You can try freecodecamp.org's youtube channel if you like to learn from
>> videos else Django docs are also great.
>>
>> On Sunday, 13 June, 2021 at 7:52:22 pm UTC+5:30 desai...@gmail.com wrote:
>>
>>> I am begginer in python. how can i start to learn django from begginners
>>> to adance. please help me.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/853d870f-5e57-419d-b3b1-e49738d2746cn%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKGT9mxtPhHc%3Dqq3e7ggH1ZymnKxqOfmJkykxfO%2BN%3D97aJw66w%40mail.gmail.com
> 
> .
>

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


Re: Best way to optimize API requests calls from over 10,000 users simultaneously

2021-06-26 Thread Chetan Ganji
This will help you brother. It is FREE 😉

https://www.scaler.com/event/learn-how-youtube-serves-billions-of-users-in-a-free-masterclass


On Mon, Jun 21, 2021, 8:49 PM Alejandro Garrido Gongora <
nolodelato...@gmail.com> wrote:

> For big problems the answer is in 99% of cases split the problem, maybe
> your problem is your architecture, also you will need cache, also Async,
> maybe you need to en queue  some routines maybe you need more hardware,
> maybe you need to optimize your data structures, maybe the join of all
> those solutions is what you need.
>
> Regards.
>
> Obtener Outlook para iOS 
> --
> *De:* django-users@googlegroups.com  en
> nombre de carlos 
> *Enviado:* Monday, June 21, 2021 4:57:02 PM
> *Para:* django-users@googlegroups.com 
> *Asunto:* Re: Best way to optimize API requests calls from over 10,000
> users simultaneously
>
> maybe try used cache when call many users
> https://www.django-rest-framework.org/api-guide/caching/
>
> Cheers
>
> On Mon, Jun 21, 2021 at 8:18 AM Kasper Laudrup 
> wrote:
>
> On 21/06/2021 15.55, Sunday Iyanu Ajayi wrote:
> > I want to be able to manage API calls from over 1 users without
> > getting network timeout errors
>
> Are you having issues doing so now?
>
> What have you done to try and profile your code for bottlenecks?
>
> What kind of help are you looking? Paid consultancy?
>
> Etc.
>
> You cannot really expect anyone to be able to help you if you don't take
> some time trying to formulate a real question.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7a436427-1069-d173-3e32-0339be9328dc%40stacktrace.dk
> .
>
>
>
> --
> att.
> Carlos Rocha
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAM-7rO33XnZDcXrjQJS%2Bbawy7%3D_HTAMfxfa2MT8ruyDXkE8h%2Bw%40mail.gmail.com
> 
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/VI1PR0402MB3342DC9605EF444EA2B6CF35F60A9%40VI1PR0402MB3342.eurprd04.prod.outlook.com
> 
> .
>

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


Free Webinar

2021-06-26 Thread Chetan Ganji
Dear members,

FYI

https://www.scaler.com/event/learn-how-youtube-serves-billions-of-users-in-a-free-masterclass

Thanks!

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


Re: Django tutor/coach wanted

2020-02-14 Thread Chetan Ganji
Not sure about one on one. Will certainly help.
https://www.youtube.com/user/CodingEntrepreneurs

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Sat, Feb 15, 2020 at 12:32 AM davidrpando2 
wrote:

> Hello,
>
> My name is David Pando. I am new to Django/Python and also looking for a
> tutor/teacher (BTW - Have you seen Corey Shaffer? Execllent Youtube
> tutorial series, but not available for 1-1- teaching).
>
> Have you found anyone available to do this type of instruction?
>
> Thank you,
> David
> dpan...@bellsouth.net
>
>
> On Friday, February 5, 2016 at 9:37:45 PM UTC-5, Django Learner wrote:
>
>> I'm a very experienced developer, but not experienced with Python/Django.
>> I have a site that I'd like to build using these tools, and am hoping to
>> find someone to help make climbing the learning curve an efficient process.
>> I'm in Boston, but remote is OK. Willing to pay well for comensurate
>> expertise. Contact me at melear...@gmail.com. Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/900c1cb9-6706-469c-a4a3-4df57541b6c1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/900c1cb9-6706-469c-a4a3-4df57541b6c1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: reg: User model data missing from web page

2020-05-05 Thread Chetan Ganji
Hi Amitesh,

If you post the models, then only someone will be able to give you exact
solution.

Couple of things I noticed.
How is this even working??
You have not defined User variable in the function??
If its the default User model, how would passing it to UserProfile will
help in your scenario??
pr = UserProfile(User)

You dont need this line as it is already available as request.user.  Why do
you want to fetch it again, when it is already available???
*pr.user = User.objects.get(id=request.user.id <http://request.user.id/>)*
data2 = get_object_or_404(User, user=request.user)

In the *profile_page *view, you can use reverse relation on the user model.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, May 5, 2020 at 9:02 PM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> I have a profile page where I am fetching data from two models. One from
> the default User model and another one is custom UserProfile.
>
> However, The data from the custom model is getting populated, but not the
> User model.
> Below are the two functions responsible for the whole procedure.
>
> *def userprofileview(request):  # Authenticated user filling the form to
> complete the registration*
> *if request.method == 'POST':*
> *form = UserProfileForm(request.POST, request.FILES)*
> *if form.is_valid():*
> *pr = UserProfile(User)*
>
> *pr.user = User.objects.get(id=request.user.id
> <http://request.user.id>)*
> *pr.first_name = form.cleaned_data['first_name']*
> *pr.last_name = form.cleaned_data['last_name']*
> *pr.email = form.cleaned_data['email']*
>
> *pr.dob = form.cleaned_data['dob']*
> *pr.country = form.cleaned_data['country']*
> *pr.State = form.cleaned_data['State']*
> *pr.District = form.cleaned_data['District']*
> *pr.phone = form.cleaned_data['phone']*
> *pr.save()*
>
> *messages.success(request, f'Profile has been updated
> successfully')*
> *return redirect('/profile')*
> *else:*
> *messages.error(request, AssertionError)*
> *else:*
> *form = UserProfileForm()*
> *return render(request, 'authenticate\\bolo.html', context={'form':
> form})*
>
>
> *@login_required*
> *def profile_page(request):  # Fetching data from DB to show user's
> complete profile page*
> *data = get_object_or_404(UserProfile, user=request.user)*
> *data2 = get_object_or_404(User, user=request.user)*
> *context = {'data': data, 'data2': data2}*
> *return render(request, 'authenticate\\profile.html', locals())*
>
> To test it further, I realized that the three fields (email, first_name,
> and last_name) is coming from the "user". So, in the *"userprofileview" *I
> added* "user" *for those fields in the below format.
>
> pr.user.first_name = form.cleaned_data['first_name']
> pr.user.last_name = form.cleaned_data['last_name']
> pr.user.email = form.cleaned_data['email']
>
> However, I started to get below error
>
> -
> Internal Server Error: /fetch_data/ * # HTML Template*
> Traceback (most recent call last):
>   File "C:\Python38\lib\site-packages\django\core\handlers\exception.py",
> line 34, in inner
> response = get_response(request)
>   File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line
> 115, in _get_response
> response = self.process_exception_by_middleware(e, request)
>   File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line
> 113, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File "C:\Users\anshu\djago-project\AUTHENTICATION\views.py", line 65, in
> userprofileview
>
> *pr.user.first_name = form.cleaned_data['first_name']KeyError:
> 'first_name'*
> *--*
>
> It would be very kind of anybody who can help me rectify the issue. I have
> been struggling for 4 days minimum now.
>
> Amitesh
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this dis

Re: Dynamic Radio Form

2020-05-05 Thread Chetan Ganji
To answer your question, you could add an extra field on schedule model to
store the winner
e.g. winner = models.CharField(max_length=55)

IMO, league and team in the schedule model should be separate tables. You
would use fk to them in schedule model.
winner should also be an fk to team.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, May 5, 2020 at 3:54 AM J.T.  wrote:

> I'm working on an app that will allow the user to select the winner
> between two teams (radio buttons) and I need the info saved to the
> database. I'm having trouble with the radio forms part. I've read the
> documentation and searched Google all day, but I can't seem to wrap my
> heads around it.
>
> Here are my models:
>
> class Schedule(models.Model):
> LEAGUE_CHOICES = (('HS','HS'), ('NFL', 'NFL'), ('NCAA','NCAA'))
> week = models.IntegerField()
> game_id = models.IntegerField(unique=True)
> away_team = models.CharField(max_length=55)
> home_team = models.CharField(max_length=55)
> away_id = models.IntegerField(unique=True)
> home_id = models.IntegerField(unique=True)
> league = models.CharField(max_length=15, choices=LEAGUE_CHOICES)
> def __str__(self):
> return f'Week {self.week} {self.away_team} vs {self.home_team}'
>
> class Selection(models.Model):
> username = models.ForeignKey(User, on_delete=models.CASCADE)
> week = models.ForeignKey(Schedule, on_delete=models.CASCADE)
> select_one = models.CharField(max_length=50)
> select_two = models.CharField(max_length=50)
> select_three = models.CharField(max_length=50)
> select_four = models.CharField(max_length=50)
> select_five = models.CharField(max_length=50)
> select_six = models.CharField(max_length=50)
> select_seven = models.CharField(max_length=50)
> select_eight = models.CharField(max_length=50)
> select_nine = models.CharField(max_length=50)
> select_ten = models.CharField(max_length=50)
> tie_breaker = models.IntegerField()
> def __str__(self):
> return f'Week {self.week} selections for {self.username}'
>
> Below is a portion of what I want the template to look like when rendered.
> It takes the teams from the "Schedule" model
> and displays them.
> I then want the id of the selection (the value) of each game saved to the
> "Selections" model (select_one, select_two, etc.)
> I can't figure out how to tie in the view so it saves the data to the db.
> I realize I need to create a forms.py, import it into the view, but that
> is the part I'm having trouble understanding. I don't
> know what my forms.py should look like since the team names will change
> weekly and each match-up is it's own radio selection.
> Any help is greatly appreciated. Also, if I'm screwing this up on the
> models level, let me know. I realize that could
> also be an issue.
> JT
>
> 1  Oklahoma  Oklahoma State NCAA
> 1  Texas Christian  Houston NCAA
> 1  Dallas  Philadelphia NFL
> 1  Houston  Indianapolis NFL
> 1  New Orleans  Atlanta NFL
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/398cb0ad-fb81-49ff-bbee-53aa054b6a17%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/398cb0ad-fb81-49ff-bbee-53aa054b6a17%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: reg: User model data missing from web page

2020-05-05 Thread Chetan Ganji
Hi Amitesh,

Assuming you are using model forms in django without any customisation,
as UserProfile model does not have first_name, last_name and email field,
reading the first_name from cleaned_data is failing.

To solve it, you have to add 3 extra fields in the UserProfileForm
i.e. first_name, last_name and email, and pop them before saving the form.
also save these three fields on the user model.

*request.user.first_name = form.cleaned_data.pop('first_name')*
request.user.save()

form.save()

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in



On Tue, May 5, 2020 at 10:32 PM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> Hello Chetan,
>
> I was doing some random test, so I put "User" there. It is not the part of
> the original code.
>
> Below is models.py
>
> *from django.db import models*
> *from django.urls import reverse*
> *from django.contrib.auth.models import User*
>
>
> *class UserProfile(models.Model):*
> *user = models.OneToOneField(User, on_delete=models.CASCADE)*
> *Photo = models.FileField(upload_to='documents/%Y/%m/%d)*
> *uploaded_at = models.DateTimeField(auto_now_add=True)*
> *dob = models.DateField(max_length=20)*
> *country = models.CharField(max_length=100)*
> *State = models.CharField(max_length=100)*
> *District = models.CharField(max_length=100)*
> *phone = models.CharField(max_length=10)*
>
> *def get_absolute_url(self):*
> *return reverse('profile', kwargs={'id': self.id
> <http://self.id>})*
>
> Kindly give me the modified code that you think would work.
>
> Regards,
> Amitesh
>
>
> On Tuesday, 5 May, 2020, 09:24:58 pm IST, Chetan Ganji <
> ganji.che...@gmail.com> wrote:
>
>
> Hi Amitesh,
>
> If you post the models, then only someone will be able to give you exact
> solution.
>
> Couple of things I noticed.
> How is this even working??
> You have not defined User variable in the function??
> If its the default User model, how would passing it to UserProfile will
> help in your scenario??
> pr = UserProfile(User)
>
> You dont need this line as it is already available as request.user.  Why
> do you want to fetch it again, when it is already available???
> *pr.user = User.objects.get(id=request.user.id <http://request.user.id/>)*
> data2 = get_object_or_404(User, user=request.user)
>
> In the *profile_page *view, you can use reverse relation on the user
> model.
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Tue, May 5, 2020 at 9:02 PM 'Amitesh Sahay' via Django users <
> django-users@googlegroups.com> wrote:
>
> I have a profile page where I am fetching data from two models. One from
> the default User model and another one is custom UserProfile.
>
> However, The data from the custom model is getting populated, but not the
> User model.
> Below are the two functions responsible for the whole procedure.
>
> *def userprofileview(request):  # Authenticated user filling the form to
> complete the registration*
> *if request.method == 'POST':*
> *form = UserProfileForm(request.POST, request.FILES)*
> *if form.is_valid():*
> *pr = UserProfile(User)*
>
> *pr.user = User.objects.get(id=request.user.id
> <http://request.user.id>)*
> *pr.first_name = form.cleaned_data['first_name']*
> *pr.last_name = form.cleaned_data['last_name']*
> *pr.email = form.cleaned_data['email']*
>
> *pr.dob = form.cleaned_data['dob']*
> *pr.country = form.cleaned_data['country']*
> *pr.State = form.cleaned_data['State']*
> *pr.District = form.cleaned_data['District']*
> *pr.phone = form.cleaned_data['phone']*
> *pr.save()*
>
> *messages.success(request, f'Profile has been updated
> successfully')*
> *return redirect('/profile')*
> *else:*
> *messages.error(request, AssertionError)*
> *else:*
> *form = UserProfileForm()*
> *return render(request, 'authenticate\\bolo.html', context={'form':
> form})*
>
>
> *@login_required*
> *def profile_page(request):  # Fetching data from DB to show user's
> complete profile page*
> *data = get_object_or_404(UserProfile, user=request.user)*
> *data2 = get_object_or_404(User, user=request.user)

Re: reg: User model data missing from web page

2020-05-06 Thread Chetan Ganji
Ok.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 6, 2020 at 11:42 AM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> Hello Chetan,
>
> I got the issue resolved. Below are the correct views:
>
> def userprofileview(request):  # Authenticated user filling the form to 
> complete the registration
> if request.method == 'POST':
> form = UserProfileForm(request.POST, request.FILES)
> if form.is_valid():
> pr = UserProfile()
> pr.user = User.objects.get(id=request.user.id)
> pr.dob = form.cleaned_data['dob']
> pr.country = form.cleaned_data['country']
> pr.State = form.cleaned_data['State']
> pr.District = form.cleaned_data['District']
> pr.phone = form.cleaned_data['phone']
> pr.save()
> messages.success(request, f'Profile has been updated 
> successfully')
> return redirect('/profile')
> else:
> messages.error(request, AssertionError)
> else:
> form = UserProfileForm()
> return render(request, 'authenticate\\bolo.html', context={'form': form})
>
> @login_required
> def profile_page(request):  # Fetching data from DB to show user's complete 
> profile page
> data = get_object_or_404(UserProfile, user=request.user)
> #data2 = get_object_or_404(User, user=request.user)
> data2 = User.objects.get(id = request.user.id)
> context = {'data': data, 'data2': data2}
> return render(request, 'authenticate\\profile.html', locals())
>
>
>
> Regards,
> Amitesh
>
>
> On Wednesday, 6 May, 2020, 10:34:05 am IST, 'Amitesh Sahay' via Django
> users  wrote:
>
>
> Hello Chetan,
>
> Below is how I have created the forms.
>
> from django.contrib.auth.forms import UserCreationForm
> from django.contrib.auth.models import User
> from .models import UserProfile
> from django import forms
>
>
> class SignUpForm(UserCreationForm):
> email = forms.EmailField()
> first_name = forms.CharField(max_length=100)
> last_name = forms.CharField(max_length=100)
>
> class Meta:
> model = User
> fields = ('username', 'first_name', 'last_name', 'email', 
> 'password1', 'password2')
>
>
> class UserProfileForm(forms.ModelForm):
> Photo = forms.FileField( max_length=100)  
> #widget=forms.ClearableFileInput(attrs={'multiple': True}),
> dob = forms.DateField(widget=forms.TextInput(attrs={'type': 'date'}))
> country = forms.CharField(max_length=100)
> State = forms.CharField(max_length=100)
> District = forms.CharField(max_length=100)
> phone = forms.CharField(max_length=10)
>
> class Meta:
> model = UserProfile
> fields = ('Photo', 'dob', 'country', 'State', 'District', 'phone')
>
>
> I hope that helps. Please let me know. Just to let you know that there was
> a time during the development when I could only see the User model data on
> my page, but none from the UserProfile model. During the debug process I
> have made changes in both the files over the last couple of weeks, so now I
> have reached to the point where I can see only the UserProfile data.
>
> Just wanted to give you some insight.
>
> Regards,
> Amitesh
>
>
> On Wednesday, 6 May, 2020, 12:11:32 am IST, 'Amitesh Sahay' via Django
> users  wrote:
>
>
> Hi Chetan,
>
> The default user model already has those three fields, right? And since I
> have extended the  User as a onetoone field inside the UserProfile model,
> so shouldn't that work? I mean, that's my understanding. May be I am wrong.
> Let me know, just for the sake of clarity.
>
> Right now I don't have access to my system. I will send the code snippet
> of the forms.py, may be then you can give more inputs
>
> Thank you so much for your time though
>
> Amitesh
>
> Sent from Yahoo Mail on Android
> <https://go.onelink.me/107872968?pid=InProduct&c=Global_Internal_YGrowth_AndroidEmailSig__AndroidUsers&af_wl=ym&af_sub1=Internal&af_sub2=Global_YGrowth&af_sub3=EmailSignature>
>
> On Tue, 5 May 2020 at 23:32, Chetan Ganji
>  wrote:
> Hi Amitesh,
>
> Assuming you are using model forms in django without any customisation,
> as UserProfile model does not have first_name, last_name and email

Re: help on jwt

2020-05-21 Thread Chetan Ganji
If you post the error, someone can help you better.

Did you look into authentication_classes variable of the endpoint ???

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 21, 2020 at 6:48 PM ola neat  wrote:

> halo, i'm working on implementing JWT for user registration but i'm having
> issue with that, when i make post request for signup, i get an
> authentication  detail no provided err, below is my code, hope anyone can
> help out
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn73JY3zZFQbAir-t5As%3D5VUm0Sn-AC3CqAeoPqXQ%3Dp4_zA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHLKn73JY3zZFQbAir-t5As%3D5VUm0Sn-AC3CqAeoPqXQ%3Dp4_zA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Optmized Query

2020-05-27 Thread Chetan Ganji
select_related for fk and prefetch_related for m2m in django, you can chain
them together

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 27, 2020 at 4:51 PM Soumen Khatua 
wrote:

> Hi Folks,
> I have many to many relationships and Foreign Key in the table, I'm using
> select_realted(foreign key filed name) to optimize the query but I want to
> fetch many to many and foreign key at the same time , How I can do this in
> very optimized way?
>
> Thank You
> Regards,
> Soumen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Optmized Query

2020-05-27 Thread Chetan Ganji
Profile.objects.filter().select_related("user").prefetch_related("location")

On Thu, May 28, 2020, 2:01 AM Soumen Khatua 
wrote:

> I also know about this concept but I don't how I can achieve it, Could
> you give me an example?
> Suppose I have:
>
>
>
>
>
>
>
> *class Profile(models.Model):user = models.OneToOneField(
> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
> related_name="profile")location = models.ManyToManyField(Location)*
>
>
> Thank you
>
> Regards,
> Soumen
>
> On Wed, May 27, 2020 at 7:20 PM Chetan Ganji 
> wrote:
>
>> select_related for fk and prefetch_related for m2m in django, you can
>> chain them together
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Wed, May 27, 2020 at 4:51 PM Soumen Khatua 
>> wrote:
>>
>>> Hi Folks,
>>> I have many to many relationships and Foreign Key in the table, I'm
>>> using select_realted(foreign key filed name) to optimize the query but I
>>> want to fetch many to many and foreign key at the same time , How I can do
>>> this in very optimized way?
>>>
>>> Thank You
>>> Regards,
>>> Soumen
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Django Pagination

2020-05-30 Thread Chetan Ganji
Hi akshat,
What is the difficulty?
Where have you defined the variable   is_paginated? Is it present in the
context?

On Sat, May 30, 2020, 8:53 PM maninder singh Kumar <
maninder.s.ku...@gmail.com> wrote:

> Views.py looks fine !
>
> regards
> willy
>
>
> On Sat, May 30, 2020 at 7:22 PM Akshat Zala  wrote:
>
>> Hello,
>>
>> I am finding it difficult to paginate through all the posts
>>
>> My views.py :
>>
>> @login_required
>> def home_view(request):
>> """Display all the post of friends and own posts on the dashboard"""
>> posts = Post.objects.all().order_by('-date_posted')
>> media: MEDIA_URL
>> # 'post':Post.objects.filter(Q(author=request.user) |
>> Q(author__from_user=request.user) |
>> Q(author__to_user=request.user)).order_by('-date_posted'),
>> paginator = Paginator(posts, 2)
>> page_number = request.GET.get('page')
>> page_obj = paginator.get_page(page_number)
>> return render(request, 'post/home.html',{'page_obj': page_obj})
>>
>>
>> and in template post/home.html:
>>
>> {% if is_paginated %}
>> {% if page_obj.has_previous %}
>> First
>> arrow_left
>> 
>> {% endif %}
>> {% for num in page_obj.paginator.page_range %}
>> {% if page_obj.number == num %}
>> {{ num }}
>> {% elif num > page_obj.number|add:'-4' and num < page_obj.number|add:'4'
>> %}
>> {{ num }}
>> {% endif %}
>> {% endfor %}
>> {% if page_obj.has_next %}
>> arrow_right
>> Last
>> {% endif %}
>>
>>
>> Thanks
>>
>> Akshat Zala
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/87c3f0db-3088-448c-b3c7-14450e8c2f5d%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABOHK3QumzEA417%3DMV3dTwRszxmULfHp9y-tADSD56N_sTNQ5g%40mail.gmail.com
> 
> .
>

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


Re: Issue with serving angular with django

2020-06-01 Thread Chetan Ganji
You should use nginx to serve angular n static files and gunicorn for python

Below tuts might help you.

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04

Look for a tutorial without docker.
https://medium.com/bb-tutorials-and-thoughts/how-to-serve-angular-application-with-nginx-and-docker-3af45be5b854


On Mon, Jun 1, 2020, 7:25 PM Kasper Laudrup  wrote:

> Hi Sunday,
>
> On 01/06/2020 15.48, Sunday Iyanu Ajayi wrote:
> >
> > Please What am I doing wrong? Or are there better ways of serving
> > angular build files on django?
> >
>
> You haven't described how you are currently serving static files with
> Django. I suggest you start by reading this:
>
> https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/
>
> You definitely shouldn't use DEBUG in production and you definitely
> should serve static files with your web server of choice.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/12912d74-160c-547a-5cb5-0275432e751d%40stacktrace.dk
> .
>

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


Re: How to get a full path of web page to my views.py?

2020-06-09 Thread Chetan Ganji
https://docs.djangoproject.com/en/3.0/ref/request-response/


On Tue, Jun 9, 2020, 6:41 PM Sergei Sokov  wrote:

> I would like to use a current url path in my views.py
>
> понедельник, 8 июня 2020 г., 14:25:25 UTC+2 пользователь Rupesh Dahal
> написал:
>>
>> Can you please elaborate your problem.
>>
>> On Monday, June 8, 2020 at 12:26:12 AM UTC+5:45, Sergei Sokov wrote:
>>>
>>> I have the path in the web browser like this
>>>
>>> http://192.168.0.178:8000/customers-orders/37/customers-orders-date/?datefilter=06%2F14%2F2020+-+06%2F26%2F2020
>>>
>>> How to get this path to my views.py for to work with it?
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d6fe7979-a895-4797-98b1-ea4fdbdc8c34o%40googlegroups.com
> 
> .
>

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


Re: Changing name of file in FileField field

2020-06-09 Thread Chetan Ganji
Hi,
I had come across a similar issue last year. Filename would change after
the upload.
It been time and I am not sure why it happened then. But, i think it
happened
because a file with the same name was already present the given location.
And the django/drf code would make the name of the file unique by appending
random text like above.
You can check if this is the case.

You can try a couple of things.

1. Print the name of the file being generated as soon as it gets generated.

2. Print the name of the file and Path(d1.file.name).name just before the
assertion.
3. Check if a document with the same name already exists in the db and
media root folder, and make sure that it doesnt.

I hope it helps.

Cheers


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 10, 2020 at 12:31 AM Matthew Pava 
wrote:

> Good day,
> I have been struggling with this issue for weeks, and I can't figure out
> what I'm doing wrong.
> I have a model with a FileField with a custom upload_to function. It
> seems to work fine when I'm doing runserver.
> Problems arise during my tests.
>
> My assertion error fails:
>
> AssertionError: 'Rev0_2020-06-09_L123_My_Document_63ExUTF.docx' !=
> 'Rev0_2020-06-09_L123_My_Document.docx'
> - Rev0_2020-06-09_L123_My_Document_63ExUTF.docx
> ? 
> + Rev0_2020-06-09_L123_My_Document.docx
>
>
> You see, it keeps adding these extra random characters to the filename,
> which is not at all in my upload_to function.
>
> class DocumentTestCase(TestCase):
> def create_document(self, **kwargs):
> if 'file' not in kwargs:
> kwargs['file'] = self.get_test_file()
> return Document.objects.create(**kwargs)
>
>  def _create_file(self):
> f = tempfile.NamedTemporaryFile(suffix=self.TEST_FILE_EXTENSION, 
> delete=False)
> with open(f.name, mode='wb'):
>
> f.write(b"NA")
>
> return open(f.name, mode='rb')
>
>
> TEST_FILE_EXTENSION = ".docx"
>
> def setUp(self):
> super().setUp()
>
> settings.MEDIA_ROOT = MEDIA_ROOT
>
> def get_test_file(self):
> file = self._create_file()
>
> return File(file, name=file.name)
>
> def test_rename_file_after_upload(self):
> d1 = self.create_document(title="My Document", number="L123")
>
> title = d1.title.replace(" ", "_")
> extension = Path(d1.file.path).suffix
>
> new_name = 
> f"Rev{d1.revision}_{d1.revision_date}_{d1.number}_{title}{extension}"
> self.assertEqual(Path(d1.file.name).name, new_name)
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cbc812fc-6d5e-4afb-ab64-6bc0fad303a3o%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/cbc812fc-6d5e-4afb-ab64-6bc0fad303a3o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: Need your help!!

2020-06-15 Thread Chetan Ganji
https://docs.djangoproject.com/en/3.0/topics/security/

On Mon, Jun 15, 2020, 10:59 PM Vishesh Mangla 
wrote:

> What kind of security?
>
>
>
> Sent from Mail  for
> Windows 10
>
>
>
> *From: *meera gangani 
> *Sent: *15 June 2020 22:28
> *To: *django-users@googlegroups.com
> *Subject: *Need your help!!
>
>
>
> Hello ,
>
>
>
>  How to apply security in django application and  how to
> secure django applications
>
>
>
> Thanks in advance
>
> -Meera Gangani
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANaPPPLr9DJstjDvYOOrddtY4fcfNLs7xgudWfJ1aFhkROL0GA%40mail.gmail.com
> 
> .
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6B653CD7-68CB-4C56-9FB3-034FF4902547%40hxcore.ol
> 
> .
>

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


Re: Form theory - locking a field

2020-06-24 Thread Chetan Ganji
Try this one
https://docs.djangoproject.com/en/3.0/ref/forms/fields/#disabled

On Wed, Jun 24, 2020, 8:06 PM Clive Bruton  wrote:

> I have a form in which, after filing, I would like one field to be
> locked for editing, the forms.py looks like this:
>
> **
>
> class ProfileForm(forms.ModelForm):
>  status = forms.ChoiceField(choices=Profile.status_choices,
> widget=forms.RadioSelect)
>
>  class Meta:
>  model = Profile
>  fields = (
>  'status', 'phone', 'display_phone', 'display_address',
> 'display_email', 'display_loginoverride'
>  )
>  widgets = {
>  'phone': PhoneWidget
>  }
>
> **
>
>
> While the user will be able to come back and change the other
> information on the form, I want to be able to lock the "status"
> field, so that it just shows the input they selected, not the radio
> buttons and is no longer editable by the user.
>
> Is there a way to do this in forms.py, or would I have to construct
> the logic in a template (or perhaps some other way)?
>
> Thanks
>
>
> -- Clive
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7A4BCC9C-172C-4511-A422-6E832A72E11D%40indx.co.uk
> .
>

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


Re: Question about django.utils.autoreload

2020-07-20 Thread Chetan Ganji
RE: os.path.join(BASE_DIR, 'reactapp', 'src')

It seems that the source code of react app is inside the django folder, so
if src code of django is changed, react app would be rebuild!

Try keeping the src code of django and react app if different folders, that
might solve it.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, Jul 20, 2020 at 12:47 PM Dave R  wrote:

> Hello, I'm trying to figure out how to rebuild my React.js project (with
> Django backend) and relaunch the Django dev server if a React.js file
> changes.  The code below works, but it rebuilds React even if the only code
> changes are in Django.  Can anyone suggest how to solve this problem?
>
> import subprocess
> from django.utils.autoreload import autoreload_started
> from django.dispatch import receiver
> @receiver(autoreload_started)
> def rebuild_react_app(sender, **kwargs):
> sender.watch_dir(os.path.join(BASE_DIR, 'reactapp', 'src'), '*')
> subprocess.run(r'yarn --cwd ./reactapp build', shell=True)
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/13c40a08-6084-4609-8141-ddcf029c33a7n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/13c40a08-6084-4609-8141-ddcf029c33a7n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

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


Re: creating a website with django

2020-08-28 Thread Chetan Ganji
https://www.youtube.com/watch?v=KsLHt3D_jsE&list=PLEsfXFp6DpzRcd-q4vR5qAgOZUuz8041S

On Fri, Aug 28, 2020, 9:04 PM sakshi jain  wrote:

> plz help me also
>
> On Fri, Aug 28, 2020, 19:23 Kamini Shukla 
> wrote:
>
>> i want to create a website with the help of django. pls some one help of
>> that.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/2fd61f31-8604-422a-b091-e46cd9bc25d0n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJhs3iP_YK4gCu48FkbDwSHx6bciQ%2BzZCS_N4RvWFQ71X%2BFEYA%40mail.gmail.com
> 
> .
>

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


Re: Training

2019-05-17 Thread Chetan Ganji
You need this one.

https://www.youtube.com/watch?v=KsLHt3D_jsE&list=PLEsfXFp6DpzRcd-q4vR5qAgOZUuz8041S


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 16, 2019 at 10:02 PM Scyil sharma 
wrote:

> Can anyone suggest the best Django summer training in india
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/7093afe7-4a42-4c5b-8c53-fe12c7e7699d%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/CAMKMUjtLR%2BQd8ZKxzD6%2B%2Br_cGP5%3D66ojJC6rSZX5KDnMrNh-ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Porting Django app

2019-05-17 Thread Chetan Ganji
I understand the pain of a Linux user ;) You don't need to port anything at
all ;-)

RE:  nothing can be web based, it must be in house and
disconnected from the external web.

As there would be multiple users using the same instance of the software, a
web app is that they need.
That way all the data and the actual app is located in a centralised
location.

Use any stack, you will end up creating a webapp for this scenario.

*Solution - *
Create the app in Python 3.7 and Django 2.2. Give them a desktop pc with
Ubuntu 18.04 LTS installed.
Install Nginx + Gunicorn + Python 3.7 + Django 2.2 on this desktop. Get
everything up and running.
This desktop becomes their new server for this app.

The only difference here will be that instead of hosting the server on at a
hosting providers location i.e. in the cloud,
above server would would be located locally on their premises. This server
would be different from their servers/pcs.
So they would have to use the app in a LAN setting i.e. access the app
using local ip instead of a web domain.
Just remember to charge them for the desktop server you will provide ;-)

Use AMD Ryzen or Threadripper for the server as they have more cores and
threading enabled,
they will be better than intel based cpus for a server pc.

If they don't want your server, ask them to buy a separate one for this app.

This way,

   1. They can use whichever OS they want to use.
   2. Keep their security policy "NADA, NOT GONNA INSTALL THAT".
   3. Get more security as their webserver need not be connected to
   internet at all.
   4. They don't have to install any third party softwares on their so
   called secure servers/pcs.
   5. Store everything in a centralised location.
   6. You don't have to learn C or C++.
   7. You get to pay me $1000 for consulting, LOLZ. Just kidding :)


I hope it helps :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Thu, May 16, 2019 at 3:29 PM RLM  wrote:

> Hello all.
> I eventually will need to put my dedicated Django app on another system
> owned by a Public institution. The app correlates each data set of 26
> million plus samples to a QR code for each.
> Security is major  so nothing can be web based, it must be in house and
> disconnected from the external web.
>
> A problem is I'm developing on Linux and Mac and much of the world uses
> Windows 10 et al.
>
> Installation of python3, Django, mysql and the app would rely on the IT
> people at the institution who do not like installing software on secure
> systems.
> I would also point out that schools here also fall into the "will not
> install that software" category significantly limiting student's ability
> to learn modern systems.
>
> I trialed compiling Python3 app to an .exe file, works ok, but am
> concerned that P3/Django will not do so.
>
> Bio: I'm in my 70's, been developing web apps for 25 years and do not
> want to learn C and C++.
>
> Can anyone advise me how to go about providing the system at minimum
> problems for the IT sector of the institution.
> Thanks in  advance
>
> Roger
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/f68670b3-a75d-61ef-2f5b-61065e5a9f56%40gmail.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/CAMKMUjveUrmMxHA8fgd_1vuUnw6mkSZvjS66NtiQ%3DRTD2ERdiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing multiple session support in a chatbot

2019-05-18 Thread Chetan Ganji
What you need is to implement 2 design patterns in your django app. Which
ones?

1. *Singleton* Design Pattern for the Chatbot. All the users and all of
their sessions are using the same chatbot instance.

Why?

Because when a new session is created for a user, he will be referring to
the same chatbot instance and all of previous history would be accessible.
You need to add a timestamp to each message. So that when a new session is
created,
all of previous messages can be to sent to this session by filtering on the
timestamp of the messages.

This instance can be used to store all of the sessions of all of the users.
Something like below.
That way when the observer getters and setters are called, they get a list
of active session of the current user.
So the actual message is sent by iterating over the active sessions. Hence
all the sessions get the same message.


class Chatbot(object):

_sessions = {
"username1": {
"mobile": [],
"desktop": []
},

"username2": {
"mobile": [],
"desktop": []
}

}

@classmethod
def get_sessions(self, username):
return self._sessions[username]


Other way to achieve singleton effect is create a instance of the chatbot
and import it wherever it is required.
This will given the same effect as singleton but without implementing it.


nikola = Chatbot()


Now just import nikola everywhere it is required.


2. *Observer* Design Pattern for the syncing of the messages across
multiple sessions.

Why?

Because, you need the chatbot to sync between multiple sessions. Same
message needs to goto multiple recipients.
When a new session is created, you will have to send the previous messages
to this new session.
This is the sole purpose of this design pattern. It's use is already
explained above.

As you are using django channels for websockets, you will have to combine
that code with this pattern.
I don't have any experience with websockets, you will have to figure it out
:P

I hope it helps :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Sat, May 18, 2019 at 7:17 PM Parth Sharma 
wrote:

> I am currently implementing a Chatbot purely in python.
>
> In my current implementation, each time the user starts a new chat from a
> session, another Chatbot instance is launched and hence the Chatbot starts
> from the initial state.
>
> I wish to change that behaviour and make it similar to let’s say chat on
> Facebook/Messenger, in which you can seamlessly move between sessions while
> having a chat without inconsistencies. Namely, I want these attributes:
>
>1. If the user enters anything from let’s say session A it should be
>immediately visible in all ongoing sessions. Similarly, the Chatbot reply
>should be visible in all the devices immediately.
>2. Have all sessions show the same chat history
>
> To implement the first point, I used this example
> <https://channels.readthedocs.io/en/latest/tutorial/part_2.html> from the
> django-channels docs and modified it by creating a single group/chatroom
> for each user. All the sessions from the same user get connected to the
> same group/chatroom and hence receive all the messages in the
> group/chatroom regardless of where they were sent from.
>
> However, this implementation currently has a bug. Each time that a user is
> connected, it initializes a Chatbot instance which starts from the initial
> state again while the older connections have Chatbot instances that are
> currently at a different state.
>
> This leads to inconsistent replies which are different based on which
> window the user typed something in.
>
> Basically instead of having two sessions talk to the same Chatbot
> instance, we have two sessions talking to two different Chatbot instances
> and messages from all these four sources are getting added to the same
> chatroom.
>
> Moreover, we are wasting resources by keeping multiple Chatbot instances
> per user which increases with the number of currently active sessions.
>
> I want all of the user windows to interact with the same Chatbot instance.
> What would be the best way to implement that?
>
> Currently I can think of three solutions:
>
>1. Creating another Django project the Chatbot and make requests to
>that HTTP server. The Chatbot state is maintained in that server and any
>request from the user will go to the same Chatbot instance.
>   - This is straightforward to implement for me (simply spin up
>   another server)
>   - This naturally solves all the problems regarding state as all the
>   instances will query the same Chatbot object
>2. Creating a *Master* channel thread which will hold the actual
>Chatbot instance(a python object) and any new channels will will defer to
>it for the re

Re: Porting Django app

2019-05-19 Thread Chetan Ganji
Python is said to be interpreted language. But the c python implementation
is exactly like java
i.e. is compiled + interpreted and runs on a virtual machine. Maybe that
how Java got their idea :P

Pypy is another python implementation which has a JIT compiler, please
check if it helps your scenario.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Sat, May 18, 2019 at 9:42 AM Ganesh Babu  wrote:

> i understand what you are saying..  To collect private IP address or
> create as Virtual host in LINUX server, its should available.
>
> On Thu, May 16, 2019 at 3:29 PM RLM  wrote:
>
>> Hello all.
>> I eventually will need to put my dedicated Django app on another system
>> owned by a Public institution. The app correlates each data set of 26
>> million plus samples to a QR code for each.
>> Security is major  so nothing can be web based, it must be in house and
>> disconnected from the external web.
>>
>> A problem is I'm developing on Linux and Mac and much of the world uses
>> Windows 10 et al.
>>
>> Installation of python3, Django, mysql and the app would rely on the IT
>> people at the institution who do not like installing software on secure
>> systems.
>> I would also point out that schools here also fall into the "will not
>> install that software" category significantly limiting student's ability
>> to learn modern systems.
>>
>> I trialed compiling Python3 app to an .exe file, works ok, but am
>> concerned that P3/Django will not do so.
>>
>> Bio: I'm in my 70's, been developing web apps for 25 years and do not
>> want to learn C and C++.
>>
>> Can anyone advise me how to go about providing the system at minimum
>> problems for the IT sector of the institution.
>> Thanks in  advance
>>
>> Roger
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/f68670b3-a75d-61ef-2f5b-61065e5a9f56%40gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Best Regards
> Sri Ganesh Babu.S
> Sr. Software Engineer,
>
> *Doyen Solutions*
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/CAJZVxAv1nSpLNett9kTmRKXEVsheePwqXTM2%2BGbE50rqtTW3Mw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJZVxAv1nSpLNett9kTmRKXEVsheePwqXTM2%2BGbE50rqtTW3Mw%40mail.gmail.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/CAMKMUjvm1h0vSpb-GKU8qSNRnouS5jWx9_e%3DDrTZLrYxck%3DG3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing multiple session support in a chatbot

2019-05-19 Thread Chetan Ganji
Hi Parth,

There is only one solution. It has two parts in which you will implement 2
design patterns for the chatbot.
*Singleton* and *Observer*.

RE : Where would you use it?
nikola = Chatbot() # it is called instantiating the chatbot

Wherever it is required :P

The idea is to create one and only one instance of the chatbot for the
whole project and make it available when the projects get loaded into the
memory. Two of the best ways to do this is -

   1. Instantiate the chatbot in the *wsgi.py* file of the project. From
   this file, import it and use as required.
   2. Instantiate the chatbot in the *settings.py* file of the project.
   That way you could import it wherever it is required and access it as
   *settings.nikola*.

   from django.conf import settings



RE : in which files would I import it?

Wherever it is required :P

Lets say, there is a view which will return a response. Its a fictional
example, take it with grain and salt :P

from django.conf import settings
from django.http import JsonResponse

def Reply(request, message):

sessions = settings.nikola.get_sessions(request.user.username)
response = settings.nikola.choose_response(message)

# send the message to all the remaining sessions, except the current one
# as the current session would get this reply in the response of this view
settings.nikola.send_session_replies(sessions)

return JsonResponse(data=response)


I hope its clear now :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, May 20, 2019 at 2:49 AM Parth Sharma 
wrote:

> Thanks a lot for your reply !
>
> In the first part of your reply. I didn't really understand where exactly
> would I actually use this
> nikola = Chatbot()
> and in which files would I import it? Can you please elaborate on the
> second solution a bit?
>
> On Sunday, 19 May 2019 02:59:30 UTC+5:30, Chetan Ganji wrote:
>>
>> What you need is to implement 2 design patterns in your django app. Which
>> ones?
>>
>> 1. *Singleton* Design Pattern for the Chatbot. All the users and all of
>> their sessions are using the same chatbot instance.
>>
>> Why?
>>
>> Because when a new session is created for a user, he will be referring to
>> the same chatbot instance and all of previous history would be accessible.
>> You need to add a timestamp to each message. So that when a new session
>> is created,
>> all of previous messages can be to sent to this session by filtering on
>> the timestamp of the messages.
>>
>> This instance can be used to store all of the sessions of all of the
>> users. Something like below.
>> That way when the observer getters and setters are called, they get a
>> list of active session of the current user.
>> So the actual message is sent by iterating over the active sessions.
>> Hence all the sessions get the same message.
>>
>>
>> class Chatbot(object):
>>
>> _sessions = {
>> "username1": {
>> "mobile": [],
>> "desktop": []
>> },
>>
>> "username2": {
>> "mobile": [],
>> "desktop": []
>> }
>>
>> }
>>
>> @classmethod
>> def get_sessions(self, username):
>> return self._sessions[username]
>>
>>
>> Other way to achieve singleton effect is create a instance of the chatbot
>> and import it wherever it is required.
>> This will given the same effect as singleton but without implementing it.
>>
>>
>> nikola = Chatbot()
>>
>>
>> Now just import nikola everywhere it is required.
>>
>>
>> 2. *Observer* Design Pattern for the syncing of the messages across
>> multiple sessions.
>>
>> Why?
>>
>> Because, you need the chatbot to sync between multiple sessions. Same
>> message needs to goto multiple recipients.
>> When a new session is created, you will have to send the previous
>> messages to this new session.
>> This is the sole purpose of this design pattern. It's use is already
>> explained above.
>>
>> As you are using django channels for websockets, you will have to combine
>> that code with this pattern.
>> I don't ha

Re: Django background scheduled app

2019-05-20 Thread Chetan Ganji
celery is what you need for this. It is very simple. Just stick to it, find
some examples on youtube for celery, and you should get it.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, May 20, 2019 at 5:42 PM Oguz kagan Olmez 
wrote:

> i just started django, python and back-end. i want to ask you a question
> for my first project. i have functions that creating json file. After that
> i am showing that json file on my webpage. But that functions in view take
> a lot of time and my webpage doesn't open for like 20-30 seconds. Actually
> my functions should work hourly and my web page doesn't depends to it.
> something like celery is too hard and i couldn't handle it. I tried cron
> and it gives errors on windows. thanks
> (Django Background Tasks is my last option. but i am really tired of
> this. I am working for days now just solve this problem)
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/04a993fd-dbb5-48da-8c22-f35369c3fbd5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/04a993fd-dbb5-48da-8c22-f35369c3fbd5%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/CAMKMUjs%2B1pRM-BPMH9XKA9aSqTGRn2ycxXmQxkFz7g5OzwoeNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django migrations no migrations to apply

2019-05-20 Thread Chetan Ganji
Hi Harish,

Did you commit your changes to git/svn repo after changing the models?
Did they fetch the latest changes from the repo?

Is your db file also in repo?
If yes, there would a table inside the database db.sqlite3, which stores
the information about which migrations were executed.
You have to delete the entry for the migration in question.

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Mon, May 20, 2019 at 5:42 PM Harish U Warrier  wrote:

>
>
> In django models i added a new field
>
> in my system its working fine.
>
> but in other systems its showing  no migrations to apply
>
> how to solve it without effecting data?
>
> i tried deleting contents of migrations folder except __init__.py
>
> enter code here
>
> but still same error
>
> what is real method to do migrations while working in a team, live test
> servers etc?
>
> my version is 2.2
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/00ec6e6a-73f1-4d95-9ab6-2565ae29ff40%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/00ec6e6a-73f1-4d95-9ab6-2565ae29ff40%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/CAMKMUjtKuwR0nLtTbP4P8BMWP-kx%2B36n5%2BxDvF89tuBJj4S_Vw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help for Cascading Drop Down for Continent, Country in Admin GUI - Not Getting correct Answer from Many Days

2019-05-21 Thread Chetan Ganji
Hello Balaji Sir,

AFAIK, Django does not filter the foreign key fields by default, Cascading
Drop Down is not available by default in django.
If the filtering was to be done on the initial value only, you could have
overwritten the __init__() in the form to filter the fk values.
But that does not seem to be the case, as the filtering needs to be done on
the clientside.

One solution that I know will work for sure is -
Write custom javascript code to add event listeners on the select dropdown.
Whenever an entry is selected,
AJAX request would be sent to server to fetch only the related/required
fields for the current selection and
show these fetched values in the dropdown. Use of jquery would be optimal
for this.
Hence, you would write separate endpoints to fetch the filtered list also.

Another solution would be output the values and their relations to a
javascript variables in the template.
Then show the select dropdown based on these values. This one can be
cumbersome to understand as well as implement.
I am not sure if it will work or not :P

Go for the first solution :)


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 22, 2019 at 11:22 AM Balaji Shetty 
wrote:

> Hi
>
> I have registered model in admin.py
> Added Continent  ( Cont1, Cont2, Cont3 )
>
> Added Country under Continent
>
> Cont1 - Count11
> Cont1- Count12
>
> Cont2 - Count21
> Cont2-Count22
>
> Con3-Count31
> Con3-Count31
>
> When I add Location
>
> When i select Cont1, I should get only Count11 , Count12
>
> When i select Cont2, I should get only Count21 , Count22
>
> When i select Cont3, I should get only Count31 , Count32
>
> But I get all Countries under all Continent. Cascading dependency are not
> shown
>
> I tried different option but lot of issues are there .
>
>
>
> Example
>
>
>
> On Wed, May 22, 2019 at 10:56 AM Nitin Kumar 
> wrote:
>
>> Everything seems alright. It seems you haven't created any continents
>> yet. The table is empty.
>>
>> On Wed, 22 May, 2019, 10:52 AM Balaji Shetty > wrote:
>>
>>> Hi
>>>
>>> I am learning Django from last months and want to implement Cascading
>>> Drop Down for Continent and  Country  in Admin GUI.
>>>
>>> I dropped same query two times but i could not get exact correct
>>> solution.
>>>
>>> I tried lot of option like
>>> django-smart-select and many more..
>>>
>>> But i could not get updates in drop down.
>>>
>>>  Can Any Django Expert solve this issue? Your help would be highly
>>> appreciated.
>>>
>>> This is sample Model for  demonstration of the schema
>>> models.py
>>> --
>>>
>>>
>>> class Continent(models.Model):
>>> name = models.CharField(max_length=255)
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>>
>>> class Country(models.Model):
>>> continent = models.ForeignKey(Continent,on_delete=models.CASCADE)
>>> name = models.CharField(max_length=255)
>>>
>>> def __str__(self):
>>> return self.name
>>>
>>> class Location(models.Model):
>>> continent = models.ForeignKey(Continent,on_delete=models.CASCADE)
>>> country = models.ForeignKey(Country,on_delete=models.CASCADE)
>>> city = models.CharField(max_length=50)
>>> street = models.CharField(max_length=100)
>>>
>>> def __str__(self):
>>> return self.city
>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>> *Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information
>>> Technology,*
>>> *SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India*
>>> *Official: bsshe...@sggs.ac.in  *
>>> *  Mobile: +91-9270696267*
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "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/CAECSbOtoje0sdMsoeQvCO-mq-h-AQVOKtnYA3wFnLAE-tPhXGg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAECSbO

  1   2   >