Re: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
Sorry I hadn't seen your comment, have you tried %%% ?

On Mon, Dec 3, 2012 at 7:28 AM, Joseph Mutumi  wrote:

> I think to escape a % use %%
>
>
> On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda 
> wrote:
>
>> Hi,
>> I want use postgresql pg_trgm module in django. pg_trgm defines special
>> operator percent sign. How should I escape it in django query extra method?
>>
>> # Pure SQL
>> SELECT content, similarity(content, 'text') AS sml
>>   FROM table
>>   WHERE content % 'text'
>>   ORDER BY sml DESC, content;
>>
>> # Extra throws IndexError 'tuple index out of range'
>> # I tried escape % with %%, or \%, but it throws same exception
>> objects = MyModel.objects.extra(
>> select={'rank': 'similarity(content, %s)'},
>> select_params=[content],
>> where='content % %s',
>> params=[content],
>> order_by=['-rank']
>> )
>>
>> # Raw query works fine
>> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS
>> rank FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''',
>> [content, content])
>>
>> How should I escape persent sign in extra() method?
>>
>> Thank you!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
>> 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: Escape percent sign in QuerySet.extra()

2012-12-02 Thread Joseph Mutumi
I think to escape a % use %%

On Sun, Dec 2, 2012 at 1:16 PM, Martin Svoboda wrote:

> Hi,
> I want use postgresql pg_trgm module in django. pg_trgm defines special
> operator percent sign. How should I escape it in django query extra method?
>
> # Pure SQL
> SELECT content, similarity(content, 'text') AS sml
>   FROM table
>   WHERE content % 'text'
>   ORDER BY sml DESC, content;
>
> # Extra throws IndexError 'tuple index out of range'
> # I tried escape % with %%, or \%, but it throws same exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works fine
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS rank
> FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''', [content,
> content])
>
> How should I escape persent sign in extra() method?
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
> 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: Help with manage.py sql

2012-12-02 Thread Lachlan Musicman
On Mon, Dec 3, 2012 at 1:43 PM, David Brotman
 wrote:
> Hi:
>
> I am really new to django and I am going thru the online tutorial (polls)
> app and I got to the point in the tutorial where I enter the command:
>
> python manage.py sql polls
>
> Nothing happens. No error message or anything else displayed. It just goes
> to a prompt. I included 'polls' in the installed apps section of the
> settings.py file as instructed. Anyone have any ideas on how to troubleshoot
> this issue?

1. Have you set up a DB and put the details into your settings.py? If
not, this is the problem
2. If you have done that, then the next step is to try another

python manage syncdb

Which you should have run a little earlier, when registering the
django necessary tables, and this second run should create the tables
for the polls app.

Are you running python manage.py sql polls from the directory with
manage.py in it?

What is you OS and which version of Django?

Cheers
L.


>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/BkUr0V1xy2AJ.
> 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.



--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Help with manage.py sql

2012-12-02 Thread Larry Martell
On Sunday, December 2, 2012, David Brotman wrote:

> Hi:
>
> I am really new to django and I am going thru the online tutorial (polls)
> app and I got to the point in the tutorial where I enter the command:
>
> python manage.py sql polls
>
> Nothing happens. No error message or anything else displayed. It just goes
> to a prompt. I included 'polls' in the installed apps section of the
> settings.py file as instructed. Anyone have any ideas on how to
> troubleshoot this issue?
>

I'd set a breakpoint with pdb in manage and step through it and see exactly
what it's doing.

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



Help with manage.py sql

2012-12-02 Thread David Brotman
Hi:

I am really new to django and I am going thru the online tutorial (polls) 
app and I got to the point in the tutorial where I enter the command:

python manage.py sql polls

Nothing happens. No error message or anything else displayed. It just goes 
to a prompt. I included 'polls' in the installed apps section of the 
settings.py file as instructed. Anyone have any ideas on how to 
troubleshoot this issue?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/BkUr0V1xy2AJ.
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: Can't undestrand Url pagination and template

2012-12-02 Thread Lachlan Musicman
On Sun, Dec 2, 2012 at 11:46 PM, joy  wrote:
> Hello, i'm new to Django and i'm still learning how to use it. I got a book
> but somethings doesn't work, i cannot work with templates, and every advice
> given from the book look not precise and obsolete (the book speaks about a
> previous version of django
> Anyone has a good tutorial on templates.
> I'm trying with the website of django

Hi Joy,

The tutorial on the Django site is both current and excellent:

https://docs.djangoproject.com/en/1.4/intro/tutorial01/

You will find references to the templates scattered through out it,
but page 4 has more than others
https://docs.djangoproject.com/en/1.4/intro/tutorial04/

Basically the rule is {{ varname }} and {% template function %} + standard html.

There's also the full template docs:

https://docs.djangoproject.com/en/1.4/topics/templates/


cheers
L.
--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Can't undestrand Url pagination and template

2012-12-02 Thread Satinderpal Singh
On Sun, Dec 2, 2012 at 5:16 PM, joy  wrote:
> Hello, i'm new to Django and i'm still learning how to use it. I got a book
> but somethings doesn't work, i cannot work with templates, and every advice
> given from the book look not precise and obsolete (the book speaks about a
> previous version of django.
> Anyone has a good tutorial on templates.
> I'm trying with the website of django hoping on something better. Let me
> know
This book may help you to understand urls and templates in better way:
http://www.djangobook.com/en/2.0/chapter01.html

--
Satinderpal Singh
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

-- 
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: Escape percent sign in QuerySet.extra() method

2012-12-02 Thread Chris Cogdon


On Sunday, December 2, 2012 1:55:05 AM UTC-8, Martin Svoboda wrote:
>
> Hello,
> I'm want to use functionality of postgresql module 
> pg_trgmin django. 
> pg_trgm uses special operator % (percent sign). I don't know how 
> should I escape it in query extra method.
>
> # pure SQL
> SELECT content, similarity(content, 'string') AS sml
>   FROM table
>   WHERE content % 'str'
>   ORDER BY sml DESC, content;
>
> # This throws exception IndexError 'tuple index out of range'
> # I tried to escape percent sign with %%, or \%, but I always get same 
> exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works ok
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS sml 
> FROM table WHERE content %% %s ORDER BY sml DESC''', [content, content])
>
> Can you help me how write percent sign in extra() method?
>

While this should not fix anything, can you try breaking it down like so.

objects = MyModel.objects.extra(
where='content % %s',
params=[content],
)

objects = objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
order_by=['-rank']
)

That'll give us a hint at which of the two parts are giving us a problem.


>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2EovB167MRIJ.
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: Admin UI Improvements for Ordered List Using Through Inline?

2012-12-02 Thread smcoll
Take a look at https://github.com/tkaemming/django-orderable.  i've used it 
several times.


On Saturday, December 1, 2012 3:24:49 AM UTC-6, Andrew Brown wrote:
>
> Greetings,
>
> I'm hopeful someone can point me in the right direction to improve the 
> admin UI for my app. I need to allow for the creation and display of an 
> ordered list of books. I had no problem setting this up and editing the 
> lists in the admin UI, but the UX for an admin leaves much to be desired. 
>
> The two biggest issues are that books can be saved to the same position as 
> books already on a list, and the admin always has to specify a position on 
> the list for each book (rather than simply adding the most recent book to 
> the end). Ideally books could even be dragged around and visually 
> reordered. This is a pretty classic ordered-list scenario, so I'm hoping 
> someone has already done some work to improve the admin UI for this case. 
> Is anyone aware of anything that might help?  
>
> The code I'm using in my app is below- it is dead simple and pretty much 
> straight from the documentation. I have created two models for this 
> purpose- Book and List, which are associated by a ListMember class using a 
> through relationship.
>
> class Book(models.Model):
>
> title = models.CharField(max_length=200)
>
> class List(models.Model):
>
> books = models.ManyToManyField(Book, through="ListMember")
>
> class ListMember(models.Model):
>
> list = models.ForeignKey(List)
> book = models.ForeignKey(Book)
> position = models.IntegerField()
>
>
> Then in my admin code I've created BookAdmin, ListAdmin, and 
> ListMemberInline. I've also included simplified code for these classes 
> below.
>
> class ListMemberInline(admin.TabularInline):
>
> model = List.books.through
>
> class ListAdmin(admin.ModelAdmin):
>
> inlines = ['ListMemberInline',]
> excludes = ('books',)
>
> class BookAdmin(admin.ModelAdmin):
>
> inlines = ['ListMemberInline',]
>
> If anyone is aware of improvements to the admin UI for this case that I 
> could reuse I would really appreciate a pointer in the right direction. 
> Alternatively, guidance on how to improve this myself would also be very 
> helpful.
>
> Thanks!
> Andrew
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/r_wZD1Jz_9sJ.
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: datetime deosn't work, first part of the manual

2012-12-02 Thread joy
Sorry, i got it...

Il giorno domenica 2 dicembre 2012 17:55:42 UTC+1, joy ha scritto:
>
>   return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
> NameError: global name 'datetime' is not defined
>
> But the timezone module is imported in modules.py
>
> should i define it somewhere else?
> Joy
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/F0GZ7drmPloJ.
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.



datetime deosn't work, first part of the manual

2012-12-02 Thread joy
  return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
NameError: global name 'datetime' is not defined

But the timezone module is imported in modules.py

should i define it somewhere else?
Joy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bypCLBux4boJ.
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: Admin UI Improvements for Ordered List Using Through Inline?

2012-12-02 Thread Joni Bekenstein
Check out grappelli: http://www.grappelliproject.com/


On Saturday, December 1, 2012 6:24:49 AM UTC-3, Andrew Brown wrote:
>
> Greetings,
>
> I'm hopeful someone can point me in the right direction to improve the 
> admin UI for my app. I need to allow for the creation and display of an 
> ordered list of books. I had no problem setting this up and editing the 
> lists in the admin UI, but the UX for an admin leaves much to be desired. 
>
> The two biggest issues are that books can be saved to the same position as 
> books already on a list, and the admin always has to specify a position on 
> the list for each book (rather than simply adding the most recent book to 
> the end). Ideally books could even be dragged around and visually 
> reordered. This is a pretty classic ordered-list scenario, so I'm hoping 
> someone has already done some work to improve the admin UI for this case. 
> Is anyone aware of anything that might help?  
>
> The code I'm using in my app is below- it is dead simple and pretty much 
> straight from the documentation. I have created two models for this 
> purpose- Book and List, which are associated by a ListMember class using a 
> through relationship.
>
> class Book(models.Model):
>
> title = models.CharField(max_length=200)
>
> class List(models.Model):
>
> books = models.ManyToManyField(Book, through="ListMember")
>
> class ListMember(models.Model):
>
> list = models.ForeignKey(List)
> book = models.ForeignKey(Book)
> position = models.IntegerField()
>
>
> Then in my admin code I've created BookAdmin, ListAdmin, and 
> ListMemberInline. I've also included simplified code for these classes 
> below.
>
> class ListMemberInline(admin.TabularInline):
>
> model = List.books.through
>
> class ListAdmin(admin.ModelAdmin):
>
> inlines = ['ListMemberInline',]
> excludes = ('books',)
>
> class BookAdmin(admin.ModelAdmin):
>
> inlines = ['ListMemberInline',]
>
> If anyone is aware of improvements to the admin UI for this case that I 
> could reuse I would really appreciate a pointer in the right direction. 
> Alternatively, guidance on how to improve this myself would also be very 
> helpful.
>
> Thanks!
> Andrew
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/3swNLrI-vQYJ.
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.



Escape percent sign in QuerySet.extra() method

2012-12-02 Thread Martin Svoboda
Hello,
I'm want to use functionality of postgresql module 
pg_trgmin django. 
pg_trgm uses special operator % (percent sign). I don't know how 
should I escape it in query extra method.

# pure SQL
SELECT content, similarity(content, 'string') AS sml
  FROM table
  WHERE content % 'str'
  ORDER BY sml DESC, content;

# This throws exception IndexError 'tuple index out of range'
# I tried to escape percent sign with %%, or \%, but I always get same 
exception
objects = MyModel.objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
where='content % %s',
params=[content],
order_by=['-rank']
)

# Raw query works ok
objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS sml 
FROM table WHERE content %% %s ORDER BY sml DESC''', [content, content])

Can you help me how write percent sign in extra() method?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/N7BT4BFV11oJ.
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.



Strange behaviour when adding negative timedelta to mysql backed DateTimeField

2012-12-02 Thread Oleksiy Pikalo
I got this weird behavior, specific to mysql backend, and specific to 
adding a negative timedelta to DateTimeField.

Full stackoverflow 
question

I currently have a workaround where I subtract absolute timedelta based on 
timedelta value, butthis seems either a bug or some very strange 
misconfiguration.
Any help and/or suggestions, are greatly appreciated.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Qf33ts8x44UJ.
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.



Escape percent sign in QuerySet.extra()

2012-12-02 Thread Martin Svoboda
Hi,
I want use postgresql pg_trgm module in django. pg_trgm defines special 
operator percent sign. How should I escape it in django query extra method?

# Pure SQL
SELECT content, similarity(content, 'text') AS sml
  FROM table
  WHERE content % 'text'
  ORDER BY sml DESC, content;

# Extra throws IndexError 'tuple index out of range'
# I tried escape % with %%, or \%, but it throws same exception
objects = MyModel.objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
where='content % %s',
params=[content],
order_by=['-rank']
)

# Raw query works fine
objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS rank 
FROM table WHERE content %% %s ORDER BY rank DESC LIMIT 1''', [content, 
content])

How should I escape persent sign in extra() method?

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2euBM5lHjZEJ.
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.



Can't undestrand Url pagination and template

2012-12-02 Thread joy
Hello, i'm new to Django and i'm still learning how to use it. I got a book 
but somethings doesn't work, i cannot work with templates, and every advice 
given from the book look not precise and obsolete (the book speaks about a 
previous version of django.
Anyone has a good tutorial on templates.
I'm trying with the website of django hoping on something better. Let me 
know 
Joy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eRJfMkCS6EEJ.
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.