Format a python date

2011-05-09 Thread Sithembewena Lloyd Dube
Hi all,

I am using a jquery datepicker control on a page of mine, and it formats the
date different than the django admin datepicker. (MM-DD-YYY).

If I have a date in that format, how can I format it to DD-MM-? I have
tried using strftime with no success.

-- 
Regards,
Sithembewena Lloyd Dube

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



Re: Problem in Configuring the database

2011-05-09 Thread Stuart MacKay

Rajul,

If disk space is a problem why did you install VMWare and SUse - it 
should be easier to run MySQL directly on Windows. If you are using a 
viurtual machine then the VMWare installation, SUSE and then MySQL is 
going to take a lot more space.


At this point I would use SQLite just to get started - it has all the 
features that you would find in a MySQL installation and is great for 
development work - I do my development on Windows XP with SQLite then 
deploy to a linux box runing PostgreSQL with no problems at all. Using 
linux and a production level database is not necessary to run Django 
locally. That would eliminate all your problems in one go and allow you 
to get started with your first project. After that you can try MySQL 
once you are more familiar with Django and understand you needs better.


Regards,

Stuart

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



unpredictable CSRF error on mobile devices

2011-05-09 Thread nederhoed
Hi everyone,

just a few users of our website get an CSRF error when trying to log
on using a mobile device. This behavior only occurs with about 3 out
of 150 users. We have 2 colleagues with the same device (iPhone) of
which one of the two has this problem. The other hasn't.
The user can login using a desktop PC...

What could be an explanation?


We have applied all the csrf inclusions (Middleware, RequestContext,
csrf tag in POST forms), yet some users can't log in and get the ugly
CSRF error on their mobile.

Our website runs Django 1.2.1: http://im.knmp.nl/

Fragment form settings.py
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

Any help would be highly appreciated.

Kind regards, Robert-Reinder
--

-- 
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: filter in python

2011-05-09 Thread pankaj sharma
thanks for ur answer jani but i didn't get it . as i am getting one
query for branch {which is Qbranch} so where i use this?

On May 8, 10:40 pm, Jani Tiainen  wrote:
> On Sun, 2011-05-08 at 09:59 -0700, pankaj sharma wrote:
> > hello ..
>
> > i am having a database of college  which have a name city state
> > branches etc...
> > so
>
> > class College(models.Model):
>
> >    name = models.CharField(max_length=250)
>
> >    city = models.ForeignKey(City)
>
> >    branch1 = models.BooleanField(default=False, blank=True)
> >    branch2 = models.BooleanField(default=False, blank=True)
> >    branch3 = models.BooleanField(default=False, blank=True)
> >    branch4 = models.BooleanField(default=False, blank=True)
>
> > now i want to provide user that they can search colleges from
> > branches..
> > so i am giving them a select box where they can select the city and
> > branches
> > suppose i get two queries Qcity and Qbranch
> > so i will filter all the colleges having city = Qcity and
> > Branches=Qbranch
> > so please tell me how to filter
>
> > i have filtered city but how to add one another filter for branch {as
> > it is bolleanfield}
> > college_list = College.objects.filter(city__title__icontains=Qcity)
>
> In case of branch1:
> college_list = College.objects.filter(city__title__icontains=Qcity,
> branch1=True)
>
> if you want to search multiple branches:
>
> branches_query = Q(branch1=True) | Q(branch2=True)
> college_list = College.objects.filter(branches_query,
> city__title__icontains=Qcity)
>
> Though since you have boolean field that will always be either true or
> false, you can construct:
>
> branches_query=Q(branch1=branch1_form_field_value) |
> Q(branch2=branch2_form_field_value) | ...
>
> --
>
> Jani Tiainen

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



ajax cart

2011-05-09 Thread Паша Тявин
Hello. I'm newbie and trying to make a simple shopping cart using anonymous 
session under ajax control.
I have a special url "/update_cart/" for only post request from the the page 
"/product/" and I made a dictionary "request.session['cart']" with a text 
like [{'id':'2','quant':3},{'id':4','quant':1}].
The answer from "/update_cart/" has a mimetype "application/json" and I can 
see the answer in the ff firebug, but the client js cathes it like "[Object 
object]".
How can I read the data not like [object, object], but 
like  [{'id':'2','quant':3},{'id':4','quant':1}] ?

The question, maybe not for the using django, but for js. So the next 
question is: Am I doing the cart in a django way? Or should I do something 
different?

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



boolwan field filter

2011-05-09 Thread pankaj sharma
hello ..
i am having a database of college  which have a name city state
branches etc...
so
class College(models.Model):
   name = models.CharField(max_length=250)
   city = models.ForeignKey(City)
   branch1 = models.BooleanField(default=False, blank=True)
   branch2 = models.BooleanField(default=False, blank=True)
   branch3 = models.BooleanField(default=False, blank=True)
   branch4 = models.BooleanField(default=False, blank=True)
now i want to provide user that they can search colleges from
branches..
so i am giving them a select box where they can select the city and
branches
suppose i get two queries c and b
so i will filter all the colleges having city = c and
Branches=b
so please tell me how to filter
i have filtered city but how to add one another filter for branch {as
it is bolleanfield}
college_list = College.objects.filter(city__title__icontains=Qcity)

-- 
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: filter in python

2011-05-09 Thread Jani Tiainen
Since I'm not really good at reading people minds, can you clarify your
question, preferably with code how your view/form/query does work now
and how you have tried to resolve this particular problem and where the
problem then is.

On Mon, 2011-05-09 at 03:50 -0700, pankaj sharma wrote:
> thanks for ur answer jani but i didn't get it . as i am getting one
> query for branch {which is Qbranch} so where i use this?
> 
> On May 8, 10:40 pm, Jani Tiainen  wrote:
> > On Sun, 2011-05-08 at 09:59 -0700, pankaj sharma wrote:
> > > hello ..
> >
> > > i am having a database of college  which have a name city state
> > > branches etc...
> > > so
> >
> > > class College(models.Model):
> >
> > >name = models.CharField(max_length=250)
> >
> > >city = models.ForeignKey(City)
> >
> > >branch1 = models.BooleanField(default=False, blank=True)
> > >branch2 = models.BooleanField(default=False, blank=True)
> > >branch3 = models.BooleanField(default=False, blank=True)
> > >branch4 = models.BooleanField(default=False, blank=True)
> >
> > > now i want to provide user that they can search colleges from
> > > branches..
> > > so i am giving them a select box where they can select the city and
> > > branches
> > > suppose i get two queries Qcity and Qbranch
> > > so i will filter all the colleges having city = Qcity and
> > > Branches=Qbranch
> > > so please tell me how to filter
> >
> > > i have filtered city but how to add one another filter for branch {as
> > > it is bolleanfield}
> > > college_list = College.objects.filter(city__title__icontains=Qcity)
> >
> > In case of branch1:
> > college_list = College.objects.filter(city__title__icontains=Qcity,
> > branch1=True)
> >
> > if you want to search multiple branches:
> >
> > branches_query = Q(branch1=True) | Q(branch2=True)
> > college_list = College.objects.filter(branches_query,
> > city__title__icontains=Qcity)
> >
> > Though since you have boolean field that will always be either true or
> > false, you can construct:
> >
> > branches_query=Q(branch1=branch1_form_field_value) |
> > Q(branch2=branch2_form_field_value) | ...
> >
> > --
> >
> > Jani Tiainen
> 


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



Encrpting urls to hide PKs

2011-05-09 Thread ALJ
I have a form that I use to collect contact information from
unregistered users. When they submit the form I want to redirect to a
confirmation page (as the Django documentation suggests). However,
instead of a generic page, I wanted to include the information that
they have submitted and the contact details of the person for their
area. I was also thinking that I could include the current status of
their enquiry. Therefore they could perhaps use the same link to come
back to check the status of their query.

Given that, is there a best practice pattern for handling this
situation? I have a quick demo where the URL is:

http://www.mydomain.com/contact/confirmation/1234

... where '1234' is the pk for the query. Obviously I would want to
encrypt the pk in this case, otherwise someone could just use the pk
to trawl through the database.

Are there any default ways of encrypting django urls?

-- 
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: ajax cart

2011-05-09 Thread Oleg Lomaka
you your answer object is 'data', for example, then
data[0].id
data[0].quant

On Mon, May 9, 2011 at 1:56 PM, Паша Тявин  wrote:

> Hello. I'm newbie and trying to make a simple shopping cart using anonymous
> session under ajax control.
> I have a special url "/update_cart/" for only post request from the the
> page "/product/" and I made a dictionary "request.session['cart']" with a
> text like [{'id':'2','quant':3},{'id':4','quant':1}].
> The answer from "/update_cart/" has a mimetype "application/json" and I can
> see the answer in the ff firebug, but the client js cathes it like "[Object
> object]".
> How can I read the data not like [object, object], but
> like  [{'id':'2','quant':3},{'id':4','quant':1}] ?
>
> The question, maybe not for the using django, but for js. So the next
> question is: Am I doing the cart in a django way? Or should I do something
> different?
>
> --
> 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: Encrpting urls to hide PKs

2011-05-09 Thread Oleg Lomaka
Take a look at django-registration app. With slight modification it should
satisfy your requirements.

For URL encryption, you can generate some sort of UUID and save in your
database that such UUID corresponds to given profile PK. django-registration
uses such urls for email confirmation.

On Mon, May 9, 2011 at 3:24 PM, ALJ  wrote:

> I have a form that I use to collect contact information from
> unregistered users. When they submit the form I want to redirect to a
> confirmation page (as the Django documentation suggests). However,
> instead of a generic page, I wanted to include the information that
> they have submitted and the contact details of the person for their
> area. I was also thinking that I could include the current status of
> their enquiry. Therefore they could perhaps use the same link to come
> back to check the status of their query.
>
> Given that, is there a best practice pattern for handling this
> situation? I have a quick demo where the URL is:
>
> http://www.mydomain.com/contact/confirmation/1234
>
> ... where '1234' is the pk for the query. Obviously I would want to
> encrypt the pk in this case, otherwise someone could just use the pk
> to trawl through the database.
>
> Are there any default ways of encrypting django urls?
>
>

-- 
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: Format a python date

2011-05-09 Thread Oleg Lomaka
You can format your python date in template using
datefilter.
Also your default date format depends on your current locale. And
you can change your date format in settings.py by setting
DATE_FORMAT

From another
side, you can load appropriate locale file to modify your datepicker's
default date format for your country standard.

That is my settings for russian dates.

https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js
">
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/i18n/jquery.ui.datepicker-ru.min.js
">

And if you want your datepicker be custom formatted, then you can configure
it separately.

$('#id_date').datepicker({dateFormat: 'yy-mm-dd'});




On Mon, May 9, 2011 at 10:54 AM, Sithembewena Lloyd Dube
wrote:

> Hi all,
>
> I am using a jquery datepicker control on a page of mine, and it formats
> the date different than the django admin datepicker. (MM-DD-YYY).
>
> If I have a date in that format, how can I format it to DD-MM-? I have
> tried using strftime with no success.
>
>

-- 
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: Encrpting urls to hide PKs

2011-05-09 Thread Cal Leeming [Simplicity Media Ltd]
To be honest, I'd be careful when using this approach.

If you are intending on hiding the PKs, as a way to stop people hitting PKs
they shouldn't be able to hit, then this means your security model is flawed
from the ground up.

However, if you are doing it to stop PKs from being leaked, then this is
fine.

Remember the number 1 rule in security.. NEVER TRUST THE CLIENT!!!

On Mon, May 9, 2011 at 1:24 PM, ALJ  wrote:

> I have a form that I use to collect contact information from
> unregistered users. When they submit the form I want to redirect to a
> confirmation page (as the Django documentation suggests). However,
> instead of a generic page, I wanted to include the information that
> they have submitted and the contact details of the person for their
> area. I was also thinking that I could include the current status of
> their enquiry. Therefore they could perhaps use the same link to come
> back to check the status of their query.
>
> Given that, is there a best practice pattern for handling this
> situation? I have a quick demo where the URL is:
>
> http://www.mydomain.com/contact/confirmation/1234
>
> ... where '1234' is the pk for the query. Obviously I would want to
> encrypt the pk in this case, otherwise someone could just use the pk
> to trawl through the database.
>
> Are there any default ways of encrypting django urls?
>
> --
> 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: filter in python

2011-05-09 Thread pankaj sharma
i have 4 branches in a college..
some college have three some have 4 and so on
so i want to provide a search system to the user that they can see the
list of all the colleges which are having some branch say branch2 may
be he can select branch 3 and 4 and 1 also
so i am taking a query from the user for the branch so that i can
filter all the colleges having that branch.

no i did this ..
i took a query say B {and the calue of B may be branch 1, branch 2,
3,&4 as i have given a selectbox to user to select any branch}
now in filter tag i did this

college_list = College.objects.filter(B=True)

but it is not working... so please tell me

-- 
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: Encrpting urls to hide PKs

2011-05-09 Thread Brian Bouterse
In the name of not trusting any data coming from the client, one way that
IBM uses often is called
continuations.
 Basically you keep all data on the server, and only give the client an
identifier of that data.  This typically enforces a server-side state
machine that ensures what a user can and can't do with the application from
a given state.

This is not exactly what is being discussed here, but it is near it in
topic, so I thought I would mention it.

Brian

On Mon, May 9, 2011 at 8:59 AM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> To be honest, I'd be careful when using this approach.
>
> If you are intending on hiding the PKs, as a way to stop people hitting PKs
> they shouldn't be able to hit, then this means your security model is flawed
> from the ground up.
>
> However, if you are doing it to stop PKs from being leaked, then this is
> fine.
>
> Remember the number 1 rule in security.. NEVER TRUST THE CLIENT!!!
>
> On Mon, May 9, 2011 at 1:24 PM, ALJ  wrote:
>
>> I have a form that I use to collect contact information from
>> unregistered users. When they submit the form I want to redirect to a
>> confirmation page (as the Django documentation suggests). However,
>> instead of a generic page, I wanted to include the information that
>> they have submitted and the contact details of the person for their
>> area. I was also thinking that I could include the current status of
>> their enquiry. Therefore they could perhaps use the same link to come
>> back to check the status of their query.
>>
>> Given that, is there a best practice pattern for handling this
>> situation? I have a quick demo where the URL is:
>>
>> http://www.mydomain.com/contact/confirmation/1234
>>
>> ... where '1234' is the pk for the query. Obviously I would want to
>> encrypt the pk in this case, otherwise someone could just use the pk
>> to trawl through the database.
>>
>> Are there any default ways of encrypting django urls?
>>
>> --
>> 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.
>



-- 
Brian Bouterse
ITng Services

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



error on django admin

2011-05-09 Thread chhots
class Like(models.Model):
smartbuy = models.ForeignKey(SmartBuy)
User = models.ForeignKey(User)
def __unicode__(self):
return self.smartbuy or “Smartbuy #%d” % self.smartbuy
i have this model which is both fields are foreign key from other
table and when i tri to add some in this model through djnago admin
its showing this error

Caught TypeError while rendering: coercing to Unicode: need string or
buffer, NoneType found

-- 
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: ajax select box

2011-05-09 Thread Goodwin
I've used "Django smart selects" recently for what you want to do and it 
worked well - https://github.com/digi604/django-smart-selects

Goodwin

-- 
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: Format a python date

2011-05-09 Thread Sithembewena Lloyd Dube
Hi Oleg,

Thanks so much! Your examples (specifically the last one) do what I need. I
had done a very ugly hack in my view, which involved slicing the dates,
switching the slices around and converting to datetime objects again - not
clean at all.

I have taken that out and just went with your solution.

Again, many thanks!

On Mon, May 9, 2011 at 2:46 PM, Oleg Lomaka  wrote:

> You can format your python date in template using 
> datefilter.
>  Also your default date format depends on your current locale. And
> you can change your date format in settings.py by setting 
> DATE_FORMAT
>
> From
> another side, you can load appropriate locale file to modify your
> datepicker's default date format for your country standard.
>
> That is my settings for russian dates.
>
> https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js
> ">
> https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/i18n/jquery.ui.datepicker-ru.min.js
> ">
>
> And if you want your datepicker be custom formatted, then you can configure
> it separately.
>
> $('#id_date').datepicker({dateFormat: 'yy-mm-dd'});
>
>
>
>
> On Mon, May 9, 2011 at 10:54 AM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> Hi all,
>>
>> I am using a jquery datepicker control on a page of mine, and it formats
>> the date different than the django admin datepicker. (MM-DD-YYY).
>>
>> If I have a date in that format, how can I format it to DD-MM-? I have
>> tried using strftime with no success.
>>
>>
>  --
> 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.
>



-- 
Regards,
Sithembewena Lloyd Dube

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



Re: error on django admin

2011-05-09 Thread Oleg Lomaka
Try to add __unicode__ method to your SmartBuy model that returns string.

On Mon, May 9, 2011 at 10:32 AM, chhots  wrote:

> class Like(models.Model):
> smartbuy = models.ForeignKey(SmartBuy)
> User = models.ForeignKey(User)
> def __unicode__(self):
> return self.smartbuy or “Smartbuy #%d” % self.smartbuy
> i have this model which is both fields are foreign key from other
> table and when i tri to add some in this model through djnago admin
> its showing this error
>
> Caught TypeError while rendering: coercing to Unicode: need string or
> buffer, NoneType found
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: django admin site and debug

2011-05-09 Thread bitgandtter
i try your advices but didnt work i dont know why because the admin
pattern should handle this urls

On May 4, 3:01 pm, Ivan <492...@gmail.com> wrote:
> Try to replace your patern '^admin/' this '^admin/$', or swap
> ( r'^admin/', include( admin.site.urls ) )
> and ( r'', include( 'role.company.urls' ) )
>
>
>
>
>
>
>
> > my urlconf look like this
>
> > from django.conf.urls.defaults import patterns, include
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns( '',
> >     ( r'^admin/', include( admin.site.urls ) ),
> >     ( r'', include( 'role.company.urls' ) ),
> >  )
>
> > and in the role.company.urls i dont put anything about debug or url
> > that can override the admin ones

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



Ann: django-photofile released - thumbnail generation with automatic rotation based on Exif.Orientation

2011-05-09 Thread Thomas Weholt
Just released a simple reusable app with a templatetag for thumbnail
generation, with support for automatic rotation based on
Exif.Orientation. Looked at sorl-thumbnail and friends, but none of
them featured automatic rotation based on Exif.Orientation.

http://pypi.python.org/pypi/Django-Photofile/

Released as GPL. Alpha status. Testers and comments wanted.

Planned features: more metadata handling ( EXIF, IPTC, XMP ) and
optional use of pgmagick or similar for better thumbnail quality.


-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

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



Many2many field and ModelChoiceField

2011-05-09 Thread Roodie
Hello,

I have a small issue, I am sure the solution is simple, but I couldn't
find it (I blame Monday). I have a model with a Many2Many field, and I
have a few forms for editing that model. Everything is working fine
there. In one specific case however I have to produce a form where the
user can select only one value for the Many2many field from a dropdown
list.

My initial idea was to override the form field:

content_categories = forms.ModelChoiceField( widget=forms.Select,
queryset=ContentCategory.objects.all(), required=True )

The form validates fine, but then it gives an error upon saving it:

File "[...]\django\db\models\fields\related.py" in __set__
  746. manager.add(*value)
Exception Value: add() argument after * must be a sequence

ModelMultipleChoiceField is'nt working at all (as expected), giving
validation errors since it wants a list of items.

So any ideas before I handle the value manually in my view? :-)

--
Roodie

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



Image upload from another website using image url

2011-05-09 Thread esam al deen
i want to make an image uploader using images links on the internet
(eq: .example.com/image.jpg). The user writes the previous url and
then my model upload it.

This my code:

form>>

 view.py

def Post_date():

if request.method == 'POST':

form = Addpic()#simple form to capture data image_url =
request.POST.get('image') file = urllib.urlopen(image_url) im =
cStringIO.StringIO(file.read()) # constructs a StringIO holding the
image img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
'.gif'

img.save(save) form.image=save

if form.is_valid():

pic = form.save(commit=False) pic.save()

models.py

class Pic(models.Model):

image = ImageWithThumbsField?(upload_to='images', sizes=((128, 128),))

The image uploads but if form.is_valid(): doesn't work and I don't
know how to add it to the form data. how i can assign the downloaded
image to my form (form.image=save)?

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



Re: Django filefield

2011-05-09 Thread nederhoed
Hi Pulkit,

This could be of help too:
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form

Do not forget to add the multipart to your form element:
 

Store the file on your filesystem, store the path to the file in your
database.

Cheers, RR

On May 8, 10:32 pm, Pulkit Mehrotra  wrote:
> I want to create a system by which i can upload files to my database .This
> database will be a set of question papers .These question papers can be
> downloaded by students for their own use and evaluation.How to create it
> .What is the use of django filefield.Please provide any links for it .
>
> thank you,

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



DateTime in Django (Help)

2011-05-09 Thread Kevin Miller
Dear all,

I am new to django but is in the process of building my first website. I have 
been ok for a while as I am not new to programming in python. However, I have 
one problem that I cannot figure out the proper way to do it. I want to use 
ModelForm but have a DateTime Field. I can do it without using a ModelForm but 
I think using the ModelForm is the proper way to do it.

Can someone show me a small example of using ModelForm with DateTime field?
How can can the DateTime field me displayed in django templates?

Thank you so much in advance.

Kevin Miller  

-- 
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: Error (EXTERNAL IP): /add_comment/10/

2011-05-09 Thread Aragorn
This is line 44:

message = "Comment was was added to '%s' by '%s': \n\n%s" %
(self.post, self.author,
 
self.body)


another one more thing I do not understand,
I put 6 post in the blog , where I insert the comment
to Nr. 4 in the article the comment is accepted and I get
e-mail. When I put the comment in other posts, I get the error that I
wrote. Why ?

On 8 Mag, 02:20, Andy McKay  wrote:
> Su 2011/05/04, a 04:44, Aragorn ha scritto:
>
> > File "/ home / max / public_html / examplesite.com / django / DBE / blog /> 
> > "Models.py, linea 44, in salvo> Self.body)
>
> Tu ci hai detto un sacco di roba, compreso il metodo di salvataggio, ma dal 
> momento che non sappiamo i numeri di riga, qual è la linea 44?
>
> > UnicodeDecodeError: 'ascii' codec non è in grado di decodificare 0xe2 byte 
> > in posizione> 41: ordinale non in range (128)
>
> Ci sono alcune informazioni utili su questo errore da Google, ecco uno di 
> loro:
>
> http://wiki.python.org/moin/UnicodeDecodeError-  Andy McKay  uno...@ 
> clearwind.ca  Twitter: @ andymckay

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



best framework/reusable app for caching model instances (object level cache) ?

2011-05-09 Thread stargazer
What is the best framework/library/reusable app for caching model
instances in Django? (This approach is also known as transparently
object cache, ORM cache, row-level object cache, object level cache)

The are reausable apps implementing this. The problem is there are so
many of them! Here what I found (probably even more exist):
http://github.com/mmalone/django-caching/
http://github.com/dcramer/django-orm-cache
http://github.com/dziegler/django-cachebot
http://bitbucket.org/jmoiron/johnny-cache
http://github.com/jbalogh/django-cache-machine
http://github.com/SeanHayes/django-query-caching

I do not want test every library, just want to peek one that do the
job, that solve more problems than it creates ("There are only two
hard problems in Computer Science: cache invalidation and naming
things")

Please share your experience

-- 
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: Image upload from another website using image url

2011-05-09 Thread nederhoed
Hi Esam,

If I understand you correctly, you want to preserve the image data
even if the user used an invalid value in another form field,
rendering the form invalid?

You could:
1. add the image to the user's session, without saving it to the DB.
2. add the image URL to the user's session, showing a thumb it in the
form using the URL.
3. first validate the form, then download the image, preserving the
location of the image in the form field until the form validates
(4. retrieve the image using an AJAX call over the server, before the
form even gets sent
This is how Google Contacts does it. But I consider this option not
within the scope of your question.)

I would first try 3. since that is the easiest. Then to improve the
user experience, I would probably switch to 2.
And if I have time left, I would implement 1.

Good luck! RR

On May 9, 4:46 pm, esam al deen  wrote:
> i want to make an image uploader using images links on the internet
> (eq: .example.com/image.jpg). The user writes the previous url and
> then my model upload it.
>
> This my code:
>
> form>>
>
>  value="www.example.com/main.jpg" /> view.py
>
> def Post_date():
>
> if request.method == 'POST':
>
> form = Addpic()#simple form to capture data image_url =
> request.POST.get('image') file = urllib.urlopen(image_url) im =
> cStringIO.StringIO(file.read()) # constructs a StringIO holding the
> image img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
> '.gif'
>
> img.save(save) form.image=save
>
> if form.is_valid():
>
> pic = form.save(commit=False) pic.save()
>
> models.py
>
> class Pic(models.Model):
>
> image = ImageWithThumbsField?(upload_to='images', sizes=((128, 128),))
>
> The image uploads but if form.is_valid(): doesn't work and I don't
> know how to add it to the form data. how i can assign the downloaded
> image to my form (form.image=save)?

-- 
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: Many2many field and ModelChoiceField

2011-05-09 Thread Shawn Milochik
You can exclude that field from your ModelForm and manually add in a new 
field with just the option(s) you want.


Then override the save() of your ModelForm to set the proper value of 
self.cleaned_data or self.instance to the value from your custom field.



--
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: Many2many field and ModelChoiceField

2011-05-09 Thread Roodie
Hello,

Thanks, yes, that was my idea when I mentioned manual handling. I just
wanted to ask since it is quite common for me to miss a relevant
parameter or a small note in the documentation ;-)

On máj. 9, 17:21, Shawn Milochik  wrote:
> You can exclude that field from your ModelForm and manually add in a new
> field with just the option(s) you want.
>
> Then override the save() of your ModelForm to set the proper value of
> self.cleaned_data or self.instance to the value from your custom field.

-- 
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: DateTime in Django (Help)

2011-05-09 Thread Kenny Meyer
On Mon, May 9, 2011 at 10:55 AM, Kevin Miller  wrote:
> Dear all,
>
> I am new to django but is in the process of building my first website. I have
> been ok for a while as I am not new to programming in python. However, I have
> one problem that I cannot figure out the proper way to do it. I want to use
> ModelForm but have a DateTime Field. I can do it without using a ModelForm but
> I think using the ModelForm is the proper way to do it.

What's the problem with the DateTimeField in a model?

> Can someone show me a small example of using ModelForm with DateTime field?
> How can can the DateTime field me displayed in django templates?

in your models.py:

class Foo(models.Model):
datetime = models.DateTimeField()

class FooForm(forms.ModelForm):
class Meta:
model = Foo


in your views.py:

def bar(request):
form = FooForm()
return render_to_response("bar.html", {"form": form})


in template bar.html:

{{ foo }}


There's absolutely nothing special here :) .

If you couldn't understand some of the code, then you should read the
documentation .
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

-- 
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: DateTime in Django (Help)

2011-05-09 Thread Kevin Miller
Thanks so much for your response. I have done all that and I have
model forms working for other models.
However, I keep getting validating errors with datetime, probably is
how I am entering the data. I have also tried the SplitDateTimeWidget
I am getting the same
validation error. I have tried manually creating  the form and it
worked. I wonder what is the normally approach to DateTimeField in
django templates. Is using the
SplitDateTimeWidget the norm or should I use the AdminDateTimeWidget ?

Thanks again.



On Mon, May 9, 2011 at 11:11 AM, Kenny Meyer  wrote:
> On Mon, May 9, 2011 at 10:55 AM, Kevin Miller  wrote:
>> Dear all,
>>
>> I am new to django but is in the process of building my first website. I have
>> been ok for a while as I am not new to programming in python. However, I have
>> one problem that I cannot figure out the proper way to do it. I want to use
>> ModelForm but have a DateTime Field. I can do it without using a ModelForm 
>> but
>> I think using the ModelForm is the proper way to do it.
>
> What's the problem with the DateTimeField in a model?
>
>> Can someone show me a small example of using ModelForm with DateTime field?
>> How can can the DateTime field me displayed in django templates?
>
> in your models.py:
>
> class Foo(models.Model):
>    datetime = models.DateTimeField()
>
> class FooForm(forms.ModelForm):
>    class Meta:
>        model = Foo
>
>
> in your views.py:
>
> def bar(request):
>    form = FooForm()
>    return render_to_response("bar.html", {"form": form})
>
>
> in template bar.html:
>
>    {{ foo }}
>
>
> There's absolutely nothing special here :) .
>
> If you couldn't understand some of the code, then you should read the
> documentation .
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> --
> 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.
>
>



-- 
Kevin Miller
Acting Data Controller
Department of Computing
UWI, Mona
Kingston 7

-- 
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: Loading initial data with a post_syncdb hook?

2011-05-09 Thread Karen Tracey
On Mon, May 9, 2011 at 12:56 AM, Adam Seering  wrote:

> On May 8, 10:53 pm, Karen Tracey  wrote:>
> > The change you have noticed is documented in the 1.3
> > backwards-incompatibility list:
> http://docs.djangoproject.com/en/1.3/releases/1.3/#use-of-custom-sql-...
>
> Actually, that's a different issue:  I'm not using the custom-SQL
> loader, I'm using Python code with the post_syncdb hook.  This one
> isn't in the backwards-compatibility page as far as I can tell.
>
> (Was that comment intended to cover this case as well?  Maybe a typo
> somewhere?)
>

Hmm, you are right, this change is not supposed to affect data added via
post_syncdb handlers. Specifically the change here is:
https://code.djangoproject.com/changeset/15239. On an initial read it looks
like it might cause post_syncdb-added data to get thrown away, since the
post_syncdb signal is sent during the call_command('syncdb'). However, the
call_command('flush', ...) that was added after the call_command('syncdb',
...) will also cause that signal to get sent.

So your post_syncdb-added data should still be available in your test cases.
I've verified via some experiments that if I add a post_syncdb handler that
inserts data for one of my apps, that data is available for my test cases.
So I'm confused why you are seeing different behavior -- what you are
describing happening is not what I observe happening.

[snip]
> Right now, we're working on adding tests, and on encouraging
> developers to write tests for new parts of the code, new apps/code
> that are being developed, etc.  Right now, as I understand it with
> Django's current behavior and our post_syncdb hook setup, we want to
> re-load the data in three cases:  (1) The current test is the first
> test, (2) all prior tests are TestCase (as opposed to
> TransactionTestCase) instances, or (3) we are a TransactionTestCase
> instance.


This is all kind of beside the point since I'm not understanding why your
post_syncdb-hander-added data is not available to your tests, but for the
record: Worrying about whether a particular test is run first, or is
preceded by other tests of a certain kind, is something your code should
never have to do (excluding doctests, where Django makes no guarantees that
things done by one doctest are invisible to others). It's Django's job to
ensure that the database is "clean" when each test starts running. In fact
Django will run all TestCase tests before any TransactionTestCase tests (as
noted in the doc
http://docs.djangoproject.com/en/1.3/topics/testing/#testcase), precisely
because the mechanism used to reset the database for these different kinds
of tests can't ensure that a TestCase run after a TransactionTestCase will
see a "clean" database on start. Django will also ensure that anything
changed in the DB (including anything done by setUp) in the first test is
undone before the second test runs, so if you did add something to setUp of
the first test that could then be seen by the 2nd test to run, that would be
a bug in Django's test support.


> [snip]
> What I personally wish that Django did in this case would be to trust
> the data that syncdb puts into the database; do the necessary
> bookkeeping to restore it to its initial state at the end of each test
> as needed.  If I thought it would be accepted, I'd submit a patch.
> But if it were that simple, I assume someone would have done it that
> way at the start; I don't know enough about this project to understand
> the reasoning behind the TRUNCATE here in any case...  Hopefully
> that'll do a better job framing of what I'd like to accomplish with
> our code, though.
>
>
What you describe is exactly what Django does for TestCases: restore the
state of the DB to its initial post-syncdb version at the end of the test.
It does not do that for TransactionTestCases because that would be
prohibitively expensive, and unnecessary given first that
TransactionTestCases clear the database on entry and second that Django
ensures that all TestCases run before any TranactionTestCases. Django makes
no guarantees about the state of the DB for doctests, but they don't seem to
factor into your setup?

What you are describing happening is contrary to what I observe, and
contrary to what Django promises, so it would be helpful if you could gives
us some information to recreate the behavior you are seeing.

Karen
-- 
http://tracey.org/kmt/

-- 
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 use CreateView?

2011-05-09 Thread Bryan L


You need to specify "action"... what was the URI for the get form? The
action should be the same.



On Mar 11, 2:41 pm, hassan  wrote:
> Hi,
>
> I am testing django 1.3 class based generic views. I have a model like
> this one:
>
> class Book(models.Model):
>     name = models.CharField(max_length=50)
>     author = models.CharField(max_length=50)
>
> and in views.py:
>
> class BookUpdateView(CreateView):
>     model = Book
>     template_name = "create_book.html"
>
> and in create_book.html
> 
> ...
> 
> 
>
> But when i press the save button it form it does nothing!
> What's wrong with me?

-- 
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 use CreateView?

2011-05-09 Thread Boštjan Mejak


What if you add the dot to action, like above? What does that mean? And note
that my form method is get. Anyone knows about what the dot does?

-- 
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: error on django admin

2011-05-09 Thread Karen Tracey
On Mon, May 9, 2011 at 3:32 AM, chhots  wrote:

> class Like(models.Model):
> smartbuy = models.ForeignKey(SmartBuy)
> User = models.ForeignKey(User)
> def __unicode__(self):
> return self.smartbuy or “Smartbuy #%d” % self.smartbuy
>

What are you trying to do here? If you are trying to do something different
depending on if self.smartbuy has a value you have not accomplished it with
that statement. Well, maybe you have but the fact that you are still trying
to use self.smartbuy's value in the case where it doesn't have a (non-empty)
value indicates the code is probably not really doing what you were
intending.

Returning self.smartbuy is your problem: your __unicode__ method needs to
return unicode, not an instance of some other Django model, which is what
return self.smartbuy does.

Karen
-- 
http://tracey.org/kmt/

-- 
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: ajax cart

2011-05-09 Thread nederhoed
Hi Pasha,

1. Try using a dict instead of a list:
data = {
'items': [{'id':'2','quant':3},{'id':4','quant':1}]
}

2. could you provide the relevant part of the view?

I expect something like:

from django.http import HttpResponse
from django.utils import simplejson

def update_cart(request):
data = {'items': [{'id':'2','quant':3},{'id':4','quant':1}]}
...
return HttpResponse(
simplejson.dumps(data),
content_type='application/javascript; charset=utf8'
)

Answer based on:
* 
http://stackoverflow.com/questions/798111/how-do-i-json-serialize-a-python-dictionary
* 
http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/
* personal experience :-)

Good luck, RR

On May 9, 12:56 pm, Паша Тявин  wrote:
> Hello. I'm newbie and trying to make a simple shopping cart using anonymous
> session under ajax control.
> I have a special url "/update_cart/" for only post request from the the page
> "/product/" and I made a dictionary "request.session['cart']" with a text
> like [{'id':'2','quant':3},{'id':4','quant':1}].
> The answer from "/update_cart/" has a mimetype "application/json" and I can
> see the answer in the ff firebug, but the client js cathes it like "[Object
> object]".
> How can I read the data not like [object, object], but
> like  [{'id':'2','quant':3},{'id':4','quant':1}] ?
>
> The question, maybe not for the using django, but for js. So the next
> question is: Am I doing the cart in a django way? Or should I do something
> different?

-- 
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: boolwan field filter

2011-05-09 Thread nederhoed
A bit off topic, but I can't resist. Does a college really always have
4 "branches"?
(I might be mistaken, but a branch sounds to me like a dynamic
property.)

I would consider using a many-to-many relation between colleges and
branches. It would change your question a lot...

class Branch(models.Model):
   name = models.CharField(max_length=63)

class College(models.Model):
   name = models.CharField(max_length=250)
   city = models.ForeignKey(City)
   branches = models.ManyToManyField(Branch)

I do not know of hand how to use an OR query on the join, when several
branches have been selected...

Given the assumption that a city has only a few colleges, I would
probably do something like this:
def search(request):
... form validation ...
city = City.objects.get(pk=form.cleaned_data['city_id'])  # id
from a drop-down field
branches = form.cleaned_data['branch_ids']
# e.g. branches = [1, 45] id's coming from multiple choice,
multiple value check boxes
colleges = []
for college in city.colleges:
# city.colleges was implicitly created from the ForeignKey
definition in College
for branch in college.branches:
if branch.id in branches:
colleges.append(college)
break  # next college
return render_to_response('search_results.html', {'colleges':
colleges})

See also:
http://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships
http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

Good luck! RR

-- 
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: Image upload from another website using image url

2011-05-09 Thread esam al deen

@nederhoed: what i need to to do is allow user to store files from
anywhere include another web site  , when user give me a file "browse
button " i  get it and store it, another method that user can give me
file url >>www.example.com/main.jpg ,, i wrote the code that got the
file and stored it into /tmp ,, how i can assign form.image to this
stored file ?
my code again ..
 view.py
def Post_date():
  if request.method == 'POST':
 form = Addpic()#simple form to capture data image_url =
 request.POST.get('image')
 file = urllib.urlopen(image_url)
 im = cStringIO.StringIO(file.read()) # constructs a StringIO
holding the image
 img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
'.gif'
 img.save(save) form.image=save
if form.is_valid():
 pic = form.save(commit=False) pic.save()

models.py

class Pic(models.Model):
image = ImageWithThumbsField(upload_to='images', sizes=((128,
128),))


The image uploads but if form.is_valid(): doesn't work and I don't
know how to add it to the form data. how i can assign the downloaded
image to my form (form.image=save)?

-- 
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: Encrpting urls to hide PKs

2011-05-09 Thread ALJ
I was really looking for something lightweight. I didn't really want
to have to change the model structure to include a UUID ... although I
realise that this seems to way to go. I really just wanted to avoid
any 'opportunistic' attempts at extracting the data. The data itself
isn't critical and not worth the effort of going to great lengths to
crack any encryption I would put in. I was tempted to just use base64,
perhaps joining the PK and the postcode for example. That might be
enough just to obfuscate the id a bit and have a pseudo dual key.

Oh well.

Thanks anyway.

ALJ

-- 
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: Image upload from another website using image url

2011-05-09 Thread esam al deen
@nederhoed: what i need to to do is allow user to store files from
anywhere include another web site  , when user give me a file "browse
button " i  get it and store it, another method that user can give me
file url >>www.example.com/main.jpg ,, i wrote the code that got the
file and stored it into /tmp ,, how i can assign form.image to this
stored file ?
my code again ..
 view.py
def Post_date():
  if request.method == 'POST':
 form = Addpic()#simple form to capture data image_url =
 request.POST.get('image')
 file = urllib.urlopen(image_url)
 im = cStringIO.StringIO(file.read()) # constructs a StringIO
holding the image
 img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
'.gif'
 img.save(save)
 form.image=save
  if form.is_valid():
 pic = form.save(commit=False)
 pic.save()

models.py

class Pic(models.Model):
image = ImageWithThumbsField(upload_to='images', sizes=((128,
128),))
The image uploads but if form.is_valid(): doesn't work and I don't
know how to add it to the form data. how i can assign the downloaded
image to my form (form.image=save)?

-- 
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: Encrpting urls to hide PKs

2011-05-09 Thread Shawn Milochik

There's no need to change your models to add UUIDs.

You can just store a dict of UUID-to-primary key values in the session data.

--
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: Image upload from another website using image url

2011-05-09 Thread nederhoed
Hi Esam,

first of all:
form = Addpic(request.POST)

Secondly, could you respond to my 3 suggestions, are they clear?

Why would start processing the form before checking if it is valid?

See also:
http://docs.djangoproject.com/en/dev/topics/forms/

Good luck! RR

On May 9, 8:45 pm, esam al deen  wrote:
> @nederhoed: what i need to to do is allow user to store files from
> anywhere include another web site  , when user give me a file "browse
> button " i  get it and store it, another method that user can give me
> file url >>www.example.com/main.jpg,, i wrote the code that got the
> file and stored it into /tmp ,, how i can assign form.image to this
> stored file ?
> my code again ..
>  value="www.example.com/main.jpg" /> view.py
> def Post_date():
>   if request.method == 'POST':
>      form = Addpic()#simple form to capture data image_url =
>      request.POST.get('image')
>      file = urllib.urlopen(image_url)
>      im = cStringIO.StringIO(file.read()) # constructs a StringIO
> holding the image
>      img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
> '.gif'
>      img.save(save)
>      form.image=save
>   if form.is_valid():
>      pic = form.save(commit=False)
>      pic.save()
>
> models.py
>
> class Pic(models.Model):
>     image = ImageWithThumbsField(upload_to='images', sizes=((128,
> 128),))
> The image uploads but if form.is_valid(): doesn't work and I don't
> know how to add it to the form data. how i can assign the downloaded
> image to my form (form.image=save)?

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



forms.URLField and models.URLField not having the same default for verify_exists

2011-05-09 Thread etienned
verify_exists default to false in forms.URLField and defaults to True
in models.URLField. Is there any reasons for that? It can lead to some
troubles because it's easy for people to assume that both Fields have
the same default.

I understand that changing one or the other default now in Django will
break all apps that use the default value. But is there any rational
that had lead to that choice or it's just a mistake that's now hard to
correct without breaking anything?

Thanks

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



Re: Loading project to alwaysdata

2011-05-09 Thread werefrog

Hi,

From their wiki [1], they provide a link for activating your ssh 
account [2]. Then, you can connect from your client (they link to PuTTY 
[3]). I see that your host provides a browser based client [4].


Using a ssh client is really easy, you've done hardest things. Just 
install it, connect to your account, then, you type your shell commands.


You should grab a client and try it. I Assume it's documentation is 
better than any of my explanations. Later, you may be interested to try 
Twisted.


[1] http://wiki.alwaysdata.com/wiki/Se_connecter_en_SSH (french)
[2] https://admin.alwaysdata.com/ssh/
[3] http://www.chiark.greenend.org.uk/~sgtatham/putty/
[4] https://ssh.alwaysdata.com/anyterm.html

Le 08/05/2011 18:26, ruler501 a écrit :

I do not understand how ssh works or how to use it. Like I said I
don't know much more than the code


--
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: Encrpting urls to hide PKs

2011-05-09 Thread Eric Chamberlain

On May 9, 2011, at 11:43 AM, ALJ wrote:

> I was really looking for something lightweight. I didn't really want
> to have to change the model structure to include a UUID ... although I
> realise that this seems to way to go. I really just wanted to avoid
> any 'opportunistic' attempts at extracting the data. The data itself
> isn't critical and not worth the effort of going to great lengths to
> crack any encryption I would put in. I was tempted to just use base64,
> perhaps joining the PK and the postcode for example. That might be
> enough just to obfuscate the id a bit and have a pseudo dual key.
> 
> Oh well.
> 
> Thanks anyway.
> 

We needed a similar way to obfuscate publicly accessible objects and we didn't 
want usage information leaked by exposing the public key.  We found and have 
been using short_url for over six months now.  We use 
 to 
generate short URL's from the primary key (integer).  The short_url code is 
handy, because it doesn't need any extra columns in the database and it is 
pretty hard for users to reverse engineer the primary key id from the short URL.

--
Eric Chamberlain, Founder
RF.com - http://RF.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: Encrpting urls to hide PKs

2011-05-09 Thread Greg Donald
On Mon, May 9, 2011 at 8:15 AM, Brian Bouterse  wrote:
> In the name of not trusting any data coming from the client, one way that
> IBM uses often is called continuations.

I thought they were called cookies?

> Basically you keep all data on the
> server, and only give the client an identifier of that data.

Yeah, sounds exactly like a session-based cookie.


-- 
Greg Donald
destiney.com | gregdonald.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: Encrpting urls to hide PKs

2011-05-09 Thread Cal Leeming [Simplicity Media Ltd]
If you are looking for a quick and easy way to encrypt the URLs, why not 
create some Middleware which encrypts/decrypts them on the fly with a 
secret string from settings?


Although, the URLs are going to look ugly as sin, and I wouldn't 
recommend this if you want decent SEO lol.


Remember you'd have to cater for encrypting redirects, query string 
separation etc, and you've have to overwrite the request META vars so 
that the app logic doesn't need to be patched.


Cal

On 09/05/2011 19:43, ALJ wrote:

I was really looking for something lightweight. I didn't really want
to have to change the model structure to include a UUID ... although I
realise that this seems to way to go. I really just wanted to avoid
any 'opportunistic' attempts at extracting the data. The data itself
isn't critical and not worth the effort of going to great lengths to
crack any encryption I would put in. I was tempted to just use base64,
perhaps joining the PK and the postcode for example. That might be
enough just to obfuscate the id a bit and have a pseudo dual key.

Oh well.

Thanks anyway.

ALJ



--
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: Encrpting urls to hide PKs

2011-05-09 Thread Cal Leeming [Simplicity Media Ltd]
Just to be clear, the issue I was referring to, was to not trust the 
data sent by the client.


I.e. if you are allowing the user to access an object in the database, 
and not enforcing any restrictions other than client side UI, then this 
is bad.


This topic spreads wa long cookies and sessions lol.

On 09/05/2011 22:12, Greg Donald wrote:

On Mon, May 9, 2011 at 8:15 AM, Brian Bouterse  wrote:

In the name of not trusting any data coming from the client, one way that
IBM uses often is called continuations.

I thought they were called cookies?


Basically you keep all data on the
server, and only give the client an identifier of that data.

Yeah, sounds exactly like a session-based cookie.




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



QUESTION

2011-05-09 Thread Amadou L .Diallo
I'am new in django  and i have some:
if  i  launch
django-admin.py runserver  i have this sentence
   iError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.
 help brother!!

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



Can't Test Apps Without Models?

2011-05-09 Thread protonpopsicle
Is this a bug?

If I run my unittest with './manage.py test myapp' and myapp does not
contain a models.py file, the following error results:

django.core.exceptions.ImproperlyConfigured: App with label fogbugz
could not be found

This error does not describe the problem. Also, shouldn't one be able
to run tests on apps without models?

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

2011-05-09 Thread Boštjan Mejak
Don't do it like that. Do it like this: *manage.py* runserver

-- 
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 Test Apps Without Models?

2011-05-09 Thread Boštjan Mejak
You must create a tests.py file in your project's directory. Have your tests
in that file. I am not sure on that one, but try.

-- 
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 Test Apps Without Models?

2011-05-09 Thread Maksymus007
just create empty models,py file in your app folder. I don't know why,but
thats how Django 'sees' your applications.

Pozdrawiam, Maksymilian Pawlak
09-05-2011 23:58 użytkownik "protonpopsicle" 
napisał:
> Is this a bug?
>
> If I run my unittest with './manage.py test myapp' and myapp does not
> contain a models.py file, the following error results:
>
> django.core.exceptions.ImproperlyConfigured: App with label fogbugz
> could not be found
>
> This error does not describe the problem. Also, shouldn't one be able
> to run tests on apps without models?
>
> --
> 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: DateTime in Django (Help)

2011-05-09 Thread Kenny Meyer
> However, I keep getting validating errors with datetime, probably is
> how I am entering the data. I have also tried the SplitDateTimeWidget
> I am getting the same
> validation error
These are the valid input formats:
http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.DateTimeField.input_formats

Check if they look like the sting you are feeding your form input with.

If you still keep getting validation errors, it would be nice if you
could attach the stack trace in a reply to this mail.

Kenny


On Mon, May 9, 2011 at 12:36 PM, Kevin Miller  wrote:
> Thanks so much for your response. I have done all that and I have
> model forms working for other models.
> However, I keep getting validating errors with datetime, probably is
> how I am entering the data. I have also tried the SplitDateTimeWidget
> I am getting the same
> validation error. I have tried manually creating  the form and it
> worked. I wonder what is the normally approach to DateTimeField in
> django templates. Is using the
> SplitDateTimeWidget the norm or should I use the AdminDateTimeWidget ?
>
> Thanks again.
>
>
>
> On Mon, May 9, 2011 at 11:11 AM, Kenny Meyer  wrote:
>> On Mon, May 9, 2011 at 10:55 AM, Kevin Miller  wrote:
>>> Dear all,
>>>
>>> I am new to django but is in the process of building my first website. I 
>>> have
>>> been ok for a while as I am not new to programming in python. However, I 
>>> have
>>> one problem that I cannot figure out the proper way to do it. I want to use
>>> ModelForm but have a DateTime Field. I can do it without using a ModelForm 
>>> but
>>> I think using the ModelForm is the proper way to do it.
>>
>> What's the problem with the DateTimeField in a model?
>>
>>> Can someone show me a small example of using ModelForm with DateTime field?
>>> How can can the DateTime field me displayed in django templates?
>>
>> in your models.py:
>>
>> class Foo(models.Model):
>>    datetime = models.DateTimeField()
>>
>> class FooForm(forms.ModelForm):
>>    class Meta:
>>        model = Foo
>>
>>
>> in your views.py:
>>
>> def bar(request):
>>    form = FooForm()
>>    return render_to_response("bar.html", {"form": form})
>>
>>
>> in template bar.html:
>>
>>    {{ foo }}
>>
>>
>> There's absolutely nothing special here :) .
>>
>> If you couldn't understand some of the code, then you should read the
>> documentation .
>> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>>
>> --
>> 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.
>>
>>
>
>
>
> --
> Kevin Miller
> Acting Data Controller
> Department of Computing
> UWI, Mona
> Kingston 7
>
> --
> 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: DateTime in Django (Help)

2011-05-09 Thread Kenny Meyer
s/sting/string

On Mon, May 9, 2011 at 9:27 PM, Kenny Meyer  wrote:
>> However, I keep getting validating errors with datetime, probably is
>> how I am entering the data. I have also tried the SplitDateTimeWidget
>> I am getting the same
>> validation error
> These are the valid input formats:
> http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.DateTimeField.input_formats
>
> Check if they look like the sting you are feeding your form input with.
>
> If you still keep getting validation errors, it would be nice if you
> could attach the stack trace in a reply to this mail.
>
> Kenny
>
>
> On Mon, May 9, 2011 at 12:36 PM, Kevin Miller  wrote:
>> Thanks so much for your response. I have done all that and I have
>> model forms working for other models.
>> However, I keep getting validating errors with datetime, probably is
>> how I am entering the data. I have also tried the SplitDateTimeWidget
>> I am getting the same
>> validation error. I have tried manually creating  the form and it
>> worked. I wonder what is the normally approach to DateTimeField in
>> django templates. Is using the
>> SplitDateTimeWidget the norm or should I use the AdminDateTimeWidget ?
>>
>> Thanks again.
>>
>>
>>
>> On Mon, May 9, 2011 at 11:11 AM, Kenny Meyer  wrote:
>>> On Mon, May 9, 2011 at 10:55 AM, Kevin Miller  
>>> wrote:
 Dear all,

 I am new to django but is in the process of building my first website. I 
 have
 been ok for a while as I am not new to programming in python. However, I 
 have
 one problem that I cannot figure out the proper way to do it. I want to use
 ModelForm but have a DateTime Field. I can do it without using a ModelForm 
 but
 I think using the ModelForm is the proper way to do it.
>>>
>>> What's the problem with the DateTimeField in a model?
>>>
 Can someone show me a small example of using ModelForm with DateTime field?
 How can can the DateTime field me displayed in django templates?
>>>
>>> in your models.py:
>>>
>>> class Foo(models.Model):
>>>    datetime = models.DateTimeField()
>>>
>>> class FooForm(forms.ModelForm):
>>>    class Meta:
>>>        model = Foo
>>>
>>>
>>> in your views.py:
>>>
>>> def bar(request):
>>>    form = FooForm()
>>>    return render_to_response("bar.html", {"form": form})
>>>
>>>
>>> in template bar.html:
>>>
>>>    {{ foo }}
>>>
>>>
>>> There's absolutely nothing special here :) .
>>>
>>> If you couldn't understand some of the code, then you should read the
>>> documentation .
>>> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>>
>> --
>> Kevin Miller
>> Acting Data Controller
>> Department of Computing
>> UWI, Mona
>> Kingston 7
>>
>> --
>> 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: DateTime in Django (Help)

2011-05-09 Thread Kenny Meyer
Oh! I have found a precious discussion on SO.
http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form

I think you might like the highest-voted solution.

Kenny



On Mon, May 9, 2011 at 9:28 PM, Kenny Meyer  wrote:
> s/sting/string
>
> On Mon, May 9, 2011 at 9:27 PM, Kenny Meyer  wrote:
>>> However, I keep getting validating errors with datetime, probably is
>>> how I am entering the data. I have also tried the SplitDateTimeWidget
>>> I am getting the same
>>> validation error
>> These are the valid input formats:
>> http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.DateTimeField.input_formats
>>
>> Check if they look like the sting you are feeding your form input with.
>>
>> If you still keep getting validation errors, it would be nice if you
>> could attach the stack trace in a reply to this mail.
>>
>> Kenny
>>
>>
>> On Mon, May 9, 2011 at 12:36 PM, Kevin Miller  wrote:
>>> Thanks so much for your response. I have done all that and I have
>>> model forms working for other models.
>>> However, I keep getting validating errors with datetime, probably is
>>> how I am entering the data. I have also tried the SplitDateTimeWidget
>>> I am getting the same
>>> validation error. I have tried manually creating  the form and it
>>> worked. I wonder what is the normally approach to DateTimeField in
>>> django templates. Is using the
>>> SplitDateTimeWidget the norm or should I use the AdminDateTimeWidget ?
>>>
>>> Thanks again.
>>>
>>>
>>>
>>> On Mon, May 9, 2011 at 11:11 AM, Kenny Meyer  wrote:
 On Mon, May 9, 2011 at 10:55 AM, Kevin Miller  
 wrote:
> Dear all,
>
> I am new to django but is in the process of building my first website. I 
> have
> been ok for a while as I am not new to programming in python. However, I 
> have
> one problem that I cannot figure out the proper way to do it. I want to 
> use
> ModelForm but have a DateTime Field. I can do it without using a 
> ModelForm but
> I think using the ModelForm is the proper way to do it.

 What's the problem with the DateTimeField in a model?

> Can someone show me a small example of using ModelForm with DateTime 
> field?
> How can can the DateTime field me displayed in django templates?

 in your models.py:

 class Foo(models.Model):
    datetime = models.DateTimeField()

 class FooForm(forms.ModelForm):
    class Meta:
        model = Foo


 in your views.py:

 def bar(request):
    form = FooForm()
    return render_to_response("bar.html", {"form": form})


 in template bar.html:

    {{ foo }}


 There's absolutely nothing special here :) .

 If you couldn't understand some of the code, then you should read the
 documentation .
 http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

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


>>>
>>>
>>>
>>> --
>>> Kevin Miller
>>> Acting Data Controller
>>> Department of Computing
>>> UWI, Mona
>>> Kingston 7
>>>
>>> --
>>> 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: Error (EXTERNAL IP): /add_comment/10/

2011-05-09 Thread Ulrich Petri
> message = "Comment was was added to '%s' by '%s': \n\n%s" % (self.post, 
> self.author, self.body)

Most likely your users are posting utf-8 data which you are trying to insert 
into a byte string .

To fix this change that line to:

message = u"Comment was was added to '%s' by '%s': \n\n%s" % (self.post, 
self.author, self.body)

(I.e. Change the format string to a Unicode string)

This is a common pitfall when dealing with user entered data. 

Bye
Ulrich

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



performance of model instgance save()

2011-05-09 Thread Brian
Hi,

I've been writing a testing to backfill a database (postgres) with a
year's history to test the performance and I've been a bit surprised
by the length of time it takes to run. I have a simple model that
contains only a single datetime value and it seems (based on timing
1000 operations) that creating and saving an instance takes about
100ms, where as running "EXPLAIN ANALYZE" on a corresponding INSERT
via psql claims that to take 0.1ms.

Does anyone have an idea as to whether that ratio sounds reasonable?
If so, is there any way to speed up the saving process?

Thanks for any advice you can offer,

Brian

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



using django on a server?

2011-05-09 Thread raj
Hey guys,

I'm sort of new to the whole web framework idea. I have very good
knowledge of python and cgi scripting and I have a few questions about
django.
1. What is the purpose of using a web framework like django? Could I
get the same functionality by just using pythong cgi and python to
access mysql? (like php scripting)
2. If I do use a framework like django, how exactly do I use django on
a server? Like I have hosting through ipage. How do I use django on
it? If ipage can't handle django scripting, what hosting websites
would handle it?

Thank you,
Sincerely,
-Raj Agarwal

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



Looking for recommendations to replace vBulletin with a django based forum

2011-05-09 Thread Eric Chamberlain
Hello,

We are thinking about replacing our low-usage vBulletin forum with a django 
integrated forum.  

Has anyone used djangobb, pybb, or askbot?

--
Eric Chamberlain, Founder
RF.com - http://RF.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: using django on a server?

2011-05-09 Thread Greg Donald
On Mon, May 9, 2011 at 6:25 PM, raj  wrote:
> what hosting websites
> would handle it?

Any host that does cloud-based virtual servers will work.  I use
Rackspace Cloud.

Put on your sysadmin hat, spin up an instance and go.  No real need to
depend on a host to "support" anything nowadays.


-- 
Greg Donald
destiney.com | gregdonald.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: using django on a server?

2011-05-09 Thread raj
I'm sort of new to all of this, why cloud computing? What exactly is
the advantage of it. I'm not quite sure how all of this works. I
looked at the rackspace cloud website, and it looked confusing. Like a
server is like greater than $750 a month. I'm not really connecting
all the dots together. I don't really understand your second statement
either... I really want to learn all of this stuff. Please help. Thank
you!
Sincerely,
-Raj

On May 9, 10:38 pm, Greg Donald  wrote:
> On Mon, May 9, 2011 at 6:25 PM, raj  wrote:
> > what hosting websites
> > would handle it?
>
> Any host that does cloud-based virtual servers will work.  I use
> Rackspace Cloud.
>
> Put on your sysadmin hat, spin up an instance and go.  No real need to
> depend on a host to "support" anything nowadays.
>
> --
> Greg Donald
> destiney.com | gregdonald.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: Loading initial data with a post_syncdb hook?

2011-05-09 Thread Adam Seering


On May 9, 12:24 pm, Karen Tracey  wrote:
> On Mon, May 9, 2011 at 12:56 AM, Adam Seering  wrote:
> > On May 8, 10:53 pm, Karen Tracey  wrote:>
> > > The change you have noticed is documented in the 1.3
> > > backwards-incompatibility list:
> >http://docs.djangoproject.com/en/1.3/releases/1.3/#use-of-custom-sql-...
>
> > Actually, that's a different issue:  I'm not using the custom-SQL
> > loader, I'm using Python code with the post_syncdb hook.  This one
> > isn't in the backwards-compatibility page as far as I can tell.
>
> > (Was that comment intended to cover this case as well?  Maybe a typo
> > somewhere?)
>
> Hmm, you are right, this change is not supposed to affect data added via
> post_syncdb handlers. Specifically the change here 
> is:https://code.djangoproject.com/changeset/15239. On an initial read it looks
> like it might cause post_syncdb-added data to get thrown away, since the
> post_syncdb signal is sent during the call_command('syncdb'). However, the
> call_command('flush', ...) that was added after the call_command('syncdb',
> ...) will also cause that signal to get sent.

Ah, I see what's going on.  Apologies; it sounds like this was a mess-
up / misunderstanding on my part:  Our syncdb hooks aren't safely
reentrant or re-runnable; they're not idempotent, and they depend for
correctness on having a clear django.core.cache to run queries against
and to push stuff into (or at least a cache that we haven't already
stuffed rows into that have since been deleted from the database but
not the cache; we have a fancy system that listens to post_delete to
keep the cache in sync with the database, but it looks like "flush"
doesn't fire post_delete?).  Most were written prior to Django's handy
"dispatch_uid" deduplication mechanism, so they have a simple one-off
global latch that only allows them to run once.  So they ran once for
the syncdb, then the "flush" cleared out all the database data and
they didn't run again the second time around.  My mistake was to look
at the queries being sent to the database, see the data being loaded
and the following TRUNCATE, and assume that things were supposed to
stop there.

(Out of curiosity, any idea why this was done this way?  It feels a
bit odd to me to generate data, throw it out, and generate it
again...  Could the SQL-loader just be turned off during "./manage.py
test" runs?)

This mostly leads to a nice clean obvious solution:  Make our loading
functions be safely reentrant and go start using dispatch_uid.  One
new problem, though:  We'll have to do something to flush the cache
whenever "flush" is called, so that stale data doesn't get left
behind.  Should be quite doable, if a little clunky.


> > Right now, we're working on adding tests, and on encouraging
> > developers to write tests for new parts of the code, new apps/code
> > that are being developed, etc.  Right now, as I understand it with
> > Django's current behavior and our post_syncdb hook setup, we want to
> > re-load the data in three cases:  (1) The current test is the first
> > test, (2) all prior tests are TestCase (as opposed to
> > TransactionTestCase) instances, or (3) we are a TransactionTestCase
> > instance.
>
> (...) In fact
> Django will run all TestCase tests before any TransactionTestCase tests (as
> noted in the 
> dochttp://docs.djangoproject.com/en/1.3/topics/testing/#testcase), precisely
> because the mechanism used to reset the database for these different kinds
> of tests can't ensure that a TestCase run after a TransactionTestCase will
> see a "clean" database on start.

Ah, ok:  Because that text listed "(e.g. doctests)" as the
counterexample, and since it seemed to be comparing both
django.test.TestCase and django.test.TransactionTestCase, I took the
first sentence of that paragraph to mean "A unittest.TestCase, on the other hand, ...".  If all the TransactionTestCases are at
the end as well, then that does in fact get rid of the weird edge
cases that I cited, modulo doctests as you noted (which we do use
occasionally but not very often).


Thanks,
Adam

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



Re: using django on a server?

2011-05-09 Thread Eric Chamberlain
Cloud computing is basically resources that you don't have to pay for when you 
don't use them and no long-term commitments.

We use Amazon Web Services and can change our setup on an hourly basis.

We just finished consolidating some low utilization servers with Amazon EC2.  
We cut our costs down to about $.035/hr.

And we really like that we can turn on and off development/testing servers and 
only pay for them when we need them, those are currently running about $.007/hr.

We also leverage Amazon to serve our static files (javascript, image & css) 
from S3 and CloudFront.  That traffic doesn't even hit our servers.

On May 9, 2011, at 8:33 PM, raj wrote:

> I'm sort of new to all of this, why cloud computing? What exactly is
> the advantage of it. I'm not quite sure how all of this works. I
> looked at the rackspace cloud website, and it looked confusing. Like a
> server is like greater than $750 a month. I'm not really connecting
> all the dots together. I don't really understand your second statement
> either... I really want to learn all of this stuff. Please help. Thank
> you!
> Sincerely,
> -Raj
> 
> On May 9, 10:38 pm, Greg Donald  wrote:
>> On Mon, May 9, 2011 at 6:25 PM, raj  wrote:
>>> what hosting websites
>>> would handle it?
>> 
>> Any host that does cloud-based virtual servers will work.  I use
>> Rackspace Cloud.
>> 
>> Put on your sysadmin hat, spin up an instance and go.  No real need to
>> depend on a host to "support" anything nowadays.
>> 
>> --
>> Greg Donald
>> destiney.com | gregdonald.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: using django on a server?

2011-05-09 Thread Greg Donald
On Mon, May 9, 2011 at 10:33 PM, raj  wrote:
> I'm sort of new to all of this, why cloud computing? What exactly is
> the advantage of it.

Not depending on a host to provide software you have an interest in?

> I'm not quite sure how all of this works. I
> looked at the rackspace cloud website, and it looked confusing. Like a
> server is like greater than $750 a month.

http://www.rackspace.com/cloud/cloud_hosting_products/servers/

It's about $12 to start.

> I'm not really connecting
> all the dots together.

If you run your own server you can install what you want.  The
question of "Does my host support that?" becomes irrelevant.  You can
support whatever because you can install whatever.


-- 
Greg Donald
destiney.com | gregdonald.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: using django on a server?

2011-05-09 Thread Greg Donald
On Mon, May 9, 2011 at 11:02 PM, Eric Chamberlain  wrote:
> We use Amazon Web Services and can change our setup on an hourly basis.

Do they support DNS yet, or are you still responsible for that yourself?


-- 
Greg Donald
destiney.com | gregdonald.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: using django on a server?

2011-05-09 Thread Kenneth Gonsalves
On Mon, 2011-05-09 at 20:33 -0700, raj wrote:
> I'm sort of new to all of this, why cloud computing?

low end use webfaction
medium use a vps
high end go for a dedicated server or cloud
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

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



Re: filter in python

2011-05-09 Thread Jani Tiainen
On Mon, 2011-05-09 at 06:15 -0700, pankaj sharma wrote:
> i have 4 branches in a college..
> some college have three some have 4 and so on
> so i want to provide a search system to the user that they can see the
> list of all the colleges which are having some branch say branch2 may
> be he can select branch 3 and 4 and 1 also
> so i am taking a query from the user for the branch so that i can
> filter all the colleges having that branch.
> 
> no i did this ..
> i took a query say B {and the calue of B may be branch 1, branch 2,
> 3,&4 as i have given a selectbox to user to select any branch}
> now in filter tag i did this
> 
> college_list = College.objects.filter(B=True)
> 
> but it is not working... so please tell me


You have to construct your HTML to be something like this:


 Branch 1
 Branch 2
 Branch 3
 Branch 4


And in code:
# Retrieve branch column name:
branch = form.cleaned_data['branch']

# Build kwargs dictionary. 
# See python docs about keyword argument expansion
branch_kwargs = { branch : True }

# Create Q object (not necessary, see below)
branch_q = Q(**branch_kwargs)

# Filter
college_list = College.objects.filter(branch_q)

note that branch_q construction is not necessary, you can do it
directly:

college_list = College.objects.filter(**branch_kwargs)



-- 

Jani Tiainen


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



outer joins, raw sql or one-to-many?

2011-05-09 Thread Michel30
Hey all,

I'm having trouble wrapping my head around querying multiple tables
with relations between them.
I'm writing an (cms-like) app that will use an existing mysql
database. I modeled that, got my code up and running and am now in the
process of trying to retrieve and submit data to it.
Here is an example of my model:

class Author(models.Model):
authorid = models.IntegerField(primary_key=True,
db_column='AuthorID')
firstname = models.CharField(max_length=96,
db_column='FirstName')
lastname = models.CharField(max_length=96, db_column='LastName')

class Meta:
db_table = u'Author'
def __unicode__(self):
return self.middleinitials

class Documentrevision(models.Model):
docrevid = models.IntegerField(primary_key=True,
db_column='DocRevID')
documentid = models.IntegerField(db_column='DocumentID')
submitterid = models.IntegerField(db_column='SubmitterID')
...
class Meta:
db_table = u'DocumentRevision'
def __unicode__(self):
return self.documenttitle

Now, for every documentid I retrieve I want to find it's firstname and
lastname. Authorid relates to submitterid in this case.
Can someone help me on my way on how to accomplish this?

Many thanks,
Michel

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