save and session

2005-12-12 Thread Dody Suria Wijaya
Is it possible in djanggo to access current request's session variables inside _pre_save or _post_save function? I need to save current login userid into a "last_update_userid" field automatically by simply calling .save() Thanks -- dsw

Re: save and session

2005-12-12 Thread Dody Suria Wijaya
ore a Model finish with the previous request? plisk wrote: Dody Suria Wijaya wrote: Is it possible in djanggo to access current request's session variables inside _pre_save or _post_save function? I need to save current login userid into a "last_update_userid" field automatical

Re: save and session

2005-12-12 Thread Dody Suria Wijaya
h the previous request? plisk wrote: Dody Suria Wijaya wrote: Is it possible in djanggo to access current request's session variables inside _pre_save or _post_save function? I need to save current login userid into a "last_update_userid" field automatically by simply calling .save

django design decision to use meta class

2005-12-27 Thread Dody Suria Wijaya
Gdday, After few days of intensive reading of django source codes, I don't quite get the reasoning behind a few of key python-django design decision that came into use in django model: 1. why use ONLY meta class in 1st place? class inheritance seems to be much simpler, less magic, and has e

Re: django design decision to use meta class

2005-12-27 Thread Dody Suria Wijaya
Joseph Kocherhans wrote: On 12/27/05, Dody Suria Wijaya <[EMAIL PROTECTED]> wrote: 2. why create a "virtual" module at runtime for each model (the plural+lowercase of model class name)? I suppose binding the methods (get_XXX) to the model's class (class method) is m

misleading pk use in db api

2005-12-29 Thread Dody Suria Wijaya
DB API documentation stated that: pk lookups also work across joins. In the polls example, these two statements are equivalent: choices.get_list(poll__id__exact=3) choices.get_list(poll__pk=3) which is incorrect. looking at meta/__init__.py (svn djago trunk), if lookup_list[-1] == '

iMpressive compactness

2005-12-31 Thread Dody Suria Wijaya
Had just rewritten a basic portion of my voucher-processing accounting model and logics to django ORM over the new year's week end. So far, it shows up as 15% of the original lines of code, and more readable as well (SQLs are now gone). And with the admin page immediately available for me t

Re: DB Field metadata

2006-01-03 Thread Dody Suria Wijaya
Alice wrote: Is there a way of retrieving a database field's metadata? For example, the maxlength or choices parameters? It would be nice to automatically display the number of allowed characters for a given textfield. Alice Hi Alice, try accessing via its class: Poll._meta.fields[2].ma

cross importing application in models

2006-01-04 Thread Dody Suria Wijaya
Hi, need a hand on this. I have two applications, called accounting and enterprise, located in myproject/accounting and myproject/enterprise. enterprise has a model which has foreign keys in accounting. so I import it beforehand: from django.models import accounting class Company(meta

Re: Superfluent _id in field name results in SQL error

2006-01-04 Thread Dody Suria Wijaya
I agree, there seems to be a small typo in django/core/management.py col_type = db.DATA_TYPES[data_type] if col_type is not None: --> field_output = [db.db.quote_name(f.column), col_type % rel_field.__dict__] field_output.append('%sNULL' % (not f

Re: Superfluent _id in field name results in SQL error

2006-01-04 Thread Dody Suria Wijaya
Sure thing, Arthur. From my observation, it's a kind of convention built into django on every ForeignKey field. Those get a default column name with '_id' suffix. But it's easily overridden by specifying db_column parameter. As of Primary key, the only magic I know is if a model does not have

Re: cross importing application in models

2006-01-04 Thread Dody Suria Wijaya
You meant another table that designed specifically to link those fields? This come to mind: class CompanyAccount(meta.Model): company = meta.ForeignKey(enterprise.Company) account = meta.ForeignKey(accounting.Account) or better, a OneToOneField since a company's main account is s

Re: cross importing application in models

2006-01-04 Thread Dody Suria Wijaya
No, the foreign key looks the same, but logically it's for different purpose. You can easily imagine a table of Paint Suppliers, with a field for their cheapest color product. And another table listing all color products from all suppliers, with a field identifying which supplier owns the pro

Re: one-to-one design problem

2006-01-07 Thread Dody Suria Wijaya
Alice wrote: Not really django specific, I was having problems with it in java+hibernate implementation too... I have a model, 'Items', which is generic enough to extend to more specialized items, like a 'book items' model for example. This relationship has been modelled as a one-to-one, but wh

Re: Django DB Design Question (help please!)

2006-01-09 Thread Dody Suria Wijaya
My approach is, if you would often be needing to get list of news both by company and user, for performance reason I would put both foreignkey (one 2 many) to company and user in newsposting model. That way, the resulting join query only need to join maximum of two tables and be faster. Alth

Re: Django DB Design Question (help please!)

2006-01-09 Thread Dody Suria Wijaya
people seems to be quite content with having 1 pk, then who cares? Dody Suria Wijaya wrote: My approach is, if you would often be needing to get list of news both by company and user, for performance reason I would put both foreignkey (one 2 many) to company and user in newsposting model. T

Re: Django DB Design Question (help please!)

2006-01-09 Thread Dody Suria Wijaya
In my experience, some designers used primary key to enforce logical parent/child relationship (where the parent's pk is prefixed into one of the child's primay key), and usually to signify the pk fields to be "uneditable" since it actually also doubles as "foreignkey", the value refer to the

Re: Django and MS SQL

2006-01-10 Thread Dody Suria Wijaya
Jeremy Dunck wrote: I'm philosophically in line with much of the Free philosophy, but FSF didn't decide not to run on Unix while developing the tools to replace it; some compromises are necessary. There exists a huge install base locked into MS SQL; denying django to those folks won't help the

Re: Duplicate object

2006-01-11 Thread Dody Suria Wijaya
I think you meant __dict__, instead of __dict__(). Secondly, that would still copy the primary key, which turns into update query on save. An easy way to duplicate in choice case would be to set id as False value (0, None, or False), and thus force the saving routine to generate a new one and

Re: Duplicate object

2006-01-12 Thread Dody Suria Wijaya
Simon Willison wrote: Maybe it would be useful for all Django model objects to gain themselves a duplicate() method which does exactly this - returns an identical object but with id set to None. There is still complication for non autofield primary key. And it's just 3 lines or under. --

Re: psycopg 2.2

2006-01-15 Thread Dody Suria Wijaya
you could try copying psycopg module files to the django/core/db/backends/ (the same location as postgresql.py) [EMAIL PROTECTED] wrote: Dear All , I have a certain problem with Django and i need help from anyone 1- I am using psycopg 2.2 on my pc for development of some projects 2- i need to

Re: Apache2 - Mod_python: ValueError: Empty module name

2006-01-16 Thread Dody Suria Wijaya
It used to be that if user does not define the environment variable, django tell us with a more helpful line like "Environment variable DJANGO_SETTINGS_MODULE is undefined". Adrian Holovaty wrote: On 1/16/06, Krietjur <[EMAIL PROTECTED]> wrote: line 32, in ? mod = __import__(me.SETTIN

Re: several django questions, models, apache

2006-01-24 Thread Dody Suria Wijaya
greg wrote: i have to modifie my url.py file previously urlpatterns = patterns('', (r'^recettes/$', 'cefinban.recettes.views.index'), (r'^recettes/(?P\d+)/$', 'cefinban.recettes.views.detail'), . ) to (r'^cefinban/recettes/(?P\d+)/$', 'cefinban.recettes.views.detail

Re: Memory leaks in DB API

2006-02-04 Thread Dody Suria Wijaya
Your setting might be using DEBUG = True, which save all SQL queries and its start/stop time for debugging when something goes wrong. Try turning it to False. [EMAIL PROTECTED] wrote: Hi all I am wondering if other people have noticed an apparent bug in Django when using the DB API to inser

Re: Memory leaks in DB API

2006-02-07 Thread Dody Suria Wijaya
Didn't you see my reply? His problem wasn't memory leak at all. It was just a case of django (on debug mode) filling up list with debugging info, which could fill up when many sql queries being done in a single request/response cycle. Jason Huggins wrote: I don't know what is wrong in this