Re: Problems extracting valid form data lately

2012-04-16 Thread Kejun He
paste your form code please

On Sun, Apr 15, 2012 at 11:54 PM, Andy McKay  wrote:

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

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



Re: Any tool to validate django templates?

2012-04-16 Thread Matt Schinckel
Generally, I just use syntax highlighting in my text editor: that usually 
helps me find errors.

TextMate has a nice HTML (Django Template) mode.

Matt.


On Monday, April 16, 2012 2:12:14 AM UTC+9:30, Marcin wrote:
>
> Hi all,
>
> I've got a template that isn't parsing, but the error is the 
> nondescript: TemplateSyntaxError: Could not parse the remainder: '"{%' from 
> '"{%'
>
> Is there a tool that can help locate the source of the error?
>
> Marcin
>
> -- 
> Marcin Tustin
> Tel: 07773 787 105
>
>  

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



Re: Problems extracting valid form data lately

2012-04-16 Thread Blackpearl
you can check the form data dictionary by:

if form.is_valid():
print form.__dict__

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



Re: How to change widgets for admin site?

2012-04-16 Thread Marc Patermann

Hi,

Gchorn schrieb (16.04.2012 07:24 Uhr):

Hello, I'm trying to create a blog site using Django (with "Post" as
my main model and "text" as the attribute corresponding to the main
body of text for each post).  On the admin page, when someone is
filling out fields to create a new blog post, I want the "text" entry
field to be larger than the default field for a CharField attribute.

In this part of the docs:

https://docs.djangoproject.com/en/1.4/ref/contrib/admin/
what you see in the admin interface is inherited form the model of the 
corresponding object - like your blog post object.

I think you have to change the field length there.

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


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



Re: Passing additional variables to flatpage template

2012-04-16 Thread Tom Evans
On Sat, Apr 14, 2012 at 9:27 PM, Swaroop Shankar V  wrote:
> Hi All,
>
> Am using flatpage app in my application. I want to send
> few additional variables that can be accessible from the flatpage templates.
> So how can i accomplish the same?
>

You cannot. The only way to get additional variables into the template
context when using flatpages is to use TEMPLATE_CONTEXT_PROCESSORS, as
flatpages are rendered using a RequestContext.

Cheers

Tom

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



Re: [Question] Filter Queryset in a Template

2012-04-16 Thread Nikhil Somaru
I appreciate your reply, but you haven't quite helped me out.

If I do the filtering in views.py, I the template would have to make
assumptions about the type of context variables I will be passing it.

Or am I seeing this the wrong way?

On 15 April 2012 00:41, dummyman dummyman  wrote:

> do the filtering part in views.py . templates is meant only for visual
> purpose
>
> On Sat, Apr 14, 2012 at 2:21 PM, Nikhil Somaru  wrote:
>
>> Greetings,
>>
>>
>> I would like to do something like queryset filtering in a template. Is
>> the only solution via a template tag?
>>
>>
>> # models.py
>>
>> class StudentProfile(models.Model):
>>
>> # class defined here
>>
>> # ...
>>
>>
>> class Department(models.Model):
>>
>> # ...
>>
>> students = models.ManyToManyField('StudentProfile',  null=True,
>> blank=True)
>>
>> # ...
>>
>>
>> class Activity (models.Model):
>>
>> # ...
>>
>> department = models.ForeignKey('Department')
>> # ...
>>
>> I would like to do the following in a template:
>>
>> The context variable is student
>>
>> {% for dept in student.department_set.all %}
>> **{% for activity in student.activity_set.all.*
>> filter(department=dept)* %}
>> {{ activity }}
>> {% endfor %}
>> {% endfor %}
>>
>> This would produce something like a list of all activities for each
>> department the student is in. I have removed formatting and html to make it
>> clearer.
>>
>> Obviously, you can't pass arguments to filter in a template. How can one
>> achieve this?
>>
>> --
>> Yours,
>> Nikhil Somaru
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Yours,
Nikhil Somaru

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



Re: [Question] Filter Queryset in a Template

2012-04-16 Thread waax
You can use templatetags for example: 
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs

On Saturday, April 14, 2012 10:51:51 AM UTC+2, Nikhil Somaru wrote:
>
> Greetings,
>
>
> I would like to do something like queryset filtering in a template. Is the 
> only solution via a template tag?
>
>
> # models.py
>
> class StudentProfile(models.Model):
>
> # class defined here
>
> # ...
>
>
> class Department(models.Model):
>
> # ...
>
> students = models.ManyToManyField('StudentProfile',  null=True, blank=True)
>
> # ...
>
>
> class Activity (models.Model):
>
> # ...
>
> department = models.ForeignKey('Department')
> # ...
>
> I would like to do the following in a template:
>
> The context variable is student
>
> {% for dept in student.department_set.all %}
> **{% for activity in student.activity_set.all.*
> filter(department=dept)* %}
> {{ activity }}
> {% endfor %}
> {% endfor %}
>
> This would produce something like a list of all activities for each 
> department the student is in. I have removed formatting and html to make it 
> clearer.
>
> Obviously, you can't pass arguments to filter in a template. How can one 
> achieve this?
>
> -- 
> Yours,
> Nikhil Somaru
>
>  

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



Missing manage.py

2012-04-16 Thread Faeez Abd Rahman
Hi,

I have a problem whenever I create a new project using the start project
command, no manage.py file is created.

I'm using Mac OS X. Thank you in advance

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



Re: How to change widgets for admin site?

2012-04-16 Thread Guillaume Chorn
Hi Marc,

Thanks for your reply.  Are you referring to the "max_length" element of my
"text" CharField?  If so, I don't think this is the issue; I've set the max
length to 10,000 characters which is quite long.  Also this setting does
not change the size of the text input area relative to my other CharFields
with much shorter max_length values (such as "title", which has a max
length of only 1000).

cheers,
Guillaume

On Mon, Apr 16, 2012 at 4:51 PM, Marc Patermann <
hans.mo...@ofd-z.niedersachsen.de> wrote:

> Hi,
>
> Gchorn schrieb (16.04.2012 07:24 Uhr):
>
>  Hello, I'm trying to create a blog site using Django (with "Post" as
>> my main model and "text" as the attribute corresponding to the main
>> body of text for each post).  On the admin page, when someone is
>> filling out fields to create a new blog post, I want the "text" entry
>> field to be larger than the default field for a CharField attribute.
>>
>> In this part of the docs:
>>
>> https://docs.djangoproject.**com/en/1.4/ref/contrib/admin/
>>
> what you see in the admin interface is inherited form the model of the
> corresponding object - like your blog post object.
> I think you have to change the field length there.
>
> https://docs.djangoproject.**com/en/1.4/intro/tutorial01/
>
>
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

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



Re: Any tool to validate django templates?

2012-04-16 Thread william ratcliff
Wing IDE also highlights templates.
On Apr 16, 2012 3:16 AM, "Matt Schinckel"  wrote:

> Generally, I just use syntax highlighting in my text editor: that usually
> helps me find errors.
>
> TextMate has a nice HTML (Django Template) mode.
>
> Matt.
>
>
> On Monday, April 16, 2012 2:12:14 AM UTC+9:30, Marcin wrote:
>>
>> Hi all,
>>
>> I've got a template that isn't parsing, but the error is the nondescript:
>> **TemplateSyntaxError: Could not parse the remainder: '"{%' from '"{%'
>>
>> Is there a tool that can help locate the source of the error?
>>
>> Marcin
>>
>> --
>> Marcin Tustin
>> Tel: 07773 787 105
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/IOteWda5w0UJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: [Question] Filter Queryset in a Template

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 6:00 AM, Nikhil Somaru  wrote:
> If I do the filtering in views.py, I the template would have to make
> assumptions about the type of context variables I will be passing it.
>
> Or am I seeing this the wrong way?

i think so.   the view is where you manage _what_ is shown, the
template is where you manage _how_ is shown.

from that, filtering is usually more apropriate to be done on the view.

i usually don't worry too much about the template assuming the view
works in a specific way, since templates are _so_ rarely reusable
(except for inheritance, but i don't think it's your problem)

i don't really get what do you mean by "would have to make assumptions
about the type of context variables", filtering data (in the view)
usually shoudln't change type of variables (querysets are still
querysets), it should only change the content of them.

-- 
Javier

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



Building composite keys?

2012-04-16 Thread Roy Smith
I've got a model in django 1.4:

class Image(Model):
serial = AutoField(primary_key=True)
version = IntegerField(default=1)

I want (serial, version) to be unique.  Is there a way to express that in the 
model layer?

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



Re: Building composite keys?

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 9:24 AM, Roy Smith  wrote:
> I want (serial, version) to be unique.

class Meta
unique_together = [('serial','version')]

-- 
Javier

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



Re: How to change widgets for admin site?

2012-04-16 Thread Daniel Roseman
On Monday, 16 April 2012 06:24:54 UTC+1, Gchorn wrote:
>
> Hello, I'm trying to create a blog site using Django (with "Post" as 
> my main model and "text" as the attribute corresponding to the main 
> body of text for each post).  On the admin page, when someone is 
> filling out fields to create a new blog post, I want the "text" entry 
> field to be larger than the default field for a CharField attribute. 
>
> In this part of the docs: 
>
> https://docs.djangoproject.com/en/1.4/ref/contrib/admin/ 
>
> in the "ModelAdmin options" section, under "ModelAdmin.fieldsets", 
> there is an image of pretty much what I want--a set of text entry 
> fields, where one of the fields, named "Content", is much larger than 
> the others to make it easier for whoever uses the admin site to type 
> in larger amounts of text.  However, there isn't any clear explanation 
> that I can find in this section about how to achieve this. 
>
> The closest thing I can find is a little ways further, there's a 
> section that says you can use "classes" as a field_options dictionary 
> key, and it mentions two classes defined by the default admin style 
> sheet (collapse and wide).  I think I need to specify some kind of 
> class in this way, but I don't know where on my file system the 
> default admin style sheet is located in order to read it and see if 
> there are any classes there I can use. 
>
> Can anyone help with this?  Is there a built-in CSS class that does 
> what I want, or do I need to write it myself?  If the latter, can 
> anyone tell me where I should write it and where I need to reference 
> it so that it affects the admin site?


'content' in that model is a models.TextField, not models.CharField. 
TextFields by default render with the Textarea widget.
--
DR.

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



Re: Building composite keys?

2012-04-16 Thread Gerald Klein
I understand serial by nature is unique.

On Mon, Apr 16, 2012 at 9:24 AM, Roy Smith  wrote:

> I've got a model in django 1.4:
>
> class Image(Model):
>serial = AutoField(primary_key=True)
>version = IntegerField(default=1)
>
> I want (serial, version) to be unique.  Is there a way to express that in
> the model layer?
>
> ---
> Roy Smith
> r...@panix.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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 

Gerald Klein DBA

contac...@geraldklein.com

www.geraldklein.com 

j...@zognet.com

708-599-0352


Linux registered user #548580

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



Passing parameters to class Meta:

2012-04-16 Thread Mario Gudelj
Hi Djangoers,

I have an issue I can't work out. This is the situation:

I have a model called payment, which has a custom constructor which takes a
parameter. This is the code:

class Payment(models.Model):
id = models.AutoField(primary_key=True)
amount = models.FloatField("Total payment amount")
...

def __init__(self, business, *args, **kwargs):
super(Payment, self).__init__(*args, **kwargs)
self.business = business



Then in my forms file I have this model form:


class PaymentForm(forms.ModelForm):
class Meta:
model = Payment

def __init__(self, *args, **kwargs):
self.business = kwargs.pop('business')
super(PaymentForm, self).__init__(*args, **kwargs)



The problem I have is that when I try to create an instance of this form
with:

form = PaymentForm(request.GET, business=business)

I get the following error:

TypeError at /payment/

__init__() takes at least 2 arguments (1 given)

The stacktrace shows that it fails on self.instance = opts.model() ... in
this location.

/django/forms/models.py in __init__
 initial=None, error_class=ErrorList, label_suffix=':',
 empty_permitted=False, instance=None):
opts = self._meta
if instance is None:
if opts.model is None:
raise ValueError('ModelForm has no model class specified.')
# if we didn't get an instance, instantiate a new one
self.instance = opts.model() ...
object_data = {}
else:
self.instance = instance
object_data = model_to_dict(instance, opts.fields, opts.exclude)
# if initial was provided, it should override the values from
instance
if initial is not None:

I think I need to somehow pass the business object to model = Payment
inside the Meta class... Is this the case and does anyone know how to do it?

I have remove the constructor from the model and everything works.

Thanks a million!

-m

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



Re: Any tool to validate django templates?

2012-04-16 Thread John Yeukhon Wong
Would this help?
http://stackoverflow.com/questions/3086637/how-should-i-validate-html-in-django-templates-during-the-development-process

I quite like the not-accepted-as-answer. Just go through your urls. 
Essentially, you have two types of possible template errors:

1. human errors (missing a close tag / mispell)
2. logic error

For logic error, you are dealing with mostly logic tags  such as url tags 
or custom tags rendering problem. For example, does your {% url my_view id 
username %} actually works? are the variables passing to / from view are 
good for these tags? THis kind of error is not possible checked with going 
through all urls because u can't test possibility like that. THat has to be 
handled by unit test and integration (system) test.


Good luck. 

On Sunday, April 15, 2012 12:42:14 PM UTC-4, Marcin wrote:
>
> Hi all,
>
> I've got a template that isn't parsing, but the error is the 
> nondescript: TemplateSyntaxError: Could not parse the remainder: '"{%' from 
> '"{%'
>
> Is there a tool that can help locate the source of the error?
>
> Marcin
>
> -- 
> Marcin Tustin
> Tel: 07773 787 105
>
>  

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



Re: Any tool to validate django templates?

2012-04-16 Thread Mario Gudelj
PyCharm does a very good job here when it comes to highlighting and error
detection in templates. Try it out.

On 17 April 2012 01:12, John Yeukhon Wong  wrote:

> Would this help?
>
> http://stackoverflow.com/questions/3086637/how-should-i-validate-html-in-django-templates-during-the-development-process
>
> I quite like the not-accepted-as-answer. Just go through your urls.
> Essentially, you have two types of possible template errors:
>
> 1. human errors (missing a close tag / mispell)
> 2. logic error
>
> For logic error, you are dealing with mostly logic tags  such as url tags
> or custom tags rendering problem. For example, does your {% url my_view id
> username %} actually works? are the variables passing to / from view are
> good for these tags? THis kind of error is not possible checked with going
> through all urls because u can't test possibility like that. THat has to be
> handled by unit test and integration (system) test.
>
>
> Good luck.
>
> On Sunday, April 15, 2012 12:42:14 PM UTC-4, Marcin wrote:
>>
>> Hi all,
>>
>> I've got a template that isn't parsing, but the error is the nondescript:
>> **TemplateSyntaxError: Could not parse the remainder: '"{%' from '"{%'
>>
>> Is there a tool that can help locate the source of the error?
>>
>> Marcin
>>
>> --
>> Marcin Tustin
>> Tel: 07773 787 105
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Ml-zdg0y4WEJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



AutoFields must have primary_key=True?

2012-04-16 Thread Roy Smith
I need an integer field which generates increasing integers.  But I don't want 
it to be my primary key.  In fact, it can't be, because I want the ability to 
manually reset it to something else.  The auto-increment is just a default 
value.

If I do:

> class Image(Model):
> serial = AutoField()

I get an error when I do syncdb or schemamigration:

> AssertionError: AutoFields must have primary_key=True.

Is this a bug?

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



Re: Any tool to validate django templates?

2012-04-16 Thread Marcin Tustin
Thanks. Neither of those would help with my problem, which is that django
itself was refusing to parse my template.

My solution was to simply comment out regions, and re-instate them until
the error was once again detected.

On Mon, Apr 16, 2012 at 16:12, John Yeukhon Wong wrote:

> Would this help?
>
> http://stackoverflow.com/questions/3086637/how-should-i-validate-html-in-django-templates-during-the-development-process
>
> I quite like the not-accepted-as-answer. Just go through your urls.
> Essentially, you have two types of possible template errors:
>
> 1. human errors (missing a close tag / mispell)
> 2. logic error
>
> For logic error, you are dealing with mostly logic tags  such as url tags
> or custom tags rendering problem. For example, does your {% url my_view id
> username %} actually works? are the variables passing to / from view are
> good for these tags? THis kind of error is not possible checked with going
> through all urls because u can't test possibility like that. THat has to be
> handled by unit test and integration (system) test.
>
>
> Good luck.
>
> On Sunday, April 15, 2012 12:42:14 PM UTC-4, Marcin wrote:
>>
>> Hi all,
>>
>> I've got a template that isn't parsing, but the error is the nondescript:
>> **TemplateSyntaxError: Could not parse the remainder: '"{%' from '"{%'
>>
>> Is there a tool that can help locate the source of the error?
>>
>> Marcin
>>
>> --
>> Marcin Tustin
>> Tel: 07773 787 105
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Ml-zdg0y4WEJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Marcin Tustin
Tel: 07773 787 105

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



Re: AutoFields must have primary_key=True?

2012-04-16 Thread Gerald Klein
Auto-incrementing fields are meant to be primary keys that is their
purpose. I have never tried it but a formula in the default value for an
integer field to increment it might work

On Mon, Apr 16, 2012 at 10:17 AM, Roy Smith  wrote:

> I need an integer field which generates increasing integers.  But I don't
> want it to be my primary key.  In fact, it can't be, because I want the
> ability to manually reset it to something else.  The auto-increment is just
> a default value.
>
> If I do:
>
> > class Image(Model):
> > serial = AutoField()
>
> I get an error when I do syncdb or schemamigration:
>
> > AssertionError: AutoFields must have primary_key=True.
>
> Is this a bug?
>
> ---
> Roy Smith
> r...@panix.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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 

Gerald Klein DBA

contac...@geraldklein.com

www.geraldklein.com 

j...@zognet.com

708-599-0352


Linux registered user #548580

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



Re: AutoFields must have primary_key=True?

2012-04-16 Thread Marcin Tustin
I came up against this also. My work-around was to create a model that
exists explicitly for the purpose of generating sequential integers (I also
need them to be unique, so it's acceptable for my purposes). You might like
to have two fields to accomplish the same thing with duplicates (which I
admit is less than ideal).

On Mon, Apr 16, 2012 at 16:17, Roy Smith  wrote:

> I need an integer field which generates increasing integers.  But I don't
> want it to be my primary key.  In fact, it can't be, because I want the
> ability to manually reset it to something else.  The auto-increment is just
> a default value.
>
> If I do:
>
> > class Image(Model):
> > serial = AutoField()
>
> I get an error when I do syncdb or schemamigration:
>
> > AssertionError: AutoFields must have primary_key=True.
>
> Is this a bug?
>
> ---
> Roy Smith
> r...@panix.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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Marcin Tustin
Tel: 07773 787 105

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 10:11 AM, Mario Gudelj  wrote:
> I think I need to somehow pass the business object to model = Payment inside
> the Meta class...

how many 'business' options are there?

if it's a fixed num, you could add a Proxy 'subclass' for each one
that simply provides the apropriate parameter in the constructor.

if not fixed but small quantity (say, less than a hundred), maybe you
could create those Proxies programatically?

if it's an unbounded number of different 'business objects', then
you'll have to override the model construction parts of the form i
guess a mixin class would be easiest to carry to several forms.


-- 
Javier

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Tom Evans
On Mon, Apr 16, 2012 at 4:11 PM, Mario Gudelj  wrote:
> Hi Djangoers,
>
> I have an issue I can't work out. This is the situation:
>
> I have a model called payment, which has a custom constructor which takes a
> parameter. This is the code:
>
> class Payment(models.Model):
>     id = models.AutoField(primary_key=True)
>     amount = models.FloatField("Total payment amount")
>     ...
>
>     def __init__(self, business, *args, **kwargs):
>         super(Payment, self).__init__(*args, **kwargs)
>         self.business = business
>

As you've found out, this causes pain. Your model instances need to be
constructable without arguments for most automatic form related stuff
to happen.

In this specific case, your problem is that when you do not pass an
instance to a ModelForm based upon this model, the code will by
default attempt to construct an empty instance, without passing any
arguments, and an exception is raised.

To work around this, you have to avoid that scenario. You can override
the __init__ method of the form, and examine the instance out of
kwargs. If an instance has not been passed through, you need to
construct an empty instance there, and pass it to the form.

This will solve this specific use of ModelForms and your model. It
would not, for instance, make the admin site suddenly start working
with this model.

In general though, you should look at your design:

In order to construct an instance of your class, your design says that
you must pass additional information to that class. However, your
class represents a row in a database table - why does an instance of
your class rely on information that is not persisted in the database?

How do you expect something like "Payment.objects.get(id=1)" to work?

Cheers

Tom

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



Re: How to change widgets for admin site?

2012-04-16 Thread Guillaume Chorn
Shoot! I was thinking that might be the case originally, but I must have 
overlooked TextField in the model field docs. Thanks!!!

I'm still curious though--how can I find out what all of the CSS classes are 
that are defined by the default admin style sheet (I guess I'm asking where 
this style sheet normally resides in a typical Django installation)?

On 16 Apr, 2012, at 10:28 PM, Daniel Roseman  wrote:

> On Monday, 16 April 2012 06:24:54 UTC+1, Gchorn wrote:
> Hello, I'm trying to create a blog site using Django (with "Post" as 
> my main model and "text" as the attribute corresponding to the main 
> body of text for each post).  On the admin page, when someone is 
> filling out fields to create a new blog post, I want the "text" entry 
> field to be larger than the default field for a CharField attribute. 
> 
> In this part of the docs: 
> 
> https://docs.djangoproject.com/en/1.4/ref/contrib/admin/ 
> 
> in the "ModelAdmin options" section, under "ModelAdmin.fieldsets", 
> there is an image of pretty much what I want--a set of text entry 
> fields, where one of the fields, named "Content", is much larger than 
> the others to make it easier for whoever uses the admin site to type 
> in larger amounts of text.  However, there isn't any clear explanation 
> that I can find in this section about how to achieve this. 
> 
> The closest thing I can find is a little ways further, there's a 
> section that says you can use "classes" as a field_options dictionary 
> key, and it mentions two classes defined by the default admin style 
> sheet (collapse and wide).  I think I need to specify some kind of 
> class in this way, but I don't know where on my file system the 
> default admin style sheet is located in order to read it and see if 
> there are any classes there I can use. 
> 
> Can anyone help with this?  Is there a built-in CSS class that does 
> what I want, or do I need to write it myself?  If the latter, can 
> anyone tell me where I should write it and where I need to reference 
> it so that it affects the admin site?
> 
> 'content' in that model is a models.TextField, not models.CharField. 
> TextFields by default render with the Textarea widget.
> --
> DR.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/7aPR5gfE6mYJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: Problems extracting valid form data lately

2012-04-16 Thread Chris Seberino
INVITATION_CODE = "You should have received one of these."
PAR_EMAIL_ADD   = "Will be used for all communications."
PASSWORD= ""
STUD_FIRST_NAME = "Enter what the student prefers to go by."
STUD_LAST_NAME  = ""
COURSE_1= "Select the course enrolled in and/or getting
tutoring in."
COURSE_2= "Select the second course, if any, enrolled in."
COURSE_3= "Select the third course, if any, enrolled in."
HOW_HEARD_ABOUT = "Please provide specific names."
REPEAT  = "This is to avoid any errors."
class RegisterForm(django.forms.Form):
 
"""
Represents form
data.
"""

invitation_code = CustomCharField(help_text =
INVITATION_CODE)
username= CustomCharField()
parental_email_address  = EMAIL_FIELD(help_text =
PAR_EMAIL_ADD)
parental_email_address2 = EMAIL_FIELD(help_text = REPEAT)
password= CustomCharField(help_text =
PASSWORD,
  widget=
PASSWORD_INPUT)
password2   = CustomCharField(help_text = REPEAT,
  widget=
PASSWORD_INPUT)
student_first_name  = CustomCharField(help_text =
STUD_FIRST_NAME)
student_last_name   = CustomCharField(help_text =
STUD_LAST_NAME)
course_1= CHOICE_FIELD(widget= SELECT(),
   choices   =
COURSE_1_CHOICES,
   help_text = COURSE_1)
course_2= CHOICE_FIELD(widget= SELECT(),
   choices   =
COURSE_2_CHOICES,
   help_text = COURSE_2)
course_3= CHOICE_FIELD(widget= SELECT(),
   choices   =
COURSE_3_CHOICES,
   help_text = COURSE_3)
session = CHOICE_FIELD(widget  = SELECT(),
   choices =
SESSION_CHOICES)
how_heard_about_categ   = CHOICE_FIELD(widget= SELECT(),
   choices =
CATEG_CHOICES)

how_heard_about_detail  = CustomCharField(help_text =
HOW_HEARD_ABOUT)

def clean_username(self):
 
"""
custom validation
code
"""

if "username" in self.cleaned_data:
username = self.cleaned_data["username"]
if USER.objects.filter(username = username):
raise VALID_ERROR("Username is not
available.")

return self.cleaned_data

def clean_invitation_code(self):
 
"""
custom validation
code
"""

if self.cleaned_data["invitation_code"] != "abc123":
raise VALID_ERROR("Invitation code is
invalid.")

return self.cleaned_data

def clean_parental_email_address2(self):
 
"""
custom validation
code
"""

cd = self.cleaned_data
if ("parental_email_address"  not in
self.cleaned_data) or\
   ("parental_email_address2" not in
self.cleaned_data) or\
   (cd["parental_email_address"] !=
 
cd["parental_email_address2"]):
raise VALID_ERROR("Email addresses do not
match.")

return self.cleaned_data
def clean_password2(self):
 
"""
custom validation
code
"""

cd = self.cleaned_data
if ("password"  not in self.cleaned_data)
or  \
   ("password2" not in self.cleaned_data)
or  \
   (cd["password"] != cd["password2"]):
raise VALID_ERROR("Passwords do not match.")

return self.cleaned_data



On Apr 16, 2:06 am, Kejun He  wrote:
> paste your form code please
>
> On Sun, Apr 15, 2012 at 11:54 PM, Andy McKay  wrote:
> > What does your form code look like?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Mario Gudelj
Hey Javier,

Thanks for the reply. There are thousands of different businesses, so I
guess I'll have to go with the last option...

Is this kind of what you're referring to there
http://stackoverflow.com/questions/7114710/using-a-mixin-with-a-django-form-class
?

Thanks again.

-m

On 17 April 2012 01:28, Javier Guerra Giraldez  wrote:

> On Mon, Apr 16, 2012 at 10:11 AM, Mario Gudelj 
> wrote:
> > I think I need to somehow pass the business object to model = Payment
> inside
> > the Meta class...
>
> how many 'business' options are there?
>
> if it's a fixed num, you could add a Proxy 'subclass' for each one
> that simply provides the apropriate parameter in the constructor.
>
> if not fixed but small quantity (say, less than a hundred), maybe you
> could create those Proxies programatically?
>
> if it's an unbounded number of different 'business objects', then
> you'll have to override the model construction parts of the form i
> guess a mixin class would be easiest to carry to several forms.
>
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Problems extracting valid form data lately

2012-04-16 Thread Tom Evans
On Mon, Apr 16, 2012 at 4:39 PM, Chris Seberino  wrote:
>        def clean_username(self):
>
> """
>                custom validation
> code
>                """
>
>                if "username" in self.cleaned_data:
>                        username = self.cleaned_data["username"]
>                        if USER.objects.filter(username = username):
>                                raise VALID_ERROR("Username is not
> available.")
>
>                return self.cleaned_data

Field clean methods do not return cleaned_data dict, they return
specific data from within that dict.

https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-a-specific-field-attribute

Cheers

Tom

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



Re: AutoFields must have primary_key=True?

2012-04-16 Thread Masklinn

On 2012-04-16, at 17:17 , Roy Smith wrote:
>> AssertionError: AutoFields must have primary_key=True.
> 
> Is this a bug?

Unlikely considering the assertion was specifically added to AutoField as part 
of a commit noting:

> Refactored the way save() works so that non-integer primary keys are
> now possible. custom_pk unit tests (from [458]) now pass. Refs #81.

There doesn't seem to be any more information than that, but a quick
search on the tracker[0] many databases seem to have… issues with
non-key autofields (let alone multiple autofields in a single table)

So the solution would be to either use a sequences-using DB backend (aka
not MySQL unless you want to hack that horribly via a dedicated table
with an autoinc PK) and create your own sequence field (which may or may
not be easy, I don't know how complex the SQL underpinnings of a Django
model field can be), or to just do it "by hand" in your model's
overridden save.

[0] https://code.djangoproject.com/ticket/8576

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Mario Gudelj
Hi Tom,

Thanks for chiming in, mate.

What I'm doing here is I'm getting the subdomain from the request and
matching it to the business when paypal PDT notification gets posted with
GET to my app.

I then need to save the payment info and sine a foreign key for the payment
is business I need to save that business against the payment. There are
many businesses running on the same app, so I have to relate payments to
businesses.

My thoughts were to generate the form from the payment model and save this
info inside the model when paypal comes back to me. But I've ran into this
issue.

Cheers,

-mario


On 17 April 2012 01:42, Mario Gudelj  wrote:

> Hey Javier,
>
> Thanks for the reply. There are thousands of different businesses, so I
> guess I'll have to go with the last option...
>
> Is this kind of what you're referring to there
> http://stackoverflow.com/questions/7114710/using-a-mixin-with-a-django-form-class
> ?
>
> Thanks again.
>
> -m
>
>
> On 17 April 2012 01:28, Javier Guerra Giraldez  wrote:
>
>> On Mon, Apr 16, 2012 at 10:11 AM, Mario Gudelj 
>> wrote:
>> > I think I need to somehow pass the business object to model = Payment
>> inside
>> > the Meta class...
>>
>> how many 'business' options are there?
>>
>> if it's a fixed num, you could add a Proxy 'subclass' for each one
>> that simply provides the apropriate parameter in the constructor.
>>
>> if not fixed but small quantity (say, less than a hundred), maybe you
>> could create those Proxies programatically?
>>
>> if it's an unbounded number of different 'business objects', then
>> you'll have to override the model construction parts of the form i
>> guess a mixin class would be easiest to carry to several forms.
>>
>>
>> --
>> Javier
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Tom Evans
On Mon, Apr 16, 2012 at 4:50 PM, Mario Gudelj  wrote:
> Hi Tom,
>
> Thanks for chiming in, mate.
>
> What I'm doing here is I'm getting the subdomain from the request and
> matching it to the business when paypal PDT notification gets posted with
> GET to my app.
>
> I then need to save the payment info and sine a foreign key for the payment
> is business I need to save that business against the payment. There are many
> businesses running on the same app, so I have to relate payments to
> businesses.
>
> My thoughts were to generate the form from the payment model and save this
> info inside the model when paypal comes back to me. But I've ran into this
> issue.
>
> Cheers,
>
> -mario
>

Surely you would want what business a payment relates to to be stored
directly in the database?! At which point it simply becomes an
additional field in your payment model, and the only problems come
with automatically populating that field.

I would add to your payment model a foreign key to your
company/business model, and adjust forms that deal with creating
payments to deduce the current company from the request.

Cheers

Tom

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



Dynamically generated models using exec. Is it too custly?

2012-04-16 Thread Arruda
I'm doing something like this to generate some models dynamically:

SIMILAR_MODELS_TEMPLATE=
> """
> @some_decorator
> class %(PREFIX)sModel (Some_Abs_model):
> \"""%(DESCRIPTION)s
> \"""
> pass
> """


then I have a factory:

> def similar_models_factory(prefix,description):
>  format_dict = {
>   'PREFIX' : prefix,
>   'DESCRIPTION' : description,
>  }
>  cls_name = "%sModel" % prefix
>  cls_source = SIMILAR_MODELS_TEMPLATE % format_dict
>  
>  exec(cls_source)
>  new_cls = locals().get(cls_name)
>  return new_cls


And finally I have in the models.py:

> from my_factories import similar_models_factory 
>
 

SIMILAR_MODELS_LIST =(
> {'prefix': 'Foo', 'desc' : 'Foo model and etc..',},
> {'prefix': 'Bars', 'desc' : 'Bars model and etc..',},
> .
> )
>
 

for smodel in SIMILAR_MODELS_LIST:
> cls = similar_models_factory(smodels['prefix'], smodels['desc'])
> vars()[cls.__name__] = cls


And this gives my just what I want, but I read somewhere that if you do:

> exec ""

 
It would be too costly, and I would like to know if this would have some 
heavy load in my project(and if please, how can I calculate this, to 
compare?) 
Thanks!

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



Re: Dynamically generated models using exec. Is it too custly?

2012-04-16 Thread Philip Mountifield
Did you know that you can use the type function to dynamiclly generate a 
class definition?


See http://docs.python.org/library/functions.html?highlight=type#type

From the example:


 class  X(object):

... a  =  1

Is exactly the same as doing...


 X  =  type('X',  (object,),  dict(a=1))


No exec required...

Regards
Phil


On 16/04/2012 17:19, Arruda wrote:

I'm doing something like this to generate some models dynamically:

SIMILAR_MODELS_TEMPLATE=
"""
@some_decorator
class %(PREFIX)sModel (Some_Abs_model):
\"""%(DESCRIPTION)s
\"""
pass
"""


then I have a factory:

def similar_models_factory(prefix,description):
 format_dict = {
  'PREFIX' : prefix,
  'DESCRIPTION' : description,
 }
 cls_name = "%sModel" % prefix
 cls_source = SIMILAR_MODELS_TEMPLATE % format_dict

 exec(cls_source)
 new_cls = locals().get(cls_name)
 return new_cls


And finally I have in the models.py:

from my_factories import similar_models_factory

SIMILAR_MODELS_LIST =(
{'prefix': 'Foo', 'desc' : 'Foo model and etc..',},
{'prefix': 'Bars', 'desc' : 'Bars model and etc..',},
.
)

for smodel in SIMILAR_MODELS_LIST:
cls = similar_models_factory(smodels['prefix'], smodels['desc'])
vars()[cls.__name__] = cls


And this gives my just what I want, but I read somewhere that if you do:

exec ""

It would be too costly, and I would like to know if this would have 
some heavy load in my project(and if please, how can I calculate this, 
to compare?)

Thanks!
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/64JCLnsIFu0J.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



--

Philip Mountifield
Formac Electronics Ltd
tel  +44 (0) 1225 837333
fax  +44 (0) 1225 430995

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



Re: Dynamically generated models using exec. Is it too custly?

2012-04-16 Thread Jeff Heard
Check https://github.com/JeffHeard/ga_dynamic_models.  It may be similar to
what you're looking for.  Even if you don't want the code, you can see a
way of dynamically generating models.

On Mon, Apr 16, 2012 at 12:40 PM, Philip Mountifield <
pmountifi...@formac.net> wrote:

>  Did you know that you can use the type function to dynamiclly generate a
> class definition?
>
> See http://docs.python.org/library/functions.html?highlight=type#type
>
> From the example:
>
> >>> class X(object):... a = 1
> Is exactly the same as doing...>>> X = type('X', (object,), dict(a=1))
>
> No exec required...
>
> Regards
> Phil
>
>
>
> On 16/04/2012 17:19, Arruda wrote:
>
> I'm doing something like this to generate some models dynamically:
>
>  SIMILAR_MODELS_TEMPLATE=
>> """
>> @some_decorator
>> class %(PREFIX)sModel (Some_Abs_model):
>> \"""%(DESCRIPTION)s
>> \"""
>> pass
>> """
>
>
>  then I have a factory:
>
>> def similar_models_factory(prefix,description):
>>  format_dict = {
>>   'PREFIX' : prefix,
>>   'DESCRIPTION' : description,
>>  }
>>  cls_name = "%sModel" % prefix
>>  cls_source = SIMILAR_MODELS_TEMPLATE % format_dict
>>
>>  exec(cls_source)
>>  new_cls = locals().get(cls_name)
>>  return new_cls
>
>
>  And finally I have in the models.py:
>
>> from my_factories import similar_models_factory
>>
>
>
> SIMILAR_MODELS_LIST =(
>> {'prefix': 'Foo', 'desc' : 'Foo model and etc..',},
>> {'prefix': 'Bars', 'desc' : 'Bars model and etc..',},
>> .
>> )
>>
>
>
> for smodel in SIMILAR_MODELS_LIST:
>> cls = similar_models_factory(smodels['prefix'], smodels['desc'])
>> vars()[cls.__name__] = cls
>
>
>  And this gives my just what I want, but I read somewhere that if you do:
>
>> exec ""
>
>
> It would be too costly, and I would like to know if this would have some
> heavy load in my project(and if please, how can I calculate this, to
> compare?)
> Thanks!
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/64JCLnsIFu0J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
> --
>
> Philip Mountifield
> Formac Electronics Ltd
> tel  +44 (0) 1225 837333
> fax  +44 (0) 1225 430995
> pmountifi...@formac.netwww.formac.netwww.telgas.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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Dynamically generated models using exec. Is it too custly?

2012-04-16 Thread Arruda
Hummm, I see, thanks for that, I didn't know about type.
And is there a way to generate functions too?(I was also doing it using 
exec).

And do you have any idea of how can I see the difference in performance 
when using one or the other?
Thanks. 

Em segunda-feira, 16 de abril de 2012 13h45min58s UTC-3, Jefferson Heard 
escreveu:
>
> Check https://github.com/JeffHeard/ga_dynamic_models.  It may be similar 
> to what you're looking for.  Even if you don't want the code, you can see a 
> way of dynamically generating models.  
>
> On Mon, Apr 16, 2012 at 12:40 PM, Philip Mountifield <
> pmountifi...@formac.net> wrote:
>
>>  Did you know that you can use the type function to dynamiclly generate a 
>> class definition?
>>
>> See http://docs.python.org/library/functions.html?highlight=type#type
>>
>> From the example:
>>
>> >>> class X(object):... a = 1
>> Is exactly the same as doing...>>> X = type('X', (object,), dict(a=1))
>>
>> No exec required...
>>
>> Regards
>> Phil
>>
>>
>>
>> On 16/04/2012 17:19, Arruda wrote: 
>>
>> I'm doing something like this to generate some models dynamically: 
>>
>>  SIMILAR_MODELS_TEMPLATE=
>>> """
>>> @some_decorator
>>> class %(PREFIX)sModel (Some_Abs_model):
>>> \"""%(DESCRIPTION)s
>>> \"""
>>> pass
>>> """
>>
>>
>>  then I have a factory:
>>
>>> def similar_models_factory(prefix,description):
>>>  format_dict = {
>>>   'PREFIX' : prefix,
>>>   'DESCRIPTION' : description,
>>>  }
>>>  cls_name = "%sModel" % prefix
>>>  cls_source = SIMILAR_MODELS_TEMPLATE % format_dict
>>>  
>>>  exec(cls_source)
>>>  new_cls = locals().get(cls_name)
>>>  return new_cls
>>
>>
>>  And finally I have in the models.py:
>>
>>> from my_factories import similar_models_factory 
>>>
>>  
>>
>> SIMILAR_MODELS_LIST =(
>>> {'prefix': 'Foo', 'desc' : 'Foo model and etc..',},
>>> {'prefix': 'Bars', 'desc' : 'Bars model and etc..',},
>>> .
>>> )
>>>
>>  
>>
>> for smodel in SIMILAR_MODELS_LIST:
>>> cls = similar_models_factory(smodels['prefix'], smodels['desc'])
>>> vars()[cls.__name__] = cls
>>
>>
>>  And this gives my just what I want, but I read somewhere that if you do:
>>
>>> exec ""
>>
>>  
>> It would be too costly, and I would like to know if this would have some 
>> heavy load in my project(and if please, how can I calculate this, to 
>> compare?) 
>> Thanks!
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/64JCLnsIFu0J.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> -- 
>>
>> Philip Mountifield
>> Formac Electronics Ltd
>> tel  +44 (0) 1225 837333
>> fax  +44 (0) 1225 430995
>> pmountifi...@formac.netwww.formac.netwww.telgas.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-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 11:08 AM, Tom Evans  wrote:
> Surely you would want what business a payment relates to to be stored
> directly in the database?! At which point it simply becomes an
> additional field in your payment model, and the only problems come
> with automatically populating that field.

my thoughts exactly

-- 
Javier

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



Re: Missing manage.py

2012-04-16 Thread andrea mucci
hi

could you post 
django version
python version
you use virtualenv? if yes what version
and the code you use to generate the project

cheers
El 16/04/2012, a las 13:26, Faeez Abd Rahman escribió:

> Hi,
> 
> I have a problem whenever I create a new project using the start project 
> command, no manage.py file is created. 
> 
> I'm using Mac OS X. Thank you in advance
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: Missing manage.py

2012-04-16 Thread Buddy Lindsey, Jr.
If you are using Django 1.4 check in the application folder of your 
project below your project folder. It should be in there.


Faeez Abd Rahman wrote:


Hi,

I have a problem whenever I create a new project using the start
project command, no manage.py file is created.

I'm using Mac OS X. Thank you in advance

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


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



Re: Missing manage.py

2012-04-16 Thread Tonton
after project you need to do start app for making module

T.

On Mon, Apr 16, 2012 at 8:17 PM, Buddy Lindsey, Jr.
wrote:

> If you are using Django 1.4 check in the application folder of your
> project below your project folder. It should be in there.
>
>
> Faeez Abd Rahman wrote:
>
>
> Hi,
>
> I have a problem whenever I create a new project using the start
> project command, no manage.py file is created.
>
> I'm using Mac OS X. Thank you in advance
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



High Traffic

2012-04-16 Thread Yarden Sachs
Hello, I am using django 1.3 on apache 2.* on windows server 2008.
mysql 5.*

When i try to access a view that does this: def view(request):
len(User.objects.all()) return HttpResponse()

i have about 9K results on that. i am doing len and not .count,
because i want to test the server.

the server becomes reaally slow. i am trying to test how much weight
my server could manage, but it seems that 10 parallel requests to that
view, slows the response down to 15 seconds!!

THIS IS just an example. i will soon manage many requests, maybe not
to that view always, but if 10 requests slows the server down that
much, what would 1000 requests do?

Please help. i dont want to migrate fomr django.

is it the data to object proccess? or mysql throughput?

How can i make this to go to a normal speed?

BTW, even without a view: only py files calling that
len(User.objects.all()), slows it really down!

* COUNTING THE RESULTS IS NOT THE POINT

Yarden

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



Re: High Traffic

2012-04-16 Thread creecode
Hello Yarden,

On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:

Hello, I am using django 1.3 on apache 2.* on windows server 2008. 
> mysql 5.* 
>
> When i try to access a view that does this: def view(request): 
> len(User.objects.all()) return HttpResponse() 
>
> i have about 9K results on that. i am doing len and not .count, 
> because i want to test the server. 
>
> the server becomes reaally slow.
>

Are you running Django and MySQL on the same server box?  If so then you 
are possibly running into speed issues because of contention.  There are 
several Djagno configuration docs on the web that talk about using at least 
one server for your app and another for your database.  Another thing to do 
is move static files onto their own sever.

You might want to try django-debug-toolbar to examine your queries for your 
webpages to see if you can do some optimization.  I highly recommend giving 
it a go!

Of course there are many things one can do to make things faster but you'll 
need to give us some more info about your setup before we can help you more.

Toodle-loo.
creecode

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs


using aws ec2 & rds. so rolling out that. i monitor every query for high 
performance. but Users all is very simple query.

 what do u think it could other than those?

thanks for all the help


On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:
>
> Hello Yarden,
>
> On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:
>
> Hello, I am using django 1.3 on apache 2.* on windows server 2008. 
>> mysql 5.* 
>>
>> When i try to access a view that does this: def view(request): 
>> len(User.objects.all()) return HttpResponse() 
>>
>> i have about 9K results on that. i am doing len and not .count, 
>> because i want to test the server. 
>>
>> the server becomes reaally slow.
>>
>
> Are you running Django and MySQL on the same server box?  If so then you 
> are possibly running into speed issues because of contention.  There are 
> several Djagno configuration docs on the web that talk about using at least 
> one server for your app and another for your database.  Another thing to do 
> is move static files onto their own sever.
>
> You might want to try django-debug-toolbar to examine your queries for 
> your webpages to see if you can do some optimization.  I highly recommend 
> giving it a go!
>
> Of course there are many things one can do to make things faster but 
> you'll need to give us some more info about your setup before we can help 
> you more.
>
> Toodle-loo.
> creecode
>

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



Re: High Traffic

2012-04-16 Thread andrea mucci
hi Yarden

how many users have you in your database?
you use mod_fcgi or mod_python? ( more recommendable will be mod_fcgi or 
mod_fcgid )

Django is framework that suppert very very large traffic.
you can see an example here
http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of

so, the most important think is configure well all the different component 
around your project
like Apache2 ( big monster ), mod_fcgi etc….

cheers,


El 16/04/2012, a las 22:06, Yarden Sachs escribió:

> using aws ec2 & rds. so rolling out that. i monitor every query for high 
> performance. but Users all is very simple query.
> 
> 
> what do u think it could other than those?
> 
> thanks for all the help
> 
> 
> 
> On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:
> Hello Yarden,
> 
> On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:
> 
> Hello, I am using django 1.3 on apache 2.* on windows server 2008. 
> mysql 5.* 
> 
> When i try to access a view that does this: def view(request): 
> len(User.objects.all()) return HttpResponse() 
> 
> i have about 9K results on that. i am doing len and not .count, 
> because i want to test the server. 
> 
> the server becomes reaally slow.
> 
> Are you running Django and MySQL on the same server box?  If so then you are 
> possibly running into speed issues because of contention.  There are several 
> Djagno configuration docs on the web that talk about using at least one 
> server for your app and another for your database.  Another thing to do is 
> move static files onto their own sever.
> 
> You might want to try django-debug-toolbar to examine your queries for your 
> webpages to see if you can do some optimization.  I highly recommend giving 
> it a go!
> 
> Of course there are many things one can do to make things faster but you'll 
> need to give us some more info about your setup before we can help you more.
> 
> Toodle-loo.
> creecode
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/gTlmPOgGsIkJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs
i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong? i
tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same
results.

any ideas?
On 16 באפר 2012 23:18, "andrea mucci"  wrote:

> hi Yarden
>
> how many users have you in your database?
> you use mod_fcgi or mod_python? ( more recommendable will be mod_fcgi or
> mod_fcgid )
>
> Django is framework that suppert very very large traffic.
> you can see an example here
>
> http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of
>
> so, the most important think is configure well all the different component
> around your project
> like Apache2 ( big monster ), mod_fcgi etc….
>
> cheers,
>
>
> El 16/04/2012, a las 22:06, Yarden Sachs escribió:
>
> using aws ec2 & rds. so rolling out that. i monitor every query for high
> performance. but Users all is very simple query.
>
> what do u think it could other than those?
>
> thanks for all the help
>
>
> On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:
>>
>> Hello Yarden,
>>
>> On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:
>>
>> Hello, I am using django 1.3 on apache 2.* on windows server 2008.
>>> mysql 5.*
>>>
>>> When i try to access a view that does this: def view(request):
>>> len(User.objects.all()) return HttpResponse()
>>>
>>> i have about 9K results on that. i am doing len and not .count,
>>> because i want to test the server.
>>>
>>> the server becomes reaally slow.
>>>
>>
>> Are you running Django and MySQL on the same server box?  If so then you
>> are possibly running into speed issues because of contention.  There are
>> several Djagno configuration docs on the web that talk about using at least
>> one server for your app and another for your database.  Another thing to do
>> is move static files onto their own sever.
>>
>> You might want to try django-debug-toolbar to examine your queries for
>> your webpages to see if you can do some optimization.  I highly recommend
>> giving it a go!
>>
>> Of course there are many things one can do to make things faster but
>> you'll need to give us some more info about your setup before we can help
>> you more.
>>
>> Toodle-loo**.
>> creecode
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/gTlmPOgGsIkJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: High Traffic

2012-04-16 Thread Ramiro Morales
On Mon, Apr 16, 2012 at 5:22 PM, Yarden Sachs  wrote:
> i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong? i
> tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same
> results.
>
> any ideas?

Do you have DEBUG=False in your settings?

-- 
Ramiro Morales

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs
ofcourse... i am using django since dec 10, and now i dont know what to do
On 16 באפר 2012 23:30, "Ramiro Morales"  wrote:

> On Mon, Apr 16, 2012 at 5:22 PM, Yarden Sachs  wrote:
> > i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong?
> i
> > tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same
> > results.
> >
> > any ideas?
>
> Do you have DEBUG=False in your settings?
>
> --
> Ramiro Morales
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: High Traffic

2012-04-16 Thread andrea mucci
have you debugged the mysql query

nginx+fgi work pretty well so is very very strange.

have you tried to test, other type of query result without len method?


El 16/04/2012, a las 22:22, Yarden Sachs escribió:

> i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong? i 
> tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same results.
> 
> any ideas?
> 
> On 16 באפר 2012 23:18, "andrea mucci"  wrote:
> hi Yarden
> 
> how many users have you in your database?
> you use mod_fcgi or mod_python? ( more recommendable will be mod_fcgi or 
> mod_fcgid )
> 
> Django is framework that suppert very very large traffic.
> you can see an example here
> http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of
> 
> so, the most important think is configure well all the different component 
> around your project
> like Apache2 ( big monster ), mod_fcgi etc….
> 
> cheers,
> 
> 
> El 16/04/2012, a las 22:06, Yarden Sachs escribió:
> 
>> using aws ec2 & rds. so rolling out that. i monitor every query for high 
>> performance. but Users all is very simple query.
>> 
>> 
>> what do u think it could other than those?
>> 
>> thanks for all the help
>> 
>> 
>> 
>> On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:
>> Hello Yarden,
>> 
>> On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:
>> 
>> Hello, I am using django 1.3 on apache 2.* on windows server 2008. 
>> mysql 5.* 
>> 
>> When i try to access a view that does this: def view(request): 
>> len(User.objects.all()) return HttpResponse() 
>> 
>> i have about 9K results on that. i am doing len and not .count, 
>> because i want to test the server. 
>> 
>> the server becomes reaally slow.
>> 
>> Are you running Django and MySQL on the same server box?  If so then you are 
>> possibly running into speed issues because of contention.  There are several 
>> Djagno configuration docs on the web that talk about using at least one 
>> server for your app and another for your database.  Another thing to do is 
>> move static files onto their own sever.
>> 
>> You might want to try django-debug-toolbar to examine your queries for your 
>> webpages to see if you can do some optimization.  I highly recommend giving 
>> it a go!
>> 
>> Of course there are many things one can do to make things faster but you'll 
>> need to give us some more info about your setup before we can help you more.
>> 
>> Toodle-loo.
>> creecode
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/gTlmPOgGsIkJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: High Traffic

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 2:25 PM, Yarden Sachs  wrote:
> * COUNTING THE RESULTS IS NOT THE POINT

ok, then that len(User.objects.all()) is not an appropriate benchmark, right?

what you're doing is a view that fetches all 9K records from the DB,
without any filtering.  will your views do that?  usually you should
filter in the DB, where it can benefit from any indexes, and process
only those records that are relevant for that view.

if you _have_ to do heavy processes to big portions of the data, then
you should do some denormalization, preprocessing, or queue
management.

why don't you explain what do you want to achieve?

-- 
Javier

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs
what perpesfully used. for heavy system performance
On 16 באפר 2012 23:38, "andrea mucci"  wrote:

> have you debugged the mysql query
>
> nginx+fgi work pretty well so is very very strange.
>
> have you tried to test, other type of query result without len method?
>
>
> El 16/04/2012, a las 22:22, Yarden Sachs escribió:
>
> i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong? i
> tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same
> results.
>
> any ideas?
> On 16 באפר 2012 23:18, "andrea mucci"  wrote:
>
>> hi Yarden
>>
>> how many users have you in your database?
>> you use mod_fcgi or mod_python? ( more recommendable will be mod_fcgi or
>> mod_fcgid )
>>
>> Django is framework that suppert very very large traffic.
>> you can see an example here
>>
>> http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of
>>
>> so, the most important think is configure well all the different
>> component around your project
>> like Apache2 ( big monster ), mod_fcgi etc….
>>
>> cheers,
>>
>>
>> El 16/04/2012, a las 22:06, Yarden Sachs escribió:
>>
>> using aws ec2 & rds. so rolling out that. i monitor every query for high
>> performance. but Users all is very simple query.
>>
>> what do u think it could other than those?
>>
>> thanks for all the help
>>
>>
>> On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:
>>>
>>> Hello Yarden,
>>>
>>> On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:
>>>
>>> Hello, I am using django 1.3 on apache 2.* on windows server 2008.
 mysql 5.*

 When i try to access a view that does this: def view(request):
 len(User.objects.all()) return HttpResponse()

 i have about 9K results on that. i am doing len and not .count,
 because i want to test the server.

 the server becomes reaally slow.

>>>
>>> Are you running Django and MySQL on the same server box?  If so then you
>>> are possibly running into speed issues because of contention.  There are
>>> several Djagno configuration docs on the web that talk about using at least
>>> one server for your app and another for your database.  Another thing to do
>>> is move static files onto their own sever.
>>>
>>> You might want to try django-debug-toolbar to examine your queries for
>>> your webpages to see if you can do some optimization.  I highly recommend
>>> giving it a go!
>>>
>>> Of course there are many things one can do to make things faster but
>>> you'll need to give us some more info about your setup before we can help
>>> you more.
>>>
>>> Toodle-loo**.
>>> creecode
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/gTlmPOgGsIkJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: High Traffic

2012-04-16 Thread Chris Czub
You're creating a contrived test though. If you really wanted the
count of users you'd probably do a "count" in the database itself.

I don't think you're getting any valuable data on your application's
actual performance: you basically made a view that just loops over
9000 items. Of course it will be slow if you keep reloading it!

Try using a tool like "ab"(Apache Benchmark) or tsung to hit real
application pages quickly and concurrently.

On Mon, Apr 16, 2012 at 4:41 PM, Yarden Sachs  wrote:
> what perpesfully used. for heavy system performance
>
> On 16 באפר 2012 23:38, "andrea mucci"  wrote:
>>
>> have you debugged the mysql query
>>
>> nginx+fgi work pretty well so is very very strange.
>>
>> have you tried to test, other type of query result without len method?
>>
>>
>> El 16/04/2012, a las 22:22, Yarden Sachs escribió:
>>
>> i have 9000 rows. and using mod_wsgi on apache2. what am i doing wrong? i
>> tried to switch to nginx+fcgi. and tried ubuntu srrver as well. same
>> results.
>>
>> any ideas?
>>
>> On 16 באפר 2012 23:18, "andrea mucci"  wrote:
>>>
>>> hi Yarden
>>>
>>> how many users have you in your database?
>>> you use mod_fcgi or mod_python? ( more recommendable will be mod_fcgi or
>>> mod_fcgid )
>>>
>>> Django is framework that suppert very very large traffic.
>>> you can see an example here
>>>
>>> http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of
>>>
>>> so, the most important think is configure well all the different
>>> component around your project
>>> like Apache2 ( big monster ), mod_fcgi etc….
>>>
>>> cheers,
>>>
>>>
>>> El 16/04/2012, a las 22:06, Yarden Sachs escribió:
>>>
>>> using aws ec2 & rds. so rolling out that. i monitor every query for high
>>> performance. but Users all is very simple query.
>>>
>>>
>>> what do u think it could other than those?
>>>
>>> thanks for all the help
>>>
>>>
>>>
>>> On Monday, April 16, 2012 10:59:55 PM UTC+3, creecode wrote:

 Hello Yarden,

 On Monday, April 16, 2012 12:25:36 PM UTC-7, Yarden Sachs wrote:

> Hello, I am using django 1.3 on apache 2.* on windows server 2008.
> mysql 5.*
>
> When i try to access a view that does this: def view(request):
> len(User.objects.all()) return HttpResponse()
>
> i have about 9K results on that. i am doing len and not .count,
> because i want to test the server.
>
> the server becomes reaally slow.


 Are you running Django and MySQL on the same server box?  If so then you
 are possibly running into speed issues because of contention.  There are
 several Djagno configuration docs on the web that talk about using at least
 one server for your app and another for your database.  Another thing to do
 is move static files onto their own sever.

 You might want to try django-debug-toolbar to examine your queries for
 your webpages to see if you can do some optimization.  I highly recommend
 giving it a go!

 Of course there are many things one can do to make things faster but
 you'll need to give us some more info about your setup before we can help
 you more.

 Toodle-loo.
 creecode
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/django-users/-/gTlmPOgGsIkJ.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.

Re: High Traffic

2012-04-16 Thread Yarden Sachs
Sure,

I experienced unknown performance issues(slow responses) when high traffic 
would hit that site.

so, started to test what happens if i hit the web site with a big 
calculation, like len function on an 9k objects.
when i try to do it from client, it takes 0.7 secs to come back with 
response, if try to do it from 10 parralel client, it takes 15 secs for one 
http response!

my team member, tried to find out the problem, and his conclusion is - 
python+django is not fast. and i DONT like that. its not right!

So i am trying to find out why is that.

if a i am trying to do simpler tasks like empty template rendering. or 
.count method, things go faster.

but apart from the len function, i still performance issues if many users 
try to access the web site. its a delivery service application.

Any ideas?


On Monday, April 16, 2012 11:39:55 PM UTC+3, Javier Guerra wrote:
>
> On Mon, Apr 16, 2012 at 2:25 PM, Yarden Sachs  wrote:
> > * COUNTING THE RESULTS IS NOT THE POINT
>
> ok, then that len(User.objects.all()) is not an appropriate benchmark, 
> right?
>
> what you're doing is a view that fetches all 9K records from the DB,
> without any filtering.  will your views do that?  usually you should
> filter in the DB, where it can benefit from any indexes, and process
> only those records that are relevant for that view.
>
> if you _have_ to do heavy processes to big portions of the data, then
> you should do some denormalization, preprocessing, or queue
> management.
>
> why don't you explain what do you want to achieve?
>
> -- 
> Javier
>
>

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



Re: High Traffic

2012-04-16 Thread Javier Guerra Giraldez
On Mon, Apr 16, 2012 at 3:49 PM, Yarden Sachs  wrote:
> when i try to do it from client, it takes 0.7 secs to come back with
> response, if try to do it from 10 parralel client, it takes 15 secs for one
> http response!


well, if you do a heavy and memory intensive task, then doing it ten
times is ten times as much process and ten times as much memory.  i
think it's ok to take 20 times as much time.


> my team member, tried to find out the problem, and his conclusion is -
> python+django is not fast. and i DONT like that. its not right!

no, the conclusion is that doing slow things is not fast

-- 
Javier

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs
it took 20 times more for EACH request. that means that if 20 users accross
the web ask for differrent heavy data- instead of taking a second for each
one, every user will wait for 20 seconds before the response will answer.
On 16 באפר 2012 23:54, "Javier Guerra Giraldez"  wrote:

> On Mon, Apr 16, 2012 at 3:49 PM, Yarden Sachs  wrote:
> > when i try to do it from client, it takes 0.7 secs to come back with
> > response, if try to do it from 10 parralel client, it takes 15 secs for
> one
> > http response!
>
>
> well, if you do a heavy and memory intensive task, then doing it ten
> times is ten times as much process and ten times as much memory.  i
> think it's ok to take 20 times as much time.
>
>
> > my team member, tried to find out the problem, and his conclusion is -
> > python+django is not fast. and i DONT like that. its not right!
>
> no, the conclusion is that doing slow things is not fast
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: High Traffic

2012-04-16 Thread CLIFFORD ILKAY

On 04/16/2012 04:49 PM, Yarden Sachs wrote:

Sure,

I experienced unknown performance issues(slow responses) when high
traffic would hit that site.

>

so, started to test what happens if i hit the web site with a big
calculation, like len function on an 9k objects. when i try to do it
from client, it takes 0.7 secs to come back with response, if try to
do it from 10 parralel client, it takes 15 secs for one http
response!


If you're using MyISAM tables, that's a big performance killer. Every 
new or expired session is going to get an exclusive table lock on the 
session table. That will block reads for everyone else until the new row 
is inserted. In the meantime, Apache is either forking and spawning new 
threads, and you're creating more MySQL connections, which in turn is 
consuming more RAM. Eventually, you'll run out of RAM and start hitting 
swap/virtual memory. That only makes things worse. You have a contrived, 
long-running query that only exacerbates the problem because while that 
query is running, inserts or updates have to wait. All you've proved is 
that you can create a cascade effect, which is hardly surprising.



my team member, tried to find out the problem, and his conclusion is
- python+django is not fast. and i DONT like that. its not right!


I don't see how you can jump to that conclusion based on the evidence 
you presented. Django powers some very busy sites on quite modest 
hardware comparatively speaking but Django isn't going to make 
inefficient code or poor architectural choices, like MyISAM tables, 
magically better. You need to do some real profiling, not some contrived 
test that proves that running slow queries is, well... slow.

--
Regards,

Clifford Ilkay
Dinamis
1419-3230 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326

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



Re: High Traffic

2012-04-16 Thread Yarden Sachs
thanks! have any advice for good performance? and profiling?
On 17 באפר 2012 00:18, "CLIFFORD ILKAY"  wrote:

> On 04/16/2012 04:49 PM, Yarden Sachs wrote:
>
>> Sure,
>>
>> I experienced unknown performance issues(slow responses) when high
>> traffic would hit that site.
>>
> >
>
>> so, started to test what happens if i hit the web site with a big
>> calculation, like len function on an 9k objects. when i try to do it
>> from client, it takes 0.7 secs to come back with response, if try to
>> do it from 10 parralel client, it takes 15 secs for one http
>> response!
>>
>
> If you're using MyISAM tables, that's a big performance killer. Every new
> or expired session is going to get an exclusive table lock on the session
> table. That will block reads for everyone else until the new row is
> inserted. In the meantime, Apache is either forking and spawning new
> threads, and you're creating more MySQL connections, which in turn is
> consuming more RAM. Eventually, you'll run out of RAM and start hitting
> swap/virtual memory. That only makes things worse. You have a contrived,
> long-running query that only exacerbates the problem because while that
> query is running, inserts or updates have to wait. All you've proved is
> that you can create a cascade effect, which is hardly surprising.
>
>  my team member, tried to find out the problem, and his conclusion is
>> - python+django is not fast. and i DONT like that. its not right!
>>
>
> I don't see how you can jump to that conclusion based on the evidence you
> presented. Django powers some very busy sites on quite modest hardware
> comparatively speaking but Django isn't going to make inefficient code or
> poor architectural choices, like MyISAM tables, magically better. You need
> to do some real profiling, not some contrived test that proves that running
> slow queries is, well... slow.
> --
> Regards,
>
> Clifford Ilkay
> Dinamis
> 1419-3230 Yonge St.
> Toronto, ON
> Canada  M4N 3P6
>
> 
> +1 416-410-3326
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

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



Re: Passing parameters to class Meta:

2012-04-16 Thread Mario Gudelj
TIL don't override model class constructor if you don't really have to.

Thanks for all your help guys! Now when I think about it I don't even know
why I did it in the first place.

On 17 April 2012 03:12, Javier Guerra Giraldez  wrote:

> On Mon, Apr 16, 2012 at 11:08 AM, Tom Evans 
> wrote:
> > Surely you would want what business a payment relates to to be stored
> > directly in the database?! At which point it simply becomes an
> > additional field in your payment model, and the only problems come
> > with automatically populating that field.
>
> my thoughts exactly
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: basci question about queryset for retrieving top element

2012-04-16 Thread NENAD CIKIC
OK, thanks for sharing this

On 16 Apr, 07:54, Pavan Verma  wrote:
> I am a Django newbie and also interested in this question.
>
> From reading the Django bookhttp://www.djangobook.com/en/2.0/chapter05/,
> I see that the query 'Publisher.objects.order_by('name')[0:2]' maps
> to:
>
> SELECT id, name, address, city, state_province, country, website
> FROM books_publisher
> ORDER BY name
> OFFSET 0 LIMIT 2;
>
> Also, Django delays execution of the db query until the result is
> actually required.
>
> Given the above two observations, I would think that both the type of
> accesses you mentioned will do exactly the same thing, which is to do
> a query with "OFFSET 0 LIMIT 1".
>
> To confirm this, you can use the django-devserver (https://github.com/
> dcramer/django-devserver) with SQL queries enabled which will display
> every query made in real time.
>
> thanks,
> -pavan
>
> On Apr 14, 9:56 pm, NENAD CIKIC  wrote:
>
>
>
>
>
>
>
> > Hello!
> > I want to get just the top element of one queryset. SO I have
> > something as
> > qs=MyModel.objects.filter(...).order_by(..)
>
> > and then use qs[0] and check some value
>
> > I wonder now if i did the right thing or it is better to use .extra on
> > queryset.
> > Is the queryset object allocated for all objects, or is django/python
> > smarter than me and gets only the  needed object?
>
> > Should I maybe do directly
> > topObj=MyModel.objects.filter(...).order_by(..)[0]
>
> > What is better?
> > Thanks
> > Nenad

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



Re: Problems extracting valid form data lately

2012-04-16 Thread Chris Seberino

> Field clean methods do not return cleaned_data dict, they return
> specific data from within that dict.

Tom

Thanks so much!  That fixed it!   For the life of me I can't
understand how my site has been operating
for MONTHS without this bug manifesting itself.  I guess my site
didn't have to use the return objects from my clean_* methods until
recently.  Weird.

Thanks again!

Chris

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



Re: High Traffic

2012-04-16 Thread Andy McKay
Run django debug toolbar, see what queries you are running and how
long they take and that you've got database indexes set up.

Failing that, run a middleware or other logging tool to tell you slow
pages. Then test with django debug toolbar. Rinse and repeat.

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



Re: basci question about queryset for retrieving top element

2012-04-16 Thread HarpB
Both patterns will produce same query. You can also use 
django-debug-toolbar, which gives ur debugsqlshell tool. So you can execute 
code from the commandline and can see what the query will be.

Django also has a code pattern for your case - for getting the first 
element, you can just use latest() 
https://docs.djangoproject.com/en/dev/ref/models/querysets/#latest
i.e. Model.objects.latest()

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



row level permissions - why?

2012-04-16 Thread Mike
In my app I need a way to associate objects with a specific user.  Users 
should not have access to other users objects. I'm implementing this in my 
model by setting a ForeignKey to the user that owns the object:

owner = models.ForeignKey(User)

Is this a bad idea?  Can someone explain under what circumstances I would 
need to use a row level permissions app?


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



Can't access database with normal Ubuntu Terminal user

2012-04-16 Thread Gchorn
I'm not totally sure if this qualifies as a Django question, but it's 
impeding my ability to make a website with Django so I thought I'd ask 
here.  I'm working with Django in Ubuntu 11.10, where I've set up 
PostgreSQL to make and manage databases for my Django-powered website.  
Unfortunately, when working with Django in the Terminal, I need to first 
switch over to the user "postgres" (the user I created when installing 
PostgreSQL) in order to do anything with PostgreSQL or its databases.  This 
becomes a problem when I need to simultaneously access my database and the 
local file system, since my local filesystem is only accessible to my 
normal Ubuntu Terminal user, "guillaume."

I already have the correct user and passwords entered in my settings.py 
file for my database, but this doesn't seem to help--I still need to switch 
over to "posgres" in the Terminal to access my databases.  I'm guessing I 
need to either a) give "guillaume" access to my databases (which I've tried 
reading up on in the PostgreSQL docs, but am still not sure how to 
do...part of it is I'm not sure how to tell apart Ubuntu users, Unix users, 
and Postgres users), or I need to b) give "postgres" access to my local 
file system.  Can anyone tell me which is the better route to follow, and 
how to achieve it? 

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



Returning template data from a ManyToMany model

2012-04-16 Thread LJ
I am having trouble figuring out how to query the database and return
the results in a format that my template can render appropriately.
I have a model that has a ManyToMany field:

class Student()
 ...
 parents = models.ManyToManyField('parents.Parent', blank=True,
null=True)
 ...
The Parent model looks like:

class Parent()
...
first_name  models.CharField(max_length=30)
last_name  models.CharField(max_length=30)
gender  models.CharField(max_length=1)
...
def __unicode__(self):
  return u'Parent : %s %s' % (self.first_name, self.last_name)

The method in my view currently looks something like this:

def get_parents( request, template )
   id=request.GET['id']
   template_data["parents"] = Parent.objects.filter(student=id)
   return render_to_response( template, template_data,
context_instance=RequestContext(request))

The template data is returning the data in the format:
  [ , ]

Instead, I need the template data formatted with the other fields in
my Parent model, like:
  [ ,
 ]

The format doesn't have to be exactly like the above, but I need to
include the index, and to return some of the other fields defined in
my Parent model.
My template will look something like:
{% for parent in parents.object_list %}

 {{parent.id}}
 {{parent.first_name}}
 {{parent.last_name}}
{% endfor %}

Can someone give me some ideas about how I can change my view to
return my template data in a more useable format?

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



Re: Can't access database with normal Ubuntu Terminal user

2012-04-16 Thread Guillaume Chorn
Something more specific in case it helps: as an example, when I try to
access my admin view while logged in as my regular user ("guillaume")
instead of "postgres", I get the following error:

OperationalError at /admin/

FATAL:  Peer authentication failed for user "postgres"

 Request Method: GET  Request URL: http://127.0.0.1:8000/admin/  Django
Version: 1.3.1  Exception Type: OperationalError  Exception Value:

FATAL:  Peer authentication failed for user "postgres"

 Exception Location:
/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py
in _cursor, line 140  Python Executable: /usr/bin/python  Python Version:
2.7.2  Python Path:

['/home/guillaume/moisiedarling',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
 '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

 Server time: Tue, 17 Apr 2012 01:46:23 -0500

On Tue, Apr 17, 2012 at 2:07 PM, Gchorn  wrote:

> I'm not totally sure if this qualifies as a Django question, but it's
> impeding my ability to make a website with Django so I thought I'd ask
> here.  I'm working with Django in Ubuntu 11.10, where I've set up
> PostgreSQL to make and manage databases for my Django-powered website.
> Unfortunately, when working with Django in the Terminal, I need to first
> switch over to the user "postgres" (the user I created when installing
> PostgreSQL) in order to do anything with PostgreSQL or its databases.  This
> becomes a problem when I need to simultaneously access my database and the
> local file system, since my local filesystem is only accessible to my
> normal Ubuntu Terminal user, "guillaume."
>
> I already have the correct user and passwords entered in my settings.py
> file for my database, but this doesn't seem to help--I still need to switch
> over to "posgres" in the Terminal to access my databases.  I'm guessing I
> need to either a) give "guillaume" access to my databases (which I've tried
> reading up on in the PostgreSQL docs, but am still not sure how to
> do...part of it is I'm not sure how to tell apart Ubuntu users, Unix users,
> and Postgres users), or I need to b) give "postgres" access to my local
> file system.  Can anyone tell me which is the better route to follow, and
> how to achieve it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/1NWyssjq5sYJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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