Using distinct and ordering

2011-06-24 Thread Chris Matthews
Hi,

I had a problem with using distinct() which was not so distinct. It was because 
I did not specify an order_by() and the underlying ordering column on the model 
was in values().

It also selects my ordering column (SQL needs it for the ordering) and the SQL 
DISTINCT is applied at row level.

It might be unfortunate that Django does not implement distinct(column/s).

Note that Postgres has this constraint: ERROR: SELECT DISTINCT ON expressions 
must match initial ORDER BY expressions.

It would actually be nice if:
  I could select values('town_name', 'province__country__name', 
'province__name').distinct('town_name').
  Then the distinct('town_name') should generate a SQL DISTINCT ON (town_name) 
town_name.
  The generated SQL should also drop the model ordering if the values(column/s) 
and ordering column/s do not match (because of the SQL constraint).

I am not sure if the other databases supports this.

Here is my model & query (we use Postal Code not Zip Code):

class Postal_Code(AbstractCommonAll):
suburb   = models.CharField()
box_code = models.CharField()
street_code  = models.CharField()
town_name= models.CharField()
province = models.ForeignKey(Province)

class Meta:
ordering = ("suburb",)

For brevity I have left out models: Province (which has ForeignKey to Country).

And my statement was:
self.filter(town_name__istartswith='Randfo').values('town_name').distinct() 
- returns multiple rows 'cos it selects suburb for the ordering.


self.filter(town_name__istartswith='Randfo').values('town_name').distinct().order_by('town_name')
 - works 'cos it's the correct way if you use ordering on another column.

self.filter(town_name__istartswith='Randfo').values('town_name').distinct().order_by()
 - this works as I would have expected 'cos it drops the SQL ORDER BY.

So it would be nice to do this:
self.filter(town_name__istartswith='Randfo').values('town_name', 
'province__country__name', 'province__name').distinct('town_name')

Regards

Chris Matthews


-- 
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: Django app for data management and visualization

2011-04-08 Thread Chris Matthews
Hi Marwan,

Another option that I'll investigate is Google Chart Tools / Image Charts (aka 
Chart API) see http://code.google.com/apis/chart/
Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Marwan Al-Sabbagh
Sent: 07 April 2011 09:59
To: django-users@googlegroups.com
Subject: Re: Django app for data management and visualization

Hi Chris,
  thanks so much for all the information and the links, Its really
helpful. I really like xlwt it's easy, fast, and powerful. I'll most
likely start with allowing the user to export a table of results to an
excel sheet where they can do whatever additional calculations,
formatting, or analysis they want.
  I'm very interested in dealing with charts and graphs but I must say
at this stage its more of a bonus then something our users are
demanding. I'll keep you guys updated on my progress and would love to
get all your feedback on the direction I'm taking and if it's
something that any of you can use on your projects. looking forward to
it.

cheers,
Marwan

On Thu, Apr 7, 2011 at 9:50 AM, Chris Matthews <ch...@bbd.co.za> wrote:
> Hi Marwan,
>
> I am considering an "Excel Export" button wherever I have a table (or 
> jQuery-UI grid).
>
> If you just want data sheets, before writing something, consider this:
> xlwt 0.7.2 Library to create spreadsheet files compatible with MS Excel 
> 97/2000/XP/2003 XLS files, on any platform, with Python 2.3 to 2.6
> http://pypi.python.org/pypi/xlwt
>
> Example (using xwlt) to do export_selected_objects 
> http://davidmburke.com/tag/django/
>
> Xwlt does not do graphs.
>
> There is probably a lot on graphs but I just saw this:
> http://www.gnuplot.info/ and then also a Python interface 
> http://gnuplot-py.sourceforge.net/
>
> Or
> http://sourceforge.net/projects/django-dataplot/
>
>
> For a interesting take on spreadsheets:
> Use Django and jQuery to create a spreadsheet application 
> http://www.ibm.com/developerworks/web/library/wa-django/?ca=drs-
>
> http://www.spreadsheetgear.com/ seemed cool but you net .Net and it will cost 
> you (not sure if it will save you some money).
>
> Regards
> Chris
>
> -Original Message-
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of Marwan Al-Sabbagh
> Sent: 06 April 2011 16:59
> To: django-users@googlegroups.com
> Subject: Re: Django app for data management and visualization
>
> this sounds very interesting to me too. I'm working at a financial
> institution and I'm facing a similar challenge of allowing the users
> to generate ad hoc reports and export those reports to excel. I've
> already implemented this requirement in PHP and I'm in the process of
> migrating these reporting systems to django. I'm very interested to
> see how you plan to do excel exports. I'll also be righting a library
> within the next two months to do that, because I haven't found
> anything that meets our requirements. If it's something you are
> interested in please shoot me an email.
>  as far as importing data from excel sheets into a database check out
> www.python-excel.org and specifically their xlrd package that lets you
> read excel files and traverse the cells. You could use this to extract
> values and populate your database.
>
> Marwan
>
> On Tue, Apr 5, 2011 at 7:03 PM, Gianluca Riccardi
> <riccardi.gianl...@gmail.com> wrote:
>>
>>
>> On 5 Apr, 17:06, alessio c <viandant...@gmail.com> wrote:
>>> Ciao,
>>
>> ciao Alessio,
>>
>>>
>>> yes I do. I need more basic stuff then that and I need tables. Think of this
>>> as tentative to reduce Excel use (which is killing me).
>>>
>>> I can use matplotlib or openflash if I want to go really fancy. However, now
>>> I need to set up the framework. After that, I have a platform from which I
>>> can run all my scripts.
>>>
>>> Let's say I have a database with invoice data from different subsidiaries. I
>>> want to be able to: 1) create different views (subsidiary level, macro
>>> level, invoice level, first 10 invoice, first 10 customers, etc.); 2) upload
>>> data from different formats (because people are lazy and it is impossible to
>>> impose a single format); 3) allow some users to upload data (to avoid them
>>> to send me excel files by email, this is a huge feature...); 4) allow some
>>> other users (managers) to access and download online reports (tables and
>>> graphs).
>>>
>>> Theoretically, when I get this right I am hoping to start a project on git.
>>> The main idea is to create a shared reporting tool.
>>
>>

RE: Django app for data management and visualization

2011-04-07 Thread Chris Matthews
Hi Marwan,

I am considering an "Excel Export" button wherever I have a table (or jQuery-UI 
grid).

If you just want data sheets, before writing something, consider this:
xlwt 0.7.2 Library to create spreadsheet files compatible with MS Excel 
97/2000/XP/2003 XLS files, on any platform, with Python 2.3 to 2.6
http://pypi.python.org/pypi/xlwt

Example (using xwlt) to do export_selected_objects 
http://davidmburke.com/tag/django/

Xwlt does not do graphs.

There is probably a lot on graphs but I just saw this:
http://www.gnuplot.info/ and then also a Python interface 
http://gnuplot-py.sourceforge.net/

Or
http://sourceforge.net/projects/django-dataplot/


For a interesting take on spreadsheets:
Use Django and jQuery to create a spreadsheet application 
http://www.ibm.com/developerworks/web/library/wa-django/?ca=drs-

http://www.spreadsheetgear.com/ seemed cool but you net .Net and it will cost 
you (not sure if it will save you some money).

Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Marwan Al-Sabbagh
Sent: 06 April 2011 16:59
To: django-users@googlegroups.com
Subject: Re: Django app for data management and visualization

this sounds very interesting to me too. I'm working at a financial
institution and I'm facing a similar challenge of allowing the users
to generate ad hoc reports and export those reports to excel. I've
already implemented this requirement in PHP and I'm in the process of
migrating these reporting systems to django. I'm very interested to
see how you plan to do excel exports. I'll also be righting a library
within the next two months to do that, because I haven't found
anything that meets our requirements. If it's something you are
interested in please shoot me an email.
  as far as importing data from excel sheets into a database check out
www.python-excel.org and specifically their xlrd package that lets you
read excel files and traverse the cells. You could use this to extract
values and populate your database.

Marwan

On Tue, Apr 5, 2011 at 7:03 PM, Gianluca Riccardi
 wrote:
>
>
> On 5 Apr, 17:06, alessio c  wrote:
>> Ciao,
>
> ciao Alessio,
>
>>
>> yes I do. I need more basic stuff then that and I need tables. Think of this
>> as tentative to reduce Excel use (which is killing me).
>>
>> I can use matplotlib or openflash if I want to go really fancy. However, now
>> I need to set up the framework. After that, I have a platform from which I
>> can run all my scripts.
>>
>> Let's say I have a database with invoice data from different subsidiaries. I
>> want to be able to: 1) create different views (subsidiary level, macro
>> level, invoice level, first 10 invoice, first 10 customers, etc.); 2) upload
>> data from different formats (because people are lazy and it is impossible to
>> impose a single format); 3) allow some users to upload data (to avoid them
>> to send me excel files by email, this is a huge feature...); 4) allow some
>> other users (managers) to access and download online reports (tables and
>> graphs).
>>
>> Theoretically, when I get this right I am hoping to start a project on git.
>> The main idea is to create a shared reporting tool.
>
> sounds like your going to have some fun ;) good luck, especially if
> you can get rid of dealing with spreadsheets and automate it I'm sure
> users will be happier(you at first;)
>
> if You start a public git repo i'd like to read your progresses
>
> regards,
> Gianluca Riccardi
>
> --
> 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.
>
>

-- 
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.

-- 
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: using a models fields

2011-04-05 Thread Chris Matthews
Hi Jay,

I am no Geo expert but if you use the CharField then you can specify N/E/S/W 
(North/East/South/West) or + and - to control latitude & longitude. With the 
DecimalField you can only use the + and -.

BTW, Marty Alchin's book Pro Django (Chapter 5 page 118), shows a nice example 
to validate user input for latitude & longitude. He actually use the 
DecimalField and extends it with a clean method, checking that latitude values 
to fall in -90 to 90 & longitude values to fall in -180 to 180.

Regards
Chris


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of bishwendu kundu
Sent: 05 April 2011 02:41
To: django-users@googlegroups.com
Subject: Re: using a models fields

You can try saving the data as 
latitude=models.DecimalField(max_digits=7,decimal_places=4).Same for the 
longitude field.Here the max_digits takes into account both decimal and 
non-decimal places.All the data can be given in string form as it will be 
automatically converted to proper format as specified in your models for 
storing in database. I guess you will be using some criteria to extract data 
from the database...so,code can look like

list_of_XYZ()=XYZ.objects.filter(criteria)
for i in list_of_XYZ:
i.latitude,i.longitude ,i.zoomlevel
On Tue, Apr 5, 2011 at 1:45 AM, jay K. 
> wrote:
Hello,

I got a couple of fields from a model I want to use

so the models.py looks like this

class XZY():

   latitude = models.CharField()
   longitude = models.CharField(.)
   zoomlevel = models.CharField()

I want to retrieve the data inside latitude, longitude and zoomlevel
to be able to create a static map for different locations, using google maps

How can I retrieve the fields data?

thanks
--
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.

--
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.

-- 
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: Python Decorators

2011-04-05 Thread Chris Matthews
Hi cootetom,

For decorators you must have a look at the excellent articles/tutorials:
http://www.artima.com/weblogs/viewpost.jsp?thread=240808 
http://www.artima.com/weblogs/viewpost.jsp?thread=240845

It covers decorators with (what you want to do) and without parameters.
Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of cootetom
Sent: 04 April 2011 15:31
To: Django users
Subject: Python Decorators

Hi all, not exactly a django question but here goes... I'm trying to
implement a decorator with one positional argument and one keyword
argument. My wrapper function gets the positional argument just fine
but the keyword argument throws an error "NameError: name 'as_string'
is not defined."

Code is;

def widget(widget_switch, as_string=False):
def decorator(func):
def wrapper(*args, **kwargs):
# logic in here can access the value of 'widget_switch'
but 'as_string' is not defined?
return func(*args, **kwargs)
return wrapper
return decorator

So if I decorate a view function with "@widget('some_widget',
as_string=True)" then the wrapper function is unable to use
'as_string'. I thought this was how python closer worked?

Any ideas?

-- 
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.

-- 
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: How to check the text field values are in my database or not ?

2011-04-01 Thread Chris Matthews
Hi Nge,

Use pgAdmin that was installed with your postgresql. Open a connection to your 
database->Schema->Public->Tables. Right-click on your table and click on View 
data and then take one of the view options.

You can also open a SQL window and run the SQL select yourself. See pgAdmin's 
help.

Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Nge Nge
Sent: 01 April 2011 04:30
To: Django users
Subject: How to check the text field values are in my database or not ?

Hi All!

How can I check the text field value in my database ?
For example, I type user name and password from text box on my web
page. Then I want to check these values are in my database or not.
How should I do? I am using postgresql database.


Thanks
Nge Nge

-- 
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.

-- 
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: staticfile app question

2011-03-31 Thread Chris Matthews
Hi,
I liked this explanation/convention 
http://forum.webfaction.com/viewtopic.php?id=4345 (I opted for this one).

If you want more consider django-css 
https://github.com/dziegler/django-css#readme (I have not tried this).

Regards
Chris


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of typeshige
Sent: 31 March 2011 01:07
To: Django users
Subject: staticfile app question

Like many people, I'm switching over to use a static directory to
serve site media. Overall, it works extremely well, but I have a
question about one aspect of it.

I have a CSS file that includes urls. I was wondering about the
possibility of the staticfile app inserting the proper STATIC_URL as
it's being collected.

For example, things like:

#container-head {
background: transparent url('/static/img/bg/cap/head-inner-
bg.gif') 50% 0 no-repeat;
}

Would it be a bad idea to write like this:

#container-head {
background: transparent url('{{ STATIC_URL }}img/bg/cap/head-inner-
bg.gif') 50% 0 no-repeat;
}

the collectstatic command could insert the right url as it is being
copied?

-- 
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.

-- 
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: multiline TextField

2011-03-31 Thread Chris Matthews
By using the Textarea widget:

class SomeForm(forms.Form):
description = forms.CharField(widget=forms.Textarea())

Regards
Chris


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of electrocoder
Sent: 31 March 2011 00:18
To: Django users
Subject: multiline TextField

Hi. I write blog application. I want multiline TextField.
Sample : paragraph or tab or return
thanks.

-- 
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.

-- 
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: model manager and request

2011-03-31 Thread Chris Matthews
Hi,

1) My need for getting the current user is that I want the following columns on 
all tables: created, created_by, updated and updated_by.

So I defined this abstract class which I inherit from on all models:

class AbstractCommonAll(models.Model):
r''' All our tables will be defined with this class. We always want to know 
who
created it and when it was done. The same goes for who updated it and when 
it was done.

We could either have:
1 A char field for the user.
2 A foreign key to the user table.

If we take option 2 then we must define users for our batch jobs as well 
and all the queries
and updates will have to link to the user table. So let us just implement 
option 1 for now.
We can always change this at a later stage.
'''
created= models.DateTimeField(editable=False, help_text='When this row 
was created')
created_by = models.CharField(max_length=20, editable=False, help_text='Who 
created this row')
updated= models.DateTimeField(editable=False, help_text='When this row 
was updated')
updated_by = models.CharField(max_length=20, editable=False, help_text='Who 
updated this row')

class Meta:
abstract = True

def save(self):
if not self.id:
self.created = datetime.today()
self.created_by = 'user' # we should get this from 
request.User.username 
self.updated = datetime.today()
self.updated_by = 'user' # we should get this from request.User.username

super(AbstractCommonAll, self).save()

I am still going to implement getting the request.User.username as per ProJango 
by Marty Alchin Chapter 11 (page 253 onwards). I could do it in a view but then 
I still need it in the saves via admin. I should probably allocate a user for 
the batch programs and let them sign on so that they may have authenticated 
access and I suspect that I should make this batch user name available to 
AbstractCommonAll.save() because there will not be a request structure 
available.


2) For Audit/History records see the book ProJango by Marty Alchin Chapter 11 
(page 263 onwards) and 
http://qr7.com/2010/10/django-simple-history-ftw/ by Corey Bertram.
It handles the Historical records.

There is a possible error (depending upon your naming convention) when the 
indexes for the history tables are created:
sql_indexes_for_field() in 
/Python26/lib/site-packages/django/db/backends/creation.py creates the database 
index with name being model name + column name. This causes a problem for this 
implementation of history. 
The error is: Failed to install index for myapp.historical_Line model: relation 
" myapp_historical_line_type_id" already exists

It happens when the one modelname + foreignkey column name + '_id' is the same 
as the referenced modelname + '_id', as in the following example:

class Line_Type(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=100)

class Line(models.Model):
type= models.ForeignKey(Line_Type)


So the indexes created would be:
CREATE INDEX " myapp_historical_line*_type_id" ON " myapp_historical_line" 
("type_id");
CREATE INDEX " myapp_historical_line_type*_id" ON " 
myapp_historical_line_type" ("id");
 * is on the model/column name border.

To bypass this error I renamed my linked field (I thought that it would be more 
difficult to have sql_indexes_for_field changed [put a specified literal e.g. 
'_x_' between model & column names]) as follows:

class Line(models.Model):
line_type= models.ForeignKey(Line_Type)

(PS: I prefixed 'zz' to the history table names so that pgAdmin lists them at 
the end of, or after, the 'real' tables).

Regards
Chris


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Tony
Sent: 30 March 2011 22:27
To: Django users
Subject: Re: model manager and request

yeah, shawn said the exact dilemma I am having.  I am working with a
plugged in app and dont want to change its code and mess with its
views and create a new fork, it just seems like small thing to make a
change for (and I would probably mess something else up).

On Mar 30, 11:58 am, Shawn Milochik  wrote:
> Jacob,
>
> This sort of thing comes up so frequently on this list that we've all
> seen those answers dozens of times, although not usually in so concise
> a manner.
>
> My question, to which there seems to be no answer, is what a good
> approach to do something that I know (from spending a long time on
> this list) is also in high demand: Storing audit information.
>
> Simple requirement:
>     Store datetime.now(), request.user, and changes to a model
> automatically on post_save.
>
> Problem:
>     The "correct" solutions do not work. If you're using any pluggable
> apps at all you have to fork them or not log them. Refactoring is not
> an option.
>
> I 

RE: ANN: Django 1.3 released

2011-03-23 Thread Chris Matthews
Thanks it was.
Chrome consistently downloaded it with only 799,034 bytes. I used Windows 
Internet Explorer which downloaded 6,504,003 bytes and the SHA1 is correct and 
7Zip is happy with it. 
PS: I am not punting Internet Explorer ;-)

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Russell Keith-Magee
Sent: 23 March 2011 12:47
To: django-users@googlegroups.com
Subject: Re: ANN: Django 1.3 released

On Wed, Mar 23, 2011 at 6:25 PM, Chris Matthews <ch...@bbd.co.za> wrote:
> I must add my SHA1 on Django-1.3.tar.gz is
> 63e62f9a4834c1c8dbb591aac4ef2b1b84c5ea63 (on all of the downloads I did).
>

In which case, there's something going screwy with your downloads. The
correct SHA1 for Django-1.3.tar.gz, as documented [1] is:

f8814d5e1412bb932318db5130260da5bf053ff7

[1] http://media.djangoproject.com/pgp/Django-1.3.checksum.txt

A number of people validated this independently during the release
process, and I've just revalidated it. There's obviously something
going wrong with your download.

Yours,
Russ Magee %-)

-- 
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.

-- 
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: ANN: Django 1.3 released

2011-03-23 Thread Chris Matthews
I must add my SHA1 on Django-1.3.tar.gz is 
63e62f9a4834c1c8dbb591aac4ef2b1b84c5ea63 (on all of the downloads I did).

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Matthews
Sent: 23 March 2011 12:20
To: django-users@googlegroups.com
Subject: RE: ANN: Django 1.3 released

Well done! Thanks for all the hard work.
I downloaded my version from http://www.djangoproject.com/download/ and Chrome 
says it comes from http://media.djangoproject.com/releases/1.3/Django-1.3.tar.gz

7zip says "Data error in Django-1.3.tar' File is broken". I have downloaded it 
a few times with the same result.



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sultan Imanhodjaev
Sent: 23 March 2011 12:02
To: django-users@googlegroups.com
Subject: Re: ANN: Django 1.3 released

Wow!!! Congratulations people, thanks to developers!
On Wed, Mar 23, 2011 at 3:59 PM, Marco 
<chopin1...@gmail.com<mailto:chopin1...@gmail.com>> wrote:
so happy
On Wed, Mar 23, 2011 at 5:34 PM, bruno desthuilliers 
<bruno.desthuilli...@gmail.com<mailto:bruno.desthuilli...@gmail.com>> wrote:
On 23 mar, 07:15, James Bennett 
<ubernost...@gmail.com<mailto:ubernost...@gmail.com>> wrote:
> It's here!
>
> Django 1.3 has been officially released.
Yay great ! Congrats guys.

--
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<mailto:django-users@googlegroups.com>.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com<mailto:django-users%2bunsubscr...@googlegroups.com>.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



--
LinuX
Violin
Canon EOS
--
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<mailto:django-users@googlegroups.com>.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com<mailto:django-users%2bunsubscr...@googlegroups.com>.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



--
Kind regards,
Sultan Imanhodjaev
+996 779 230 968
--
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.
--
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.

-- 
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: ANN: Django 1.3 released

2011-03-23 Thread Chris Matthews
Well done! Thanks for all the hard work.
I downloaded my version from http://www.djangoproject.com/download/ and Chrome 
says it comes from http://media.djangoproject.com/releases/1.3/Django-1.3.tar.gz

7zip says "Data error in Django-1.3.tar' File is broken". I have downloaded it 
a few times with the same result.



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sultan Imanhodjaev
Sent: 23 March 2011 12:02
To: django-users@googlegroups.com
Subject: Re: ANN: Django 1.3 released

Wow!!! Congratulations people, thanks to developers!
On Wed, Mar 23, 2011 at 3:59 PM, Marco 
> wrote:
so happy
On Wed, Mar 23, 2011 at 5:34 PM, bruno desthuilliers 
> wrote:
On 23 mar, 07:15, James Bennett 
> wrote:
> It's here!
>
> Django 1.3 has been officially released.
Yay great ! Congrats guys.

--
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.



--
LinuX
Violin
Canon EOS
--
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.



--
Kind regards,
Sultan Imanhodjaev
+996 779 230 968
--
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.

-- 
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: Tracking Row changes

2011-02-24 Thread Chris Matthews
Hi Andre,

Also have a look at:
http://code.google.com/p/django-history-tables/
and
http://qr7.com/2010/10/django-simple-history-ftw/ by Corey Bertram based on 
book ProJango by Marty Alchin Chapter 11 (page 263 onwards)

Regards
Chris
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andre Terra
Sent: 25 February 2011 00:56
To: elijah rutschman
Cc: django-users@googlegroups.com
Subject: Re: Tracking Row changes

Thanks a lot! Will look into it first thing tomorrow.

Meanwhile, if anyone has other suggestions, keep them coming, please. Thanks in 
advance!


Sincerely,
André
On Thu, Feb 24, 2011 at 6:15 PM, elijah rutschman 
> wrote:
On Thu, Feb 24, 2011 at 2:54 PM, Andre Terra 
> wrote:
> Hello everyone,
> I'd like to log user changes to MyModel in an app I'm writing. What are some
> third-party solutions that you recommend for this?
django-activity-stream might meet your needs.
https://github.com/justquick/django-activity-stream

Regards,
Elijah

--
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.

-- 
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: field choices() as queryset?

2011-02-24 Thread Chris Matthews
Typo
choices.append((item.name, item.name))
should be
choices.append((item.id, item.name))

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Ramirez
Sent: 24 February 2011 14:10
To: django-users@googlegroups.com
Subject: Re: field choices() as queryset?


On Thursday, February 24, 2011 03:53:03 am galago wrote:

> I need to make a form, which have 1 select and 1 text input. Select must be

> taken from database.

> model looks like this:

> class Province(models.Model):

> name = models.CharField(max_length=30)

> slug = models.SlugField(max_length=30)

>

> def __unicode__(self):

> return self.name

>

> It's rows to this are added only by admin, but all users can see it in

> forms.

> I want to make a ModelForm from that. I made something like this:

> class ProvinceForm(ModelForm):

> class Meta:

> CHOICES = Province.objects.all()

>

> model = Province

> fields = ('name',)

> widgets = {

> 'name': Select(choices=CHOICES),

> }

>

> but it doesn't work. The select tag is not displayed in html. What did I

> wrong?

I haven't done this one in a while, but you need to make the CHOICES a tuple or 
a list[1], not a queryset (unless there has been changes in this specific area).

something like this:

def make_choices():

choices = []

for item in Province.objects.all()

choices.append((item.name, item.name))

return choices

# your form stuff

...

widgets = { 'name': Select(choices=make_choices()), }

The first value is the value stored, the second one is the human readable form 
in the tuple.

Mike

[1] http://docs.djangoproject.com/en/1.2/ref/models/fields/#field-choices

--

Banacek's Eighteenth Polish Proverb:

The hippo has no sting, but the wise man would rather be sat upon

by the bee.
--
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.

-- 
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: urls.py and views.generic issue

2011-02-22 Thread Chris Matthews
Hi Antti,



1) Your day match is for \w{1,2} which will match one or 2 digits but also word 
characters because \w is same as [a-zA-Z0-9_] (see re documentation).



(r'(?P\d{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-w]+)/$'

Should be

(r'(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P[-w]+)/$'



2) The slash before the [ is wrong. See http://docs.python.org/library/re.html 
[] is used to match a set/range of characters.

 (?P\[a-z]{3})"



 
(r'^(?P\d{4})/(?P\[a-z]{3})/(?P\w{1,2})/(?P\[-w]+)/$',

 (r'^(?P\d{4})/(?P\[a-z]{3})/(?P\w{1,2})/$',

 (r'^(?P\d{4})/(?P\[a-z]{3})/$',



3) The list.html is shown because it matches:

(r'^blog/', include('anttipetaisto.blog.urls')),

and then

(r'^$','archive_index', dict(info_dict, template_name='blog/list.html')),





What URL do you enter when you get the error?



Regards

Chris



-Original Message-

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Antti

Sent: 23 February 2011 06:56

To: Django users

Subject: Re: urls.py and views.generic issue



Thanks jnns for the response.  I tried adding the backslash but it

still doesn't match. Would I need to put a different character after

the other entries in the expression? What I mean would there be a

different character used in "(?P\[a-z]{3})" ?  Also one more

note if I type in http://127.0.0.1:8000/blog/ then the page loads

using the list.html template as it should.   I have included the main

urls.py as well as the blog urls.py



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Antti
Sent: 23 February 2011 06:48
To: Django users
Subject: Re: urls.py and views.generic issue



Hello Chris, thanks for the response. I don't know where that space is

coming from.  When I type in http://127.0.0.1:8000/blog/ a page loads

using the list.html template as it should. Would that mean that the

space might be fine because the main urls.py is calling the blog

urls.py?



I have a main urls.py and then I have a blog urls.py. The files are as

below and the space is added somewhere along the lines.



Main urls.py



from django.conf.urls.defaults import *



# Uncomment the next two lines to enable the admin:

from django.contrib import admin



admin.autodiscover()



urlpatterns = patterns('',

# Example:

# (r'^anttipetaisto/', include('anttipetaisto.foo.urls')),



# Uncomment the admin/doc line below to enable admin

documentation:

 (r'^admin/doc/', include('django.contrib.admindocs.urls')),



# Uncomment the next line to enable the admin:

 (r'^admin/', include(admin.site.urls)),

 (r'^tags/(?P[a-zA-Z0-9_.-]+)/$',

'anttipetaisto.tag_views.tag_detail'),

 (r'^blog/', include('anttipetaisto.blog.urls')),

 (r'^static_files/(?P.*)$', 'django.views.static.serve',

{'document_root': '/home/antti/django/anttipetaisto/static_files'}),





Blog urls.py



from django.conf.urls.defaults import *

from anttipetaisto.blog.models import Entry

from tagging.views import tagged_object_list



info_dict = {

'queryset': Entry.objects.filter(status=1),

'date_field': 'pub_date',

}



urlpatterns = patterns('django.views.generic.date_based',

 (r'(?P\d{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-

w]+)/$', 'object_detail', dict(info_dict, slug_field='slug',

template_name='blog/detail.html')),

 (r'^(?P\d{4})/(?P\[a-z]{3})/(?P\w{1,2})/(?

P\[-w]+)/$', 'object_detail', dict(info_dict,

template_name='blog/list.html')),

 (r'^(?P\d{4})/(?P\[a-z]{3})/(?P\w{1,2})/

$','archive_day',dict(info_dict,template_name='blog/list.html')),

 (r'^(?P\d{4})/(?P\[a-z]{3})/$','archive_month',

dict(info_dict, template_name='blog/list.html')),

 (r'^(?P\d{4})/$','archive_year', dict(info_dict,

template_name='blog/list.html')),

 (r'^$','archive_index', dict(info_dict, template_name='blog/

list.html')),

)



On Feb 20, 10:47 pm, Chris Matthews <ch...@bbd.co.za> wrote:

> It also seems that the space preceding the caret ^ should not be there

>

> So

>

> ^blog/ ^(?P\d{4})/$

>

> Should be

>

> ^blog/^(?P\d{4})/$

>

>

>

>

>

>

>

> -Original Message-

> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of jnns

> Sent: 20 February 2011 03:07

> To: Django users

> Subject: Re: urls.py and views.generic issue

>

> Hi Antti,

>

> the url patterns in the tutorial are not correct. The regular

>

> expressions are not using character classes but merely plain

>

> characters.

>

> ^blog/ ^(?Pd{4})/$

>

> should be

>

> ^blog/ ^(?P\d{4})/$

>

> Mind the backslash in \d{4}. This way we're matching for a sequence of

>

> four digits and not for a sequence of four "d"s.

>

> Regards,

>

> jnns

>

> On Feb 20, 12:57 am, Antti <ahpetai...@gmai

RE: urls.py and views.generic issue

2011-02-20 Thread Chris Matthews
It also seems that the space preceding the caret ^ should not be there

So

^blog/ ^(?P\d{4})/$

Should be

^blog/^(?P\d{4})/$





-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of jnns
Sent: 20 February 2011 03:07
To: Django users
Subject: Re: urls.py and views.generic issue



Hi Antti,



the url patterns in the tutorial are not correct. The regular

expressions are not using character classes but merely plain

characters.



^blog/ ^(?Pd{4})/$

should be

^blog/ ^(?P\d{4})/$



Mind the backslash in \d{4}. This way we're matching for a sequence of

four digits and not for a sequence of four "d"s.



Regards,

jnns



On Feb 20, 12:57 am, Antti  wrote:

> The problem:

>

> I can't seem to get most of my urls that I type in my browser to math

> a url in my urls.py file.  I am currently doing Web Monkey's Blog

> Tutorial (http://www.webmonkey.com/2010/02/Get_Started_With_Django/)

> To date everything has worked but when I try to use the urls from the

> blog urls.py I get the following error:

>

> Using the URLconf defined in anttipetaisto.urls, Django tried these

> URL patterns, in this order:

>

> ^admin/doc/

> ^admin/

> ^blog/ (?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-w]

> +)/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-

> w]+)/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/$

> ^blog/ ^(?Pd{4})/$

> ^blog/ ^$

> ^tags/(?P[a-zA-Z0-9_.-]+)/$

> ^static_files/(?P.*)$

>

> The current URL, blog/2011/jan/20/things-learned-finland/, didn't

> match any of these.

>

> What I don't understand why this is saying that isn't a url match.

> Shouldn't it match the third one down?

>

> Thanks

>

> Antti



--

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.


-- 
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: list indices must be integers not unicode

2011-02-18 Thread Chris Matthews
Then you probably want:
id_list = [int(x) for x in data.keys()]

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of balu
Sent: 18 February 2011 13:56
To: Django users
Subject: Re: list indices must be integers not unicode

Thank you Chris Matthews for your reply.

I'm working on a online examination system. I could able to generate
some random questions from a data base containg hundreds of questions.
So when ever a user answer and submit those random questions a
dictionary contating a "Question_id and Answer" pair will be send as a
request.


Now I have to get those dictionary keys first, i.e., the Question_id
and then I have to cross  check the values i.e., the values with the
database values.

On Feb 18, 4:37 pm, Chris Matthews <ch...@bbd.co.za> wrote:
> Oh and you probably wanted:
>
>     if request.method=="POST":
>
>         data = request.POST
>
>        id_list = [int(x) for x in data.values()]
>
>        questions = MyModel.objects.filter(id__in = id_list)
>
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of Chris Matthews
> Sent: 18 February 2011 13:34
> To: django-users@googlegroups.com
> Subject: RE: list indices must be integers not unicode
>
> Hi Balu,
>
> Numeric data from the form must be converted to int. I suspect you wanted to 
> index data; not id_list.
>
>     if request.method=="POST":
>
>         data = request.POST
>
>         temp_list = data.keys()
>
>         id_list = []
>
>        for i in temp_list:
>
>              id_list.append(id_list[i])
>
>        questions = MyModel.objects.filter(id__in = id_list)
>
> Should
>
> id_list.append(id_list[i])
>
> Not be
>
> id_list.append(data[i])
>
>
>
> -Original Message-
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of balu
> Sent: 18 February 2011 13:24
> To: Django users
> Subject: list indices must be integers not unicode
>
> Hi all :)
>
> I'm processing a user submitted form. In that the user will answer a
>
> series of multiple choice questions. Depending on the question "id"
>
> which are submitted I'll find the compare the values and increment the
>
> score to count his marks.
>
> The question ids are  keys from the dictionary request.POST. But it is
>
> showing an error the list indices must be integers not unicode. I
>
> wrote the code as follows.
>
> // In the view function
>
>     if request.method=="POST":
>
>         data = reques.POST
>
>         temp_list = data.keys()
>
>         id_list = []
>
>        for i in temp_list:
>
>              id_list.append(id_list[i])
>
>        questions = MyModel.objects.filter(id__in = id_list)
>
> --
>
> 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 
> athttp://groups.google.com/group/django-users?hl=en.
>
> --
> 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 
> athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

-- 
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.

-- 
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: list indices must be integers not unicode

2011-02-18 Thread Chris Matthews
Oh and you probably wanted:

if request.method=="POST":

data = request.POST

   id_list = [int(x) for x in data.values()]



   questions = MyModel.objects.filter(id__in = id_list)


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Matthews
Sent: 18 February 2011 13:34
To: django-users@googlegroups.com
Subject: RE: list indices must be integers not unicode


Hi Balu,



Numeric data from the form must be converted to int. I suspect you wanted to 
index data; not id_list.





if request.method=="POST":

data = request.POST

temp_list = data.keys()

id_list = []



   for i in temp_list:

 id_list.append(id_list[i])



   questions = MyModel.objects.filter(id__in = id_list)



Should

id_list.append(id_list[i])

Not be

id_list.append(data[i])





-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of balu
Sent: 18 February 2011 13:24
To: Django users
Subject: list indices must be integers not unicode



Hi all :)



I'm processing a user submitted form. In that the user will answer a

series of multiple choice questions. Depending on the question "id"

which are submitted I'll find the compare the values and increment the

score to count his marks.



The question ids are  keys from the dictionary request.POST. But it is

showing an error the list indices must be integers not unicode. I

wrote the code as follows.





// In the view function



if request.method=="POST":

data = reques.POST

temp_list = data.keys()

id_list = []



   for i in temp_list:

 id_list.append(id_list[i])



   questions = MyModel.objects.filter(id__in = id_list)



--

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.


--
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.

-- 
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: list indices must be integers not unicode

2011-02-18 Thread Chris Matthews
Hi Balu,



Numeric data from the form must be converted to int. I suspect you wanted to 
index data; not id_list.





if request.method=="POST":

data = request.POST

temp_list = data.keys()

id_list = []



   for i in temp_list:

 id_list.append(id_list[i])



   questions = MyModel.objects.filter(id__in = id_list)



Should

id_list.append(id_list[i])

Not be

id_list.append(data[i])





-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of balu
Sent: 18 February 2011 13:24
To: Django users
Subject: list indices must be integers not unicode



Hi all :)



I'm processing a user submitted form. In that the user will answer a

series of multiple choice questions. Depending on the question "id"

which are submitted I'll find the compare the values and increment the

score to count his marks.



The question ids are  keys from the dictionary request.POST. But it is

showing an error the list indices must be integers not unicode. I

wrote the code as follows.





// In the view function



if request.method=="POST":

data = reques.POST

temp_list = data.keys()

id_list = []



   for i in temp_list:

 id_list.append(id_list[i])



   questions = MyModel.objects.filter(id__in = id_list)



--

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.


-- 
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: How to Auto fill fields on Save in Django Admin?

2011-02-16 Thread Chris Matthews
Hi Matteius,

You must set blank=True in the model so that the form can be returned to you 
with those fields empty and then you fill it in the save().

pub_date = models.DateTimeField(blank=True)
author = models.ForeignKey(User, blank=True, verbose_name='Author')

Also read up on editable=False

Regards
Chris
-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Matteius
Sent: 17 February 2011 08:47
To: Django users
Subject: How to Auto fill fields on Save in Django Admin?

I have an Announcement model that has two fields I want to auto-fill
in when they are left blank (they are required fields with normal
defaults).  I have the following Code (simplified data listing for
this post)  THe Problem is that when I go to save an Announement
in the admin with either of those fields blank it returns to the Add/
Edit Form with "This field is required." despite my code to try and
fill that in.  Clearly I'm missing how to do this, any advice?

class Announcement(models.Model):
""" Represents an Announcement in the classcomm system. """

# Data Model Fields
pub_date = models.DateTimeField()
author = models.ForeignKey(User, verbose_name='Author')

def clean(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).clean()
# EndDef

def save(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).save()
# EndDef
# EndClass

Then in admin.py I have:

class AnnouncementAdmin(admin.ModelAdmin):
""" Admin customizations for Announcement Models. """
fieldsets = (
(None, {
'fields': ('headline', 'department', 'course', 'content')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('author', 'pub_date', 'make_global')
}),
)

def save_model(self, request, obj, form, change):
""" Autofill in author when blank on save models. """
obj.author = request.user
obj.save()
# EndDef

def save_formset(self, request, form, formset, change):
""" Autofill in author when blank on save formsets. """
instances = formset.save(commit=False)
for instance in instances:
instance.author = request.user
instance.save()
formset.save_m2m()
# EndDef
# EndClass


Regards,
Matt

-- 
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.

-- 
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: how can I filter related (foreign key) objects?

2011-02-16 Thread Chris Matthews
Hi Serek,



Try this

def doMagic(self):

date = '2010-05-04'

#//here I need to take 10 conencted Bbb objects whcich data is less 
then date

previous10days = Bbb.objects.filter(date__lt=date).order_by('data')



Also read up about managers 
http://docs.djangoproject.com/en/1.2/topics/db/managers/ in case you should 
consider using it (depending upon how much magic is required from your 
function).



Regards

Chris



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of serek
Sent: 17 February 2011 00:51
To: Django users
Subject: how can I filter related (foreign key) objects?



Hi



I have not idea how to describe my problem, so I show pice of code:





class Aaa(models.Model):

name = models.CharField(max_length=200, unique=True)

is_active = models.BooleanField()



class Meta:

ordering = ('name',)



def doMagic(self):

  date = '2010-05-04'

  //here I need to take 10 conencted Bbb objects whcich data is less

then date

previous10days = self.bbb_set.filter(Bbb.date <

date).order_by('data')





class Bbb(models.Model):

date = models.DateField()

value = models.DecimalField(max_digits=7, decimal_places=2)

aaa = models.ForeignKey(Aaa)



a = Aaa()

a.doMagic throw error that Bbb.date is undefined - what can be wrong?



--

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.


-- 
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: form select box how to (help needed)

2011-02-16 Thread Chris Matthews
Hi Bobby,

See 
http://adil.2scomplement.com/2008/05/django-add-choices-to-form-fields-on-runtime/

Try something like the following:

# Define your choices
LOCATION_CHOICES = ((1,'location1'),
(2,'location2'),
(3,'location3'),
(4,'location4'),
   )

LOCATION_CHOICES_PUBLIC = ((1,'location1'),
(2,'location2'),
(3,'location3'),
   )

Example 1
-
class ProfileForm(forms.Form):
class Meta:
model = Profile

locations = forms.ChoiceField(required=True)

def __init__(self, *args, **kwargs):
# This is a bit of a hack
if 'user_type' in kwargs and kwargs['user_type'] == 'public':
public = True
# We do not want to pass our kwarg to super
del kwargs['user_type']
else:
public = False

super(ProfileForm, self).__init__(*args, **kwargs)

if 'user_type' in kwargs and kwargs['user_type'] == 'public':
self.fields['locations'].choices = LOCATION_CHOICES_PUBLIC
else:
self.fields['locations'].choices = LOCATION_CHOICES

In your module use
form = ProfileForm(user_type='public')
or
form = ProfileForm()

Example 2
-
class ProfileForm(forms.Form):
class Meta:
model = Profile

# the limited choices are our default
locations = forms.ChoiceField(choices = LOCATION_CHOICES_PUBLIC, 
required=True)

In your module
form = ProfileForm()
if not public:
form.fields['locations'].choices = LOCATION_CHOICES


Example 2 is a bit 'cleaner'/neater I think.

Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bobby Roberts
Sent: 16 February 2011 15:14
To: Django users
Subject: Re: form select box how to (help needed)

i have no idea what this means is there an example anywhere?

On Feb 16, 12:43 am, Kenneth Gonsalves  wrote:
> On Tue, 2011-02-15 at 19:05 -0800, Bobby Roberts wrote:
> > I can't load it through the "CHOICES" parameter in my forms field...
> > how can I do this?
>
> override __init__ in your form and populate there
> --
> regards
> KGhttp://lawgon.livejournal.com
> Coimbatore LUG roxhttp://ilugcbe.techstud.org/

-- 
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.

-- 
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: 'str' object is not callable

2011-02-16 Thread Chris Matthews
Hi Patrick,



You can typically get it by:

1)missing the % for a string format:

  x = "Hello number %d" (5)

  TypeError: 'str' object is not callable



2) And if you overwrite a function name with a string, e.g."

>>> min(5,2,3)

2



>>> hour,min,sec = "14:59:03".split(":")

>>> min(5,2,3)

TypeError: 'str' object is not callable



Just check your recent code.



Regards

Chris



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Szabo, Patrick (LNG-VIE)
Sent: 16 February 2011 14:03
To: django-users@googlegroups.com
Subject: 'str' object is not callable



Hi,



Im getting 'str' object is not callable and i have no idea why.

What I'm doing is the following:



delete



buchung is a list and the 6th element oft hat list is an object with an

attribute id.



In my urls.py i did this:



(r'deletion_time/(?P\d+)/$', 'deletion_time'),



And the view looks like this:



def deletion_time(request, obj_id):

buchung = Buchung.object.filter(id = obj_id)

buchung.delete()

return HttpResponseRedirect('/main/')



Can anyone tell me what's causing this error ?!



Kind regards



. . . . . . . . . . . . . . . . . . . . . . . . . .

Patrick Szabo

 XSLT-Entwickler

LexisNexis

Marxergasse 25, 1030 Wien



mailto:patrick.sz...@lexisnexis.at

Tel.: +43 (1) 534 52 - 1573

Fax: +43 (1) 534 52 - 146











--

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.


-- 
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: Importing modules in code

2011-02-16 Thread Chris Matthews
Hi Galago,

For some conventions see 
http://docs.djangoproject.com/en/dev/internals/contributing/?from=olddocs#django-conventions
and http://www.python.org/dev/peps/pep-0008/

Generally I do imports at the top of the module in this order (with a blank 
line inbetween):

1.   python modules

2.   django modules

3.   3rd party modules

4.   Your project/application modules

Regards
Chris

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of galago
Sent: 16 February 2011 10:39
To: django-users@googlegroups.com
Subject: Importing modules in code

Is it a good idea to import modules in the middle of the code, and not on the 
beginning?
I want to make a hash generation. It's few lines - it's used once in all 
application. Should I import hashlib just on the beginning of the file? Now I 
put it with the rest of the code.
Is it bad?

I don't want to import it with all requests in my app view.
--
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.

-- 
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: Progress Bar/ProgressBarUploadHandler Documentation Examples

2011-02-15 Thread Chris Matthews
Hi Hank,

I just got the book "jQuery UI 1.7" by Dan Wellman. Chapter 8 covers 
Progressbar. Have not worked through it yet so I can't give my view on it.

Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of hank23
Sent: 16 February 2011 00:27
To: Django users
Subject: Re: Progress Bar/ProgressBarUploadHandler Documentation Examples

Are there any other good options or coding examples besides this one
or is it the best and most complete?

On Feb 15, 8:20 am, Derek  wrote:
> Fortunately, other clever coders have written up on 
> this:http://fairviewcomputing.com/blog/2008/10/21/ajax-upload-progress-bar...
>
> On Feb 14, 4:56 pm, hank23  wrote:
>
>
>
> > Are there any exampels of how to code Progress bars or the handlers
> > which support them somewhere in the django documentation? they're
> > referenced in the documentation, but without showing any actual coding
> > examples.- Hide quoted text -
>
> - Show quoted text -

-- 
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.

-- 
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: Saving multiple records from admin list page

2011-02-15 Thread Chris Matthews
Hi Sithembewena,

If you want to monitor changes to tables then you might also be interested in 
keeping audit/history records. See the book ProJango by Marty Alchin Chapter 11 
(page 263 onwards) and http://qr7.com/2010/10/django-simple-history-ftw/  by 
Corey Bertram

Regards
Chris

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sithembewena Lloyd Dube
Sent: 15 February 2011 11:17
To: django-users@googlegroups.com
Subject: Saving multiple records from admin list page

Hi all,

In my admin.py, I overrode the save() function of a model as follows:

from myproject.myapp.functions import 
send_staking_request_status_notification_email

def save_model(self, request, obj, form, change):
  staking_request = obj
  obj.save()
  send_staking_request_status_notification_email(staking_request)

Therefore, when an admin user logs in and saves a record, an email is sent off 
to a site member. The function that does the emailing is imported from a custom 
module and this works fine.

However, on the list page of said model in the admin area, the admin user is 
also able to select an action to apply to multiple records. How can I modify my 
admin.py so that the save() override specified above
fires for all records?

Thanks.
--
Regards,
Sithembewena Lloyd Dube
--
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.

-- 
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: Django Form Doesn't Render

2011-02-14 Thread Chris Matthews
Hi Dean,



Looks like you pass the class ContractForm in to your render (and not the 
variable contractForm). Also on naming (PEP 8) contract_form would have been 
nicer for the variable (and would have stood out more so that the error was 
easier to spot).



Regards

Chris



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Dean Chester
Sent: 15 February 2011 00:25
To: Django users
Subject: Django Form Doesn't Render



Hi,

I have written a form in forms.py that looks like this:

class ContractForm(forms.Form):

  title = forms.CharField()

  start_date = forms.DateField()

  end_date = forms.DateField()

  description = forms.CharField(widget=forms.Textarea)

  client = forms.ModelChoiceField(queryset=Client.objects.all())



And in my view (yes i know there are problems with data not being

checked but the aim was to get the client field to display clients

associated with that user):

def addContractTEST(request):

  if request.method == 'POST':

contractForm = ContractForm(request.POST)

title = request.POST['title']

start_date = request.POST['start_date']

end_date = request.POST['end_date']

description = request.POST['description']

client = request.POST['client']

user = request.user

contract =

Contract(title,start_date,end_date,description,client,user)

contract.save()

return HttpResponseRedirect('../../accounts/profile/')

  else:

user = request.user

print user.username

contractForm = ContractForm()

return render_to_response('newcontract.html', {'ContractForm':

ContractForm})



And my newcontract.html:



 





  {% if contractForm.errors %}

  

Please correct the error{{ contractForm.errors|pluralize }} below.

  

  {% endif %}

  



  {{ contractForm.as_p }}



  



  



But all that appears is my submit button so what am I doing wrong?



Thanks in Advance,

Dean



--

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.


-- 
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: Need a tutorial for 'regexpr'

2011-02-10 Thread Chris Matthews
Hi Navaneethan,

It is like riding a bicycle; initially you falter a bit but later you ride with 
style.

See http://www.regular-expressions.info/tutorial.html and 
http://www.regular-expressions.info/javascript.html

Try not to build too complex expressions; always think of the guy who has to 
maintain it long after you have coded it.

Run /Python26/Tools/Scripts/redemo.py to interactively test your regular 
expressions. It works really well.
If you want to use and see named groups you can update redemo.py with:
Between line 150 and 151: 
 self.grouplist.insert(END, g)
nmatches = nmatches + 1

Insert (de-dented once, same as for line 148):
#_Start Chris Matthews 
10 May 2005
self.grouplist.insert(END, "Named Groups:")
GroupDict = m.groupdict()
if GroupDict:
   self.grouplist.insert(END, "{")
   keysGroupDict = GroupDict.keys()
   keysGroupDict.sort()
   for Name in keysGroupDict:
  self.grouplist.insert(END, "'%s': '%s'" % (Name, 
GroupDict[Name]))
   self.grouplist.insert(END, "}")
lstFindAll = self.compiled.findall(text)
self.grouplist.insert(END, "\nFindAll: %s" % (lstFindAll))

   
Here is a nice quick reference to print and keep close by:
=
 Regular Expression Primitive Quick Reference
Regular expressions can contain both special and ordinary characters. Most 
ordinary characters, like "A", "a", or "0", are the simplest regular 
expressions; they simply match themselves. You can concatenate ordinary 
characters, so last matches the string 'last'. 
Some characters, like "|" or "(", are special. Special characters either stand 
for classes of ordinary characters, or affect how the regular expressions 
around them are interpreted. 
The special characters are: 
.   (Dot.) In the default mode, this matches any character except a 
newline. 
^   (Caret.) Matches the start of the string. 
$   Matches the end of the string. 
*   Match 0 or more repetitions of the preceding RE.
+   Match 1 or more repetitions of the preceding RE. 
?   Match 0 or 1 repetitions of the preceding RE. 
{m} Specifies that exactly m copies of the previous RE should be matched. 
{m,n}   Causes the resulting RE to match from m to n repetitions of the 
preceding RE.
\   Escapes special characters ("*", "?", or \a \b \f \n \r \t \v \x \\)
[]  Range of characters e.g. [0-3A-C]  for 0123ABC,  [^5] match any except 
"5".
|   Or
()  Group
(?P...) Named group

Regular Expression Extended Quick Reference
\d  Any decimal digit; same as [0-9]. 
\D  Any non-digit character; same as [^0-9]. 
\s  Any whitespace character; same as [ \t\n\r\f\v]. 
\S  Any non-whitespace character; same as [^ \t\n\r\f\v]. 
\w  Any alphanumeric character and the underscore; same as [a-zA-Z0-9_].
\W  Any non-alphanumeric character; same as [^a-zA-Z0-9_].
=


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Kenneth Gonsalves
Sent: 11 February 2011 08:50
To: django-users@googlegroups.com
Subject: Re: Need a tutorial for 'regexpr'

On Thu, 2011-02-10 at 22:47 -0800, NavaTux wrote:
> Do you know any elegant tutorial to learn a regular 
> expression from a nutshell ? i have referred some links which are
> given in 
> a syntax without simple example, just i need a simple examples with
> clear 
> explanation even i tried in past two days to pick it 

http://www.python.org/doc//current/howto/regex.html
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

-- 
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.

-- 
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: Adding popups for edit

2011-02-02 Thread Chris Matthews
Hi Marco,

Again the book "Django JavaScript Integration: AJAX and jQuery" by Jonathan 
Hayward. In Chapter 6 he covers jQuery In-place editing by using 
http://www.appelsiini.net/projects/jeditable

PS: I have never met Jonathan, I live far-away in Africa, so I am not plugging 
his book. I happen to read it currently and it seems to cover the questions.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Dekker
Sent: 02 February 2011 12:44
To: Django users
Subject: Adding popups for edit

Hi

Django Admin includes Popups for adding (FK) records by clicking the
"+"-image next to the foreign key.

I would like to add an "edit"-button, that would allow for a popup to
edit the currently selected entry. Can I "copy" the behaviour of the
"+"-image (showAddAnotherPopup and dismissAddAnotherPopup) or is there
a reason why this was never implemented?

Any supporting hints will be gladly taken!

Thanks,
Marco

-- 
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.

-- 
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: Filtered drop down choice django

2011-02-02 Thread Chris Matthews
Hi Sushanth,

I am currently working through the book "Django JavaScript Integration: AJAX 
and jQuery" by Jonathan Hayward. In Chapter 7 he covers autocomplete (see 
http://jqueryui.com/ or more specifically 
http://jqueryui.com/demos/autocomplete/) to handle filtered drop down.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andre Terra
Sent: 02 February 2011 12:05
To: django-users@googlegroups.com
Subject: Re: Filtered drop down choice django

Patches are welcome!
On Wed, Feb 2, 2011 at 07:48, Derek 
> wrote:
I suspect I am not the only one really hoping for An Official Way to
be developed at some time...

In the meantime, also look at:
http://www.stereoplex.com/blog/filtering-dropdown-lists-in-the-django-admin

I think this is quite detailed and has some good comments as well.

On Feb 1, 7:07 pm, shacker 
> wrote:
> On Jan 31, 6:40 am, sushanth Reddy 
> > wrote:
>
> > I am trying to create a dynamic filtered drop down choice fields,i gone
> > through below blog but it confusing,can any one suggest easy way to do this
> > in django.
>
> Do you mean in the admin or on your live site? If in the admin,  check
> out the docs on ModelAdmin.formfield_for_foreignkey:
>
> http://docs.djangoproject.com/en/1.1/ref/contrib/admin/
>
> class MyModelAdmin(admin.ModelAdmin):
> def formfield_for_foreignkey(self, db_field, request, **kwargs):
> if db_field.name == "car":
> kwargs["queryset"] =
> Car.objects.filter(owner=request.user)
> return db_field.formfield(**kwargs)
> return super(MyModelAdmin,
> self).formfield_for_foreignkey(db_field, request, **kwargs)
>
> If you're trying to do this on your live site, you can do whatever
> filtering you like in your view of course.

--
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.

--
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.

-- 
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: Django SQL Query does not stop

2011-02-01 Thread Chris Matthews
Hi Ivo,

SQL is like regular expressions. You can go complex (with one mega 
query/expression) but it could create a maintenance nightmare. See if you 
cannot simplify the query into multiple queries and a bit of code (for loops 
and using the joining columns) to lash them together. The code sequence should 
be such that you limit access to a huge amount of rows; so you filter the data 
accessed. It is usually easier to debug as well. And using Tom's advice 
(EXPLAIN SELECT ...) on smaller join queries is often more useful (than the 
explain on a mega join query).

In my experience it often runs way faster if the query is simplified.

Regards
Chris
-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Ivo Brodien
Sent: 01 February 2011 23:49
To: django-users@googlegroups.com
Subject: Re: Django SQL Query does not stop

I found a solution be changing the MySQL server setting optimizer_search_depth 
to 3 (default 62)

http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_optimizer_search_depth

My query had over 20 INNER JOINTS and it made the optimizer search a long 
process.

So at the moment a value of 3 is fine.

On 01.02.2011, at 21:20, Ivo Brodien wrote:

> The Change List that I am calling is a Intermediate Table if that is of any 
> interest.
> 
> Is it possible that there is some sort of circular inner joints or something?
> 
> 

-- 
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.

-- 
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: Django Template CSS Load Path

2011-01-30 Thread Chris Matthews
change
href='{{ MEDIA_URL }}/static/PageStyle.css' />
to
href='{{ MEDIA_URL }}static/PageStyle.css' />

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of octopusgrabbus
Sent: 29 January 2011 21:17
To: Django users
Subject: Re: Django Template CSS Load Path

I still cannot get the css page to load.

On Jan 19, 4:02 pm, Matías Iturburu  wrote:
> On Wed, Jan 19, 2011 at 5:30 PM, Eduardo Cereto Carvalho <
>
> eduardocer...@gmail.com> wrote:
> > You can use MEDIA_URL conf to get the root path to your media files.
>
> >  > />
>

My MEDIA_URL is MEDIA_URL = 'http://localhost:8002/'

I have added 
to my base template.

I'm not sure what changes I'm supposed to make regarding
TEMPLATE_CONTEXT_PROCESSORS. I don't have that constant in my
settings.py nor do I have   'django.core.context_processors.request'
or 'django.core.context_processors.media' in any of my application
files.

tnx
cmn

> the above code is correct, just make sure that you are using the media
> context processor or returning a RequestContext, not just plain Context.
> Check out your settings.py for this one of this in the
> TEMPLATE_CONTEXT_PROCESSORS constant.
>
> 'django.core.context_processors.request',
> 'django.core.context_processors.media',
>
>
>
>
>
> > On Wed, Jan 19, 2011 at 5:55 PM, octopusgrabbus  > > wrote:
>
> >> I am trying to load a css file in my base.html template
>
> >> 
> >>
> >>
> >>{% block title %}Test{% endblock %} 
> >>
> >>   
>
> >> What kind of path is supposed to go in the href? Is it relative to the
> >> document root?
>
> >> Does anyone have an example of loading a css file including the Apache
> >> configuration?
>
> >> Thanks.
> >> cmn
>
> >> --
> >> 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.
>
> > --
> > Eduardo Cereto Carvalho
>
> > --
> > 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.
>
> --
> Matías Iturburuhttp://www.linkedin.com/in/miturburu|http://ltmo.com.ar

-- 
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.

-- 
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: abstract base class and overwriting save()

2011-01-28 Thread Chris Matthews
The "save def save(self, *args, **kwargs):" should not have the leading save.

Also, if you are making a car system then this structure seems more appropriate:
class CarMake(models.Model):
   ...


class Car(models.Model):
   make = models.ForeignKey(CarMaker)
   ...
 def save(self, *args, **kwargs):
do_something()
super(Car, self).save(*args, **kwargs)



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Daniel Roseman
Sent: 28 January 2011 11:36
To: django-users@googlegroups.com
Subject: Re: abstract base class and overwriting save()

On Friday, January 28, 2011 9:21:48 AM UTC, Jaroslav Dobrek wrote:
Hi,

if I have got several models that have identical code, except for
their save method, how can I use an abstract base class for them? Will
I have to overwrite save() for each model? Or is there a generic way
to define save(), i.e. a way that I have to use only once -- in the
abstract base class?

class BMW(models.Model):
   ...
  save def save(self, *args, **kwargs):
do_something()
super(BMW, self).save(*args, **kwargs)

class Fiat(models.Model):
   ...
  save def save(self, *args, **kwargs):
do_something()
super(Fiat, self).save(*args, **kwargs)

Jaroslav

The whole point of subclassing is that subclasses inherit models from the 
superclass. That's how the model save() method is definted in the first place, 
if you don't override it. What exactly are you having problems with?
--
DR.
--
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.

-- 
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: Challenge with installing django on windows 7 64 bit

2011-01-26 Thread Chris Matthews
1) Generally "not a valid archive" means the file was corrupted during the 
download/copy or the download/copy did not complete. If you used ftp to copy 
the file and the file mode settings was ASCII (not binary) then you can have a 
corrupt file (because CR 0x0D gets converted to CRLF 0x0D0A). If that is the 
case then download it again. You can confirm it was corrupt if you keep the 1st 
version of your archive and compare it with the 2nd one (using DOS/Windows file 
compare command: comp file1 file2

2) You can see if Python's gzip likes your archive (from Python help):
import gzip
f = gzip.open('/home/joe/file.txt.gz', 'rb')
file_content = f.read()
f.close()

3) If it is a 64 bit/Windows 7 issue then:
Have you tried changing your 7z's compatibility settings to run it in an older 
mode? In explorer: Right-click on exe file -> properties -> compatibility -> 
"Run this program in compatibility mode for" and then choose Windows XP


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Magge
Sent: 26 January 2011 19:24
To: Django users
Subject: Challenge with installing django on windows 7 64 bit

Hi,

I am trying to extract the installation files from the
Django-1.2.4.tar.gz file that I got from the django website. I tried
using winzip, 7z, cygwin and so forth. All these programs complain
that the file isnt a valid archive.

I used to work with django back in 2009 on Window. The installation
used to be off the extract of a zip file I remember. How do I get
going with the installation?

I appreciate any inputs on this

Thanks
Keshav Magge

-- 
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.

-- 
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: forbid clones

2011-01-26 Thread Chris Matthews
Have a look at unique_together:
Django | Model Meta options | Django documentation
http://docs.djangoproject.com/en/dev/ref/models/options/

Jump to unique_together‎: Options.unique_together¶. Sets of field names that, 
... For convenience, unique_together can be a single list when dealing ...
docs.djangoproject.com/en/dev/ref/models/options/
Labeled Latest docs  1.0 docs  All docs


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jaroslav Dobrek
Sent: 26 January 2011 14:26
To: Django users
Subject: Re: forbid clones

>
> http://docs.djangoproject.com/en/1.2/ref/models/fields/#unique

Although this does help, it leaves one question open:

How can we forbid only such pairs of objects that have the same value
in all of their attributes.

Example:

This should be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "baz"

This should not be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "bar"


-- 
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.

-- 
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: DB-Views or read-only tables in models

2011-01-25 Thread Chris Matthews
Not sure if http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/ 
will be of some help. See admin.site.disable_action('delete_selected')
; but this is only via the admin app. You could build some logic in the model 
by overriding the save() method, conditionally, based upon user. So your 
developers/administrators can have full access but 'normal' users not.


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of bvdb
Sent: 25 January 2011 18:20
To: Django users
Subject: DB-Views or read-only tables in models

A developer sometimes has to access and present data that existed
before his application. Common practice is for a database
administrator to define a database view (with a CREATE VIEW sql
command, not to be confused with the V in MVC) and give the Django
developer access to this. This is only a read access because in most
cases it is not possible or desireable to allow an UPDATE on a view.

Now I am new to Django, have some experience with databases - and
couldn't find a "read-only attribute" when defining a model.
Without knowing that a view - that is accessed with the same SELECT
syntax as a table - is read-only Django would for example generate an
admin interface that produces errors, and leave the user wondering
why.
It makes also sense in some cases to define a table read-only for a
model even it is fully accessible by the Django team.

Is it really not possible to define read-only access in Djangos ORM?
Or maybe I just overlooked the description?

-- 
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.

-- 
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: list of lists in template

2011-01-07 Thread Chris Matthews
{%  for Ltarp in  smth.3 %}
SHOULD BE 
{%  for Ltarp in  smth.2 %}
'cos Lans only has 3 elements and Ltarp is Lans[2].

Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com] On 
Behalf Of gintare
Sent: 07 January 2011 08:52
To: Django users
Subject: list of lists in template


in view.py
...
Ltarp.append([item.Wordword, item.WordTranslEn, item.WordNotesGram,
item.WordConcl])
..
Lans.append([sen.Sent, sen.SentTransl, Ltarp ] )

in template.html
{% if Lans %}

{%  for smth in Lans %}

  {{smth.0}} 

{%  for Ltarp in  smth.3 %}

 {{Ltarp.0}} 


{% endfor %}


{% endfor %}

{% endif %}

###

the rows from smth.0 are shown
the rows from  Ltarp in  smth.3, i.e. {{Ltarp.0}} are not shown.

I tried also:Ltarp, Ltarp[0], smth.Ltarp.0

nothing works in the second for cycle where i need to get items from
list built in third item of list in the first for cycle.

Could you please help with syntax, when i need to dislay item from
list in another list in template

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.