Re: Unit Testing: temporarily altering django settings

2011-02-21 Thread Mikhail Korobov
Why doesn't setattr work? Just make sure you're setting the proper option because apps often cache options at e.g. their 'config.py' file in order to provide default values: # captha_app/config.py from django.conf import settings CAPTCHA = getattr(settings, 'CAPTCHA', True) So you'll have to

Re: Select x random rows from DB

2011-02-21 Thread Mikhail Korobov
Stackoverflow: http://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm/971671#971671 On 22 фев, 03:06, Mikhail Korobov <kmik...@googlemail.com> wrote: > This is the function for getting 1 item that works even if some rows > were deleted that works

Re: Select x random rows from DB

2011-02-21 Thread Mikhail Korobov
This is the function for getting 1 item that works even if some rows were deleted that works times faster than order_by('?') even for not- so-big datasets at least on mysql: def get_random_item(model, max_id=None): if max_id is None: max_id =

Re: Query Set involving Model Method

2011-01-16 Thread Mikhail Korobov
It doesn't work that way. ORM translates you queries to SQL and the DB is responsible for filtering. It is not possible to translate arbitrary python function to SQL or pass it to DB engine. So you have to formulate you query using .filter syntax or raw SQL. Another possibility is to denormalize

ANN: django-widget-tweaks

2011-01-12 Thread Mikhail Korobov
Hi guys, Designers often want to add some css classes and html attributes to django form fields. But now they have to either patch the python code or copy-paste full html widget output and then customize it. In order to make them happy I just released an app (

Re: how to map admin actions with shortcut keys

2011-01-09 Thread Mikhail Korobov
Hi Rahul, This can be solved using custom javascript. Override ModelAdmin's changelist template ( http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-admin-templates ) in order to insert the necessary javascript code. On 10 янв, 00:37, rahul jain wrote:

Re: How to get an dictionary item in template

2010-12-26 Thread Mikhail Korobov
production = Production.objects.all() for product in production: try: product.image = product.image_set.get (somefield = somevalue) except Image.DoesNotExist: pass {% for product in production %} {{ product.title }} {% endfor %} or even better implement the

Re: Access to request from tag

2010-12-26 Thread Mikhail Korobov
Hi Igor, If you use django <= 1.2 the you can replace 'render_to_response' with 'direct_to_template'. They do almost the same but 'direct_to_template' uses RequestContext by default: from django.views.generic.simple import direct_to_template def my_view(request): # ... return

Re: Group models by personal order and no by app in admin

2010-12-24 Thread Mikhail Korobov
Hi Alex, django-admin-tools should solve all your problems with admin index page. https://bitbucket.org/izi/django-admin-tools/ On 24 дек, 17:48, Álex González wrote: > Hi! > > I have a lot of models in same app at my django app, can I group then > another way that app

Re: add template variable to an external view, without changing the view

2010-12-20 Thread Mikhail Korobov
Hi Yves, In django 1.3 there is also a TemplateResponse ( http://docs.djangoproject.com/en/dev/ref/template-response/ ) that can perform as render_to_response replacement, doesn't require class based views and enables developer to change the template context (as well as the template to be

Re: How to aggregate values by month

2010-11-04 Thread Mikhail Korobov
; --- > e-mail: rogerio.carrasque...@gmail.com > skype: rgcarrasqueira > MSN: rcarrasque...@hotmail.com > ICQ: 50525616 > Tel.: (11) 7805-0074 > > 2010/10/28 Mikhail Korobov <kmik...@googlemail.com> > > > > > Hi Rogério, > > > You can givehttp://bitbucket.or

Re: How to aggregate values by month

2010-10-28 Thread Mikhail Korobov
Hi Rogério, You can give http://bitbucket.org/kmike/django-qsstats-magic/src a try. It currently have efficient aggregate lookups (1 query for the whole time series) only for mysql but it'll be great if someone contribute efficient lookups for other databases :) On 28 окт, 19:31, Rogério

Re: Saving a location with a model

2010-08-30 Thread Mikhail Korobov
You may find this useful: http://bitbucket.org/barttc/django-generic-location On 31 авг, 04:05, Joel Klabo wrote: > I want to tie a location to each instance of a model. I am planning on > getting the lat/long. from navigator.geolocation through javascript. > My original

Re: Performance monitoring

2009-12-09 Thread Mikhail Korobov
Performance monitoring doesn't have to be related to django itself. There are external projects that cant do performance monitoring (CPU, i/o, memory usage over time). You may give munin (http:// munin.projects.linpro.no/) a chance. On Dec 10, 7:43 am, Kegan Gan wrote: > Hi, >

Re: Filtering on model methods

2009-10-28 Thread Mikhail Korobov
I think if your methods are really complex then the best you can do is to denormalise your DB. Make your calculated fields real fields in a table and update them in model's save method or using signals. Another way is to make them calculated by DB using triggers or DB views but I would prefer

Re: Filtering on model methods

2009-10-28 Thread Mikhail Korobov
Maybe I wrote a reply without undersanding what you need. You have 2 separate issues: 1. Want to sort and filter by calculated field 2. Want to create calculated field that is calculated in python Am I correct? 1) can be acheived using ".extra" method or aggregations

Re: Filtering on model methods

2009-10-27 Thread Mikhail Korobov
If you want to be able to sort by some python method you have to fetch ALL data from all tables that are used in this method. It is indeed a bad practice and so it is not encouraged in django. The best you can do is to put your code to model's manager as a method. Model managers are often used

Re: Adding button to admin change form

2009-10-26 Thread Mikhail Korobov
You should override change_form.html template and save it as /your_project/templates/admin/your_app/change_form.html or /your_project/templates/admin/your_app/your_model/change_form.html On 26 окт, 21:45, Aaron wrote: > I need to add a button to the admin change form of

Re: Admin interface is doing nothing

2009-10-26 Thread Mikhail Korobov
It is very likely that your urls.py is wrong. Re-check if admin urls are included exactly as in documentation example: "(r'^admin/', include (admin.site.urls))", without any wildcards. On 27 окт, 00:12, "M." wrote: > Hi, > > I've installed the Admin interface, but the

Re: update() (for bulks) is a atomic operation?

2009-10-25 Thread Mikhail Korobov
Yes, it's a single query. Take a look at django-debug-toolbar. It can display all SQL queries that was executed during request/response so you'll always be sure what's going on. On 26 окт, 03:12, wancharle sebastiao quirino wrote: > Hello, > > I currently am using raw sql