Re: Getting data from user via HTML

2009-09-15 Thread koranthala



On Sep 15, 9:02 am, Nitin Boladra  wrote:
> Hi Django users,
>                 I am trying to create a simple Django application
> wherein I want to run a python function with an argument that is
> obtained from text-box whenever I click the button on my web-page. The
> problem is passing the value obtained in text-box to the python
> function. So as I am new to Django can anybody help me out to resolve
> this problem. Thanks in advance.
>
> Regards,
> Nitin

Hi,
   This might help:
http://www.djangobook.com/en/2.0/chapter07/
http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index

  It will be good to read the djangobook (first link) once thoroughly
because all the basic scenarios are considered there. The
documentation in Django website is also very extensive. Do check it
out too.

Regards
K
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Updating request.POST

2009-09-13 Thread koranthala



On Sep 13, 6:38 am, koranthala  wrote:
> Hi,
>    I have the following scenario.
>    I am creating a custom admin page for one of the models. I am
> adding few extra fields. If the extra fields are set, then the user
> does not need to set the model fields. An example is given below:
>
> Model A:
>     val1 models.ForeignKey(A1)
>     val2 models.ForeignKey(A2)
>     val3 models.CharField()
>
> Form F:
>     val_x_1 forms.CharField()
>
> Now, on the add/change page for Model A, I am giving an option. It
> would look like the following:
>
> Add A:
> --
> val_x_1:    []
> val2:       []
> 
>               OR
> 
> val1:       []
> val2:       []
> val3:       []
>
> [Save] [Save and Add Another]
>
> The user can either type in val1, val2 and val3 or he can put in
> values in val_x_1 and val2 only, and my custom add_view should take
> care of everything.
>
> Now, the whole page is working fine. But, I am unable to update
> request.POST to set up values for val1, val2 and val3 based on the
> values val_x_1 and val2. I created a mutable copy and tried putting
> that copy back to request.POST, but everytime I am getting the 'cant
> adapt' error. The backend is PostgreSQL.
>
> If I dont update request.POST, the form.validate would fail inside the
> proper add_view. I cannot make it as blank=True straightaway because
> if the val_x_1 and val2 is not updated by the user, he needs to update
> mandatorily val1, val2 and val3.
>
> Can anyone help me on this?

Sorry for this question. There was a very foolish mistake from my part
which caused this issue.
I solved the same.
Thank You.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Updating request.POST

2009-09-12 Thread koranthala

Hi,
   I have the following scenario.
   I am creating a custom admin page for one of the models. I am
adding few extra fields. If the extra fields are set, then the user
does not need to set the model fields. An example is given below:

Model A:
val1 models.ForeignKey(A1)
val2 models.ForeignKey(A2)
val3 models.CharField()

Form F:
val_x_1 forms.CharField()

Now, on the add/change page for Model A, I am giving an option. It
would look like the following:

Add A:
--
val_x_1:[]
val2:   []

  OR

val1:   []
val2:   []
val3:   []

[Save] [Save and Add Another]

The user can either type in val1, val2 and val3 or he can put in
values in val_x_1 and val2 only, and my custom add_view should take
care of everything.

Now, the whole page is working fine. But, I am unable to update
request.POST to set up values for val1, val2 and val3 based on the
values val_x_1 and val2. I created a mutable copy and tried putting
that copy back to request.POST, but everytime I am getting the 'cant
adapt' error. The backend is PostgreSQL.

If I dont update request.POST, the form.validate would fail inside the
proper add_view. I cannot make it as blank=True straightaway because
if the val_x_1 and val2 is not updated by the user, he needs to update
mandatorily val1, val2 and val3.

Can anyone help me on this?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How much DB queries is too much?

2009-08-06 Thread koranthala

Hi,
   I am designing a website with Django and Apache. This is my first
foray to web designing, even though I have quite a bit of experience
in another area.
   The logic for the site is somewhat involved - It is better to think
of it as more of an application rather than a site.
   The problem is as follows:
   On an average, every GET query for the home page takes about 400 DB
Queries. I am now running it in my personal machine, with the Apache
and PostgreSQL DB all running in my machine itself. Here, it takes
around 5 seconds to complete a GET query. Please note that  have used
the select_related etc quite liberally.
   I feel that the query count is too high. I earlier tried to solve
it using memoization - wherein the query count came down to ~100, but
since I have moved from development server to Apache, I removed it
since I had written a thread-unsafe memoization.
   One of the reasons the query count is this high is because of the
high modularization - I reuse many code again and again, so each code
tries to get the data again. One way I can think of improving
performance is by destroying the modularization. But that would be my
last choice.

   Since this is my first application, could you please let me know
whether this is too high?
   Should I try to improve the memoization code - say using a memoized
data passed all over?

   What are the other ways to improve the performance?

TIA
K

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Hard linking an image

2009-06-25 Thread koranthala



On Jun 26, 2:21 am, Kevin Teague  wrote:
> Presumably you already have all of the data required to generate a
> chart on the server? If so, then store the chart data in a model, and
> just reference it by id. e.g.
>
> 
>
> (or w/ a pretty URL: )
>
> And create a Chart object and store it before sending out the HTML
> response. Then update your chart view so that it fetches that object
> and uses it as input to generate the graph.

The data required to create the chart is calculated from the server. I
can create a model and store it, but when should I delete the same?
Once the image is created? In case the image is not created - say full
page did not load - before that the user closed it etc. In such case,
how do I delete the stored data?

Also, is it good to store these temperory data in models?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Hard linking an image

2009-06-25 Thread koranthala

Hi,
I have a chart which I generate on the fly.
Basically, I have hard linked an image. The image src contains GET
parameters, which is used to generate the chart image via matplotlib.
The resultant image is returned back as 'Content-Type' = 'image/png',
and thus the chart is displayed.
 i.e.  is there in
HTML - created using templates. The parameters key1, key2, field1,
field2 etc are used to create the image.

Now, this was working perfectly till now. Now, I need to create a
huge chart with lot of keys and fields. But, when I tried the same
mechanism, it failed because it is above the maximum characters
supported by GET. Even though I could not find any specific spec which
mentioned the max char limit, I understand that many browsers support
very less characters only ~300.

In such a case, how can I create the chart on the fly? Is there a
way to send the data as POST while hardlinking? Since I am getting the
values and generating the links using templates, I cannot think of too
many options. What si the usual mechanism used by fellow Djangoites?

Any help would be much appreciated. Thank you all in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Block delete

2009-04-17 Thread koranthala



On Apr 18, 1:26 am, koranthala  wrote:
> On Apr 18, 1:08 am, Alex Gaynor  wrote:
>
>
>
> > On Fri, Apr 17, 2009 at 4:05 PM, koranthala  wrote:
>
> > > On Apr 17, 11:57 pm, koranthala  wrote:
> > > > On Apr 17, 11:51 pm, Alex Gaynor  wrote:
>
> > > > > On Fri, Apr 17, 2009 at 2:47 PM, koranthala 
> > > wrote:
>
> > > > > > Hi,
> > > > > >    I am facing a problem which I believe should be a usual issue for
> > > > > > everyone. But I cannot find a way to do it in a straightforward
> > > > > > manner.
> > > > > >   I have to select a list of items from table A and delete everyone
> > > > > > of them. Now, there are close to 20K elements which I want to 
> > > > > > delete.
> > > > > > So, what I do now is:
> > > > > >    fields = tableA.filter(**)
> > > > > >    for field in fields:
> > > > > >      field.delete()
>
> > > > > >   Now, this is invoking 20K separate messages to the DB - which is
> > > > > > rather suboptimal. However I think, I could not find a mechanism to
> > > > > > delete it in a straightway. One option I could think of is to create
> > > > > > raw SQL and invoke - but I would like to do that as the last resort.
> > > > > > Is there any other mechanism to do the same?
>
> > > > > tableA.objects.filter(...).delete()
>
> > > > > Won't pull in each of the objects to delete them:
> > >http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> > > > > Alex
> > > > > --
> > > > > "I disapprove of what you say, but I will defend to the death your
> > > right to
> > > > > say it." --Voltaire
> > > > > "The people's good is the highest law."--Cicero
>
> > > > Thank you Alex.
>
> > > Sorry for troubling everyone further. But, I had a similar case of
> > > insert too - wherein I insert close to 2K elements at a time.
> > > Currently, I do it as
> > > list = []
> > > ...
> > > in some loop
> > > ...
> > > table = Table(values)
> > > list.append(table)
> > > ...
>
> > > for l in list: l.save()
>
> > > Is there something similar to block delete - for block insert too?
>
> > Not right now there isn't no(although you don't need the intermediary list,
> > just save the items in the original loop, it will still do 2k queries, but
> > you won't be using a lot of memory storing 2k items).  There is a ticket
> > requesting a bulk insert, however I can't seem to find it now.
>
> > Alex
>
> > --
> > "I disapprove of what you say, but I will defend to the death your right to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
>
> Thank you very much Alex.

Again, sorry for troubling you like this.
As I mentioned earlier in this chain, I wanted to delete 20K tuples
from table A.
I am now using tableA.filter(***).delete() to do the same.

Now, table A is referenced by table B - and those need to be deleted
too - via cascade.
What is happening is that - Django is actually sending a query to
table B for each tuple in table A to find out tuples to delete in
table B.
So, I get 20K queries for table B, and 2 delete queries for table A
and B each.

I was wondering whether Django does not support - ON DELETE CASCADE -
in this thread 
http://groups.google.com/group/django-users/browse_thread/thread/51f93c9596f9ecd9/9c671e8d16e99b90,
it says it does not support it.

I understand it is done because all backends does not support it - but
can it be supported for backends which actually support it? I am using
postgresql - and now I have to do many non-optimal things to decrease
this query count.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Block delete

2009-04-17 Thread koranthala



On Apr 18, 1:08 am, Alex Gaynor  wrote:
> On Fri, Apr 17, 2009 at 4:05 PM, koranthala  wrote:
>
> > On Apr 17, 11:57 pm, koranthala  wrote:
> > > On Apr 17, 11:51 pm, Alex Gaynor  wrote:
>
> > > > On Fri, Apr 17, 2009 at 2:47 PM, koranthala 
> > wrote:
>
> > > > > Hi,
> > > > >    I am facing a problem which I believe should be a usual issue for
> > > > > everyone. But I cannot find a way to do it in a straightforward
> > > > > manner.
> > > > >   I have to select a list of items from table A and delete everyone
> > > > > of them. Now, there are close to 20K elements which I want to delete.
> > > > > So, what I do now is:
> > > > >    fields = tableA.filter(**)
> > > > >    for field in fields:
> > > > >      field.delete()
>
> > > > >   Now, this is invoking 20K separate messages to the DB - which is
> > > > > rather suboptimal. However I think, I could not find a mechanism to
> > > > > delete it in a straightway. One option I could think of is to create
> > > > > raw SQL and invoke - but I would like to do that as the last resort.
> > > > > Is there any other mechanism to do the same?
>
> > > > tableA.objects.filter(...).delete()
>
> > > > Won't pull in each of the objects to delete them:
> >http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> > > > Alex
> > > > --
> > > > "I disapprove of what you say, but I will defend to the death your
> > right to
> > > > say it." --Voltaire
> > > > "The people's good is the highest law."--Cicero
>
> > > Thank you Alex.
>
> > Sorry for troubling everyone further. But, I had a similar case of
> > insert too - wherein I insert close to 2K elements at a time.
> > Currently, I do it as
> > list = []
> > ...
> > in some loop
> > ...
> > table = Table(values)
> > list.append(table)
> > ...
>
> > for l in list: l.save()
>
> > Is there something similar to block delete - for block insert too?
>
> Not right now there isn't no(although you don't need the intermediary list,
> just save the items in the original loop, it will still do 2k queries, but
> you won't be using a lot of memory storing 2k items).  There is a ticket
> requesting a bulk insert, however I can't seem to find it now.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

Thank you very much Alex.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Block delete

2009-04-17 Thread koranthala



On Apr 17, 11:57 pm, koranthala  wrote:
> On Apr 17, 11:51 pm, Alex Gaynor  wrote:
>
>
>
> > On Fri, Apr 17, 2009 at 2:47 PM, koranthala  wrote:
>
> > > Hi,
> > >    I am facing a problem which I believe should be a usual issue for
> > > everyone. But I cannot find a way to do it in a straightforward
> > > manner.
> > >   I have to select a list of items from table A and delete everyone
> > > of them. Now, there are close to 20K elements which I want to delete.
> > > So, what I do now is:
> > >    fields = tableA.filter(**)
> > >    for field in fields:
> > >      field.delete()
>
> > >   Now, this is invoking 20K separate messages to the DB - which is
> > > rather suboptimal. However I think, I could not find a mechanism to
> > > delete it in a straightway. One option I could think of is to create
> > > raw SQL and invoke - but I would like to do that as the last resort.
> > > Is there any other mechanism to do the same?
>
> > tableA.objects.filter(...).delete()
>
> > Won't pull in each of the objects to delete 
> > them:http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> > Alex
> > --
> > "I disapprove of what you say, but I will defend to the death your right to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
>
> Thank you Alex.

Sorry for troubling everyone further. But, I had a similar case of
insert too - wherein I insert close to 2K elements at a time.
Currently, I do it as
list = []
...
in some loop
...
table = Table(values)
list.append(table)
...

for l in list: l.save()

Is there something similar to block delete - for block insert too?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Block delete

2009-04-17 Thread koranthala



On Apr 17, 11:51 pm, Alex Gaynor  wrote:
> On Fri, Apr 17, 2009 at 2:47 PM, koranthala  wrote:
>
> > Hi,
> >    I am facing a problem which I believe should be a usual issue for
> > everyone. But I cannot find a way to do it in a straightforward
> > manner.
> >   I have to select a list of items from table A and delete everyone
> > of them. Now, there are close to 20K elements which I want to delete.
> > So, what I do now is:
> >    fields = tableA.filter(**)
> >    for field in fields:
> >      field.delete()
>
> >   Now, this is invoking 20K separate messages to the DB - which is
> > rather suboptimal. However I think, I could not find a mechanism to
> > delete it in a straightway. One option I could think of is to create
> > raw SQL and invoke - but I would like to do that as the last resort.
> > Is there any other mechanism to do the same?
>
> tableA.objects.filter(...).delete()
>
> Won't pull in each of the objects to delete 
> them:http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
>
> Alex
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

Thank you Alex.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Block delete

2009-04-17 Thread koranthala

Hi,
I am facing a problem which I believe should be a usual issue for
everyone. But I cannot find a way to do it in a straightforward
manner.
   I have to select a list of items from table A and delete everyone
of them. Now, there are close to 20K elements which I want to delete.
So, what I do now is:
fields = tableA.filter(**)
for field in fields:
  field.delete()

   Now, this is invoking 20K separate messages to the DB - which is
rather suboptimal. However I think, I could not find a mechanism to
delete it in a straightway. One option I could think of is to create
raw SQL and invoke - but I would like to do that as the last resort.
Is there any other mechanism to do the same?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: signals vs. save()

2009-04-16 Thread koranthala



On Apr 16, 6:41 pm, Alex Gaynor  wrote:
> On Thu, Apr 16, 2009 at 6:39 AM, koranthala  wrote:
>
> > Hi,
> >    I was comparing between signal and save() and came across this
> > following mail chain -
>
> >http://groups.google.com/group/django-users/browse_thread/thread/d0ff...
>
> >    In this it is mentioned that -
> > ---
> > If you want to implement some
> > functionality that operates across multiple types of models, you need
> > to
> > use the signal infrastructure, since the same signal is raised no
> > matter
> > what the type of model (you can differentiate the model type in the
> > signal handler, though).
> > 
>
> >   I was unable to understand why we should go for signals in case we
> > have to work across models?
> >   Say, for example - I have ModelA and ModelB. Everytime, I save an
> > element in ModelA, I need to update 15 fields in ModelB.
> >   In this case, shouldn't I do everything in ModelA.save itself?
> > ModelA.save():
> >   super.save()
> >   Update 15 fields in ModelB
>
> >   I do not understand why we should go for signals in this case too?
> >   Sorry if I am dense :-)
>
> One of the simplest reasons to use signals in that situation is because you
> can't change the code in that application.  Say you want to trigger
> something on the User object being saved, you don't want to monkey patch
> django.contrib.auth so use just use the signal for code clarity.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

Thank you Alex.
But considering the scenario mentioned above - wherein I need to make
modifications to a separate table - both of which I have full access
to - should I go ahead with signals or should I go with save?
Malcolms mail  - the link mentioned earlier - seems to suggest that I
should be using signals - but I am unable to understand the
justification for it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



signals vs. save()

2009-04-16 Thread koranthala

Hi,
I was comparing between signal and save() and came across this
following mail chain -
http://groups.google.com/group/django-users/browse_thread/thread/d0ff6dd3432d25fa/99a92f9f4b343b1e

In this it is mentioned that -
---
If you want to implement some
functionality that operates across multiple types of models, you need
to
use the signal infrastructure, since the same signal is raised no
matter
what the type of model (you can differentiate the model type in the
signal handler, though).


   I was unable to understand why we should go for signals in case we
have to work across models?
   Say, for example - I have ModelA and ModelB. Everytime, I save an
element in ModelA, I need to update 15 fields in ModelB.
   In this case, shouldn't I do everything in ModelA.save itself?
ModelA.save():
   super.save()
   Update 15 fields in ModelB

   I do not understand why we should go for signals in this case too?
   Sorry if I am dense :-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Default items in a template

2009-04-06 Thread koranthala

Hi,
I have many pages in my website - and all have the same default
header and side bars. The header and sidebar contains ~15 links which
are constant every time. While rendering templates for these pages, I
always have to send all these links in the context. Since it is
unseemly, I am planning to write my own context_processor for these
headers. Now, I dont want the other template_context_processors to be
hit for this - it seems a waste of time. Is it possible to go without
hitting the other context_processors - since I would not have hit it
otherwise.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



A confusing output

2009-03-21 Thread koranthala

Hi,
   Using Django 1.1
   I have the following filter
p = DB.filter( value_in = values, name__in = names).select_related()

I am facing 2 issues in here.

1. Unexpected DB queries
I did p = list(p)
The total queries was 1

I then did
p = list(p)
for a in p:
   pass

Now, the total queries is coming to be 2. I was under the impression
that in both cases query count should be same because p is already
loaded.

2. Select_related not working.
Whenever I call p.value, it is again querying the DB. value is a
foreign key to Values table which has a many-to-many relationship with
another table. Is it because of that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Aggregation Questions

2009-03-16 Thread koranthala



On Mar 16, 11:44 pm, Alex Gaynor  wrote:
> On Mon, Mar 16, 2009 at 11:52 AM, koranthala  wrote:
>
> > On Mar 16, 8:14 pm, Alex Gaynor  wrote:
> > > On Mon, Mar 16, 2009 at 11:07 AM, koranthala 
> > wrote:
>
> > > > Hi,
> > > >    I downloaded Django 1.1 due to aggregation support.
> > > >    But I am facing one issue which I cannot seem to overcome.
> > > >    I have two fields which represents two different times.
> > > >    I want to get the sum of difference of times - and I am unable to
> > > > do so.
> > > > Basically, I want to do as follows:
> > > > SELECT SUM (time2 - time1) FROM _TABLE_ WHERE __XXX___
>
> > > >    I tried 2 options:
> > > > 1. self.filter( XXX).aggregate(diff=Sum('time2 - time1'))
> > > > 2. self.filter (XXX).aggregate(t2=Sum('time2'), t1= Sum('time1')) - so
> > > > that I can do t2 - t1 later.
>
> > > >    Both is not supported in Django. I have raw SQL code in model
> > > > Manager for the same. I thought using Django Aggregation is better. Is
> > > > such operations going to be supported in Django 1.1 ?
>
> > > > Regards
> > > > Koran
>
> > > Right now that isn't possible, is there any reason you couldn't just
> > bring
> > > the seperate SUMs into python and do the subtraction there, I realize it
> > > isn't quite as clean but the overhead should be minimal?
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> > If I understand correctly:
> > Separate SUMs as in the 2nd option which I mentioned above?
> > It was not possible because currently aggregation methods does not
> > support SUM - I think because Python itself does not support SUM of
> > datetime objects.
>
> > Or was it:
> > Separate SUM as in bring all the tuples to Python and then calculate?
> > It is quite big because there are more than 1 Million tuples so I dont
> > want to bring everything to Python.
>
> > Please let me know whether I have understood correctly.
>
> Sorry, I missed that these were dates/times.  Right now there isn't complete
> support for aggregating on dates/times.  I think here the easiest route is
> just to do:
>
> self.extra(select={'diff': "SUM(field1-field2"}).values('diff')
>
> Which I believe will work.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

Thank you very much Alex.
I wrote the raw SQL code yesterday - took me about >1 hr to get it
correct (it was quite a complex one). :-(
But this seems to be much MUCH easier.
Thank you again. I will work using this method.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Aggregation Questions

2009-03-16 Thread koranthala



On Mar 16, 8:14 pm, Alex Gaynor  wrote:
> On Mon, Mar 16, 2009 at 11:07 AM, koranthala  wrote:
>
> > Hi,
> >    I downloaded Django 1.1 due to aggregation support.
> >    But I am facing one issue which I cannot seem to overcome.
> >    I have two fields which represents two different times.
> >    I want to get the sum of difference of times - and I am unable to
> > do so.
> > Basically, I want to do as follows:
> > SELECT SUM (time2 - time1) FROM _TABLE_ WHERE __XXX___
>
> >    I tried 2 options:
> > 1. self.filter( XXX).aggregate(diff=Sum('time2 - time1'))
> > 2. self.filter (XXX).aggregate(t2=Sum('time2'), t1= Sum('time1')) - so
> > that I can do t2 - t1 later.
>
> >    Both is not supported in Django. I have raw SQL code in model
> > Manager for the same. I thought using Django Aggregation is better. Is
> > such operations going to be supported in Django 1.1 ?
>
> > Regards
> > Koran
>
> Right now that isn't possible, is there any reason you couldn't just bring
> the seperate SUMs into python and do the subtraction there, I realize it
> isn't quite as clean but the overhead should be minimal?
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

If I understand correctly:
Separate SUMs as in the 2nd option which I mentioned above?
It was not possible because currently aggregation methods does not
support SUM - I think because Python itself does not support SUM of
datetime objects.

Or was it:
Separate SUM as in bring all the tuples to Python and then calculate?
It is quite big because there are more than 1 Million tuples so I dont
want to bring everything to Python.

Please let me know whether I have understood correctly.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Aggregation Questions

2009-03-16 Thread koranthala

Hi,
I downloaded Django 1.1 due to aggregation support.
But I am facing one issue which I cannot seem to overcome.
I have two fields which represents two different times.
I want to get the sum of difference of times - and I am unable to
do so.
Basically, I want to do as follows:
SELECT SUM (time2 - time1) FROM _TABLE_ WHERE __XXX___

I tried 2 options:
1. self.filter( XXX).aggregate(diff=Sum('time2 - time1'))
2. self.filter (XXX).aggregate(t2=Sum('time2'), t1= Sum('time1')) - so
that I can do t2 - t1 later.

Both is not supported in Django. I have raw SQL code in model
Manager for the same. I thought using Django Aggregation is better. Is
such operations going to be supported in Django 1.1 ?

Regards
Koran



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding UserManager

2009-03-12 Thread koranthala



On Mar 11, 8:42 pm, koranthala  wrote:
> On Mar 11, 8:34 pm, Alex Gaynor  wrote:
>
>
>
> > On Wed, Mar 11, 2009 at 10:32 AM, koranthala  wrote:
>
> > > Hi,
> > >    I have created an Identity Mapper for my website - which is as
> > > follows:
>
> > > class IdentityMap(object):
> > >    def __getattr__(self, name):
> > >        if not hasattr(self, name):
> > >            setattr(self, name, {})
> > >        return getattr(self, name)
>
> > > MAP = IdentityMap()
>
> > > class MapManager(models.Manager):
> > >    def get(self, *args, **kwargs):
> > >        if kwargs.has_key('mapname'):
> > >            parm = kwargs.pop('mapname')
> > >            dval = getattr(MAP,self.model.__name__)
> > >            if not dval.has_key(parm):
> > >                dval[parm] = super(MapManager, self).get(*args,
> > > **kwargs)
> > >            return dval[parm]
> > >        else:
> > >            return super(MapManager, self).get(*args, **kwargs)
>
> > > #Model which is overriden by all models
> > > class BaseModel(models.Model):
> > >    objects = MapManager()
>
> > >    class Meta:
> > >        abstract = True
>
> > > #--
> > >  --
> > > #
> > > Everytime a get is issued (due to lazy loading I did not implement the
> > > same for filter), it first checks whether the given mapname is already
> > > stored inside MAP, and if not only then will it issue a proper get.
> > > Mapname is given by the user - he can give any unique name to it.
>
> > > Now, I wanted to do it for all models. Since User is part of
> > > django.auth, I overrode User too as given below.
>
> > > from django.contrib.auth.models import User, UserManager
>
> > > class MyUserManager(UserManager):
> > >    def get(self, *args, **kwargs):
> > >        if kwargs.has_key('mapname'):
> > >            parm = kwargs.pop('mapname')
> > >            dval = getattr(MAP,self.model.__name__)
> > >            if not dval.has_key(parm):
> > >                dval[parm] = super(MyUserManager, self).get(*args,
> > > **kwargs)
> > >            return dval[parm]
> > >        else:
> > >            return super(MyUserManager, self).get(*args, **kwargs)
>
> > > class MyUser(User):
> > >    objects = MyUserManager()
>
> > >    class Meta:
> > >        abstract = True
>
> > > #--
> > >  --
> > > #
>
> > > But when I issued a get on MyUser, it is failing with the following
> > > error
>
> > >  File "C:\django\My\..\My\test\test.py", line 164, in UserData
> > >    data.save(form)
> > >  File "C:\django\My\..\My\test\models.py", line 361, in save
> > >    self.user = MyUser.objects.find(form.cleaned_data['user'],
> > > username=form.cleaned_data['user'])
> > >  File "C:\django\My\..\My\test\models.py", line 93, in find
> > >    dval[parm] = self.get(*args, **kwargs)
> > >  File "C:\Python24\Lib\site-packages\django\db\models\manager.py",
> > > line 93, in get
> > >    return self.get_query_set().get(*args, **kwargs)
> > >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > > 337, in get
> > >    num = len(clone)
> > >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > > 161, in __len__
> > >    self._result_cache = list(self.iterator())
> > >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > > 281, in iterator
> > >    for row in self.query.results_iter():
> > >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > > line 254, in results_iter
> > >    for rows in self.execute_sql(MULTI):
> > >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > > line 2011, in execute_sql
> > >    sql, params = self.as_sql()
> > >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > > line 362, in as_sql
> > >    out_cols = self.get_columns(with_col_aliases)
> > >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > 

Re: Overriding UserManager

2009-03-11 Thread koranthala



On Mar 11, 8:34 pm, Alex Gaynor  wrote:
> On Wed, Mar 11, 2009 at 10:32 AM, koranthala  wrote:
>
> > Hi,
> >    I have created an Identity Mapper for my website - which is as
> > follows:
>
> > class IdentityMap(object):
> >    def __getattr__(self, name):
> >        if not hasattr(self, name):
> >            setattr(self, name, {})
> >        return getattr(self, name)
>
> > MAP = IdentityMap()
>
> > class MapManager(models.Manager):
> >    def get(self, *args, **kwargs):
> >        if kwargs.has_key('mapname'):
> >            parm = kwargs.pop('mapname')
> >            dval = getattr(MAP, self.model.__name__)
> >            if not dval.has_key(parm):
> >                dval[parm] = super(MapManager, self).get(*args,
> > **kwargs)
> >            return dval[parm]
> >        else:
> >            return super(MapManager, self).get(*args, **kwargs)
>
> > #Model which is overriden by all models
> > class BaseModel(models.Model):
> >    objects = MapManager()
>
> >    class Meta:
> >        abstract = True
>
> > #-- 
> > --
> > #
> > Everytime a get is issued (due to lazy loading I did not implement the
> > same for filter), it first checks whether the given mapname is already
> > stored inside MAP, and if not only then will it issue a proper get.
> > Mapname is given by the user - he can give any unique name to it.
>
> > Now, I wanted to do it for all models. Since User is part of
> > django.auth, I overrode User too as given below.
>
> > from django.contrib.auth.models import User, UserManager
>
> > class MyUserManager(UserManager):
> >    def get(self, *args, **kwargs):
> >        if kwargs.has_key('mapname'):
> >            parm = kwargs.pop('mapname')
> >            dval = getattr(MAP, self.model.__name__)
> >            if not dval.has_key(parm):
> >                dval[parm] = super(MyUserManager, self).get(*args,
> > **kwargs)
> >            return dval[parm]
> >        else:
> >            return super(MyUserManager, self).get(*args, **kwargs)
>
> > class MyUser(User):
> >    objects = MyUserManager()
>
> >    class Meta:
> >        abstract = True
>
> > #-- 
> > --
> > #
>
> > But when I issued a get on MyUser, it is failing with the following
> > error
>
> >  File "C:\django\My\..\My\test\test.py", line 164, in UserData
> >    data.save(form)
> >  File "C:\django\My\..\My\test\models.py", line 361, in save
> >    self.user = MyUser.objects.find(form.cleaned_data['user'],
> > username=form.cleaned_data['user'])
> >  File "C:\django\My\..\My\test\models.py", line 93, in find
> >    dval[parm] = self.get(*args, **kwargs)
> >  File "C:\Python24\Lib\site-packages\django\db\models\manager.py",
> > line 93, in get
> >    return self.get_query_set().get(*args, **kwargs)
> >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > 337, in get
> >    num = len(clone)
> >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > 161, in __len__
> >    self._result_cache = list(self.iterator())
> >  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
> > 281, in iterator
> >    for row in self.query.results_iter():
> >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > line 254, in results_iter
> >    for rows in self.execute_sql(MULTI):
> >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > line 2011, in execute_sql
> >    sql, params = self.as_sql()
> >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > line 362, in as_sql
> >    out_cols = self.get_columns(with_col_aliases)
> >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > line 588, in get_columns
> >    col_aliases)
> >  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
> > line 633, in get_default_columns
> >    root_pk = opts.pk.column
> > AttributeError: 'NoneType' object has no attribute 'column'
>
> > I even tried changing the metaclass, but it does not seem to have any
> > effect.
> > Can someone help me out?
>
> There was a feature just implemented in the development version that is
> perfect for 
> this.http://docs.djangoproject.com/en/dev/ref/models/options/#managed
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero

Thank you very much. I will try it out with managed=False.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Overriding UserManager

2009-03-11 Thread koranthala

Hi,
I have created an Identity Mapper for my website - which is as
follows:

class IdentityMap(object):
def __getattr__(self, name):
if not hasattr(self, name):
setattr(self, name, {})
return getattr(self, name)


MAP = IdentityMap()

class MapManager(models.Manager):
def get(self, *args, **kwargs):
if kwargs.has_key('mapname'):
parm = kwargs.pop('mapname')
dval = getattr(MAP, self.model.__name__)
if not dval.has_key(parm):
dval[parm] = super(MapManager, self).get(*args,
**kwargs)
return dval[parm]
else:
return super(MapManager, self).get(*args, **kwargs)

#Model which is overriden by all models
class BaseModel(models.Model):
objects = MapManager()

class Meta:
abstract = True

#
#
Everytime a get is issued (due to lazy loading I did not implement the
same for filter), it first checks whether the given mapname is already
stored inside MAP, and if not only then will it issue a proper get.
Mapname is given by the user - he can give any unique name to it.

Now, I wanted to do it for all models. Since User is part of
django.auth, I overrode User too as given below.

from django.contrib.auth.models import User, UserManager

class MyUserManager(UserManager):
def get(self, *args, **kwargs):
if kwargs.has_key('mapname'):
parm = kwargs.pop('mapname')
dval = getattr(MAP, self.model.__name__)
if not dval.has_key(parm):
dval[parm] = super(MyUserManager, self).get(*args,
**kwargs)
return dval[parm]
else:
return super(MyUserManager, self).get(*args, **kwargs)

class MyUser(User):
objects = MyUserManager()

class Meta:
abstract = True

#
#

But when I issued a get on MyUser, it is failing with the following
error

  File "C:\django\My\..\My\test\test.py", line 164, in UserData
data.save(form)
  File "C:\django\My\..\My\test\models.py", line 361, in save
self.user = MyUser.objects.find(form.cleaned_data['user'],
username=form.cleaned_data['user'])
  File "C:\django\My\..\My\test\models.py", line 93, in find
dval[parm] = self.get(*args, **kwargs)
  File "C:\Python24\Lib\site-packages\django\db\models\manager.py",
line 93, in get
return self.get_query_set().get(*args, **kwargs)
  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
337, in get
num = len(clone)
  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
161, in __len__
self._result_cache = list(self.iterator())
  File "C:\Python24\Lib\site-packages\django\db\models\query.py", line
281, in iterator
for row in self.query.results_iter():
  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
line 254, in results_iter
for rows in self.execute_sql(MULTI):
  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
line 2011, in execute_sql
sql, params = self.as_sql()
  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
line 362, in as_sql
out_cols = self.get_columns(with_col_aliases)
  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
line 588, in get_columns
col_aliases)
  File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py",
line 633, in get_default_columns
root_pk = opts.pk.column
AttributeError: 'NoneType' object has no attribute 'column'

I even tried changing the metaclass, but it does not seem to have any
effect.
Can someone help me out?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: opposite of icontains

2009-03-06 Thread koranthala



On Mar 6, 9:15 pm, Jeff FW  wrote:
> Clearly, you get to work on cooler projects than I :-)  I had thought
> of the keywords/phrases case, but the other ones are far more
> interesting.  Thanks for the explanation!
>
> -Jeff
>
> On Mar 5, 7:02 pm, Malcolm Tredinnick 
> wrote:
>
> > On Thu, 2009-03-05 at 12:54 -0800, Jeff FW wrote:
> > > Well, then, that is quite a strange use case :-)  Nevermind my simple
> > > methods.  Malcom's suggestion of an extension for postgres seems like
> > > a good idea--writing functions in various languages (like Python!) is
> > > _really_ easy in postgres.
>
> > > Just out of curiosity (for either of you,) what is a search like that
> > > used for?  I've had a lot of strange requests from a lot of (generally
> > > strange) clients, but that's a pretty weird one.
>
> > It's not that weird at all. It simply depends on the domains you're
> > working in. No idea how it might apply to article headlines, although
> > finding "related matches" could well use something like this.
>
> > It's very common for finding overlaps in sequences of strings, though.
> > The almost "standard" example is DNA sequences where you're trying to
> > find if one sequenced set of data (bases extracted from a genetic
> > sample) correspond to anything else already in the database. Since there
> > can be damage at the extremeties of extractions, or even in the middle
> > (or mutations), finding the longest common substring is the standard
> > approach. There's a whole related area of reasearch in finding the
> > longest palindrome sequences, too, for similar matching and folding
> > purposes.
>
> > Plagarism or even "similar article" testing is another case like this.
> > Finding all "reasonably long" common sequences between a set of source
> > documents and a candidate document is a start.
>
> > One case I built something for was a compressed storage and
> > transmissiong system for PDF and ODF documents. That required doing,
> > essentially, a context-aware diff'ing process and pulling out any large
> > chunks of commonality was the first step.
>
> > Finally, not quite the same problem, but highly related, is the issue
> > of, say, quickly finding all tags or other keywords or phrases that
> > appear in a collection documents. Sometimes partial matching is an
> > appropriate place for generating new phrases, so a modified Aho-Corasick
> > search (just to give you a term to search on if you care) is a starting
> > point.
>
> > This whole domain is a very interesting area for algorithms and
> > implementation.
>
> > Regards,
> > Malcolm

I used the headline example since icontains in Django documentation
was showing that example.
Mine is a case where string search from document text matches specific
values in stored data.
The document in my case, even though text, contained directories,
basic text, and many other similar cases.
The string stored might be a path of the directory - or even a single
piece of text.
So, mine is a very usual case, not at all close to exotic as Malcolm's.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: opposite of icontains

2009-03-04 Thread koranthala

Thank you very much Jeff and Malcolm for the extremely helpful
replies.
Jeff, the substring match is not based on spaces. Rather, the string
can start anywhere and end anywhere.
So, I cannot think of a way to do it, as Malcolm said.
I had also done the same thing as Malcolm, i.e. pulled every tuple to
memory (luckily I dont expect more than 200 odd tuples for this
particular scenario) and am comparing individually - except for the
fact that I was stopping at the first substring match. -  I guess I
should be doing the "longest common substring" as Malcolm mentioned.
Again, thank you Jeff and Malcolm.

On Mar 5, 6:18 am, Malcolm Tredinnick 
wrote:
> On Wed, 2009-03-04 at 05:01 -0800,koranthalawrote:
> > Hi,
> >      How do I implement a substring query?
> >      Please find the example below.
> > From Django Documentation:
> >   Entry.objects.get(headline__icontains='Lennon')
> >   => This matches the headline 'Today lennon honoured'
>
> > My query is the opposite:
> >    I have the string 'Lennon' inside my DB, and I have to match 'Today
> > Lennon honoured'
> > Say:
> > Entry.objects.get(headline__isubstring='Today Lennon Honoured')
> > should return headline 'Lennon'.
>
> >     I checked iregex too, but I cannot seem to solve it myself. If
> > somebody has solved this, could you please help me out.
>
> This isn't the type of searching operating that is going to be standard
> outside of specialised packages. It's actually a really hard problem
> (not impossible, there are solutions, but hard) in general. The
> complexity comes from the fact that the match could start anywhere and
> involve any number of characters. So to do this efficiently requires
> some special datastructures (with suffix trees and some other
> structures, you can the search in about O(total length of text)).
>
> Now, I'm sure it wouldn't be impossible to write, say, an extension for,
> say, PostgreSQL (picking that database because of its excellent support
> for extensions) that supported this kind of searching, but it would be a
> fair bit of work. It would require a particular sort of index structure
> to support the searches. I don't know any package off the top of my head
> that does this for databases. Might be a fun project for somebody with a
> bit of time and curiosity.
>
> I've done this kind of thing in the past for a couple of clients and
> I've always pulled the text to be searched into memory. Create a data
> structure of all the headlines to be searched (using your example) and
> then match the search string against them to find the longest common
> substring match. There's a lot of literature on this sort of stuff, and
> searching for things like "longest common substring" will give you a
> place to start.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



opposite of icontains

2009-03-04 Thread koranthala

Hi,
 How do I implement a substring query?
 Please find the example below.
>From Django Documentation:
  Entry.objects.get(headline__icontains='Lennon')
  => This matches the headline 'Today lennon honoured'

My query is the opposite:
   I have the string 'Lennon' inside my DB, and I have to match 'Today
Lennon honoured'
Say:
Entry.objects.get(headline__isubstring='Today Lennon Honoured')
should return headline 'Lennon'.

I checked iregex too, but I cannot seem to solve it myself. If
somebody has solved this, could you please help me out.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django - spanning relations

2009-03-01 Thread koranthala

Hi,
This is my first Django/DB project, so pardon for the naivete of
the question.

I have one relation in my DB which I cannot - whatever I think of
- seem to do it in a single DB check. Since I have around 5 other
separate SQL statements in that same view, I am worried about the
performance of the system. Is it possible for someone to help me out
how to do it in a single DB check?

 Models:
class CarType(models.Model):
type models.Charfield(max_length=32)

class CarName(models.Model);
name models.CharField(max_length=32, unique=True)
cartype models.ForeignKey(CarType)

class Buyers(models.Model):
 invoice models.IntegerField()
 ...
 cartype models.ForeignKey(CarType)

Now, I have input as car name, which is associated with the car type.
I need to get the buyer details wherein the car type is the same as
the cartype associated with the car name.
Currently, I do the following;
carNameObj = CarName.objects.filter(name__exact=iName)
buyerDetails = Buyers.objects.filter
(cartype__exact=carNameObj.cartype)

As can be seen, there are two separate DB checks for something which I
feel should be done in a single DB check. Is it possible for someone
to help me out?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Transaction Management

2009-02-26 Thread koranthala

Hi,
   Django Reference suggests that we use Transaction Middleware in the
web applications.
   What is the usual practice followed here? Do we use Transaction
Middleware most of the time?

   The reason why I am asking is due to the following reason:
   In my code, I at many places do the following
   Obj = Model(parm1, parm2)
   Obj.save()
   # Now store the id for future use
   l.append(Obj.id)
   etc.

   Now, I think this sort of code should be very usual in Web
Applications. But I cannot understand how this will work, since as per
my understanding, the _id_ will not be obtained until the DB actually
assigns one. Since transaction middleware allows the transaction to be
commited only at the end, this should fail right?

So, I wonder whether there is something missing in my code (say -
do transaction.commit() myself etc), if everybody does use transaction
middleware.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Extract values from form fields in templates

2009-02-20 Thread koranthala



On Feb 18, 11:33 pm, Karen Tracey  wrote:
> On Wed, Feb 18, 2009 at 8:52 AM, koranthala  wrote:
>
> > Hi,
> >    I am unable to extract values from form fields inside templates.
> >    For example:
> >      I have mutiple text fields in which one field says whether the
> > second field is X or not and the second field containing the actual
> > data. (These are initial values which I send from server to client)
> >     Now, in case it is of type X, I want to do something in the
> > template.
>
> > I tried to do it as follows:
> > In template:
> > {% ifequal forms.typename "username" %}
> >   {{ form.name }} 
> > {% else %}
> >   {{ form.text }}
>
> > Django Code:
> > class frm(forms.Form):
> >    typename = forms.CharField(widget=forms.TextInput())
> >    text = forms.CharField(widget=forms.TextInput())
> >    name = forms.CharField(widget=forms.TextInput())
> >    img = forms.CharField(widget=forms.TextInput())
>
> > I was unable to do it via forms, since I cannot extract the data.
> > so I have to have another variable which sends the same data - which
> > is against the DRY principle.
>
> > Is it possible to extract the text data from the form widgets?
>
> I don't have time to verify, but I believe:
>
> {% ifequal forms.typename.data "username" %}
>
> is what you want.
>
> Karen

forms.typename.data returns None.
Maybe there is some other value?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Extract values from form fields in templates

2009-02-18 Thread koranthala

Hi,
I am unable to extract values from form fields inside templates.
For example:
  I have mutiple text fields in which one field says whether the
second field is X or not and the second field containing the actual
data. (These are initial values which I send from server to client)
 Now, in case it is of type X, I want to do something in the
template.

I tried to do it as follows:
In template:
{% ifequal forms.typename "username" %}
   {{ form.name }} 
{% else %}
   {{ form.text }}

Django Code:
class frm(forms.Form):
typename = forms.CharField(widget=forms.TextInput())
text = forms.CharField(widget=forms.TextInput())
name = forms.CharField(widget=forms.TextInput())
img = forms.CharField(widget=forms.TextInput())

I was unable to do it via forms, since I cannot extract the data.
so I have to have another variable which sends the same data - which
is against the DRY principle.

Is it possible to extract the text data from the form widgets?



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Some questions on using Django

2009-02-11 Thread koranthala

Hi all,
   Please excuse me if this is a naive question. I am a developer/
programmer who is now into web development for the first time.
   I have read through Django tutorial and I have a moderate
understanding of how Django works.

   I have two major questions, which is bugging me quite a lot. I will
try to put it succinctly.

(1)
   One problem is that in my site, I am not using templates very much
- My understanding is that on using templates quite a bit only one can
unlock the full efficiency of Django.
   However, when I am designing my site, I find that I am not using
templates too much.

   To explain more: My site is a ajax based site which uses YUI quite
a bit. In almost all pages, html part is very less compared to
javascript and CSS. On an average, the html portion would be around
20-25 lines while CSS is ~300 lines and javascript (not considering
YUI) is ~1000 lines. Using ajax I get 20-30 bytes of data everytime
the user performs some action, and is made in a viewable format using
Javascript.

   Since the code is like this, I use templates for just displaying
very small things - like name of the user etc. Other than that I am
not using template functionalitiles (filters or constructs like if,
for etc) at all.

Could somebody let me know whether this is usual? Am I missing
some basic viewpoints which is causing me to write far too much code
than necessary? i.e. Am I or am I not following Django framework
properly?

(2)
Another question that I have is - is it usual to have no major
architecture in the web coding? i.e. When I used to do C programming,
I used to use all sort of design patterns etc. Now I am into web
programming using Django, and now I dont find the need to have a
complex architecture. The functionality is complex - but I am
implicitly following MVT pattern by using Django and I do not find any
need for other major architectural decisions. The only decisions that
we make now is how to have the DB setup - other than that we just have
code in views to handle individual scenarios based on user actions.
This is very different from my earlier programming experience. So,
I am very much worried that I am missing something major and it is
going to blow up in my face later. If someone can help me on this too,
it would be very helpful.

Regards
Koran

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---