Re: Beginner's doubt

2010-05-23 Thread ravi krishna
This is the error i get now

InvalidURL at /index

nonnumeric port:



On Mon, May 24, 2010 at 10:51 AM, ravi krishna  wrote:

> sorry the VIEW.py is:
>
>
>
> conn=httplib.HTTPConnection("www.python.org")
> conn.request("GET", "/index.html")
>
> r1 = conn.getresponse()
> print r1.status, r1.reason
> data1 = r1.read()
> conn.close()
>
>
> On Mon, May 24, 2010 at 10:30 AM, ravi krishna wrote:
>
>> Hi,
>> I want to retrieve data from wikimapia api. For this i am using httplib
>> function of python.
>> this is my VIEW.py file( just the httplic() )
>>
>> conn=httplib.HTTPConnection("www.python.org")
>> r1 = conn.getresponse()
>> print r1.status, r1.reason
>> data1 = r1.read()
>> conn.close()
>>
>> Initially i gave the wikimapia API instead of www.python.org, then it
>> gave invalid URL error; but the url was working.
>> Then i gave www.python.org instead of wikimapia API just lyk given in the
>> example of python documentation ; now its showing Response Not Ready error
>> at /index.
>> Somebody please help me to solve this solution.
>>  --
>> Regards,
>> Rav!
>>
>
>
>
> --
> Regards,
> Rav!
>



-- 
Regards,
Rav!

-- 
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: Beginner's doubt

2010-05-23 Thread ravi krishna
sorry the VIEW.py is:


conn=httplib.HTTPConnection("www.python.org")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
conn.close()


On Mon, May 24, 2010 at 10:30 AM, ravi krishna  wrote:

> Hi,
> I want to retrieve data from wikimapia api. For this i am using httplib
> function of python.
> this is my VIEW.py file( just the httplic() )
>
> conn=httplib.HTTPConnection("www.python.org")
> r1 = conn.getresponse()
> print r1.status, r1.reason
> data1 = r1.read()
> conn.close()
>
> Initially i gave the wikimapia API instead of www.python.org, then it gave
> invalid URL error; but the url was working.
> Then i gave www.python.org instead of wikimapia API just lyk given in the
> example of python documentation ; now its showing Response Not Ready error
> at /index.
> Somebody please help me to solve this solution.
> --
> Regards,
> Rav!
>



-- 
Regards,
Rav!

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



Beginner's doubt

2010-05-23 Thread ravi krishna
Hi,
I want to retrieve data from wikimapia api. For this i am using httplib
function of python.
this is my VIEW.py file( just the httplic() )

conn=httplib.HTTPConnection("www.python.org")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
conn.close()

Initially i gave the wikimapia API instead of www.python.org, then it gave
invalid URL error; but the url was working.
Then i gave www.python.org instead of wikimapia API just lyk given in the
example of python documentation ; now its showing Response Not Ready error
at /index.
Somebody please help me to solve this solution.
-- 
Regards,
Rav!

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



API with django

2010-05-23 Thread Alexandre González
Hi!

I must develop a django app that receives XML and returns XML.

What's the best way to do this? Create a view that receive the XML and parse
it to return a template with the XML resultant?

I'm newbie in django and need your tips :)

Regards,
Álex González

-- 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.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.



One of those C.Y.A. User Policy Liability Pages?

2010-05-23 Thread steve
Just wondering if anyone has found a "recipe" anywhere that advices a
good way to add an intermediate (after they enter new Registration
info)  ..."New User, you Have to Agree to these risks, etc.."
pages, where they have to click on "Agree" before it takes them to the
opening page of their newly created account.

I'd imagine, I wouldn't even have to change the pages I'm using
(currently doing a HttpResponseRedirect("main_page")).

I could simply have a popup DIV appear with the scrollable text on top
and the "Agree" button at the bottom of the opening page. And that
would simply read all the rules (yeah right), and then click "Agree",
dismissing the popup and they'd be at the /main_page.

-Steve

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



Unicode Error when Saving Django Model

2010-05-23 Thread vjimw
I have been reading up on Unicode with Python and Django and I think I
have my code set to use UTF8 data when saving or updating an object
but I get an error on model.save()

My database and all of its tables are UTF8 encoded with UTF8 collation
(DEFAULT CHARSET=utf8;)
The data I am inputting is unicode
(u'Save up to 25% on your online order of select HP LaserJet\x92s')


But when I try to save this data I get an error
Incorrect string value: '\\xC2\\x92s' for column 'title' at row 1

I assume I am missing something, but not sure what I am missing.

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.



Items from multiple tables on one form?

2010-05-23 Thread Michael Davis
I have 2 tables/models, which for all practical purposes are the same
as the standard Author/Book example, but with the additional
restriction that in my application each Author can only write 0 or 1
books. (eg, the ForeignKey field in the Book model is or can be a
OneToOneField, and there may be authors who have no corresponding book
in the Book table.)

Suppose the models look like this:
# Models
class Author(models.Model):
name = models.CharField(max_length=100)
address = models.CharField(max_length=100)

class Book(models.Model):
author_id = models.OneToOneField(Author)
title = models.CharField(max_length=100)


I'd like to have a form that allowed me to edit both the title of the
book belonging to a particular author AND also edit his address (and
possibly name). Even better, I'd like to do this in a formset_factory
type situation, not just a single book/author combo at a time, but one
form with multiple entries.

The "inline_formset" allows me to pull up the book belonging to a
particular author (queried by author name, form example) but it does
NOT give me access to the Author part of the model in the resulting
formset.

Any thoughts?

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: slow filtering by related and local fields, only on sqlite, not on postgres?

2010-05-23 Thread Chris Withers

Chris Withers wrote:

queryset = TicketStatus.objects.filter(active=True)
if user_id:
queryset = queryset.filter(owner=User.objects.get(id=user_id))
queryset = queryset.filter(ticket__event=event)
return list_detail.object_list(
request,
queryset = 
queryset.order_by('ticket__number').select_related('Ticket'),

template_name = 'tickets_list.html',
paginate_by = 50,
extra_context = dict(
events = events,
current_event_id = event.id,
users = users,
current_user_id = user_id
)
)

And it shows the culprit:

SELECT COUNT(*) FROM "tracker_ticketstatus" INNER JOIN "tracker_ticket" 
ON ("tracker_ticketstatus"."ticket_id" = "tracker_ticket"."id") WHERE 
("tracker_ticketstatus"."active" = True  AND 
"tracker_ticketstatus"."owner_id" = 1  AND "tracker_ticket"."event_id" = 
3 )

38.143


However, when I have exactly the same models on a postgres backend, 
everything is fine.


So, it's just slow on a sqlite backend, which is a shame as that's how I 
normally develop!


Any ideas?

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: is it possible ?

2010-05-23 Thread rahul jain
Hi Daniel,

I think this will solve this problem

if i have a boolean field in my model and if I would like to display
only if that fileld id true to the non-super users and otherwise
always show the boolean field.

But my question was

how to disable the select all widget from the admin panel if the user
is non-super user. The select all widget helps in selecting all the
objects but since my action is empty, i dont want to show any widget.

Also, I am not sure why we need this as well

def change_view(self, request, object_id, extra_context=None):
if Part.objects.get(id=object_id).is_deleted==True and
request.user.is_superuser == False:
return HttpResponseRedirect('/admin/')
else:
return super(PartAdmin, self).change_view(request,
object_id,extra_context=None)

Thanks.

--RJ





2010/5/21 Danfi :
> ChangeList is in the file /python**/Lib/site-packages/django/contrib/
> admin/views/main.py ,and we use ModelAdmin so change_view function can
> direct to be used.
>
> On 5月21日, 下午2时08分, rahul jain  wrote:
>> Hi Danfi,
>>
>> Thanks for your quick response. But can you explain a little more how
>> can we connect ChangeList class with that function change_view.
>> Confuse about it.
>>
>> --RJ
>>
>> 2010/5/20 Danfi :
>>
>>
>>
>> > In Auth group you can create a group and set the limits.
>>
>> > see different panel maybe use changelist_view
>>
>> > I saw this just be similar to yours'
>>
>> > class Part(models.Model):
>> > is_deleted = models.BooleanField()
>> > //
>> > class PartAdmin(admin.ModelAdmin):
>> > actions =None
>> > def change_view(self, request, object_id, extra_context=None):
>> > if Part.objects.get(id=object_id).is_deleted==True and
>> > request.user.is_superuser == False:
>> > return HttpResponseRedirect('/admin/')
>> > else:
>> > return super(PartAdmin, self).change_view(request,
>> > object_id,extra_context=None)
>>
>> > /
>> > edit admin/views/main.py
>> > IS_DELETED_VAR = 'is_deleted'
>>
>> > class ChangeList(object):
>> > def __init__(self, request, model, list_display, list_display_links,
>> > list_filter, date_hierarchy, search_fields, list_select_related,
>> > list_per_page, list_editable, model_admin):
>> > self.model = model
>> > self.opts = model._meta
>> > self.lookup_opts = self.opts
>> > self.root_query_set = model_admin.queryset(request)
>> >  try:
>> > f =self.lookup_opts.get_field(IS_DELETED_VAR)
>> > except models.FieldDoesNotExist:
>> > self.root_query_set = self.root_query_set
>> > else:
>> > if isinstance(f,models.BooleanField) and (request.user.is_superuser ==
>> > False):
>> > self.root_query_set = self.root_query_set.exclude(is_deleted = 'True')
>> > else:
>> > self.root_query_set = self.root_query_set
>>
>> > On 5月21日, 下午12时01分, rahul jain  wrote:
>> >> Hi Everyone,
>>
>> >> I would like to implement different views in admin panel based on the 
>> >> user.
>>
>> >> if the user is any other user apart from admin
>>
>> >> then for all those models, the user should just be able to see those
>> >> objects,( no change, delete and add).
>> >> Those users should also not see the select boxes or basically select all.
>>
>> >> So by default django provides three permissions, add, delete,change. I
>> >> would like to add one more permission on admin panel.
>>
>> >> I know this could be done on our own views through this
>>
>> >> class USCitizen(models.Model):
>> >> # ...
>> >> class Meta:
>> >> permissions = (
>> >> ("can_drive", "Can drive"),
>> >> ("can_vote", "Can vote in elections"),
>> >> ("can_drink", "Can drink alcohol"),
>> >> )
>>
>> >> {% if perms.foo %}
>> >> You have permission to do something in the foo app.
>> >> {% if perms.foo.can_vote %}
>> >> You can vote!
>> >> {% endif %}
>> >> {% if perms.foo.can_drive %}
>> >> You can drive!
>> >> {% endif %}
>> >> {% else %}
>> >> You don't have permission to do anything in the foo app.
>> >> {% endif %}
>>
>> >> But how to do the same thing on the django admin. Also, how to remove
>> >> the select all functionality for selected users.
>>
>> >> --RJ
>>
>> >> --
>> >> 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 
>> >> 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-us...@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 thi

Re: Problem installing django 1.2 on Mac OS 10.6.3

2010-05-23 Thread Tor Nordam
My bad. Turns out it was a problem with multiple versions of python
installed. Fixed it.

On May 23, 7:43 pm, Tor Nordam  wrote:
> Hello,
>
> I run into a problem when installing django 1.2 on my Mac. I follow
> the recipe on the web page, i.e. I download django-1.2.tar.gz, unpack
> it, and install by running sudo python setup.py install.
>
> After installing, django seems to work fine, but if I delete the
> directory I installed it from, i.e. the django-1.2 directory created
> by unpacking django-1.2.tar.gz, python suddenly claims there is no
> such thing as django. So it sort of seems like django is installed in
> the directory I'm installing from, instead of the usual site-packages
> directory. I've tried some googling, but I couldn't find anything on
> this issue.
>
> Cheers,
> Tor
>
> --
> 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 
> 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-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: filtering by related object causes query to grind to a halt

2010-05-23 Thread Chris Withers
Okay, so I noticed that it's the following code, and it's only when I 
filter on user *end* event:


Chris Withers wrote:

queryset = TicketStatus.objects.filter(active=True)
if user_id:
queryset = queryset.filter(owner=User.objects.get(id=user_id))
queryset = queryset.filter(ticket__event=event)
return list_detail.object_list(
request,
queryset = 
queryset.order_by('ticket__number').select_related('Ticket'),

template_name = 'tickets_list.html',
paginate_by = 50,
extra_context = dict(
events = events,
current_event_id = event.id,
users = users,
current_user_id = user_id
)
)


Here I added:

from django.db import connection
for query in connection.queries:
print query['sql']
print query['time']
print

And it shows the culprit:

SELECT COUNT(*) FROM "tracker_ticketstatus" INNER JOIN "tracker_ticket" 
ON ("tracker_ticketstatus"."ticket_id" = "tracker_ticket"."id") WHERE 
("tracker_ticketstatus"."active" = True  AND 
"tracker_ticketstatus"."owner_id" = 1  AND "tracker_ticket"."event_id" = 3 )

38.143

Why is this select being executed? Well, how can I find out what code is 
causing it?


Also, why is it so slow?

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.



Using StdImageField in an inherit context

2010-05-23 Thread Rodrigue Villetard
Hello There, 

I'm using the custom field StdImageField which automatically create a
thumbnail and resize the image
(http://code.google.com/p/django-stdimage/).

It works pretty fine in a "standard" model context. But when I use it in
a model which inherit an other one, the field behave just like
models.ImageField (StdImageField inherit models.ImageField).

NB : The StdImageField is used in the parent class.

Do you have any idea ? It seems that django bypass this custom field.

Regards.

PS : It's my first mail in this mailgroup so I've to introduce myself,
i'm a french php/Zend Framework developper and totally newbie with
django AND python... 

I wanted to try python/django for my personnal fun use as php became my
paid job. I wanted a full friendly community developped framework and
the little i've seen from django is far more attractive than Zend
Framework...

I've a nice end of week end.

Rodrigue Villetard

-- 
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: Newbie Question? Why I can not use _set?

2010-05-23 Thread Daemoneye
Sorry My opera mail downIt makes sth wrong to send out 3 mails I'm too  
late to stop it

Thanks for helping me
在 Mon, 24 May 2010 02:08:34 +0800,Daniel Roseman   
写道:



On May 23, 6:39 pm, 伟泓 徐  wrote:

class People(models.Model):
GenderChoice=(
(u'M', u'Male'),
(u'F', u'Female'),
)
PositionChoice=(
(u'S',u'Student'),
(u'A',u'Admin'),
)
Schoolnum=models.IntegerField(primary_key=True)
Gender=models.CharField(max_length=100,choices=GenderChoice)
Name=models.CharField(max_length=100)
Birthday=models.DateField()
Age=models.IntegerField()
Email=models.EmailField(blank=True)
Password=models.CharField(max_length=100)
Position=models.CharField(max_length=100,choices=PositionChoice)
CellPhoneNumber=models.IntegerField(max_length=11)
HeadImage=models.ImageField(upload_to='c:\website\photos')
def __unicode__(self):
return self.Name
def meta(self):
ordering=['Name']
abstract=True

class Comment(models.Model):
CommentSchoolNum=models.ForeignKey('People')
CommentWord=models.TextField()
CommentTime=models.DateField()
def __unicode__(self):
return self.CommentWord

why I cannot use such sentense:
s=People.objects.filter(Position='A')
s.comment_set.all()

The django says that the queryset does not have the attribution  
comment_set.Why?




Not sure why you needed to post this question three times.

`s` is a queryset, composing a number of People objects. So it doesn't
itself have a comment_set attribute - neither does it have Schoolnum
or Gender. It's the *members* of the s queryset that have these
atttributes.
--
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: Why I cannot use the _set?

2010-05-23 Thread Rolando Espinoza La Fuente
2010/5/23 Daemoneye :
[...]
> why I cannot use such sentense:
> s=People.objects.filter(Position='A')
> s.comment_set.all()
>
> The django says that the queryset does not have the attribution
> comment_set.Why?

_set is an attribute of model instances.
s=People.objects.filter(Position='A')
p1 = s[0]
p1.comment_set.all()

~Rolando

-- 
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: Newbie Question? Why I can not use _set?

2010-05-23 Thread Daniel Roseman
On May 23, 6:39 pm, 伟泓 徐  wrote:
> class People(models.Model):
>     GenderChoice=(
>         (u'M', u'Male'),
>         (u'F', u'Female'),
>     )
>     PositionChoice=(
>         (u'S',u'Student'),
>         (u'A',u'Admin'),
>     )
>     Schoolnum=models.IntegerField(primary_key=True)
>     Gender=models.CharField(max_length=100,choices=GenderChoice)
>     Name=models.CharField(max_length=100)
>     Birthday=models.DateField()
>     Age=models.IntegerField()
>     Email=models.EmailField(blank=True)
>     Password=models.CharField(max_length=100)
>     Position=models.CharField(max_length=100,choices=PositionChoice)
>     CellPhoneNumber=models.IntegerField(max_length=11)
>     HeadImage=models.ImageField(upload_to='c:\website\photos')
>     def __unicode__(self):
>         return self.Name
>     def meta(self):
>         ordering=['Name']
>         abstract=True
>
> class Comment(models.Model):
>     CommentSchoolNum=models.ForeignKey('People')
>     CommentWord=models.TextField()
>     CommentTime=models.DateField()
>     def __unicode__(self):
>         return self.CommentWord
>
> why I cannot use such sentense:
> s=People.objects.filter(Position='A')
> s.comment_set.all()
>
> The django says that the queryset does not have the attribution 
> comment_set.Why?
>

Not sure why you needed to post this question three times.

`s` is a queryset, composing a number of People objects. So it doesn't
itself have a comment_set attribute - neither does it have Schoolnum
or Gender. It's the *members* of the s queryset that have these
atttributes.
--
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.



Why I cannot use the _set?

2010-05-23 Thread Daemoneye


class People(models.Model):
GenderChoice=(
(u'M', u'Male'),
(u'F', u'Female'),
)
PositionChoice=(
(u'S',u'Student'),
(u'A',u'Admin'),
)
Schoolnum=models.IntegerField(primary_key=True)
Gender=models.CharField(max_length=100,choices=GenderChoice)
Name=models.CharField(max_length=100)
Birthday=models.DateField()
Age=models.IntegerField()
Email=models.EmailField(blank=True)
Password=models.CharField(max_length=100)
Position=models.CharField(max_length=100,choices=PositionChoice)
CellPhoneNumber=models.IntegerField(max_length=11)
HeadImage=models.ImageField(upload_to='c:\website\photos')
def __unicode__(self):
return self.Name
def meta(self):
ordering=['Name']
abstract=True

class Comment(models.Model):
CommentSchoolNum=models.ForeignKey('People')
CommentWord=models.TextField()
CommentTime=models.DateField()
def __unicode__(self):
return self.CommentWord



why I cannot use such sentense:
s=People.objects.filter(Position='A')
s.comment_set.all()

The django says that the queryset does not have the attribution  
comment_set.Why?



--
吾血之血啊

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



Newbie question about _set

2010-05-23 Thread Daemoneye




class People(models.Model):
GenderChoice=(
(u'M', u'Male'),
(u'F', u'Female'),
)
PositionChoice=(
(u'S',u'Student'),
(u'A',u'Admin'),
)
Schoolnum=models.IntegerField(primary_key=True)
Gender=models.CharField(max_length=100,choices=GenderChoice)
Name=models.CharField(max_length=100)
Birthday=models.DateField()
Age=models.IntegerField()
Email=models.EmailField(blank=True)
Password=models.CharField(max_length=100)
Position=models.CharField(max_length=100,choices=PositionChoice)
CellPhoneNumber=models.IntegerField(max_length=11)
HeadImage=models.ImageField(upload_to='c:\website\photos')
def __unicode__(self):
return self.Name
def meta(self):
ordering=['Name']
abstract=True

class Comment(models.Model):
CommentSchoolNum=models.ForeignKey('People')
CommentWord=models.TextField()
CommentTime=models.DateField()
def __unicode__(self):
return self.CommentWord



why I cannot use such sentense:
s=People.objects.filter(Position='A')
s.comment_set.all()

The django says that the queryset does not have the attribution  
comment_set.Why?


--
吾血之血啊

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



Problem installing django 1.2 on Mac OS 10.6.3

2010-05-23 Thread Tor Nordam
Hello,

I run into a problem when installing django 1.2 on my Mac. I follow
the recipe on the web page, i.e. I download django-1.2.tar.gz, unpack
it, and install by running sudo python setup.py install.

After installing, django seems to work fine, but if I delete the
directory I installed it from, i.e. the django-1.2 directory created
by unpacking django-1.2.tar.gz, python suddenly claims there is no
such thing as django. So it sort of seems like django is installed in
the directory I'm installing from, instead of the usual site-packages
directory. I've tried some googling, but I couldn't find anything on
this issue.

Cheers,
Tor

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



Newbie Question? Why I can not use _set?

2010-05-23 Thread 伟泓 徐

class People(models.Model):
GenderChoice=(
(u'M', u'Male'),
(u'F', u'Female'),
)
PositionChoice=(
(u'S',u'Student'),
(u'A',u'Admin'),
)
Schoolnum=models.IntegerField(primary_key=True)
Gender=models.CharField(max_length=100,choices=GenderChoice)
Name=models.CharField(max_length=100)
Birthday=models.DateField()
Age=models.IntegerField()
Email=models.EmailField(blank=True)
Password=models.CharField(max_length=100)
Position=models.CharField(max_length=100,choices=PositionChoice)
CellPhoneNumber=models.IntegerField(max_length=11)
HeadImage=models.ImageField(upload_to='c:\website\photos')
def __unicode__(self):
return self.Name
def meta(self):
ordering=['Name']
abstract=True
 
class Comment(models.Model):
CommentSchoolNum=models.ForeignKey('People')
CommentWord=models.TextField()
CommentTime=models.DateField()
def __unicode__(self):
return self.CommentWord
 
 
 
why I cannot use such sentense:
s=People.objects.filter(Position='A')
s.comment_set.all()
 
The django says that the queryset does not have the attribution comment_set.Why?
  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969

-- 
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: Problems with url encoding

2010-05-23 Thread Caumons
Hello Danfi!

There is a syntax mistake. I changed the &pag={{num_pag}} by ?
pag={{num_pag}} and the problem was solved.
One thing to point out is that there is a method with the HttpRequest
objects called get_full_path() that returns the URL with the params. I
used it inside a session to track the user, this way I avoid having to
pass data from one pag. to another.

I do not know what happens with data submitted by get which contains
accents. Are there any problems?

On 21 mayo, 10:33, Danfi  wrote:
> maybe you lack of "?"before {{slug_plataform}}
>
> Return to list
>
> On 5月20日, 上午10时25分, Caumons  wrote:
>
>
>
> > Hi everybody.
>
> > I am having problems with the urlencoding. I explain. In a template I
> > have the following code:
>
> >  > class="link">Return to list
>
> > In the view I pass the variables slug_platform and num_pag to the
> > template, but the problem is that when I click the link it brings me
> > to the following page (copy/paste from the developing server):
>
> > /plataforms/wii%26pag%3D1/HTTP/1.1" 404 1738
>
> > As you can see there are these % symbols and I do not know if Django
> > does an automatic urlencoding, but then the URL does not match with
> > any pattern because of these symbols! But if I test the code with an
> > html validator it gives me errors because it says that this line is
> > not urlencoded.
>
> > I have also tried doing this:
> >  > urlencode}} class="link">Return to list
> > but this raises a syntax error in the template
>
> > I do not know what to do and I also do not know if when we do
> > something like request.get["something"] you have to unquote it or it
> > is not needed.
>
> > Thank you 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 
> > 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-us...@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-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.



filtering by related object causes query to grind to a halt

2010-05-23 Thread Chris Withers

Hi All,

I have the following models:

class Event(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=4,decimal_places=2)

class Ticket(models.Model):
number = models.IntegerField(db_index=True)
event = models.ForeignKey(Event)

class TicketStatus(models.Model):
ticket = models.ForeignKey(Ticket)
transaction = models.ForeignKey(Transaction,related_name='actions')
timestamp = models.DateTimeField()
owner = models.ForeignKey(User)
status = 
models.CharField(max_length=max_len(STATUSES),choices=STATUSES)

active = models.BooleanField()

I'm trying to build a drop-down filtered list of tickets, showing their 
current status. The dropdowns allow filtering by owner and by event.


Here's my code:

@login_required
def tickets(request):
events = Event.objects.all()
event = Event.objects.get(id=request.GET.get('event',events[0].id))
if request.user.is_staff:
user_id = request.GET.get('user',request.user.id)
users = User.objects.all()
else:
user_id = request.user.id
users = [user]
queryset = TicketStatus.objects.filter(active=True)
if user_id:
queryset = queryset.filter(owner=User.objects.get(id=user_id))
queryset = queryset.filter(ticket__event=event)
return list_detail.object_list(
request,
queryset = 
queryset.order_by('ticket__number').select_related('Ticket'),

template_name = 'tickets_list.html',
paginate_by = 50,
extra_context = dict(
events = events,
current_event_id = event.id,
users = users,
current_user_id = user_id
)
)

As soon as I added the:

queryset = queryset.filter(ticket__event=event)

...line, evaluating the queryset grinds to a halt.
Why is that? How can I make it fast?

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.



Security Question...

2010-05-23 Thread ringemup
Hi folks --

I'm putting together a simple API to allow a separately-hosted but
trusted site to perform a very limited set of actions on my site.  I'm
wondering whether the design I've come up with is reasonably secure:

- Other site gets an API key, which is actually in two parts, public
key and private key, each of which is a uuid generated by Python's
uuid module.

- The API key object in the DB references a User object, whose
permissions determine what actions the API key owner may take

- Other site submits a POST request to a special URL on my site.  POST
request contains 3 vars: public_key, data (as JSON), hash.

- Hash is a SHA1 of the data concatenated with the private key

- I use the public key to search the database for the API key and
permissions.

- I generate the SHA1 of the data concatenated with the private key
from the DB, and check it against the submitted hash; only if they
match do I decode the data dict and take the actions specified within

- I then return an HTTP response containing a JSON object of the
format:

{
return_data: [object containing success / failure codes, messages,
any other data],
hash: [SHA1 of return_data concatenated with private key]
}

- All data will be transmitted in the clear (no SSL currently
available -- *sigh*), but there will be no sensitive data in the
incoming data dict.  return_data may contain values that aren't meant
to be broadcasted, but aren't really sensitive (along the lines of
activation keys for a game)

Do you see any major potential flaws in this plan?

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: FormWizard and fields which allow only one validation

2010-05-23 Thread barbuza
Supercaptcha removes it's hash and text code from cache to prevent
using same hash and code many times. If you really need to use it with
formwizard - you'll have to invent mechanism which will prevent
supercaptcha from cleaning cache and clean it manually after all forms
are validated. I'm not using formwizard, so I'm not going to add this
feature to supercaptcha. Feel free to fork it and make a try.

On May 17, 2:01 pm, Valentin Golev  wrote:
> Hello!
>
> I've been using SuperCaptcha for Django for some time and everything
> was OK. But one day I was stupid enough and tried to use it with
> FormWizard.
>
> I think it's a bug and I could not invent a workaround for it (except
> for not using the FormWizard). The problem is, FormWizard validates
> every form every time. But after the first validation of CaptchaField
> the captcha become out-of-date, so the second validation fails with
> ValidationError.
>
> It's very simple to reproduce, just create two forms, add a captcha
> field to the first and create a wizard with these forms.
>
> I just thought you want to know. And maybe you know a solution for it.
>
> - Valentin Golev
> -http://valyagolev.net/
>
> --
> 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 
> 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-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: automatically performing an a task

2010-05-23 Thread Daniel Roseman
On May 23, 7:47 am, irum  wrote:
> Hi,
>
> Thanks:)
> However, sorry I am a newbie with this stuff. I have gotten some hands
> on Django during this project and have taken some understanding of
> cron by googling but I am still sort of lost with it.
>
> The problem is that if I fire manage.py script with cron, how do I run
> the specific task that I want to run that performs the computaion of
> checking the end date and resolving it(involving db operations, and
> sending mail to winner etc.)
> Lets suppose, I write all this funtionality as a view(e.g.
> resolveauction) in view.py and link a uri with this in urls.py (e.g.
> (r'^res_aucation/$', resolveauction)). Now how do I fire manage.py
> from cron to trigger this uri(e.g. /res_auction/) functionality?
>
> Thanks again and looking forward,
> Irum

Don't write it as a view. Either write it directly in the manage.py
command, or as a separate function that's imported and called from
there. If you really need it to be accessible from a view as well,
then keep it as the separate function and call it from the view as
well.
--
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.



code creates two copies of an uploaded image

2010-05-23 Thread shofty
def unique_file_gallerythumb(instance, file_name):
# split the file_name into dir and filename
# then split the filename into name and ext
dirname, filename = os.path.split(file_name)
prefix, suffix = os.path.splitext(filename)
smallfilename, extension = os.path.splitext(prefix)

# fd is file handle, but we arent too bothered by it
# filename is the new random filename but its absolute
# so we need to split it again.
fd, filename = tempfile.mkstemp(suffix, smallfilename+"_",
dirname)
dirname, save_filename = os.path.split(filename)
return "thumbnails/" + save_filename

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
galleryname = models.CharField(max_length=30, help_text="Give the
gallery a friendly name. not bob. something like Anne-Marie's Pics!")
gallerymessage = models.CharField(max_length=250, help_text="Leave
a quick message for the happy couple. no smut, thanks.")
gallerythumb =
models.ImageField(upload_to=unique_file_gallerythumb)

def save(self):
pdb.set_trace()
#resize image.
image = Image.open(self.gallerythumb)
#create thumbnail
Thumb_Size = (120,120)
#image = Image.open(self.photo)

if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')

image.thumbnail(Thumb_Size, Image.ANTIALIAS)

temp_handle = StringIO()
image.save(temp_handle, 'jpeg')
temp_handle.seek(0)

suf = SimpleUploadedFile(os.path.split(self.gallerythumb.name)
[-1], temp_handle.read(), content_type='image/jpg')
self.gallerythumb.save(suf.name+'.jpg', suf, save=False)

#enter info to database
super(UserProfile, self).save()



##
two problems with the above code.

1. def unique_file_gallerythumb(instance, file_name):
if you interogate the file_name in debug, it comtains two suffixes.
wedding.jpg.jpg is the uploaded file. quite strange. hance im using
splitext twice.

2. the line below creates an empty copy of the image in the root
folder, the one that the settings file lives in. empty as in zero kb.
self.gallerythumb.save(suf.name+'.jpg', suf, save=False)


anyone see any obvious reasons why the above would be happening?

-- 
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: Model design graphically or UML

2010-05-23 Thread Jasper Kennis
Visual paradigm is nice, and free for personal use.

On May 23, 11:05 am, Jon  wrote:
> Hello,
>
> Trying to include some graph tool for managing and sharing data models
> visually.
>
> Testes mysql workbench, dia, graphivz and recently read some about
> argoUML..
>
> ¿Do you know and recommend any visual tool for model design? Better if
> database independent
>
> thanks in advance !!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-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: database engine problem

2010-05-23 Thread catafest
Try reinstall django .
Set first name of database
Use python manage.py syncdb to set user and more .
See corect steps here : 
http://www.webmonkey.com/2010/02/install_django_and_build_your_first_app/


On Apr 6, 7:29 am, yangyang  wrote:
> I followed the tutorial and set up the database engine as SQLight and
> it seemed to be successful. However, when I try to do "python
> manage.py syncdb", it returns error message like
> File "manage.py", line 11, in 
>     execute_manager(settings)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/__init__.py", line 362,
> in execute_manager
>     utility.execute()
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/__init__.py", line 303,
> in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/base.py", line 195, in
> run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/base.py", line 222, in
> execute
>     output = self.handle(*args, **options)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/base.py", line 351, in
> handle
>     return self.handle_noargs(**options)
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/core/management/commands/syncdb.py",
> line 49, in handle_noargs
>     cursor = connection.cursor()
>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/django/db/backends/dummy/base.py", line 15, in
> complain
>     raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE
> setting yet."
> django.core.exceptions.ImproperlyConfigured: You haven't set the
> DATABASE_ENGINE setting yet.
>
> I wonder what went wrong... Could anyone help me out here? 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.



Multiple apps in one view

2010-05-23 Thread Jasper Kennis
Hello,

Can you run multiple apps in one view, and what would be the best way
to do that.

Let's say I have two apps and I want to display some items from app1
and some from app2 in the same view. I understand that it would be a
good idea to create a third app, but I don't want to violate the dry
principals. Now I've seen the template tag pass, and the context
processor, but I can't really find a conclusive way as to how to do
this the right way.

Is there an article about this somewhere, or can template tags and
context processors solve my problem?

Kind regards,


Jasper Kennis

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



Model design graphically or UML

2010-05-23 Thread Jon
Hello,

Trying to include some graph tool for managing and sharing data models
visually.

Testes mysql workbench, dia, graphivz and recently read some about
argoUML..

¿Do you know and recommend any visual tool for model design? Better if
database independent

thanks in advance !!

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