Re: Custom Django Admin Pages

2018-08-20 Thread Vineet Kothari
It will be a bad practise you can disable dango admin and create a new app admin but it will require effortsSent from my Huawei Mobile Original Message Subject: Custom Django Admin PagesFrom: 'Kyle Mulka' via Django users To: Django users CC: Hi there,It seems like Django Admin is designed to work with Django models. But, I'm wondering what the best way is to create custom admin pages that don't revolve around Django models. Like, maybe there's a third party API that I want admins to be able to call from the Django admin. What's the best way to get custom pages to show up and render in the Django admin?Thanks,Kyle



-- 
You received this message because you are subscribed to the Google Groups "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/57ccf869-829c-4ed4-881b-3b2031834bee%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/-xcpxy6-3x1uz9dtff28-md6b0z-mafomj-9pjcu7iy1vhz-ku8urb-uf2r8a-u9ywha-u06at27chu34a4bf336qyfe-2brsl2vbzu2351k32z-3r7vmfkj16um2wqw1mkp06tb-1d0xtt-ktzgz1k0top.1534824869335%40email.android.com.
For more options, visit https://groups.google.com/d/optout.


Custom Django Admin Pages

2018-08-20 Thread 'Kyle Mulka' via Django users
Hi there,

It seems like Django Admin is designed to work with Django models. But, I'm 
wondering what the best way is to create custom admin pages that don't 
revolve around Django models. Like, maybe there's a third party API that I 
want admins to be able to call from the Django admin. What's the best way 
to get custom pages to show up and render in the Django admin?

Thanks,

Kyle

-- 
You received this message because you are subscribed to the Google Groups 
"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/57ccf869-829c-4ed4-881b-3b2031834bee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: problems with order by month

2018-08-20 Thread Osvaldo Ruso Olea
You are a genius, thank you very much, it worked perfectly, I just made one
more modification

def cardio (request):
 now = timezone.now ()
 cardio = Alumno.objects.filter ( fechanacimiento __month = now.month)
 context = {'cardio': cardio}
 return render (request, 'cardio.html', context)

What I can not do is sort the dates from lowest to highest,

Thank you very much

El lun., 20 ago. 2018 a las 19:03, Matthew Pava ()
escribió:

> Try this:
>
> cardio = Alumno.objects.filter(fechanacimiento__month=timezone.now().month)
>
>
>
> *From:* django-users@googlegroups.com [mailto:
> django-users@googlegroups.com] *On Behalf Of *Osvaldo Ruso Olea
> *Sent:* Monday, August 20, 2018 2:58 PM
> *To:* Django users
> *Subject:* problems with order by month
>
>
>
> Hi how are you, I have problems filtering and sorting by date, precisely
> per month.
>
> my intention is to filter the database for birthdays in the current month.
>
>
>
>
>
>
>
>
>
> def cardio(request):
>
> cardio = Alumno.objects.order_by('fechanacimiento')
>
> contexto = {'cardio':cardio}
>
> return render(request, 'cardio.html', contexto)
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/e9f385a8-6b62-4e15-9020-9aa79ee7c48d%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/ae37d6672adc41f8bd4fc4187c27df80%40ISS1.ISS.LOCAL
> 
> .
> 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/CAPJtaPDoPie6B4fVUyMKojNMfwYXrJqwU3ZyGm6ny3TdmHg46Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problems with AbstractUser

2018-08-20 Thread Richard Pacheco

Hello Goodnight. I need to create a custom user model to be used in my 
django application, this in order to be able to place the fields that I 
need and in addition to be able to use the basic authentication methods 
that django already incorporates. The problem is that I do not clearly 
understand the documentation provided by django, if anyone can help me I 
will appreciate it. Regards!

Hola, buenas noches. Necesito crear un modelo de usuario personalizado para 
ser usado en mi aplicación de django, esto con el fin de poder colocarle 
los campos que necesite y adicionalmente poder utilizar los métodos de 
autenticación básicos que ya incorpora django. El problema es que no 
entiendo claramente la documentación proporcionada por django, si alguno 
puede ayudarme sabré apreciarlo. Saludos!

-- 
You received this message because you are subscribed to the Google Groups 
"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/83e34e9f-dfb9-4dad-9463-6c7d9cc43aa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: problems with order by month

2018-08-20 Thread Matthew Pava
Try this:
cardio = Alumno.objects.filter(fechanacimiento__month=timezone.now().month)

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Osvaldo Ruso Olea
Sent: Monday, August 20, 2018 2:58 PM
To: Django users
Subject: problems with order by month

Hi how are you, I have problems filtering and sorting by date, precisely per 
month.
my intention is to filter the database for birthdays in the current month.




def cardio(request):
cardio = Alumno.objects.order_by('fechanacimiento')
contexto = {'cardio':cardio}
return render(request, 'cardio.html', contexto)
--
You received this message because you are subscribed to the Google Groups 
"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/e9f385a8-6b62-4e15-9020-9aa79ee7c48d%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/ae37d6672adc41f8bd4fc4187c27df80%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


problems with order by month

2018-08-20 Thread Osvaldo Ruso Olea
Hi how are you, I have problems filtering and sorting by date, precisely 
per month.
my intention is to filter the database for birthdays in the current month.




def cardio(request):
cardio = Alumno.objects.order_by('fechanacimiento')
contexto = {'cardio':cardio}
return render(request, 'cardio.html', contexto)

-- 
You received this message because you are subscribed to the Google Groups 
"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/e9f385a8-6b62-4e15-9020-9aa79ee7c48d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-20 Thread Jani Tiainen
Hi,

Instead of doing everything by hand I would recommend doing a custom
management command in Django.

Because management commands live inside Django ecosystem you get full
benefits of Django. Migrations to setup database tables from model
definitions. Models and ORM to interact with database. (Model)forms to
validate your incoming data etc.

Also I really suggest that you do the official tutorial from the docs to
get hang of basic django concepts.

ma 20. elok. 2018 klo 19.59 Mikko Meronen 
kirjoitti:

> Hi and thanks for your help.
>
> I have tried postgress and now I have a problem using it. Here's my code
> following an error. I appreciate any help.
>
> def do():
> x = 1
> while x == 1:
> create_table()
> print('finding data')
> find_data()
> time.sleep(120)
>
> def create_table():
> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
> published TEXT, UNIQUE(url))')
>
> def find_data():
> r = requests.get(homepage)
> soup = BeautifulSoup(r.text, 'html.parser')
> results = soup.find_all('data')
> for result in results:
> title = result.find('h1').text
> url = result.find('a')['href']
> published = result.find('time')['datetime']
>
>
> c.execute("INSERT OR IGNORE INTO testi (url, title,
> published) VALUES (%s, %s, %s)",
>   ('url', 'title', 'published'))
> connection.commit()
>
>
> do()
>
> ERROR:
>
> Traceback (most recent call last):
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43, in
> 
> do()
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21, in
> do
> find_data()
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39, in
> find_data
> ('url', 'title', 'published'))
> *psycopg2.ProgrammingError: syntax error at or near "OR"*
> *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...*
>
>
>
> -Mikko
>
>
> 2018-08-17 19:09 GMT+03:00 Mikhailo Keda :
>
>> You could generate models from sqlite database -
>> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
>> Than switch to PostgresQL
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/52f5c754-7310-4baa-8008-edbcea15eafb%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/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%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/CAHn91oex8cAE1yFshSABt9QZpdiiRVtALtLx0AWDNU84w0%2Bqvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-20 Thread Mikko Meronen
Hi and thanks for your help.

I have tried postgress and now I have a problem using it. Here's my code
following an error. I appreciate any help.

def do():
x = 1
while x == 1:
create_table()
print('finding data')
find_data()
time.sleep(120)

def create_table():
c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
published TEXT, UNIQUE(url))')

def find_data():
r = requests.get(homepage)
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('data')
for result in results:
title = result.find('h1').text
url = result.find('a')['href']
published = result.find('time')['datetime']


c.execute("INSERT OR IGNORE INTO testi (url, title,
published) VALUES (%s, %s, %s)",
  ('url', 'title', 'published'))
connection.commit()


do()

ERROR:

Traceback (most recent call last):
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43, in

do()
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21, in
do
find_data()
  File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39, in
find_data
('url', 'title', 'published'))
*psycopg2.ProgrammingError: syntax error at or near "OR"*
*LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...*



-Mikko


2018-08-17 19:09 GMT+03:00 Mikhailo Keda :

> You could generate models from sqlite database -
> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
> Than switch to PostgresQL
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/52f5c754-7310-4baa-8008-edbcea15eafb%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/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /news/ Value: None must be instance of Model:

2018-08-20 Thread Mikhailo Keda
rest_framework_mongoengine was updated 1 year ago, according to djongo docs 
they have integration with Django Rest Framework, try to use Django Rest 
Framework instead of rest_framework_mongoengine.
And you need debug the error.

понеділок, 20 серпня 2018 р. 14:36:15 UTC+3 користувач Sagar написав:
>
> Hi Mikhailo
> Yes you are right, but I didn't used django-nonrel or djangotoolbox. Those 
> were totally outdated. I have used djongo which is updated as far as I 
> know. About MongoDB, I'm working on project in which we used MongoDB. We 
> want to use NoSQL database insted of SQL database. Did you work with django 
> and mongodb before?
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/246b2770-fc30-40b9-8d0e-a34ddd11e5c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /news/ Value: None must be instance of Model:

2018-08-20 Thread Jason

>
> We want to use NoSQL database insted of SQL database
>

Is your data relational, and are you going to be doing alot of joins?  If 
so, using mongo will be a pain in your application for performance. 

I really hope you have a solid technical reason why to use mongo rather 
than "ITS WEBSCALE!"

-- 
You received this message because you are subscribed to the Google Groups 
"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/2a24a45c-63a1-46d2-981e-72cd61e0be2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /news/ Value: None must be instance of Model:

2018-08-20 Thread Sagar
Hi Mikhailo
Yes you are right, but I didn't used django-nonrel or djangotoolbox. Those 
were totally outdated. I have used djongo which is updated as far as I 
know. About MongoDB, I'm working on project in which we used MongoDB. We 
want to use NoSQL database insted of SQL database. Did you work with django 
and mongodb before?

On Monday, August 20, 2018 at 12:18:17 PM UTC+5:30, Mikhailo Keda wrote:
>
> Not sure what you are using but all packages for Django + MongoDB are 
> outdated.
> Why do not use PostgreSQL instead of MongoDB?
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/918724e2-90a9-4a8e-8556-e336cfd2c621%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regarding the installation

2018-08-20 Thread Irenge Mufungizi
You can simply type pip install django and it will download for you the 
required modules

On Thursday, August 16, 2018 at 5:10:29 AM UTC-7, muthu sabarish wrote:
>
> how to download django ???can any one help me 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 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/ef28db2f-0970-4976-be1f-2c293c5f59cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible bug: Querying a model with an IntegerField value of 0 using mysql-connector/python returns a queryset where the field value becomes a NoneType 2.0.3.0

2018-08-20 Thread Jason
rather than having your dev environment exist on two separate operating 
systems, you should use virtual machines with docker or vagrant for 
development.  That way, your environment is identical through dev, staging 
and prod environments, except for env-specific settings.  Consider this 
case, if you're working fine in Linux but Windows is blowing up, using 
docker or vagrant would make this a non-issue/

On Monday, August 20, 2018 at 3:18:33 AM UTC-4, Marcus Grass wrote:
>
> Yeah I know it's recommended, but I can't for the life of my get that 
> connector to work in windows. 
> I program my project both in places where  I only have windows and only 
> Linux. 
>
> On Mon, Aug 20, 2018 at 2:20 AM, Jason > 
> wrote: 
> > that is indeed weird, but suggests its an issue with 
> python-mysql-connector, 
> > not django. 
> > 
> > 
> https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-db-api-drivers 
> > 
> > As you can see there, mysqlclient is the django project recommended way 
> to 
> > interface with mysql.  What are your reasons for going with 
> > mysql-connector-python? 
> > 
> > 
> > On Sunday, August 19, 2018 at 6:15:44 PM UTC-4, Marcus Grass wrote: 
> >> 
> >> Hi, I ran into a strange problem when i switched from using mysqlclient 
> to 
> >> mysql-connector/python. 
> >> 
> >> In practice: 
> >> class Foo(models.Model): 
> >>  bar = models.IntegerField(default=0, null=False) 
> >> 
> >> queryset = Foo.objects.all().filter(bar=0) 
> >> print(queryset[0].bar)  # prints None 
> >> 
> >> 
> >> Anyone know a fix for this? 
> >> 
> >> Using python 3.6.6, Django 2.0.3.0- 
> > 
> > -- 
> > You received this message because you are subscribed 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/6be9073b-34f1-445f-ba02-dabf09c9916c%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/1c47e38f-d898-4fcd-945e-b1e96cc9a477%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter *every* query on django?

2018-08-20 Thread Andréas Kühne
I don't know how django-tools solves it - but it usually is set for every
request to the server.

When running django you have 1 or more threads that run the server. Each
thread can handle one request at a time - others get queued (you don't
usually see this). So when the request is done the middleware should clear
the user (that's how I wrote it at least - it's perhaps overkill, but
better safe than sorry). The next incoming request will then have a new
user - even if it is the same user from the previous one.

Regards,

Andréas

2018-08-19 16:00 GMT+02:00 Fellipe Henrique :

> Thanks Andreas,
>
> Using your tip, I installed django-tools app, and now I can get the
> current user junt using single line... :)
>
> One question... these locals variable, change for each connection?
> example:  I have 1 site, and I want to get several models, with FK for each
> user.. so.. User1 can only see data from him.. that's the reason I need to
> filter...  Works like these?
>
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \
> 's/(.)/chr(ord($1)-2*3)/ge'
> *Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
> *
> *Blog: *http:www.fellipeh.eti.br
> *GitHub: https://github.com/fellipeh *
> *Twitter: @fh_bash*
>
>
> On Sun, Aug 19, 2018 at 5:14 AM Andréas Kühne 
> wrote:
>
>> What you can do is add a middleware that sets the current user in a
>> thread local variable. That way you can then add a custom model manager
>> that reads that variable.
>>
>> Then all of your filters will be set automatically.
>>
>> Regards,
>>
>> Andréas
>>
>> 2018-08-18 17:46 GMT+02:00 Fellipe Henrique :
>>
>>> Thanks Jason,
>>>
>>> But, can I get current user on model manager? I need to filter with that
>>> info.
>>>
>>>
>>>
>>> T.·.F.·.A.·. S+F
>>> *Fellipe Henrique P. Soares*
>>>
>>> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \
>>> 's/(.)/chr(ord($1)-2*3)/ge'
>>> *Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
>>> *
>>> *Blog: *http:www.fellipeh.eti.br
>>> *GitHub: https://github.com/fellipeh *
>>> *Twitter: @fh_bash*
>>>
>>>
>>> On Sat, Aug 18, 2018 at 9:10 AM Jason  wrote:
>>>
 make a custom model manager for that model.

 https://docs.djangoproject.com/en/2.1/topics/db/managers/
 #custom-managers

 --
 You received this message because you are subscribed to the Google
 Groups "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/63e2765e-96a6-4283-ba6b-7c8ac5f25cb3%
 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/CAF1jwZEoRS0%3DqOmoOcViUH_HseiLTe1670p6i%3DMQYBxG%
>>> 2BYeKjA%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/CAK4qSCfOVv3K_kzbT_F1yaheHbH5sECdOp70nNcMi-3_m%
>> 3DtDXw%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

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

2018-08-20 Thread Michal Petrucha
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On Fri, Aug 17, 2018 at 05:44:22AM -0700, Web Architect wrote:
> Hi,
> 
> We are using persistent django sessions for our website where in the 
> session information is stored in MySQL. Over last couple of years, the 
> session data has grown to a huge number and we were planning to clean it up.
> I know that there is a django management command 'clearsessions' and we are 
> using the same as a daily cronjob.
> But our challenge is we have long expiry timelines of like 100 years so 
> that our users are never logged out (unless they clear their cookies etc). 
> Hence, the clearsessions won't help. 
> 
> The solution we are looking for are removing the sessions which are never 
> used for a long period. Let's say a user never came to our site for 3 
> months after last logging in. We would like to purge those sessions. Would 
> really appreciate if anyone could suggest any such solution - be it in 
> Django or if we need to custom build it.
> 
> Thanks.

There is another de-facto standard solution to this problem, which
does not involve setting the session expiry to years – it's usually
referred to as “persistent authentication cookie”. That way, sessions
would expire after the usual short period of time, and it also makes
the persistent login feature optional for your users.

I haven't found a maintained package that would implement this for
Django applications, but you can find a bunch of material on this
topic. For example, this article seems to consider a lot of potential
attack vectors:
https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title.2

Michal
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBCgAGBQJben3lAAoJEHA7T/IPM/klRiMQAKnoqOWIrbQDiDcaARde9jl+
SuPfHZP/H44t7z610+CC2D03C4hps+7acQWslH2S+WFL/+VUJPqytGTWsAJbs12A
/R+UaIlwDGFMeRBw2xdDusZtbE4t+atGS5PPgr8hEW89/op9/DruSed1cVxoUiBp
pwNwBst+cieNhtBYpXBUCe8mRxRegc8xCz/pKRw9ZycszYgB4rTpDVwOFMmxPWuS
rKDRgMsXhYQskiGWi5oSHQ8xEgxBeGXdv3HnlwCm9TenXs1gfVQwbRhG4btivCUD
nzhpUTtHx3PP5/uDK0GM87MqB6ufuf7H/7QXgFKTWBZxSeOXwaxICsxYaG54DMld
hYxFk36RtjufWgcffQooBfw3eavtzAnPdjlZzEI3ZYj5fPx9agGJf177JAVSCovS
bppF1QbipuIfQlLyv7gee8bR6a6uLEQZ4vp9NHrfqWjXYqmIDxubnVB5B1/d6yvG
S9liRlkoGAWC9tTS5ig03QV1b4nBlJIonKIRBecrfJXHw3G2WojY8HAiSyyz9A4P
S/XcvOzK7dWsw/NUmx84GkR3SGfFeQor3bVWUeBhG6BBOjZq6cj+MHa2gZswIIYa
d6dHRCa4hyDwBLZDaEbI4EDbIkrY82L87PD9KW+0xbBYojwysQz8pL/3WHc8F1NL
0VXYCCnD/4/LdzywjR21
=njLP
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20180820083758.GS1181%40konk.org.
For more options, visit https://groups.google.com/d/optout.


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

2018-08-20 Thread Avraham Serour
maybe something like this could be useful for your use case:
https://pypi.org/project/django-session-timeout/
it has an option for SESSION_EXPIRE_AFTER_LAST_ACTIVITY


maybe this could also be useful for you:
https://django-session-security.readthedocs.io/en/latest/



On Mon, Aug 20, 2018 at 8:34 AM Web Architect  wrote:

> Hi Jason,
>
> Thanks for your response.
>
> As mentioned in my earlier post...I have a long expiry date for the
> sessions (and hence, the cookies)  as we want our users to be always logged
> in or in session (till they clear their cookies). And that's what is
> causing the issue.
>
> The goal is to keep the regular users logged in whereas flush out the non
> active users (even if their sessions haven't expired). Hence, was looking
> for a solution for the same.
>
> Thanks.
>
> On Saturday, August 18, 2018 at 5:39:19 PM UTC+5:30, Jason wrote:
>>
>> With database sessions out of the box, no.
>>
>>
>> https://github.com/django/django/blob/master/django/contrib/sessions/base_session.py
>>
>> You can see there are three attributes for a session model: key, data and
>> expire_date
>>
>> That said, since sessions are backed by browser cookies, django's default
>> is two weeks for session cookies as you can see at
>> https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-SESSION_COOKIE_AGE,
>> which are used here:
>> https://github.com/django/django/blob/master/django/contrib/sessions/backends/base.py#L225-L244
>>
>> So if you haven't altered that, all sessions expire in two weeks, and you
>> can just delete those expired sessions by using the clearsessions
>> management command
>> 
>> .
>>
>> if you have changed that, then what Hemendra suggested above seems like a
>> reasonable approach, but one that is not backwards compatible if you don't
>> have a timestamp field for last access
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4794450f-ad83-4a00-96e3-f354745b322b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Possible bug: Querying a model with an IntegerField value of 0 using mysql-connector/python returns a queryset where the field value becomes a NoneType 2.0.3.0

2018-08-20 Thread Marcus Grass
Yeah I know it's recommended, but I can't for the life of my get that
connector to work in windows.
I program my project both in places where  I only have windows and only Linux.

On Mon, Aug 20, 2018 at 2:20 AM, Jason  wrote:
> that is indeed weird, but suggests its an issue with python-mysql-connector,
> not django.
>
> https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-db-api-drivers
>
> As you can see there, mysqlclient is the django project recommended way to
> interface with mysql.  What are your reasons for going with
> mysql-connector-python?
>
>
> On Sunday, August 19, 2018 at 6:15:44 PM UTC-4, Marcus Grass wrote:
>>
>> Hi, I ran into a strange problem when i switched from using mysqlclient to
>> mysql-connector/python.
>>
>> In practice:
>> class Foo(models.Model):
>>  bar = models.IntegerField(default=0, null=False)
>>
>> queryset = Foo.objects.all().filter(bar=0)
>> print(queryset[0].bar)  # prints None
>>
>>
>> Anyone know a fix for this?
>>
>> Using python 3.6.6, Django 2.0.3.0-
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/6be9073b-34f1-445f-ba02-dabf09c9916c%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/CAAr%2BttSinXmddnHwEsoQz9ROkcrbe0UhfTsXs0V%2B89ZrB1YGOA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fail to create Django registration form with email and password only

2018-08-20 Thread Mikhailo Keda
No need to change Django registration/authentication, you need to use it.

Check this example - https://chat.mkeda.me/login?next=/
source code for registration/authentication 
- 
https://bitbucket.org/voron-raven/chat/src/f78b6531652f866109dbfa2f8aeffac6c0f1bb32/core/views.py#lines-247:283
Just set username same as email.

-- 
You received this message because you are subscribed to the Google Groups 
"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/c07aa488-d4e3-4a81-a0b4-801c8a00259c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.