Re: bulk add m2m relationship for multiple instances

2015-08-12 Thread Erik Cederstrand
> Den 12/08/2015 kl. 04.47 skrev yakkades...@gmail.com:
> 
> for row in rows:
> dp = DataPoint.objects.get(Taken_datetime=row['date']) 
> 
> sensorToAdd = []
> for sensor in sensors:
> s = Sensor.objects.get(Name=sensor.name, Value=sensor.value  )
> sensorToAdd.append( s )
> 
> dp.Sensors.add( sensorToAdd )
> 
> In the actually app I bulk create all the DataPoint and Sensor instances.  
> The problem is that |dp.Sensors.add( sensorToAdd )| does a lot of hits on the 
> db.  I want a way bulk add all the sensors.  

Try fetching all the data you need from the database up-front and place objects 
in a dict. Depending on the volume of your data, you may want to split this 
into reasonable batches:

  from django.db.models import Q

  datapoints = DataPoint.objects.filter(Taken_datetime__in={r['date'] for r in 
rows})
  datapoints_map = {(d.Taken_datetime, d) for d in datapoints}

  # To generate efficient SQL, make sure (name, value) pairs are unique
  unique_sensor_values = {(s.name, s.value) for s in my_list_of_sensors}
  sensors_q = Q()
  for name, value in my_unique_sensor_values:
  sensors |= Q(Name=name, Value=value) 
  sensors = Sensor.objects.filter(sensors_q)
  sensors_map = {((s.name, s.value), s) for s in sensors}

This reduces your queries to only two. You can then bulk-insert m2m relations 
per-object like this:

   for some_date, some_sensors in my_data:
   dp = datapoints_map[some_date]
   dp.Sensors.add(*[sensors_map[(s.name, s.value)] for s in some_sensors])


If you need better bulk-insert performance than this, you can convert the m2m 
relation between Sensor and DataPoint to an explicit m2m model. You can then 
bulk-insert all m2m relations in one go instead of per-object.

You should probably add indexes on DataPoint.Taken_datetime and Sensors.[Name, 
Value] to increase query performance.

Erik

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


Supprimer un COMMIT sur git

2015-08-12 Thread Bassirou Ndiaye
Bonjour j'ai commité une une nouvelle application sur GIT avec django et je 
veux l'annuler Comment faire?

-- 
You received this message because you are subscribed to the Google Groups 
"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/6e62ec0b-4f7f-46dc-9392-d430727fa95c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to specifyc validate_min and validate_max on contrib.Admin formset ? (From Django's code, it seems not)

2015-08-12 Thread boitoletre
Hi,

 I would need to enforce the max_num and min_num  attributes of formsets on 
my admin pages at validation time.
>From the documentation and the source, it seems that validate_max and 
validate_min would be the FormSet attributes that need to set to True for 
that to happen.

Yet, while investigating this issue, it seems to me that it is currently 
not possible to forward them to FromSet classes used in the Admin site:
1) From InlineModelAdmin.get_formset() code 
,
 
it is not useful to set validate_* on the inline itself, as it would not be 
forwarded to the inlineformset_factory() call on return.
2) From formset_factory() code 
,
 
it is not useful to set validate_* on the FormSet class itself, because it 
would be overwritten by the argument provided to the factory function.

Are you aware of a way to have the Admin instantiate FormSet classes with 
valide_min and validate_max set to true ?
If not, it seems to me it would be easy to allow it by extending the 
defaults dictionary in 1), so I am curious if there is a rationale for not 
allowing it, or if it is a simple oversight ?

Thank you very much for reading,
  Ad

-- 
You received this message because you are subscribed to the Google Groups 
"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/a13007d8-8591-479b-b82d-41ad8ab05636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ANN: eGenix mxODBC 3.3.4 - Python ODBC Database Interface

2015-08-12 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

 eGenix.com mxODBC

   Python ODBC Database Interface

   Version 3.3.4


mxODBC is our commercially supported Python extension providing
 ODBC database connectivity to Python applications
on Windows, Mac OS X, Unix and BSD platforms
   with many advanced Python DB-API extensions and
 full support of stored procedures


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-3.3.4-GA.html



INTRODUCTION

mxODBC provides an easy-to-use, high-performance, reliable and robust
Python interface to ODBC compatible databases such as MS SQL Server,
Oracle Database, IBM DB2, Informix and Netezza, SAP Sybase ASE and
Sybase Anywhere, Teradata, MySQL, MariaDB, PostgreSQL, SAP MaxDB and
many more:

http://www.egenix.com/products/python/mxODBC/

The "eGenix mxODBC - Python ODBC Database Interface" product is a
commercial extension to our open-source eGenix mx Base Distribution:

http://www.egenix.com/products/python/mxBase/



NEWS

The 3.3.4 release of our mxODBC is a patch level release of our
popular Python ODBC Interface for Windows, Linux, Mac OS X and
FreeBSD. It includes these enhancements and fixes:

Driver Compatibility


MS SQL Server

 * Added a work-around for MS SQL Server Native Client to be able to
   support VARCHAR/VARBINARY(MAX) columns when using the Native Client
   with direct execution mode or Python type binding mode. Thanks to
   ZeOmega for reporting this.

 * Added new helper singleton BinaryNull to allow binding a NULL to a
   VARBINARY column with SQL Server in direct execution mode or Python
   type binding mode (as used for FreeTDS). Using the usual None
   doesn't work in those cases, since SQL Server does not accept a
   VARCHAR data type as input for VARBINARY, except by using an
   explicit "CAST(? AS VARBINARY)". mxODBC binds None as VARCHAR for
   best compatibility, when not getting any type hints from the ODBC
   driver.

Misc:

 * The various __version__ attributes in mxODBC are now automatically
   updated during release. In the past, we sometimes missed updating a
   few places when cutting releases.

For the full set of changes please check the mxODBC change log:

http://www.egenix.com/products/python/mxODBC/changelog.html



FEATURES

mxODBC 3.3 was released on 2014-04-08. Please see the full
announcement for highlights of the 3.3 release:

http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html

For the full set of features mxODBC has to offer, please see:

http://www.egenix.com/products/python/mxODBC/#Features



EDITIONS

mxODBC is available in these two editions:

 * The Professional Edition, which gives full access to all mxODBC features.

 * The Product Development Edition, which allows including mxODBC in
   applications you develop.

For a complete overview of the available editions, please see the
product page:

http://www.egenix.com/products/python/mxODBC/#mxODBCEditions



DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/mxODBC/

In order to use the eGenix mxODBC package you will first need to
install the eGenix mx Base package:

http://www.egenix.com/products/python/mxBase/

You can also simply use:

pip install egenix-mxodbc

and then get evaluation licenses from our website to try mxODBC:

http://www.egenix.com/products/python/mxODBC/#Evaluation



UPGRADING

Users are encouraged to upgrade to this latest mxODBC release to
benefit from the new features and updated ODBC driver support.

We have taken special care not to introduce backwards incompatible
changes, making the upgrade experience as smooth as possible.

Customers who have purchased mxODBC 3.3 licenses can continue to use
their licenses with this patch level release.

For upgrade purchases, we will give out 20% discount coupons going
from mxODBC 2.x to 3.3 and 50% coupons for upgrades from mxODBC 3.x to
3.3. Please contact the eGenix.com Sales Team with your existing
license serials for details for an upgrade discount coupon.

If you want to try the new release before purchase, you can request
30-day evaluation licenses by visiting our web-site

http://www.egenix.com/products/python/mxODBC/#Evaluation

or writing to sa...@egenix.com, stating your name (or the name of the

Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Bernd Wechner
OK, I give up, seriously dismayed that Django doesn't have this built in 
already I did as I threatened to and derived a class as follows:


from django.utils import six
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape
from django.utils.encoding import force_text
from django.forms.models import model_to_dict, fields_for_model

class DetailViewWithHTML(DetailView):
fields = None
field_data = None
def __init__(self, instance):
self.fields = fields_for_model(self.model)
self.field_data = model_to_dict(instance)
   
# HTML formatters stolen straight form the Django ModelForm class
def _html_output(self, normal_row, help_text_html):
"Helper function for outputting HTML. Used by as_table(), as_ul(), 
as_p()."   
output = []

for name, field in self.fields.items():
value = self.field_data[name]

if field.label:
label = conditional_escape(force_text(field.label))
else:
label = ''
 
if field.help_text:
help_text = help_text_html % force_text(field.help_text)
else:
help_text = ''

output.append(normal_row % {
 'label': force_text(label),
 'value': six.text_type(value),
 'help_text': help_text,
 })

return mark_safe('\n'.join(output))

def as_table(self):
"Returns this form rendered as HTML s -- excluding the 
."
return self._html_output(
normal_row=
'%(label)s%(value)s%(help_text)s',
help_text_html='%s')

def as_ul(self):
"Returns this form rendered as HTML s -- excluding the 
."
return self._html_output(
normal_row='%(errors)s%(label)s %(value)s%(help_text)s'
,
help_text_html=' %s')

def as_p(self):
"Returns this form rendered as HTML s."
return self._html_output(
normal_row='%(label)s %(value)s%(help_text)s',
help_text_html=' %s')

It's a quick hack (if only, sheesh it took some time to work out how 
ModelForm does it and reduce it to the simplest of Data Viewers here) and 
hasn't been exhaustively tested or considered, and I remain blown away that 
DetailView doesn't implement these ... fail Django, fail. 

OK before anyone gets all smart and asks "why would you need that anyway", 
I admit it's not a super powerful generic per se for production 
implementations, but sheesh it's nice to produce a quick instance viewer 
using the same paradigm as the edit form and not have to do something 
different.
 

-- 
You received this message because you are subscribed to the Google Groups 
"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/914c4e04-3627-4f53-9243-14a20d50c197%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Mike Dewhirst

On 12/08/2015 8:54 PM, Bernd Wechner wrote:

OK, I give up, seriously dismayed that Django doesn't have this built in
already


Well done Bernd! Welcome to open source. Unfortunately, I can't use your 
code unless it is part of Django. I have tried implementing my own 
improvements in the past but I always encounter difficulties when the 
next release of Django comes.


Could you please get the core developers to adopt your code so I can use it?

Thanks

Mike


I did as I threatened to and derived a class as follows:



|
fromdjango.utils importsix
fromdjango.utils.safestring importmark_safe
fromdjango.utils.html importconditional_escape
fromdjango.utils.encoding importforce_text
fromdjango.forms.models importmodel_to_dict,fields_for_model

classDetailViewWithHTML(DetailView):
    fields =None
    field_data =None
   def__init__(self,instance):
       self.fields =fields_for_model(self.model)
       self.field_data =model_to_dict(instance)
                      Â
   # HTML formatters stolen straight form the Django ModelForm class
   def_html_output(self,normal_row,help_text_html):
       "Helper function for outputting HTML. Used by as_table(),
as_ul(), as_p()."Â  Â  Â
        output =[]

       forname,field inself.fields.items():
            value =self.field_data[name]

           iffield.label:
                label =conditional_escape(force_text(field.label))
           else:
                label =''
            Â
           iffield.help_text:
                help_text =help_text_html
%force_text(field.help_text)
           else:
                help_text =''
              Â
            output.append(normal_row %{
                 'label':force_text(label),
                 'value':six.text_type(value),
                 'help_text':help_text,
             })

       returnmark_safe('\n'.join(output))

   defas_table(self):
       "Returns this form rendered as HTML s -- excluding the
."
       returnself._html_output(
          Â
normal_row='%(label)s%(value)s%(help_text)s',
            help_text_html='%s')

   defas_ul(self):
       "Returns this form rendered as HTML s -- excluding the
."
       returnself._html_output(
            normal_row='%(errors)s%(label)s
%(value)s%(help_text)s',
            help_text_html=' %s')

   defas_p(self):
       "Returns this form rendered as HTML s."
       returnself._html_output(
            normal_row='%(label)s %(value)s%(help_text)s',
            help_text_html=' %s')
|

It's a quick hack (if only, sheesh it took some time to work out how
ModelForm does it and reduce it to the simplest of Data Viewers here)
and hasn't been exhaustively tested or considered, and I remain blown
away that DetailView doesn't implement these ... fail Django, fail.

OK before anyone gets all smart and asks "why would you need that
anyway", I admit it's not a super powerful generic per se for production
implementations, but sheesh it's nice to produce a quick instance viewer
using the same paradigm as the edit form and not have to do something
different.
   Â

--
You received this message because you are subscribed to the Google
Groups "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/914c4e04-3627-4f53-9243-14a20d50c197%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55CB3D86.7070403%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Console Routes With Django ??

2015-08-12 Thread Prabath Peiris
Looks like there is room for some new development.


On Tuesday, August 11, 2015 at 3:29:55 PM UTC-4, Prabath Peiris wrote:
>
> Hi 
>
> I am new to (kind of) Django framework and just finish the 
> Django-REST-framework tutorials and it looks really cool. I am a big fan of 
> ZendFramework2.0 (with Apigility) and trying to make parallels between 
> these two frameworks. My primary question is about console routes. In ZF2 
> you can define console routes very easily and execute same controllers as 
> web API requests. What is the best way to accomplish this in Django 
> (specially using REST framework). 
>
> ZF2 console routes : 
> http://framework.zend.com/manual/current/en/modules/zend.console.routes.html
>
>
> Thanks
> Prabath 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/41a45b4f-5836-46c9-b06d-60a87735fe74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


limit insert rows into model database

2015-08-12 Thread Tony Peña
Hi
exist some settings to only insert X number of rows in a model?

django.db. (i guess, restrict 5 rows)   as simple way ?

or

setting directly into MySQL  ?

because, i override the save method to check if:

# models.py
class domain(model.Model):
...
max_accounts = models.IntegerField(default=2)


# admin.py

class UserAdmin(admin.ModelAdmin):
list_display = ('user', 'domain',  'max_account')
ordering = ('user',)

def save_model(self, request, obj, form, change):
max_accounts = domains.objects.all()
accounts = users.objects.all()
if  int(max_accounts.values()[0]['max_accounts']) >
accounts.count():
super(UserAdmin, self).save_model(request, obj, form, change)
else:
messages.error(request, "Impossible create more accounts.")

In this code .. the check works... but my problem is:

when account 1 and total is 2 is fine.. save in mysql
when account 2 and total is 2 is fine and save in mysq again
when account is 3 and total is 2 i got the error... not save (because the
logic is fine)

and
django admin output the error message BUT show the OK was successfull
inserted too
(as a fake insert) ...how can I omit the OK message.?

thanxs in advance

-- 
Antonio Peña
Secure email with PGP 0x8B021001 available at https://pgp.mit.edu

Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001

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


Re: Serving uploaded files from multiple storages

2015-08-12 Thread 'Hugo Osvaldo Barrera' via Django users

On Tue, Aug 11, 2015, at 23:10, Javier Guerra Giraldez wrote:
> On Tue, Aug 11, 2015 at 6:17 PM, 'Hugo Osvaldo Barrera' via Django
> users  wrote:
> > I've an app where files are uploaded to differente storages:
> 
> 
> i would create a new storage object with a configuration that
> associates some prefix with other 'backend' storage objects.  then
> implement each storage method by stripping the prefix, using it to
> determine the apropriate backend, and calling it with the rest of the
> path.
> 

So, if I understand correctly, have an intermediate storage that
delegates to the proper one according to a path prefix received, and
expose the paths as full URLs to include in my template, is that it?

Makes sense. A wee bit ugly for my taste, but I guess there's no cleaner
solution.

Thanks,

-- 
Hugo Osvaldo Barrera

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


Re: Problems installing a Django package

2015-08-12 Thread girish ramnani

Is wheel in latest version?
Also 
 
your wheel package is installed in 
wheel in /usr/local/lib/python3.2/dist-packages

but the django-muro-humoristas
is being installed in 

/home/rompepc/.local/lib/python3.2/site-packages

So have you activated a virtualenv ? 

Also i tried to installed a package using wheel it went into
shiboken in /home/girish/anaconda3/lib/python3.4/site-packages

and location on wheel on my system is

wheel in /home/girish/anaconda3/lib/python3.4/site-packages
so as you can see they both are same.

you can try to install using
python -m pip install 

to remove the ambiguity of different pips used to install.



On Wednesday, August 12, 2015 at 1:32:39 AM UTC+5:30, durir...@gmail.com 
wrote:
>
> I did the tutorial for reusable apps for Django. All went well... but then 
> I get problems when installing the app.
> Processing ./django-muro_humoristas/dist/django-muro_humoristas-1.tar.gz
>   Requirement already satisfied (use --upgrade to upgrade): 
> django-muro-humoristas==1 from 
> file:///media/Comun/Programacion/Python/Django/Proyectos/muro_humoristas/django-muro_humoristas/dist/django-muro_humoristas-1.tar.gz
>  
> in /home/rompepc/.local/lib/python3.2/site-packages
> Building wheels for collected packages: django-muro-humoristas
>   Running setup.py bdist_wheel for django-muro-humoristas
>   Complete output from command /usr/bin/python3 -c "import 
> setuptools;__file__='/tmp/pip-ip3iaz-build/setup.py';exec(compile(open(__file__).read().replace('\r\n',
>  
> '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp3885trpip-wheel-:
>   usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
>  or: -c --help [cmd1 cmd2 ...]
>  or: -c --help-commands
>  or: -c cmd --help
>   
>   error: invalid command 'bdist_wheel'
>   
>   
>   Failed building wheel for django-muro-humoristas
> Failed to build django-muro-humoristas
>
> Searching about the error, it looks like I just have to install *wheel*. 
> However, when I run the command *sudo pip install wheel* (*pip* is 
> installed under *Python3*):
> Requirement already satisfied (use --upgrade to upgrade): wheel in 
> /usr/local/lib/python3.2/dist-packages
>
> So, seeing that I can just going, I retry the package install and... get 
> the same error: "*invalid command 'bdist_wheel'"*. Anyone could tell me 
> what is going on? Is my first time doing a reusable app.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/0fc58f4b-0faf-4350-bf81-d4b1fab73c72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: bulk add m2m relationship for multiple instances

2015-08-12 Thread yakkadesign
Hi Erik,

In the actually code I create and preload all the DataPoints and Sensors 
outside the loop.  I found a dict was too slow for DataPoints.  I ended up 
sorting the DataPoints query by date and using the fact that they were in 
the same order as the CSV to speed things up.  

Looping through the datapoinst and the dp.Sensors.add line is too slow.  

Can you explain what you mean by “If you need better bulk-insert 
performance than this, you can convert the m2m relation between Sensor and 
DataPoint to an explicit m2m model. You can then bulk-insert all m2m 
relations in one go instead of per-object”?   I’m not sure how to implement 
this.  

Here is what the data will look like
time  sensorA  sensorB
___
1  45
2  64
3  92
4  37

The problem is that I'm calling DataPoint.add at lot.  It seems like there 
should be a more efficient want to add them instead of looping though each 
datapoint and calling .add.  I'd like to do something like bulk_create.

Brian

-- 
You received this message because you are subscribed to the Google Groups 
"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/a08acbf0-6758-4187-89fc-f0c1f07a6a3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: bulk add m2m relationship for multiple instances

2015-08-12 Thread Erik Cederstrand

> Den 12/08/2015 kl. 20.00 skrev yakkades...@gmail.com:
> 
> In the actually code I create and preload all the DataPoints and Sensors 
> outside the loop.  I found a dict was too slow for DataPoints.

That's suspicious. Compared to loading data from the database, Python dicts are 
not slow, for any reasonable value of slow.

> Can you explain what you mean by “If you need better bulk-insert performance 
> than this, you can convert the m2m relation between Sensor and DataPoint to 
> an explicit m2m model. You can then bulk-insert all m2m relations in one go 
> instead of per-object”?   I’m not sure how to implement this.

Create an intermediate model for the m2m relation as described in 
https://docs.djangoproject.com/en/1.8/topics/db/models/#extra-fields-on-many-to-many-relationships

You can then bulk_create() on this model instead of using add(). Something like:


  class Datapoint(models.Model):
  sensors = models.ManyToManyField(Sensor, through='DatapointSensorRel')


  class DatapointSensorRel(models.Model):
  datapoint = models.ForeignKey(Datapoint)
  sensor = models.ForeignKey(Sensor)


Used like this:

  relations = [DatapointSensorRel(datapoint=d, sensor=s) for d, s in 
my_collected_relations]
  DatapointSensorRel.objects.bulk_create(relations)


Erik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/E9071BDE-2AD3-4D77-8D9F-0ABD1791CDDB%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Bernd Wechner
Mike,

Thanks. This was just a quick hack ripped off from ModelForm (although not 
as quick as I'd have liked as reverse engineering never is and had to read 
through ModelForm and get my head around bits) In any case wouldn't be 
ready for adding to Django as is, but others could improve it to meet any 
quality standards for integration if they wanted. Alas I'm rather new to 
Django and have no idea how to propose such an inclusion and to whom. For 
me this is working as a quick fix, and let some look at records and from 
there, design better views ;-). WHat I love about teh generics is they give 
us this quick easy view from which we can start tweaking and thinking how 
to make it what we want, by styling and/or templating.

On Wednesday, 12 August 2015 22:36:09 UTC+10, Mike Dewhirst wrote:
>
> On 12/08/2015 8:54 PM, Bernd Wechner wrote: 
> > OK, I give up, seriously dismayed that Django doesn't have this built in 
> > already 
>
> Well done Bernd! Welcome to open source. Unfortunately, I can't use your 
> code unless it is part of Django. I have tried implementing my own 
> improvements in the past but I always encounter difficulties when the 
> next release of Django comes. 
>
> Could you please get the core developers to adopt your code so I can use 
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b79f1695-0c67-406c-b088-5cdeb100233a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


1.8 RawSQL Parameter Issue

2015-08-12 Thread yongfeng
I'm using the new RawSQL class with annotate suggested by the django 
documentation. I noticed the second parameter the constructor takes is a 
tuple. When I used it in my project, however, I got a 'tuple object does 
not have attribute 'extend'' error. I looked at the trace back and source 
code, and found that django is calling 'extend()' on that parameter, which 
should not happen if the parameter is expected to be a tuple. I don't know 
if anyone has seen the same thing here. If I'm making a mistake, I'd like 
to know the correct use of RawSQL. Thanks a lot.

The example given in the django doc is:

qs.annotate(val=RawSQL("select col from sometable where othercol = %s", 
(someparam,)))

But this usage gives me an error stated above.

-- 
You received this message because you are subscribed to the Google Groups 
"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/eb1332e0-55d6-434d-b59c-c65a18cddb7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 1.8 RawSQL Parameter Issue

2015-08-12 Thread Tim Graham
Could you try adding a failing test case to Django's test suite based on 
your code in tests/expressions?

On Wednesday, August 12, 2015 at 5:47:53 PM UTC-4, yong...@bloomsky.com 
wrote:
>
> I'm using the new RawSQL class with annotate suggested by the django 
> documentation. I noticed the second parameter the constructor takes is a 
> tuple. When I used it in my project, however, I got a 'tuple object does 
> not have attribute 'extend'' error. I looked at the trace back and source 
> code, and found that django is calling 'extend()' on that parameter, which 
> should not happen if the parameter is expected to be a tuple. I don't know 
> if anyone has seen the same thing here. If I'm making a mistake, I'd like 
> to know the correct use of RawSQL. Thanks a lot.
>
> The example given in the django doc is:
>
> qs.annotate(val=RawSQL("select col from sometable where othercol = %s", 
> (someparam,)))
>
> But this usage gives me an error stated above.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/5f21fa37-240b-4ade-922f-6c2f831c8f00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Supprimer un COMMIT sur git

2015-08-12 Thread reduxionist
On Wednesday, August 12, 2015 at 5:01:03 PM UTC+7, Bassirou Ndiaye wrote:
>
> Bonjour j'ai commité une une nouvelle application sur GIT avec django et 
> je veux l'annuler Comment faire?
>

Vous n'êtes pas sur la bonne liste, ici c'est du Django en anglais, ce 
n'est pas de git en français, mais s.v.p. voire: 

https://git-scm.com/book/fr/v2/Utilitaires-Git-Reset-d%C3%A9mystifi%C3%A9#Le-rôle-de-reset
 

pour l'utilisation de:

 git reset --hard

-- 
You received this message because you are subscribed to the Google Groups 
"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/c17747c5-3fc5-4d06-bae2-32963f517b61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: bulk add m2m relationship for multiple instances

2015-08-12 Thread yakkadesign
 

I'll run a test with the dict vs list+position counter. I know I saw a 
speed improvement but I can't remember if that was the only thing I 
changed. 


I'd have to change a lot of code if I change the DB scheme so I'm not 
wanting to create an intermediate table. I'm going to go down the SQL path. 
Let me know if you have any suggestions. I'm still a beginner with SQL. 


Thanks for your help!!!


Brian



-- 
You received this message because you are subscribed to the Google Groups 
"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/92d75f9f-b406-4f53-ba52-773d50fe6564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Mike Dewhirst

On 13/08/2015 7:20 AM, Bernd Wechner wrote:

Mike,

Thanks. This was just a quick hack ripped off from ModelForm (although
not as quick as I'd have liked as reverse engineering never is and had
to read through ModelForm and get my head around bits) In any case
wouldn't be ready for adding to Django as is, but others could improve
it to meet any quality standards for integration if they wanted. Alas
I'm rather new to Django and have no idea how to propose such an
inclusion and to whom.


https://docs.djangoproject.com/en/1.8/#the-django-open-source-project

This link is at the bottom of the most useful page in the Django docs. 
The first link after the Community heading will answer all your questions.


Good luck and welcome again!

Cheers

Mike


For me this is working as a quick fix, and let

some look at records and from there, design better views ;-). WHat I
love about teh generics is they give us this quick easy view from which
we can start tweaking and thinking how to make it what we want, by
styling and/or templating.

On Wednesday, 12 August 2015 22:36:09 UTC+10, Mike Dewhirst wrote:

On 12/08/2015 8:54 PM, Bernd Wechner wrote:
 > OK, I give up, seriously dismayed that Django doesn't have this
built in
 > already

Well done Bernd! Welcome to open source. Unfortunately, I can't use
your
code unless it is part of Django. I have tried implementing my own
improvements in the past but I always encounter difficulties when the
next release of Django comes.

Could you please get the core developers to adopt your code so I can
use 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b79f1695-0c67-406c-b088-5cdeb100233a%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55CC0DF1.9030106%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: bulk add m2m relationship for multiple instances

2015-08-12 Thread Derek
This Python wiki 
(https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Choose_the_Right_Data_Structure)
 
suggests:

* Membership testing with sets and dictionaries is much faster, O(1), than 
searching sequences, O(n). When testing "a in b", b should be a set or 
dictionary instead of a list or tuple.

This may or may not apply to your use case.   There is also more discussion 
in this thread:
http://bytes.com/topic/python/answers/587277-how-much-slower-dict-indexing-vs-list-indexing

I have also found in some of my own cases (not involving m2m models though) 
that dropping down to raw SQL for bulk uploads is fast enough to justify 
doing it; but I am trading off against all the model checks/balances that 
Django provides.

On Thursday, 13 August 2015 04:09:04 UTC+2, yakka...@gmail.com wrote:
>
> I'll run a test with the dict vs list+position counter. I know I saw a 
> speed improvement but I can't remember if that was the only thing I 
> changed. 
>
>
> I'd have to change a lot of code if I change the DB scheme so I'm not 
> wanting to create an intermediate table. I'm going to go down the SQL path. 
> Let me know if you have any suggestions. I'm still a beginner with SQL. 
>
>
> Thanks for your help!!!
>
>
> Brian
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/4dab3118-8317-43ea-82a9-e425d4218b1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.