Re: Django ORM - better handling of connections

2018-05-14 Thread andre
Hello Simon. On Monday, May 14, 2018 at 6:15:50 PM UTC+1, Simon Charette wrote: > > > Is there a way to force Django to close the DB connection after each > operation (unless we're in an atomic block)? > > The only way I can think of achieving that is by bundling your own > database backend

Re: Django login() function works in production but not in development

2018-05-14 Thread 童话root
Hello there, I think the reason is that your login session is stored in the database. The two programs share a set of databases, so the login status is synchronized. The corresponding solution, then copy a set of databases, and clear the current login session. Hope you can solve your problem.

Django login() function works in production but not in development

2018-05-14 Thread pieceofkayk2718
Hey All, So I have a django project in a directory for production. I have the same exact project in a separate repository for development. I literally have copied and pasted my project over and the only changes I have made are switching debug from false to true. So my project has the same

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
It was a conditional statement, albeit a seemingly poorly constructed one. "If you had a million records you were trying to filter..." Would you not just replace "annotate" with "filter" and use the same DurationField() expression? Nevertheless, in my case, I would use the annotation for a

Re: Adding to all templates context via Middleware

2018-05-14 Thread Melvyn Sopacua
On maandag 7 mei 2018 17:59:02 CEST Daniel Roseman wrote: > I still don't understand what is being repeated or why. You need to specify > that in your settings, and you can add whatever context processors you > like. You don't need to specify it twice, so nothing is being repeated. What Bernd

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 16:42:49 CEST Matthew Pava wrote: > But if in your use case, you had a million records in which you were trying > to filter Full stop right there. No one is filtering anything in the original use case, so you're comparing apples and oranges. Filtering you would do in the

Re: How Can I Select Date Based on Monday Date?

2018-05-14 Thread Alexander Joseph
Ah yes, timedelta, thats what I meant instead of deltadate haha. Thanks again On Saturday, May 12, 2018 at 1:00:29 PM UTC-6, Alexander Joseph wrote: > > I'm building a timesheet app for employees and would like the employees to > be able to select a day of the week date based on what the date

Re: Django ORM - better handling of connections

2018-05-14 Thread Simon Charette
Hello André, > Is there a way to force Django to close the DB connection after each operation (unless we're in an atomic block)? The only way I can think of achieving that is by bundling your own database backend subclass and override execute() and the cursor subclass to close the connection

Re: First Django app tutorial

2018-05-14 Thread Cuneyt Mertayak
It will be a bit generic help: To understand what's going wrong with your code when you expect other type of behavior you can use debugging tools like: pdb or (if you use an IDE like pycharm) build-in IDE debugger (https://www.jetbrains.com/help/pycharm/debugging-django-templates.html,

Password reset in Django on nginx server writes to log file instead of sending email

2018-05-14 Thread Tom Tanner
I have a Django app running on a server with uWSGI and nginx. In my `local_settings.py` file I have this: ### # EMAIL SETUP # ### EMAIL_HOST = 'smtp.privateemail.com' EMAIL_HOST_USER = 'supp...@mydomain.com' EMAIL_HOST_PASSWORD = 'MY EMAIL

Django ORM - better handling of connections

2018-05-14 Thread andre
Hello. For the last 6 years I've been using gevent's greenlets to serve Django requests, instead of tying up a thread or a process, and this has served me well for web applications that deal with slow streaming clients, or have to call some slow external services mid-request, or are just

Django model's field dynamic choices

2018-05-14 Thread Marcin
I'm using Django 1.11. I cannot set dynamic choices for model's field because: - choices must be iterable, not function, - choices iterable is always coverted to list, - iterable is evaluated oat the module import stage. The whole thing is about iterable evaluation time. The data

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
Maybe it's just me, but I had a report I was generating that took 3.5 minutes to complete that utilized for loops and the ORM. I managed to generate the same report in 18 seconds using a RawSQL query. So what's the upside? Speed. I would understand if the times were comparable, but they're

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 15:38:01 CEST Matthew Pava wrote: > You could use the ORM to get the difference of two dates like so: > Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) - > F('dob'), output_field=DurationField())) >

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
You could use the ORM to get the difference of two dates like so: Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) - F('dob'), output_field=DurationField())) https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#cast

RE: Deploy on windows IIS

2018-05-14 Thread Matthew Pava
Yes, getting the right combination of mod_wsgi in Windows can be tricky. This URL is most helpful with that: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi Be sure to get the Apache with the correct Visual C runtime and the right number of bits. No, I don’t uninstall IIS because I’m using

Re: First Django app tutorial

2018-05-14 Thread Daniel Hepper
Your template looks fine, and as the question_text is displayed correctly, it probably safe to assume that your view is correct too. Two things you can check: - does this question actually have any related choices? You can check in the admin. - check your models.py if you actually named the model

First Django app tutorial

2018-05-14 Thread Yufenyuy Veyeh Didier
Hi everyone, I'm new to python and Django. I also think I am getting it well. But I have an issue with the first Django app tutorial. My questions display well redirect to the detail view well and to the vote view well. The problem I have is that my question does not display the 'choices' of

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On zondag 13 mei 2018 03:44:37 CEST Gerald Brown wrote: > As I have said previously, I am new to Django ORM so I would like to know > howto/find reference to Django ORM Query to the following SQL Select > statements: Do you want to use SQL or use Django? Pick one. > 1. From Mariadb. > > SELECT

Re: Unit testing models.py

2018-05-14 Thread Melvyn Sopacua
Hi Mark, On zondag 13 mei 2018 18:11:07 CEST Mark Phillips wrote: > What should be unit tested in models.py? I assume the storing of data and > retrieving of data from the database does not need to be tested, as I > further assume django has a full set of tests for those operations. You should

Re: Unit testing models.py

2018-05-14 Thread 'Anthony Flury' via Django users
I would agree with that - test any custom functionality - * Custom methods (including __str__ and __repr__) * custom managers * Triggers (that maybe save custom fields on update) * validations - testing to ensure that the right validation is performed on that field - i.e. you linked the

Re: I canot upload files how can i fix it

2018-05-14 Thread 'Anthony Flury' via Django users
What does the form contain ? Does the web page you get give you an upload button ? Does the code in the view get triggered ? Do you get any errors ? On 13/05/18 04:23, carlos.davalo...@tectijuana.edu.mx wrote:  views def ArticuloFormA(request,Materiaid):     Articulos =