Mysql connector for python 3.7

2018-09-18 Thread rojasrajan85477
Unable to find a connector for python 3.7 on windows 
Does anyone know how to get 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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3d5c4c73-319e-49ff-a594-57859b4a0607%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Mysql connector for python 3.7

2018-09-18 Thread suneel singh
If mysqlclient module is not installed than you should we try
PyMysql  module
   Or
Mysql-connector-python
Or
Libmysql

In python 3.7

On Tue, 18 Sep 2018, 4:55 p.m. ,  wrote:

> Unable to find a connector for python 3.7 on windows
> Does anyone know how to get 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3d5c4c73-319e-49ff-a594-57859b4a0607%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/CAH%3DJJYK%3Dqg5M%2B6KCo531t6Mf-5LsHO2PLpiLKfipvT7EgOKFCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to update if user exist instead of create?

2018-09-18 Thread Django Lover
How i can update model when Key exist else create a new one??
 

My code is-
 
**Form.py**

class UserSettingForm(forms.ModelForm):
 class Meta:
   model = StUserSetting
   fields = ( 'default_language', 'prim_currency', 'number_format', 
'decimal_format',
'date_format', 'time_format', 'currency_format', 
'currency_position', 'financial_year_start', 
 'week_start', 'estimate_default_tab', 'invoice_default_tab',)

**View.py**


class CreateUpadateUserSetting(LoginRequiredMixin, FormView):
 template_name = 'settings/user_settings.html'
 form_class = UserSettingForm
 success_url = '/user/setting/preference/'


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


Re: How to update if user exist instead of create?

2018-09-18 Thread Larry Martell
On Tue, Sep 18, 2018 at 8:13 AM, Django Lover  wrote:
> How i can update model when Key exist else create a new one??
>
>
> My code is-
>
> **Form.py**
>
> class UserSettingForm(forms.ModelForm):
>  class Meta:
>model = StUserSetting
>fields = ( 'default_language', 'prim_currency', 'number_format',
> 'decimal_format',
> 'date_format', 'time_format', 'currency_format',
> 'currency_position', 'financial_year_start',
>  'week_start', 'estimate_default_tab', 'invoice_default_tab',)
>
> **View.py**
>
>
> class CreateUpadateUserSetting(LoginRequiredMixin, FormView):
>  template_name = 'settings/user_settings.html'
>  form_class = UserSettingForm
>  success_url = '/user/setting/preference/'

https://docs.djangoproject.com/en/2.1/ref/models/querysets/#update-or-create

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


Re: How to update if user exist instead of create?

2018-09-18 Thread Django Lover
Thanks, Larry for replying. I want to say I am new in Django and I 
don't know how to use in class-based view, Can you help me to 
integrate with CBV?

On Tuesday, September 18, 2018 at 5:57:28 PM UTC+5:30, larry@gmail.com 
wrote:
>
> On Tue, Sep 18, 2018 at 8:13 AM, Django Lover  > wrote: 
> > How i can update model when Key exist else create a new one?? 
> > 
> > 
> > My code is- 
> > 
> > **Form.py** 
> > 
> > class UserSettingForm(forms.ModelForm): 
> >  class Meta: 
> >model = StUserSetting 
> >fields = ( 'default_language', 'prim_currency', 
> 'number_format', 
> > 'decimal_format', 
> > 'date_format', 'time_format', 'currency_format', 
> > 'currency_position', 'financial_year_start', 
> >  'week_start', 'estimate_default_tab', 
> 'invoice_default_tab',) 
> > 
> > **View.py** 
> > 
> > 
> > class CreateUpadateUserSetting(LoginRequiredMixin, FormView): 
> >  template_name = 'settings/user_settings.html' 
> >  form_class = UserSettingForm 
> >  success_url = '/user/setting/preference/' 
>
>
> https://docs.djangoproject.com/en/2.1/ref/models/querysets/#update-or-create 
>

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


django ORM with asyncio

2018-09-18 Thread luke lukes


I'm looking for something that can allow the usage of the Django ORM with 
asyncio (with PostgreSQL). 

As of now I found only aiopg  in the 
*asyncio 
ecosystem* , which allows to run raw SQL or to 
use SQLAlchemy only.


I then found something in the django channels docs 

. 


is this:

https://github.com/django/channels/blob/master/channels/db.py


the missing piece that I was looking for?


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/2af17ca1-6d48-45b0-9406-37e046934567%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Running django tests with postgres

2018-09-18 Thread Bill-Torcaso-Oxfam

I two comments, and as always Your Milage May Vary.


   - I wonder if you have the right indexes on your Postgres database? The 
   previous people report much faster completion times for test that use 
   Postgres as the database.  Perhaps your domain is just hard (and you 
   description makes it sound that way), but "Explain Plan" might be your best 
   friend here.
   
   - Sqlite does not enforce length limit constraints on text fields.  You 
   can declare a field to be CharField(max_length=200), and Sqlite will 
   happily put a longer string into the field.  Postgres will not.
   
   This came up when I was importing data from an older generation of our 
   product.  My custom import code ran successfully against Sqlite and the 
   exact same command failed against Postgres.
   
   - (And yes, I said only two points.  But this just occurs to me...)
   
   Can you divide your test suite into distinct independent chunks, and run 
   them in parallel?  Either against one common database or using one database 
   per test-chunk?
   
   
On Friday, September 14, 2018 at 11:32:49 AM UTC-4, Hezi Halpert wrote:
>
> I would like to share with you an issue we encounter while moving from 
> sqlite to postgres with heavily use of Django testing.
>
> We have Django app with ~700 tests. Most of them accessing database. We 
> recently migrated the database from sqlite to postgres. 
> Many of our tests were written in a way that compares actual pk’s 
> (hard-coded pks or just file/json comparisons) . Since Django testing on 
> sqlite (testcases.TestCase class) creates in-memory database (which is 
> being reseted every unit test by default), we never had a problem with it.
> However, Django TestCase on postgres create completely another test db 
> which preserves the pk sequences between different tests. And since many of 
> our tests were written in a way that compares actual pk’s they all start 
> fail - depends on the exact tests execution order.
> Even tests which expect some pk and are were not failed yet, can 
> potentially failed in the future - depends on adding/editing other tests 
> which may change the db sequence
>
> We consider the following solutions:
>
>1. Move to TransactionTestCase (instead of TestCase) and use 
>“reset_sequences = True” flag. Cons: TransactionTestCase reduces 
>performance dramatically (~4 times longer in some of the tests) 
>2. Refactor all failed tests: remove all hard-coded references to the 
>pk. Cons: Require much Dev effort (we had more then 70 such tests)
>3. Route the database in settings.py such it will use sqlite instead 
>of postgres when running tests. Cons: It will not actually test the real 
>scenarios - not an option
>4. Combine reset_sequences flag with TestCase in our own version to 
>TestCase: OurTestCase class and make everything to inherit from it. This 
> is 
>the option we finally decided of. See below.
>
>
> from django.test import TestCase, testcases
>
>
> class OurTestCase(TestCase):
> reset_sequences = True
>
> def _fixture_setup(self):
> for db_name in self._databases_names(include_mirrors=False):
> if self.reset_sequences:
> self._reset_sequences(db_name)
> if self.fixtures:
> call_command('loaddata', *self.fixtures, **{'verbosity': 0, 
> 'database': db_name})
> if not testcases.connections_support_transactions():
> self.setUpTestData()
> return super(TestCase, self)._fixture_setup()
> self.atomics = self._enter_atomics()
>
>
> Another problem of these kind of tests is the default ordering assumption 
> of Django which changes significantly between postgres and sqlite when 
> testing.
> Therefore, models included in such tests must have a hint for Django 
> regarding the default ordering retrieval. 
> Our solution was to make all models inherit from DexterModelDefaultOrder 
> (below) 
>
>
> class DexterModelDefaultOrder(models.Model):
> class Meta:
> abstract = True
> ordering = ['id']
>
>
>
> I hope it (will) help someone
>
>

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


How to get the name and url of an uploaded file when using models.FileField

2018-09-18 Thread Joel Mathew
How to get the name and url of an uploaded file?

I am using the following files:

settings.py:

MEDIA_URL = '/data/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'data')

urls.py:
urlpatterns = [
path("photo/upload", views.upload_pic, name="uploadpic ")
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

models.py:

class Pic(models.Model):
name = models.CharField(max_length=255)
photo = models.FileField(upload_to="data/media/%Y/%m/%d")
def __str__(self):
return self.url
def path(self):
return self.url

forms.py:

from django import forms
class DocumentForm(forms.Form):
docfile = forms.FileField(
label='Select a file',
help_text='any valid file'
)

views.py:

def upload_pic(request):
documents = Pic.objects.all()
import uuid
name = uuid.uuid4().hex[:6].upper()
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
print(request.FILES)
newdoc = Pic(name=name, photo=request.FILES['docfile'])
newdoc.save()
return render(request, 'clinic/list.html', {'documents':
documents, 'form': form, 'msg': 'success'})
else:
form = DocumentForm()  # A empty, unbound form
return render(request, 'clinic/list.html', {'documents': documents,
'form': form})

template: clinic/list.html

{% extends 'clinic/newbase.html' %}
{% load static %}
{% block content %}

{% csrf_token %}

Upload

{% if uploaded_file_url %}
File uploaded at: {{
uploaded_file_url }}
{% endif %}
Return to home
{% endblock %}

However in the rendered html, the urls are blank:























Select a file: max. 42
megabytes







How can I get the media name and url in the rendered template?

Sincerely yours,

Joel G Mathew

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


Django Admin Multiple Models and Dropdown list

2018-09-18 Thread mab . mobile . 01
I have the following models and admin files and I would like to be able to 
show the text representation of the ExpenseCategory category field in the 
dropdown list on the Admin page. However, the dropdown list is displaying 
"ExpenseCategory Object(n)" instead of the actual text category such as 
"Utilities", "Office Supplies" etc. 

I need to insert the ExpenseCategory pk in the Expenses table but want a 
human readable drop down list to show the category text instead. 

Any guidance would be appreciated. Thanks in advance..
  

MAIN/MODELS>PY

class ExpenseCategory(models.Model):
category = models.CharField(max_length=200)
deductible = models.TextField(choices=BOOLEAN_CHOICE)

def __int__(self):
   return self.category

class Expenses(models.Model):
expense = models.CharField(max_length=200)
category = models.ForeignKey(ExpenseCategory, on_delete=models.PROTECT)
expense_amount = models.DecimalField(max_digits=8, decimal_places=2)
expense_date = models.DateField(auto_now_add=False)
expense_type = models.TextField(choices=SOURCE)
description = models.CharField(max_length=200)
source = models.CharField(max_length=200)

def __int__(self):
   return self.expense

MAIN/ADMIN.PY

class ExpenseCategoryAdmin(admin.ModelAdmin):
   list_display = ['category','deductible']
   list_filter = ['deductible']

admin.site.register(models.ExpenseCategory, ExpenseCategoryAdmin)

class ExpensesAdmin(admin.ModelAdmin):
   list_display = 
['expense','expense_amount','expense_date','category','expense_type']
   list_filter = ['expense_date','category','expense_type']

admin.site.register(models.Expenses, ExpensesAdmin)



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


Re: Django Admin Multiple Models and Dropdown list

2018-09-18 Thread Julio Biason
Hey Mab,

You probably need to replace you `__init__` to `__str__`. They are two
different things.

On Tue, Sep 18, 2018 at 12:18 PM,  wrote:

> I have the following models and admin files and I would like to be able to
> show the text representation of the ExpenseCategory category field in the
> dropdown list on the Admin page. However, the dropdown list is displaying
> "ExpenseCategory Object(n)" instead of the actual text category such as
> "Utilities", "Office Supplies" etc.
>
> I need to insert the ExpenseCategory pk in the Expenses table but want a
> human readable drop down list to show the category text instead.
>
> Any guidance would be appreciated. Thanks in advance..
>
>
> MAIN/MODELS>PY
>
> class ExpenseCategory(models.Model):
> category = models.CharField(max_length=200)
> deductible = models.TextField(choices=BOOLEAN_CHOICE)
>
> def __int__(self):
>return self.category
>
> class Expenses(models.Model):
> expense = models.CharField(max_length=200)
> category = models.ForeignKey(ExpenseCategory,
> on_delete=models.PROTECT)
> expense_amount = models.DecimalField(max_digits=8, decimal_places=2)
> expense_date = models.DateField(auto_now_add=False)
> expense_type = models.TextField(choices=SOURCE)
> description = models.CharField(max_length=200)
> source = models.CharField(max_length=200)
>
> def __int__(self):
>return self.expense
> 
> MAIN/ADMIN.PY
>
> class ExpenseCategoryAdmin(admin.ModelAdmin):
>list_display = ['category','deductible']
>list_filter = ['deductible']
>
> admin.site.register(models.ExpenseCategory, ExpenseCategoryAdmin)
>
> class ExpensesAdmin(admin.ModelAdmin):
>list_display = ['expense','expense_amount','expense_date','category','
> expense_type']
>list_filter = ['expense_date','category','expense_type']
>
> admin.site.register(models.Expenses, ExpensesAdmin)
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/b0d5e22e-2d20-4e11-ac22-00fb1eb9794f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


Re: Django Admin Multiple Models and Dropdown list

2018-09-18 Thread mab . mobile . 01
Hi Julio, 

Thank you so much. I should have picked that up myself. It worked!

Thanks again.

Marc

On Tuesday, September 18, 2018 at 10:30:20 AM UTC-5, Julio Biason wrote:
>
> Hey Mab,
>
> You probably need to replace you `__init__` to `__str__`. They are two 
> different things.
>
> On Tue, Sep 18, 2018 at 12:18 PM, > 
> wrote:
>
>> I have the following models and admin files and I would like to be able 
>> to show the text representation of the ExpenseCategory category field in 
>> the dropdown list on the Admin page. However, the dropdown list is 
>> displaying "ExpenseCategory Object(n)" instead of the actual text category 
>> such as "Utilities", "Office Supplies" etc. 
>>
>> I need to insert the ExpenseCategory pk in the Expenses table but want a 
>> human readable drop down list to show the category text instead. 
>>
>> Any guidance would be appreciated. Thanks in advance..
>>   
>>
>> MAIN/MODELS>PY
>>
>> class ExpenseCategory(models.Model):
>> category = models.CharField(max_length=200)
>> deductible = models.TextField(choices=BOOLEAN_CHOICE)
>>
>> def __int__(self):
>>return self.category
>>
>> class Expenses(models.Model):
>> expense = models.CharField(max_length=200)
>> category = models.ForeignKey(ExpenseCategory, 
>> on_delete=models.PROTECT)
>> expense_amount = models.DecimalField(max_digits=8, decimal_places=2)
>> expense_date = models.DateField(auto_now_add=False)
>> expense_type = models.TextField(choices=SOURCE)
>> description = models.CharField(max_length=200)
>> source = models.CharField(max_length=200)
>>
>> def __int__(self):
>>return self.expense
>> 
>> MAIN/ADMIN.PY
>>
>> class ExpenseCategoryAdmin(admin.ModelAdmin):
>>list_display = ['category','deductible']
>>list_filter = ['deductible']
>>
>> admin.site.register(models.ExpenseCategory, ExpenseCategoryAdmin)
>>
>> class ExpensesAdmin(admin.ModelAdmin):
>>list_display = 
>> ['expense','expense_amount','expense_date','category','expense_type']
>>list_filter = ['expense_date','category','expense_type']
>>
>> admin.site.register(models.Expenses, ExpensesAdmin)
>>
>>
>>
>> -- 
>> You received this message because you are subscribed 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/b0d5e22e-2d20-4e11-ac22-00fb1eb9794f%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101  |  Mobile: +55 51 *99907 0554*
>

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


Readonly ModelChoiceField of type in model foreignkey

2018-09-18 Thread nelson fernando garcia gomez
Hola estoy tratando en mi formulario (formsModel) implementar el atributo 
de *readonly*  a una foreignkey (ModelChoiceField)
pero no es posible alguna ayuda por favor GRACIAS así lo estoy haciendo: 
class CostoForm(forms.ModelForm):

"""
Edicion de Costos con formset.
"""
class Meta:
model = Costo
exclude = ('user', )

def __init__(self, *args, **kwargs):
super(CostoForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_action = ''
self.helper.form_class = 'form-inline'
self.helper.template = 'crispy_template/table_inline_formset.html'
self.helper.layout = Layout(
Field('DELETE', css_class='btn btn-primary')
)
self.helper.add_input(Submit('submit', _('Aceptar')))
self.fields['destination'].widget.attrs['readonly'] = True



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


Re: django ORM with asyncio

2018-09-18 Thread Andrew Godwin
The Django ORM can't just be used with asyncio directly, sadly. The
database_sync_to_async function you found there will help you call the ORM
from asynchronous code, but it still runs the ORM in a synchronous thread
(see https://channels.readthedocs.io/en/latest/topics/databases.html)

The project to make the ORM truly async is a tough one and yet to be
started.

Andrew

On Tue, Sep 18, 2018 at 5:55 AM luke lukes  wrote:

> I'm looking for something that can allow the usage of the Django ORM with
> asyncio (with PostgreSQL).
>
> As of now I found only aiopg  in the 
> *asyncio
> ecosystem* , which allows to run raw SQL or
> to use SQLAlchemy only.
>
>
> I then found something in the django channels docs
> 
> .
>
>
> is this:
>
> https://github.com/django/channels/blob/master/channels/db.py
>
>
> the missing piece that I was looking for?
>
>
> 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/2af17ca1-6d48-45b0-9406-37e046934567%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/CAFwN1uq7sZPzw1M6DJAqrFs7pttFz6PWemobgHogCsN6PR-jpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django on Heroku + AWS S3 thumbnails & originals

2018-09-18 Thread Mateusz
Hi,
I am a newbie in Django so my question may be a little bit odd. I tried 
looking here, on Stack and also GitHub and trying for 5 hours.

I try to host a project on Heroku dyno with AWS S3 as a media storage 
service (images sent by users). My case may be a bit specific cause I *must 
*store originals as well as thumbnails and they both have to be placed in 
the same folder (folder/.../images/...; I have no access to that AWS 
account and can't change that). I store the originals correctly, what 
bothers me are thumbnails.

I tried multiple techniques found on the internet:

   1. sorl-thumbnail have not worked locally (I do not remember pushing it 
   to Heroku feeling it was senseless, probably should have done that?);
   2. django-imagekit with ImageSpecField in model and ResizeToFill in 
   processors and original image ImageField as a source – worked locally but 
   failed because it saves thumbnails into CACHE folder;
   3. easy-thumbnails with THUMBNAIL_ALIASES and all necessary things – 
   again, worked locally saving into the folder I wanted, with a suffix, but 
   it failed to load images on Heroku (the address was looking OK, following 
   the same pattern as locally, but the image was not loading);
   4. I tried the same as in 3. with THUMBNAIL_CACHE_DIMENSIONS set both to 
   True and False – nothing changed;
   5. And also added THUMBNAIL_DEFAULT_STORAGE as 
   storages.backends.s3boto.S3BotoStorage – still not working.
   
I had two more ideas but I had no time to try them:

   1. using django-imagekit with ProcessedImageField but it does not make 
   an auto-copy of an image (am I right?). A combination of 
   ProcessedImageField (source) with ResizeToFill (upload_to) would be perfect 
   (found something like cache_to or cache_as on the internet, but it have not 
   worked at all – there's no such option);
   2. using pre_save signal making a hard copy of the image and saving it 
   resized by Pillow into another ImageField specified in the model.

Does any of package on that list 
https://djangopackages.org/grids/g/thumbnails/ fulfill my needs? If that's 
possible, I'd like the package to be stable. It does not have to be 
superfast.

Thank you in advance for answering ;)

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


Re: Running django tests with postgres

2018-09-18 Thread Mike Dewhirst

Bill

I'm about to disappear for a few days. Thank you very much for your 
suggestions - I'll tackle them when I get back.


Cheers

Mike

On 18/09/2018 11:34 PM, Bill-Torcaso-Oxfam wrote:


I two comments, and as always Your Milage May Vary.

  * I wonder if you have the right indexes on your Postgres database?
The previous people report much faster completion times for test
that use Postgres as the database.  Perhaps your domain is just
hard (and you description makes it sound that way), but "Explain
Plan" might be your best friend here.

  * Sqlite does not enforce length limit constraints on text fields. 
You can declare a field to be CharField(max_length=200), and
Sqlite will happily put a longer string into the field.  Postgres
will not.

This came up when I was importing data from an older generation of
our product.  My custom import code ran successfully against
Sqlite and the exact same command failed against Postgres.

  * (And yes, I said only two points.  But this just occurs to me...)

Can you divide your test suite into distinct independent chunks,
and run them in parallel?  Either against one common database or
using one database per test-chunk?

On Friday, September 14, 2018 at 11:32:49 AM UTC-4, Hezi Halpert wrote:

I would like to share with you an issue we encounter while moving
from sqlite to postgres with heavily use of Django testing.

We have Django app with ~700 tests. Most of them accessing
database. We recently migrated the database from sqlite to postgres.
Many of our tests were written in a way that compares actual pk’s
(hard-coded pks or just file/json comparisons) . Since Django
testing on sqlite (testcases.TestCase class) creates in-memory
database (which is being reseted every unit test by default), we
never had a problem with it.
However, Django TestCase on postgres create completely another
test db which preserves the pk sequences between different tests.
And since many of our tests were written in a way that compares
actual pk’s they all start fail - depends on the exact tests
execution order.
Even tests which expect some pk and are were not failed yet, can
potentially failed in the future - depends on adding/editing other
tests which may change the db sequence

We consider the following solutions:

 1. Move to TransactionTestCase (instead of TestCase) and use
“reset_sequences = True” flag. Cons:
TransactionTestCase reduces performance dramatically (~4 times
longer in some of the tests)
 2. Refactor all failed tests: remove all hard-coded references to
the pk. Cons: Require much Dev effort (we had more then 70
such tests)
 3. Route the database in settings.py such it will use sqlite
instead of postgres when running tests. Cons: It will not
actually test the real scenarios - not an option
 4. Combine reset_sequences flag with TestCase in our own version
to TestCase: OurTestCase class and make everything to inherit
from it. This is the option we finally decided of. See below.


fromdjango.test import TestCase, testcases

class OurTestCase(TestCase):
 reset_sequences =True def _fixture_setup(self):
 for db_namein self._databases_names(include_mirrors=False):
if self.reset_sequences:
 self._reset_sequences(db_name)
 if self.fixtures:
call_command('loaddata', *self.fixtures, **{'verbosity':0,'database': 
db_name})
 if not testcases.connections_support_transactions():
self.setUpTestData()
 return super(TestCase,self)._fixture_setup()
 self.atomics =self._enter_atomics()

Another problem of these kind of tests is the default ordering
assumption of Django which changes significantly between postgres
and sqlite when testing.
Therefore, models included in such tests must have a hint for
Django regarding the default ordering retrieval.
Our solution was to make all models inherit from
DexterModelDefaultOrder (below)


class DexterModelDefaultOrder(models.Model):
 class Meta:
 abstract =True ordering = ['id']

I hope it (will) help someone

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1e8ec552-d793-4161-ba10-070263586698%40googlegroups.com 


Re: django-filter over models

2018-09-18 Thread Mateusz
In that answer I assume Jobs are connected anyhow with Persons with a 
ForeignKey field like so:

*File /appname/models.py:*

from django.db import models


class Job(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name


class Person(models.Model):
name = models.CharField(max_length=100)
surname = models.CharField(max_length=100)

job = models.ForeignKey(Job, on_delete=models.SET_NULL, null=True, 
default=None)

def __str__(self):
return self.name + ' ' + self.surname


*File /appname/views.py:*

from django.shortcuts import render
from django.views.generic.list import ListView

from appname.models import Job, Person


class JobsWithPersonsView(ListView):
queryset = Job.objects.all()
template_name = 'jobs_list.html'



*File /appname/templates/jobs_list.html:*





Jobs


{% for job in object_list %}
{{ job.name }}
{% for person in job.person_set.all %}
{{ person.name }} {{ person.surname }}
{% empty %}
Nobody works there.
{% endfor %}
{% empty %}
No jobs.
{% endfor %}




And others you probably know how to deal with...
File /urls.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('appname/', include('appname.urls'))
]


*File /appname/urls.py:*

from django.urls import path
from appname import views

urlpatterns = [
path('jobslist/', views.JobsWithPersonsView.as_view(), name='jobslist')
]


*BTW: *Your model names should be in singular form, if you want to be able 
to use plural forms in some cases, use verbose_name_plural (docs 

).

W dniu czwartek, 13 września 2018 05:26:20 UTC+2 użytkownik René L. 
Hechavarría napisał:
>
> Hello,
>
> I have a model, Jobs and Persons, Jobs are listed in ListView, i need to 
> add a filter (django-filter), if i filter over field in Jobs all work good, 
> but i need to filter also for Persons. this is and example
>
> @property
> def get_persons(self):
> return self.persons_all.all()
>
>
> That allow to add persons to Jobs model in de html. How i filter over 
> persons in Jobs view?
>
> Thanks in advance.
>
>
>
>

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


Re: django-filter over models

2018-09-18 Thread Mateusz
Sorry, my previous answer was senseless, I realized that just after adding 
it.

1) You can filter jobs in appname/views.py:

queryset = Job.objects.filter(name__contains="job")


2) and people in template /appname/templates/jobs_list.html:

{% for job in object_list %}
{{ job.name }}
{% for person in job.person_set.all %}
{% if person.name|length <= 4 %}
{{ person.name }} {{ person.surname }}
{% endif %}
{% empty %}
Nobody works there.
{% endfor %}


I still find that 2) inefficient, but could do anything else. Read 
something about registering filters that I do not understand that well, 
sorry.

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


Re: Readonly ModelChoiceField of type in model foreignkey

2018-09-18 Thread Mateusz
(use traductor si necesita)

I hope I understand your question correctly.

When in Django 1.8 or 1.9+ you can just do
self.fields['destination'].disabled = True

in lower versions you should add
self.fields['destination'].widget.attrs['disabled'] = True
at the end of your __init__(..).


W dniu wtorek, 18 września 2018 20:58:26 UTC+2 użytkownik nelson fernando 
garcia gomez napisał:
>
> Hola estoy tratando en mi formulario (formsModel) implementar el atributo 
> de *readonly*  a una foreignkey (ModelChoiceField)
> pero no es posible alguna ayuda por favor GRACIAS así lo estoy haciendo: 
> class CostoForm(forms.ModelForm):
>
> """
> Edicion de Costos con formset.
> """
> class Meta:
> model = Costo
> exclude = ('user', )
>
> def __init__(self, *args, **kwargs):
> super(CostoForm, self).__init__(*args, **kwargs)
> self.helper = FormHelper()
> self.helper.form_tag = False
> self.helper.form_action = ''
> self.helper.form_class = 'form-inline'
> self.helper.template = 'crispy_template/table_inline_formset.html'
> self.helper.layout = Layout(
> Field('DELETE', css_class='btn btn-primary')
> )
> self.helper.add_input(Submit('submit', _('Aceptar')))
> self.fields['destination'].widget.attrs['readonly'] = True
>
>
>
>

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


Re: How to update if user exist instead of create?

2018-09-18 Thread Mateusz
Just for the record, you should probably consider using CreateView and 
UpdateView (docs 
) 
if possible. ;)
Here is an example (Stack ).

W dniu wtorek, 18 września 2018 14:13:20 UTC+2 użytkownik Django Lover 
napisał:
>
> How i can update model when Key exist else create a new one??
>  
>
> My code is-
>  
> **Form.py**
>
> class UserSettingForm(forms.ModelForm):
>  class Meta:
>model = StUserSetting
>fields = ( 'default_language', 'prim_currency', 'number_format'
> , 'decimal_format',
> 'date_format', 'time_format', 'currency_format', 
> 'currency_position', 'financial_year_start', 
>  'week_start', 'estimate_default_tab', 'invoice_default_tab',)
>
> **View.py**
>
>
> class CreateUpadateUserSetting(LoginRequiredMixin, FormView):
>  template_name = 'settings/user_settings.html'
>  form_class = UserSettingForm
>  success_url = '/user/setting/preference/'
>
>
>

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


Re: Beginner problem with sqlite3 db

2018-09-18 Thread Mateusz
Cześć! ;)

You should first answer a question, why do you even bother using dbshell 
when there's an other option to deal with data? (docs 

)
If you know why I'm asking, simply installing sqlite3 is gonna be the best 
option for you (download page ).


W dniu wtorek, 18 września 2018 01:38:57 UTC+2 użytkownik Robert 
Latoszewski napisał:
>
> Hi, 
> I'm going through "Writing your first Django app, part 2" link 
>  and 
> I have problem with sqlite3 db - I have created database tables with 
> migrate command (got db.sqlite3 file in my project folder) and I would like 
> to display those tables and have already tried milion ways with .schema 
> command but none of them worked. Any ideas what can be the problem? I 
> haven't installed sqlite3 beacuse documentation says that it's already 
> preinstalled with django, althoug when I tried "py manage.py dbshell" 
> command error appeared: "You appear not to have the 'sqlite3' program 
> installed or on your path."
> Django==2.1.1 on Windows (tried to see this db with Powershell). 
> Any help will be appreciated. 
>

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


Possible bug while using migrate or maybe not.

2018-09-18 Thread vineeth sagar

>
> So I had a migration which can be found below, so when I was applying the 
> migration I get this error  You can't delete all columns with ALTER TABLE; 
> use DROP TABLE instead  That makes sense because I have only a single 
> column. When I use the code sample 2 it works nicely.  Can anyone explain 
> the motivation behind removing fields first and then deleting a model,One 
> case I think of is seeing if the deletion of a field is valid(In case of 
> foreign keys and models.PROTECT), wouldn't sql throw an error anyway. So if 
> this is indeed a bug/Improvement I will be glad to help, if it isn't I 
> would be happy with anyone explaining why this would/should be the way to 
> delete models.



Code Sample 1

class Migration(migrations.Migration):

dependencies = [
('login', '0003_session'),
]

operations = [
migrations.RemoveField(
model_name='session',
name='session_ptr',
),
migrations.DeleteModel(
name='Session',
),
]

 
Code Sample 2

class Migration(migrations.Migration):

dependencies = [
('login', '0003_session'),
]

operations = [
migrations.DeleteModel(
name='Session',
),
]

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