Re: Comparing ManyToMany fields

2009-12-27 Thread Scott Maher
akaariai wrote:
> This is not the easiest query to perform using SQL. Something like the
> following query might work, I have tested it only quickly.
>
> select t2.pizza_id
> from (select pizza_id from pizza_toppings group by pizza_id
>having count(*) = (select count(*) from pizza_toppings where
> pizza_id = 2)) t1
> inner join pizza_toppings as t2 on t1.pizza_id = t2.pizza_id
> inner join (select * from pizza_toppings where pizza_id=2) t3 on
> t2.topping_id = t3.topping_id
> group by t2.pizza_id
> having count(*) = (select count(*) from pizza_toppings where pizza_id
> = 2);
>
> The idea of the query is to first find out all the pizzas that have
> the same amount of toppings as the mypizza instance (assumed to have
> pizza_id=2 in the query). Then from those pizzas, list the toppings
> that are in mypizza. Finally require there are exactly as many
> toppings in the list as there are toppings in mypizza.
>
> I do not think there is any way to perform this query using Django
> ORM. I haven't used the group by capabilities of the ORM much, so
> maybe it is possible...
>   
Akaari,

The logic of your method is slowly what I came up with eventually but I 
didn't have your level of awesome SQL wizardry to implement it. Thanks 
much! Someone was able to figure out how to implement it in the ORM. 
Here it is:

|qs = 
Pizza.objects.annotate(toping_count=Count("toppings")).filter(toping_count=my_pizza.toppings.count())
for toping in my_pizza.toppings.all():
qs = qs.filter(toppings=toping)
|

The key was to annotate the table first so we can match pizzas with 
topping sets of equal cardinality. I am told that doing a full table 
annotate like this might be kind of slow though.

Thanks,

--sm

--

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.




Re: constraint unique with models.Model

2009-12-27 Thread Marc Aymerich
On Mon, Dec 28, 2009 at 5:15 AM, Karen Tracey  wrote:

> On Sun, Dec 27, 2009 at 11:08 PM, Marc Aymerich wrote:
>
>> hi guys!
>>
>> I'm writing my first project with django and I have doubts in how to
>> declare a constraint unique for two fields of the same table using
>> models.Model.
>>
>
> See:
>
> http://docs.djangoproject.com/en/1.1/ref/models/options/#unique-together
>
> which is a Meta option:
>
> http://docs.djangoproject.com/en/1.1/topics/db/models/#meta-options
>
> Karen
>

Thank you very much Karen!!  :)

If someone serves...

class virtual_aliases(models.Model):
domain = models.ForeignKey(domains)
 source = models.CharField(max_length=50)
destination = models.CharField(max_length=60)
 class Meta:
unique_together = ("source", "domain")

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




Re: constraint unique with models.Model

2009-12-27 Thread Karen Tracey
On Sun, Dec 27, 2009 at 11:08 PM, Marc Aymerich  wrote:

> hi guys!
>
> I'm writing my first project with django and I have doubts in how to
> declare a constraint unique for two fields of the same table using
> models.Model.
>

See:

http://docs.djangoproject.com/en/1.1/ref/models/options/#unique-together

which is a Meta option:

http://docs.djangoproject.com/en/1.1/topics/db/models/#meta-options

Karen

--

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.




constraint unique with models.Model

2009-12-27 Thread Marc Aymerich
hi guys!

I'm writing my first project with django and I have doubts in how to declare
a constraint unique for two fields of the same table using models.Model. In
MySQL would be something like:

CREATE TABLE `virtual_aliases` (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domainid INT(11) NOT NULL,
 source VARCHAR(40) NOT NULL,
destination VARCHAR(80) NOT NULL,
CONSTRAINT UNIQUE_EMAIL UNIQUE (domainid,source),
 FOREIGN KEY (domainid) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE = InnoDB;

with django I only do that:

class virtual_aliases(models.Model):
domain = models.ForeignKey(virtual_domains)
source = models.CharField(max_length=50)
 destination = models.CharField(max_length=60)

I haven't any idea how to declare a unique constraint between 'source' and
'domain'.

Any help¿¿

Thanks a lot!
Marc

--

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.




mapping url to feed

2009-12-27 Thread neridaj
I'm trying to retrieve blog entries for a specific category and I'm
not sure how to generate the correct url in my template. here is what
I have:


{{ category.title }}

feeds = { 'entries': LatestEntriesFeed, 'links': LatestLinksFeed,
'categories': CategoryFeed, 'tweets': LatestTweetsFeed }

(r'^feeds/(?P.*)/$', 'django.contrib.syndication.views.feed',
{ 'feed_dict': feeds }, 'category_feed'),

I think I need to have "categories/category.title" to correctly map to
"feeds/categories/category.title" but I'm not sure how/if I should do
that in the template.

Thanks for any help,

J

--

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.




Re: Twitter API

2009-12-27 Thread Christophe Pettus

On Dec 27, 2009, at 1:15 PM, Mario wrote:
> As I pointed out in
> my early email, I want to create/update/delete a twitt in django in
> lieu of the Twitter front-end.

Every reasonable Twitter API I know of (including the Python ones)  
allow the full range of Twitter operations, including creating,  
deleting and reading tweets, so you shouldn't need anything more  
exotic to do the job.

--
-- Christophe Pettus
x...@thebuild.com

--

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.




Re: Using django only for request handling work

2009-12-27 Thread Daniel Roseman
On Dec 27, 8:58 pm, Amit Sethi  wrote:
> Hi ,I have a project that is in general written to work with wsgi server
> except i wish to alter some of the environ variables provided to the app. So
> I have a function:
>
> def __call__(self, environ, start_response):   In this I want to change some
> part of environ 
>
> So my application looks something like this
>
> apache server --->> django to do url handling and changing environ  --->>
> the actual app
>
> This is my initial brainstorm . I really don't understand if it is possible
> to do this . How do I create the same kind of interface like apache or any
> other server i.e environ and start_response to be sent to the app???
>
> --
> A-M-I-T S|S

Doesn't sound like Django is the best fit for you here, since you
won't be taking advantage of any of the things it does well (ORM,
admin interface, templating, etc). If you just want a Python-based URL
dispatcher, you could try Routes[1], which is used in Pylons but is a
standalone project. Or some of the functionality in Paster/WebOb[2]
might be what you want, since they work closely with the WSGI
interface.

[1]: http://routes.groovie.org/
[2]: http://pythonpaste.org/

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




Re: Using django only for request handling work

2009-12-27 Thread Victor Lima
Restful API?

Att,
Victor Lima

Em 27/12/2009, às 18:58, Amit Sethi   
escreveu:

> Hi ,I have a project that is in general written to work with wsgi  
> server except i wish to alter some of the environ variables provided  
> to the app. So I have a function:
>
> def __call__(self, environ, start_response):   In this I want to  
> change some part of environ 
>
> So my application looks something like this
>
>
> apache server --->> django to do url handling and changing environ   
> --->>  the actual app
>
> This is my initial brainstorm . I really don't understand if it is  
> possible to do this . How do I create the same kind of interface  
> like apache or any other server i.e environ and start_response to be  
> sent to the app???
>
> -- 
> A-M-I-T S|S
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-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.




Re: Comparing ManyToMany fields

2009-12-27 Thread akaariai


On 27 joulu, 11:32, Scott Maher  wrote:
> Is it possible to filter by the ManyToMany fields?
>
> Suppose I have a Pizza model and a Topping model. Topping has a
> ManyToManyField pointing to Pizza. I now have an instance of a Pizza
> called mypizza.
>
> I would like to now search for all Pizzas with the EXACT same Toppings
> as mypizza. Intuitively it would like something like this:
>
> Pizza.objects.filter(toppings=mypizza.toppings_set)
>
> This, naturally, does not work. Any ideas? I'm happy to do some fancy
> black magic with the models to make it work, or do a custom SQL clause.
> I just don't know enough SQL to do that.
>
> I'm also interested in reasonably alternative ways to model my data if I
> have a potentially very large set of Pizzas however a limited (although
> fairly lengthy, 20+) list of toppings that might change periodically.
>
> Thanks!

This is not the easiest query to perform using SQL. Something like the
following query might work, I have tested it only quickly.

select t2.pizza_id
from (select pizza_id from pizza_toppings group by pizza_id
   having count(*) = (select count(*) from pizza_toppings where
pizza_id = 2)) t1
inner join pizza_toppings as t2 on t1.pizza_id = t2.pizza_id
inner join (select * from pizza_toppings where pizza_id=2) t3 on
t2.topping_id = t3.topping_id
group by t2.pizza_id
having count(*) = (select count(*) from pizza_toppings where pizza_id
= 2);

The idea of the query is to first find out all the pizzas that have
the same amount of toppings as the mypizza instance (assumed to have
pizza_id=2 in the query). Then from those pizzas, list the toppings
that are in mypizza. Finally require there are exactly as many
toppings in the list as there are toppings in mypizza.

I do not think there is any way to perform this query using Django
ORM. I haven't used the group by capabilities of the ORM much, so
maybe it is possible...

--

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.




Re: Twitter API

2009-12-27 Thread Mario
Thank you for you suggestions. Btw, I created a mocked-up app and was
testing the functionality of the python-twitter.  I read the docs as
posted at http://media.jesselegg.com/syncr/syncr.app.tweet.html.

I did a small unit testing and could see the results immediately, but
I could not create or update a twitt via Django. As I pointed out in
my early email, I want to create/update/delete a twitt in django in
lieu of the Twitter front-end.

I guess my choices at this point in time are either:

1. Twyt
2. Write a wrapper within the model.

Thanks again. _Mario

_Mario
On Dec 27, 3:37 pm, Christophe Pettus  wrote:
> On Dec 27, 2009, at 12:31 PM, Mario wrote:
>
> > Thank you for replying. Yes, I reviewed python twitter API, but the
> > model or the app is designed to pull down the "twitt". I would like to
> > upload a twitt via Django in lieu of using the Twitter front-end. Any
> > thoughts or suggestions?
>
> Perhaps I'm misunderstanding your issue, but the code running in  
> Django is just Python.  There's nothing magic about it.  If you want  
> your view functions to access Twitter via a Python Twitter API, it's  
> no problem to do so; you can also wrap your calls to Twitter inside of  
> a Model class, if that's a better fit.
>
> --
> -- Christophe Pettus
>     x...@thebuild.com

--

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.




Using django only for request handling work

2009-12-27 Thread Amit Sethi
Hi ,I have a project that is in general written to work with wsgi server
except i wish to alter some of the environ variables provided to the app. So
I have a function:

def __call__(self, environ, start_response):   In this I want to change some
part of environ 

So my application looks something like this


apache server --->> django to do url handling and changing environ  --->>
the actual app

This is my initial brainstorm . I really don't understand if it is possible
to do this . How do I create the same kind of interface like apache or any
other server i.e environ and start_response to be sent to the app???

-- 
A-M-I-T S|S

--

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




Re: Null constraint violations when saving objects with ForeignKey relationships

2009-12-27 Thread Łukasz Balcerzak
Hi there,

Well, just try to make sure you are passing already saved instance (having 
primary key set)
into related model which has foreign key to the first one.

Your approach:

> from test.models import A,B
> instA = A()
> instB = B(a=instA)
> 
> Now I'm done with my parsing and am happy to save them to my database:
> 
> instA.save() # all good
> instB.save() # fails with IntegrityError: null value in column "a_id"
> violates not-null constraint

Could easily be fixed:

> from test.models import A,B
> instA = A()
> #instB = B(a=instA) # We will do that later
> 
> Now I'm done with my parsing and am happy to save them to my database:
> 
> instA.save() # all good
> instB = B(a=instA) # Now is the time
> instB.save() # shouldn't raise any exception

This is common problem if you are trying to get use to ORM. I had many problems 
with
understanding Hibernate/JPA a while ago when coding in Java.

IntegrityError was risen because instA was cached at instB (you may check this 
by comparing instB.a.id and instB.__dict__), and changes in instA
haven't been pushed. It's common approach for Object-Relation Mappers.

It's probably tempting to prepare your objects first but preparing your data 
before
is even better. If there would be not too much confusion you can try to use 
dicts as data
storage first, then just pass it to the constructors of your models - just a 
note, I do
this quite frequently in some cases.

But if you are not convinced and you really have to prepare objects first you 
may simply
set instA to instB just before calling ``save`` method at instB. I would be:

> from test.models import A,B
> instA = A()
> instB = B() # prepare but don't set instA yet
> 
> Now I'm done with my parsing and am happy to save them to my database:
> 
> instA.save() # all good
> instB.a = instA # now we set instA, *after* it has proper pk already set
> instB.save() # shouldn't raise any exception


Hope it helps

On Dec 26, 2009, at 7:12 PM, gmayer wrote:

> Hi guys,
> 
> I'm new to Django but otherwise quite a seasoned python and sql
> programmer. I'm baffled by django's foreign key id behaviour and as a
> result stuck in my current coding project. Let me start immediately
> with an example of what I'm trying to do. Assume two very simple
> models:
> 
> class A(models.Model):
>pass
> class B(models.Model):
>a = models.ForeignKey(A)
> 
> Now I need to create an instance of A and B without saving either of
> them (I'm parsing a whack load of data and only want to commit objects
> to the db once successfully parsed):
> 
> from test.models import A,B
> instA = A()
> instB = B(a=instA)
> 
> Now I'm done with my parsing and am happy to save them to my database:
> 
> instA.save() # all good
> instB.save() # fails with IntegrityError: null value in column "a_id"
> violates not-null constraint
> 
> On closer inspection the second line above fails because instB.a_id is
> None, even though instB.a.id is defined. Why does django throw in a
> duplicate, now stale instB.a_id field which, to make matters worse, is
> used in generating the underlying SQL for instB.save() to result in
> failure
> 
> Perhaps I'm just to n00b to use the correct semantics which avoid the
> above issues... excuse me if that's the case.
> 
> Gunther
> 
> --
> 
> 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.




Re: Twitter API

2009-12-27 Thread Christophe Pettus

On Dec 27, 2009, at 12:31 PM, Mario wrote:
> Thank you for replying. Yes, I reviewed python twitter API, but the
> model or the app is designed to pull down the "twitt". I would like to
> upload a twitt via Django in lieu of using the Twitter front-end. Any
> thoughts or suggestions?

Perhaps I'm misunderstanding your issue, but the code running in  
Django is just Python.  There's nothing magic about it.  If you want  
your view functions to access Twitter via a Python Twitter API, it's  
no problem to do so; you can also wrap your calls to Twitter inside of  
a Model class, if that's a better fit.

--
-- Christophe Pettus
x...@thebuild.com

--

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.




Re: Twitter API

2009-12-27 Thread Tim Chase
> Is there a Twitter API that would allow me to update a Twitt via
> Django?  If so would you be kind enough to send me the link?

I've used Twyt[1] for both command-line posting and for API usage.  It's 
all pure python and AFAIK doesn't have any dependencies outside of stock 
python.  Also, (nearly?) all the API is supported, so you can do other 
things like delete posts, list, block users, etc.  It's all pretty 
straight-forward and well documented.

-tim

[1]
http://andrewprice.me.uk/projects/twyt/

--

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.




Re: how to get ManyToMany relations?

2009-12-27 Thread akaariai

> model = CarModel.objects.filter(pk = modelId)
> for m in model.modelTypes.all():
>         data = data+m.description+'|'

Your problem is that objects.filter(pk=modelId) gives you a list of
one element. You need to use either objects.get(pk=modelId) or
objects.filter(pk=modelId)[0].

--

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.




Re: Twitter API

2009-12-27 Thread Mario
Christophe,

Thank you for replying. Yes, I reviewed python twitter API, but the
model or the app is designed to pull down the "twitt". I would like to
upload a twitt via Django in lieu of using the Twitter front-end. Any
thoughts or suggestions?

_Mario

On Dec 27, 3:26 pm, Christophe Pettus  wrote:
> On Dec 27, 2009, at 12:24 PM, Mario wrote:
>
> > Is there a Twitter API that would allow me to update a Twitt via
> > Django?  If so would you be kind enough to send me the link?
>
> Not meaning to be too terribly sarcastic, but have you tried using  
> Google to search for "python twitter api"?  The results, I promise,  
> will be satisfying.
>
> --
> -- Christophe Pettus
>     x...@thebuild.com

--

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.




Re: Twitter API

2009-12-27 Thread Ovnicraft
2009/12/27 Christophe Pettus 

>
> On Dec 27, 2009, at 12:24 PM, Mario wrote:
> > Is there a Twitter API that would allow me to update a Twitt via
> > Django?  If so would you be kind enough to send me the link?
>
> Not meaning to be too terribly sarcastic, but have you tried using
> Google to search for "python twitter api"?  The results, I promise,
>
    +1



> will be satisfying.
>
> --
> -- Christophe Pettus
>x...@thebuild.com
>
> --
>
> 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.
>
>
>


-- 
Cristian Salamea
CEO GnuThink Software Labs
Software Libre / Open Source
(+593-8) 4-36-44-48

--

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.




Re: Twitter API

2009-12-27 Thread Shawn Milochik
http://code.google.com/p/python-twitter/


--

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.




Re: Twitter API

2009-12-27 Thread Carlos Ricardo Santos
Sorry.. scrobble is Last.fm, LOL
:D

2009/12/27 Carlos Ricardo Santos 

> You have python-twitter and pyscrobble.
>
>
> 2009/12/27 Mario 
>
> Good afternoon,
>>
>> Is there a Twitter API that would allow me to update a Twitt via
>> Django?  If so would you be kind enough to send me the link?
>>
>> _Mario
>>
>> --
>>
>> 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.
>>
>>
>>
>
>
> --
> Cumprimentos,
> Carlos Ricardo Santos
>



-- 
Cumprimentos,
Carlos Ricardo Santos

--

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.




Re: Twitter API

2009-12-27 Thread Christophe Pettus

On Dec 27, 2009, at 12:24 PM, Mario wrote:
> Is there a Twitter API that would allow me to update a Twitt via
> Django?  If so would you be kind enough to send me the link?

Not meaning to be too terribly sarcastic, but have you tried using  
Google to search for "python twitter api"?  The results, I promise,  
will be satisfying.

--
-- Christophe Pettus
x...@thebuild.com

--

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.




Re: Twitter API

2009-12-27 Thread Carlos Ricardo Santos
You have python-twitter and pyscrobble.


2009/12/27 Mario 

> Good afternoon,
>
> Is there a Twitter API that would allow me to update a Twitt via
> Django?  If so would you be kind enough to send me the link?
>
> _Mario
>
> --
>
> 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.
>
>
>


-- 
Cumprimentos,
Carlos Ricardo Santos

--

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.




Re: how to get ManyToMany relations?

2009-12-27 Thread Michael Jenkinson
hi

there  isnt a many to many relationship here, its down the 'is a ... has a' bit 
of OO

one manufacturer makes (one car design that has a number of (models with a set 
of features))


class manufacturer
{
 list of designs(cardesign)
}

class cardesign
{
list of models(model)
}


class model
{
list of features
}

cheers


michael




- Original Message 
From: Benjamin W. 
To: Django users 
Sent: Sun, December 27, 2009 4:37:51 PM
Subject: how to get ManyToMany relations?

Hi there,

I've problems to access manyToMany relartions.
I got the following model:

class ModelType(models.Model):
description = models.CharField(max_length=100)
def __unicode__(self):
return u"%s" % (self.description)

class CarModel(models.Model):
description = models.CharField(max_length=100)
order = models.IntegerField(null=True)
modelTypes = models.ManyToManyField(ModelType)
def __unicode__(self):
return u"%s" % (self.description)

Now I want the ModelTypes for a specfic CarModel.
I thougt it should be something like this:

model = CarModel.objects.filter(pk = modelId)
for m in model.modelTypes.all():
data = data+m.description+'|'

But I get this error:
QuerySet object has no attribute modelType.

Thanks for your help!

--

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.




Twitter API

2009-12-27 Thread Mario
Good afternoon,

Is there a Twitter API that would allow me to update a Twitt via
Django?  If so would you be kind enough to send me the link?

_Mario

--

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.




Re: Comparing ManyToMany fields

2009-12-27 Thread Michael Jenkinson
Hi

a pizza has a one to many relationship with its topping. in a list of pizzas 
there could be some that have the same topping, like thick, thin etc.

the query would look like

select pizza from pizzas where topping = xyz

cheers


michael



- Original Message 
From: Scott Maher 
To: django-users@googlegroups.com
Sent: Sun, December 27, 2009 9:32:22 AM
Subject: Comparing ManyToMany fields

Is it possible to filter by the ManyToMany fields?

Suppose I have a Pizza model and a Topping model. Topping has a 
ManyToManyField pointing to Pizza. I now have an instance of a Pizza 
called mypizza.

I would like to now search for all Pizzas with the EXACT same Toppings 
as mypizza. Intuitively it would like something like this:

Pizza.objects.filter(toppings=mypizza.toppings_set)

This, naturally, does not work. Any ideas? I'm happy to do some fancy 
black magic with the models to make it work, or do a custom SQL clause. 
I just don't know enough SQL to do that.

I'm also interested in reasonably alternative ways to model my data if I 
have a potentially very large set of Pizzas however a limited (although 
fairly lengthy, 20+) list of toppings that might change periodically.

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




Re: Null constraint violations when saving objects with ForeignKey relationships

2009-12-27 Thread Gunther Mayer
Ok, not sure why I'm not getting replies, perhaps my problem is too 
complex or I'm being too silly with my approach. Either way, I found a 
work around by writing a little function to prepare my objects for 
saving which ensures that django finds the fkey id's when I issue my save():

def prepare_object(obj): # helper method to work around django 
restrictions of NULL foreign keys before saving
for key in obj.__dict__:
if key[0] == '_' or key[-3:] != '_id': # skip private 
and ordinary fields
continue
fkey_name = key[:-3]
try:
exec 'obj.%s = obj.%s.id' % (key, fkey_name)
except:
pass # there are some normal attributes that end 
in _id but have got nothing to do with fkeys (hence don't have such 
attributes)

Perhaps it will spare another lone programmer a hair or two. If nobody 
has any further comments on this I think I'll just file a bug on 
django's trac, this issue really *shouldn't* be present.

Gunther.

gmayer wrote:
> Hi guys,
>
> I'm new to Django but otherwise quite a seasoned python and sql
> programmer. I'm baffled by django's foreign key id behaviour and as a
> result stuck in my current coding project. Let me start immediately
> with an example of what I'm trying to do. Assume two very simple
> models:
>
> class A(models.Model):
> pass
> class B(models.Model):
> a = models.ForeignKey(A)
>
> Now I need to create an instance of A and B without saving either of
> them (I'm parsing a whack load of data and only want to commit objects
> to the db once successfully parsed):
>
> from test.models import A,B
> instA = A()
> instB = B(a=instA)
>
> Now I'm done with my parsing and am happy to save them to my database:
>
> instA.save() # all good
> instB.save() # fails with IntegrityError: null value in column "a_id"
> violates not-null constraint
>
> On closer inspection the second line above fails because instB.a_id is
> None, even though instB.a.id is defined. Why does django throw in a
> duplicate, now stale instB.a_id field which, to make matters worse, is
> used in generating the underlying SQL for instB.save() to result in
> failure
>
> Perhaps I'm just to n00b to use the correct semantics which avoid the
> above issues... excuse me if that's the case.
>
> Gunther
>   

--

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.




Securing your applications with ESAPI

2009-12-27 Thread Craig Younkins
The same group of people that wrote the OWASP Top
Tennow bring you
ESAPI,
the Enterprise Security API, and I've ported it to Python.
ESAPIprovides
numerous application-level controls that are desperately needed in
today's web applications. ESAPI provides...

   - Strong encoding/decoding/canonicalization to prevent XSS and
   interpreter attacks
   - Flexible authentication and access control
   - Object reference maps to hide server-side objects and references from
   the user
   - Secure session management utilities
   - Strong input validation using whitelists
   - Easy-to-use encryption framework for symmetric-key and public-key
   cryptography
   - Secure PRNG with helper methods
   - Flexible and powerful security logging
   - Intrusion detection - block attackers before they find a weak point!

ESAPIis
pure Python and is not tied to any framework. It only takes a few
minutes
to set up and you can use as much or as little of it as you would like -
there is no lock-in.

The goal of the ESAPI project is to get strong, easy-to-use security
controls in the hands of web developers so that they can focus on what they
do best: creating brilliant websites. This project has two main ways in
which it can be used. First, application developers can pick it up and use
the controls inside to secure their applications. Second, framework
developers can look at it and incorporate the design and functionality of
the security controls into the framework itself. ESAPI is released under the
BSD license, so you can do pretty much anything you want with it.

If having a secure Django application is important to you, I hope you take a
look at ESAPI:
OWASP wiki:
http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API#tab=Python
Google code: http://code.google.com/p/owasp-esapi-python/

Questions, comments, and criticisms are all welcome. Thank you.

--

Craig Younkins
Website/Blog 

--

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.




JavaScript function call

2009-12-27 Thread gilbert F.
Hello,

I just wonder if somebody has met this problem. I need to call a
javaScript function within "".

  {% for v in data %}

showDomainTable
('{{v.publisher_id}}', '{{v.country_id}}');

>

This works well with Firebox but not with IE 8. IE just prints
"showDomainTable(...)" instead of calling it.

Any help? Thanks so much.

--

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.




Re: Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread Biju Varghese
Dear ,
Just check how you are creating that string.(1,'i'm looking for...')
you are giving it like 'i'm .
Effectively your string will be only 'I' and remaining part will be
taken as a undefined variable or something like that. if you want to
make it correct you have to add escape sequence like 'i\'m looking
for ..'
this will work.basically you have to add an escape character if you
want to add ' or " inside a string..

--

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.




Re: MySQLdb problem in conjunction with MAMP

2009-12-27 Thread Raja
You need the Mysql-dev package. Im not familiar with OSX but in Linux,
you need the libmysqlclient-dev package that contains the load
libraries for python-mysql support.
Also, you might have better luck in the
http://sourceforge.net/projects/mysql-python/forums/forum/70461 forums
as your problem seems to be more mysql-python related.

On Dec 27, 10:15 pm, Don Fox  wrote:
> I'm trying to setup MySQLdb but mysql is located @  
> /Applications/MAMP/Library/bin/mysql because of the installation of MAPI.
>
> My  .profile has:  export 
> PATH="/usr/local/bin:/usr/local/sbin:/Applications/MAMP/Library/bin:$PATH"
>
> The 'python 'setup.py build' and
>        ' sudo python setup.py install'  cmds seem to go as expected but I get 
> this when attempting to import it.
>
> python manage.py shell
> Python 2.6.1 (r261:67515, Jul  9 2009, 14:20:26)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)>>> from django.shortcuts import render_to_response
> >>> import MySQLdb
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/MySQLdb/__init__.py",
>  line 19, in 
>   File 
> "/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py",
>  line 7, in 
>   File 
> "/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py",
>  line 6, in __bootstrap__
> ImportError: 
> dlopen(/Users/donfox1/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so,
>  2): Library not loaded: /usr/local/mysql/lib/libmysqlclient_r.16.dylib
>   Referenced from: 
> /Users/donfox1/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
>   Reason: image not found
>
> Does anyone know a fix?
>
> Thanks
>
> Don Fox

--

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.




MySQLdb problem in conjunction with MAMP

2009-12-27 Thread Don Fox
I'm trying to setup MySQLdb but mysql is located @  
/Applications/MAMP/Library/bin/mysql because of the installation of MAPI.

My  .profile has:  export 
PATH="/usr/local/bin:/usr/local/sbin:/Applications/MAMP/Library/bin:$PATH"

The 'python 'setup.py build' and 
   ' sudo python setup.py install'  cmds seem to go as expected but I get 
this when attempting to import it.

python manage.py shell
Python 2.6.1 (r261:67515, Jul  9 2009, 14:20:26) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.shortcuts import render_to_response
>>> import MySQLdb
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/MySQLdb/__init__.py",
 line 19, in 
  File 
"/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py",
 line 7, in 
  File 
"/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py",
 line 6, in __bootstrap__
ImportError: 
dlopen(/Users/donfox1/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so,
 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient_r.16.dylib
  Referenced from: 
/Users/donfox1/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
  Reason: image not found


Does anyone know a fix?

Thanks

Don Fox

--

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.




[Fwd: Re: how to get ManyToMany relations?]

2009-12-27 Thread Steve Holden
Benjamin W. wrote:
> Hi there,
> 
> I've problems to access manyToMany relartions.
> I got the following model:
> 
> class ModelType(models.Model):
>   description = models.CharField(max_length=100)
>   def __unicode__(self):
>   return u"%s" % (self.description)
> 
> class CarModel(models.Model):
>   description = models.CharField(max_length=100)
>   order = models.IntegerField(null=True)
>   modelTypes = models.ManyToManyField(ModelType)
>   def __unicode__(self):
>   return u"%s" % (self.description)
> 
> Now I want the ModelTypes for a specfic CarModel.
> I thougt it should be something like this:
> 
> model = CarModel.objects.filter(pk = modelId)

This statement returns a QuerySet, but in order to use the fields of
CarModel surely you want a CarModel instance.

Therefore you should use

  model = CarModel.objects.get(pk=modelId)

(It's better Python style to write the keyword arguments with no spaces
around the "=", reserving the space-delimited form for assignments).

> for m in model.modelTypes.all():
>   data = data+m.description+'|'
> 
> But I get this error:
> QuerySet object has no attribute modelType.
> 
> Thanks for your help!

The error message was trying to be helpful - you just didn't realize
that you don't need a QuerySet, but a model instance.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/


--

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.




how to get ManyToMany relations?

2009-12-27 Thread Benjamin W.
Hi there,

I've problems to access manyToMany relartions.
I got the following model:

class ModelType(models.Model):
description = models.CharField(max_length=100)
def __unicode__(self):
return u"%s" % (self.description)

class CarModel(models.Model):
description = models.CharField(max_length=100)
order = models.IntegerField(null=True)
modelTypes = models.ManyToManyField(ModelType)
def __unicode__(self):
return u"%s" % (self.description)

Now I want the ModelTypes for a specfic CarModel.
I thougt it should be something like this:

model = CarModel.objects.filter(pk = modelId)
for m in model.modelTypes.all():
data = data+m.description+'|'

But I get this error:
QuerySet object has no attribute modelType.

Thanks for your help!

--

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.




Re: Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread Masklinn
On 27 déc. 2009, at 09:12, Continuation   
wrote:
> I have a model field:
>
> my_field  = models.IntegerField(choices=MY_CHOICES)
>
> One choice in MY_CHOICES is:
>
> (1, 'I'm looking for...'),
>
> I got a syntax error from that. The word "for" in the string was
> treated as a reserved word.
>
> Now if I change the single quotes to double quotes, it seems to work:
> (1, "I'm looking for..."),
>
> But the documentation only shows the single quote usage. I wonder if
> it's safe to use double quotes instead. If not, what can I do to avoid
> the syntax error?

This is a python issue, and in python single and double quotes are  
basically equivalent (the only constraint is that you close a string  
with the quote with which you opened it). As others explained the  
issue here is that your apostrophe is a single quote, closing the  
string and interpreting the rest if the line as python source… which  
is obviouly incorrect.


--

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.




Comparing ManyToMany fields

2009-12-27 Thread Scott Maher
Is it possible to filter by the ManyToMany fields?

Suppose I have a Pizza model and a Topping model. Topping has a 
ManyToManyField pointing to Pizza. I now have an instance of a Pizza 
called mypizza.

I would like to now search for all Pizzas with the EXACT same Toppings 
as mypizza. Intuitively it would like something like this:

Pizza.objects.filter(toppings=mypizza.toppings_set)

This, naturally, does not work. Any ideas? I'm happy to do some fancy 
black magic with the models to make it work, or do a custom SQL clause. 
I just don't know enough SQL to do that.

I'm also interested in reasonably alternative ways to model my data if I 
have a potentially very large set of Pizzas however a limited (although 
fairly lengthy, 20+) list of toppings that might change periodically.

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




Re: Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread Chris Withers
Continuation wrote:
> Now if I change the single quotes to double quotes, it seems to work:
> (1, "I'm looking for..."),

Double quotes are absolutely fine and a lot nicer to look at than
'I\'m hard to read'.

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
 - http://www.simplistix.co.uk

--

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.




Re: How to test activation email on windows?

2009-12-27 Thread 夏恺
Hi,

Please consult the documentation:

http://docs.djangoproject.com/en/dev/topics/email/#topics-email

and your problem will be solved.   :)


Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org

--
From: "vishy" 
Sent: Sunday, December 27, 2009 4:50 PM
To: "Django users" 
Subject: How to test activation email on windows?

> Hi,
>
> I have setup the registration module for a django project.Now, I want
> to test the that activation email is sent.On windows, how can I test
> this? How to send the email? Will I have to do any changes in
> settings.py?
>
> 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-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.




How to test activation email on windows?

2009-12-27 Thread vishy
Hi,

I have setup the registration module for a django project.Now, I want
to test the that activation email is sent.On windows, how can I test
this? How to send the email? Will I have to do any changes in
settings.py?

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




Re: Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread Continuation
Thank you. I totally missed that.

On Dec 27, 3:18 am, Xia Kai(夏恺)  wrote:
> Hi,
>
> Please note that you have close the quotation with a single quote right
> after the character `I`, so the next few word are treated as python source
> code instead of string.
>
> Probably you would like to try:
>
> (1, "I'm looking for..."),
> or, alternatively:
> (1, 'I\'m looking for...'),
>
> 
> Xia Kai(夏恺)
> xia...@gmail.comhttp://blog.xiaket.org
>
> --
> From: "Continuation" 
> Sent: Sunday, December 27, 2009 4:12 PM
> To: "Django users" 
> Subject: Is it ok to use double quotes instead of single quotes in
> Field.choices?
>
> > I have a model field:
>
> > my_field  = models.IntegerField(choices=MY_CHOICES)
>
> > One choice in MY_CHOICES is:
>
> > (1, 'I'm looking for...'),

--

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.




Re: Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread 夏恺
Hi,

Please note that you have close the quotation with a single quote right 
after the character `I`, so the next few word are treated as python source 
code instead of string.

Probably you would like to try:

(1, "I'm looking for..."),
or, alternatively:
(1, 'I\'m looking for...'),



Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org

--
From: "Continuation" 
Sent: Sunday, December 27, 2009 4:12 PM
To: "Django users" 
Subject: Is it ok to use double quotes instead of single quotes in 
Field.choices?

> I have a model field:
>
> my_field  = models.IntegerField(choices=MY_CHOICES)
>
> One choice in MY_CHOICES is:
>
> (1, 'I'm looking for...'),
>
 

--

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.




Is it ok to use double quotes instead of single quotes in Field.choices?

2009-12-27 Thread Continuation
I have a model field:

my_field  = models.IntegerField(choices=MY_CHOICES)

One choice in MY_CHOICES is:

(1, 'I'm looking for...'),

I got a syntax error from that. The word "for" in the string was
treated as a reserved word.

Now if I change the single quotes to double quotes, it seems to work:
(1, "I'm looking for..."),

But the documentation only shows the single quote usage. I wonder if
it's safe to use double quotes instead. If not, what can I do to avoid
the syntax error?


--

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.