Baffled by self.client.login(...) not working in unit tests

2010-04-09 Thread adambossy
I have created users for my unit tests in two ways:

1) Create a fixture for "auth.user" that looks roughly like this:

{
"pk": 1,
"model": "auth.user",
"fields": {
"username": "homer",
"is_active": 1,
"password":
"sha1$72cd3$4935449e2cd7efb8b3723fb9958fe3bb100a30f2",
...
}
}

I've left out the seemingly unimportant parts.

2) Use 'create_user' in the setUp function (although I'd rather keep
everything in my fixtures class):

  def
setUp(self):
  User.objects.create_user('homer', 'ho...@simpson.net',
'simpson')

Note that the password is simpson in both cases.

I've verified that this info is correctly being loaded into the test
database time and time again. I can grab the User object using
User.objects.get. I can verify the password is correct using
'check_password.' The user is active.

Yet, invariably, self.client.login(username='homer',
password='simpson') FAILS. I'm baffled as to why. I think I've read
every single Internet discussion pertaining to this. Can anybody help?
My login code looks like this:

login = self.client.login(username='homer',
password='simpson')
self.assertTrue(login)

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



Re: How to use CommaSeperatedIntegerList with CheckboxSelectMultiple

2010-04-09 Thread Keith

This sounds like a ChoiceField instead of a MultipleChoiceField.

A CheckboxSelectMultiple has to be used with a MultipleChoiceField.

Refer to:
http://ontehfritz.wordpress.com/2009/02/15/django-forms-choicefield-and-multiplechoicefield/

Hope this helps.

On Apr 2, 12:09 pm, ben  wrote:
> Hi, I am new to Django. I am currently using the latest Django 1.2
> from trunk. I am trying to store a list of values in a
> CommaSeperatedIntegerList. I would like to use a
> CheckboxSelectMultiple widget to render and select the values in the
> list. I have setup my code like so.
>
> SOME_CHOICES =  (('1', 'ch1'),('2', 'ch2'), ('3', 'ch3'),('4',"ch4"),
> ('5',"ch5"),)
>
> class QandA(models.Model):
>     q1 = models.CommaSeparatedIntegerField(choices=SOME_CHOICES,
> max_length=100, null=True,blank=True)
>
> class QandAForm(ModelForm):
>       class Meta:
>           model=QandA
>           fields=['q1']
>           widgets={'q1':forms.CheckboxSelectMultiple,}
>
> The form renders properly but I get the following validation error
> after posting.
>
> "Select a valid choice. [u'1'] is not one of the available choices."
>
> The same thing happens when I attempt to use SelectMultiple as the
> widget. Can anyone tell me what I am doing wrong? I have googled about
> but have not been able to find anything describing how to handle this.
>
> Thanks, Ben

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



Re: why can't i display my data onto my template and error on HttpResponse object

2010-04-09 Thread Nicola Noonan
Oh right ok, yes i understand now, thanks so much for your help Tim, it's
greatly appreciated.

On Sat, Apr 10, 2010 at 2:22 AM, Tim Shaffer  wrote:

> To be able to use the form variable in the template, you have to pass
> it to the template in render_to_response in the context like so:
>
> return render_to_response('add_user.html', {'form':form})
>
> Check out the documentation for more examples:
>
>
> http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response
>
> As for the error, there is a code path in your view that doesn't
> return anything. If request.method == 'POST' and uform.is_valid()
> returns false, nothing is returned.
>
> This can be fixed by changing your view slightly:
>
> http://pastebin.com/raw.php?i=wrJbVZ05
>
> That way if it's the first time in the view, or if the form was
> submitted, but invalid, it will display the add_user.html template.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: make the traceback silent in django

2010-04-09 Thread bob84123
I think a really nice solution to this is to use a middleware.  I've
used something like this - it catches all exceptions, and writes each
one's full django traceback to a database record.  You can change the
handling to use the logging module or whatever.  I think this is great
for a production environment.

Add the path to this class to your settings.MIDDLEWARE_CLASSES.

class ExceptionMiddleware:
  def process_exception(self, request, exception):
import sys
from django.http import HttpResponse, HttpResponseServerError
from django.views.debug import technical_500_response
import datetime

exc_type, exc_value, tb = sys.exc_info()

# This the HTML source of the full django interactive stack trace:
full_details = technical_500_response(request, exc_type,
exc_value, tb).content

class_name = exception.__class__.__name__
message = getattr(exception, 'message', '')
url = request.build_absolute_uri()
user = request.user
occurred_at = datetime.datetime.now()

if request.is_ajax():
  return HttpResponseServerError("error")
else:
  # Return some kind of friendly HttpResponseServerError




On Apr 9, 8:56 pm, mouadino  wrote:
> hello Everybody .
>
> my probelem is that i want to make the traceback disappear when an
> exception is raised .
>  I'm using the module logging with Django and i 'm  redirecting the
> output to a file and this file must contain only feedback to the
> developer , and with the traceback it's not readable at all .
>
> so i tried in every exception to print a readable message but i have
> always the traceback how print as well
> example :
>
> try
>         price = decimal.Decimal(extracted_tags.get("PRICE", "0"))
>         if price:
>             product.list_price = price
>
>     except Exception, e:
>         logging.exception('Unable to convert the followin price : ' +
> extracted_tags.get("PRICE"))
>
> and in my log file i have :
>
>   Unable to convert the followin price : " 445,54"
> Traceback (most recent call last):
> ...
>
> can someone help me please and thanks for everything .

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



Re: why can't i display my data onto my template and error on HttpResponse object

2010-04-09 Thread Tim Shaffer
To be able to use the form variable in the template, you have to pass
it to the template in render_to_response in the context like so:

return render_to_response('add_user.html', {'form':form})

Check out the documentation for more examples:

http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response

As for the error, there is a code path in your view that doesn't
return anything. If request.method == 'POST' and uform.is_valid()
returns false, nothing is returned.

This can be fixed by changing your view slightly:

http://pastebin.com/raw.php?i=wrJbVZ05

That way if it's the first time in the view, or if the form was
submitted, but invalid, it will display the add_user.html template.

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



Re: How to delete objects whose id is stored in a session when it ends?

2010-04-09 Thread Rolando Espinoza La Fuente
On Fri, Apr 9, 2010 at 6:05 PM, laser_cg  wrote:
> Hello Tom, thank you for answering so quickly.
>
> 1. OK, so if a user closes the browser, the session is not deleted
> because there is no way to notice that. However, when I use the admin
> that Django provides and I logout, I can check that the session record
> in the django_session table from the db is not deleted, even doing the
> logout explicitly. I do not know what can be wrong. Have you got any
> idea?

AFAIK, django "flushes" the session on logout. Deleting old one and
creating a fresh one for the user. So, the user will have always a session
in the db.

> 2. In short I will try the option of running a python script which
> deletes the session information periodically through Django Celery. I
> will comment how that worked.

Expired sessions had to be deleted manually by run "cleanup" command
http://docs.djangoproject.com/en/dev/ref/django-admin/#cleanup

You can try your self, just start the development server and check
the session keys with:

>>> from django.contrib.sessions.models import Session
>>> [s.session_key for s in Session.objects.all()]

Just login and check the sessions keys. Then logout and again
check the sessions keys

Regards,

~Rolando

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



why can't i display my data onto my template and error on HttpResponse object

2010-04-09 Thread NicMAN
Hi i am getting an error with my add user form,first of all it won't
display any of my textfields and it keeps giving me an error saying
"The view add_user didn't return an HttpResponse object"

Here is my forms.py file

class UserForm(forms.Form):
username = forms.CharField()
password =
forms.CharField(widget=forms.PasswordInput(render_value=False),max_length=100)
first_name = forms.CharField(max_length=20)
last_name = forms.CharField(max_length=20)
joined_on = forms.DateField()

Here is my views.py file

def add_user(request):
if request.method == "POST":
form = UserForm(request.POST)
uform = UserForm(request.POST)
if uform.is_valid():
user = uform.save()
return render_to_response ('links.html')
else:
return render_to_response('add_user.html')

Here is my add_user.html template
{% if error %}

{{ error }}
{% endif %}


{{ form.as_p }}



I am new enough to django, so some help would be greatly appreciated
thanks





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



Re: Is the DoesNotExist exception the only way to check if an object exists?

2010-04-09 Thread Kevin Teague
There is nothing exceptional about exceptions in Python. McDonc does a
good job at explaining how to think about exceptions as less than
exceptional:

http://plope.com/Members/chrism/exceptions_arent_errors/view

The only arguably exceptional part is that ideally the ORM would raise
a plain KeyError exception instead of a custom exception when a key
look-up fails ...

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



Re: HttpResponse with FileWrapper with added data

2010-04-09 Thread bfrederi
This is what I came up with (or pieced together, I don't remember
now):

from django.core.servers.basehttp import FileWrapper

class FLVWrapper(FileWrapper):
"""Wrapper to return a file-like object iterably"""

def __init__(self, filelike):
self.first_time = True
#Calls the parent class __init__ function
super(FLVWrapper, self).__init__(filelike)

def next(self):
if not self.first_time:
data = self.filelike.read(self.blksize)
else:
data = "FLV\x01\x01\x00\x00\x00\x09\x00\x00\x00\x09"
data += self.filelike.read(self.blksize)
self.first_time = False
if data:
return data
raise StopIteration

Then you'll do something like this:
(Get a file-like object "response_file", using something like
open() or urllib2.urlopen() or something of the sort)
response = HttpResponse(FLVWrapper(response_file),
mimetype=response_mimetype)
response['Content-Length'] = calculated_content_length
return response

You'll need to make sure that when you create the HttpResponse object,
you add the correct content length to the response (calculate:
original size + prepended data size). Otherwise you won't be able to
stream the data properly.

On Mar 16, 1:48 pm, bfrederi  wrote:
> *I know that I should serve static files using a static file server
> that was built for doing such, but save me the lecture and indulge me
> on this please*
>
> I am serving large video files (180+MB) through HttpResponse in
> Django, and returning the file iteratively using Django's 
> FileWrapper:http://code.djangoproject.com/browser/django/trunk/django/core/server...
>
> I need to prepend some data on that video file before I return the
> file to the user, but I don't know how to do that without reading the
> entire file into memory using .read(). Is there any way I could extend
> FileWrapper to allow me to add data at the very beginning of the file,
> while it's allowing the video file to be read in chunks?
>
> Here is a simple example of what I am doing (my code has too much
> other crap going on, so I wrote this):
>
> import urllib2
> from django.http import HttpResponse
> from django.core.servers.basehttp import FileWrapper
>
> def huge_video_view(request):
>     response_handle = urllib2.urlopen('http://example.com/
> hugeassvideo.flv')
>     return HttpResponse(FileWrapper(response_handle), mimetype='video/
> x-flv')
>
> Thanks,
> Brandon

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



Re: Is the DoesNotExist exception the only way to check if an object exists?

2010-04-09 Thread Tom X. Tobin
On Fri, Apr 9, 2010 at 4:54 PM, Joakim Hove  wrote:
> I have never really got very friendly with exceptions, I tend to
> consider them as something exceptional which "should not" happen,
> whereas the fact that the database does not contain a particular key
> is in my opinion something quite ordinary and not by any means
> "exceptional".

Exceptions (despite the name) are absolutely *not* "exceptional" in
Python; they're the standard idiom for handling all sorts of things.
The "Pythonic" idea isn't "Look Before You Leap" (check first, then
act); it's instead "Easier to Ask Forgiveness than Permission" (try to
do something, and handle failure if it does happen).

Love your exceptions; they're friendly (and quite useful) beasts.

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



Re: Is the DoesNotExist exception the only way to check if an object exists?

2010-04-09 Thread johan sommerfeld
If you don't want to use exception (which I do when doing something
similar). You can use filter and then check the length of the array
returned.

def my_view( request , pk ):
obj = Class.objects.filter( pk = pk)
if len(obj) != 1:
return bad_key_view
obj = obj[0]
# Do something with obj and return a suitable response.

/J

On Fri, Apr 9, 2010 at 11:54 PM, Joakim Hove  wrote:

> Hello,
>
> I have something I would presume was a very common pattern. I have a
> view which gets a primary-key (from the user) as second argument:
>
>
> def my_view( request , pk ):
> obj = Class.objects.get( pk = pk)
> # Do something with obj and return a suitable response.
>
>
> Now, of course I would like to check whether the object identified by
> 'pk' is in the database, and return a suitable error message if that
> fails; I was halfway expecting to find a "has_key() / exists() / ..."
> method, but it seems the only way to handle this gracefully is by
> catching the DoesNotExist exception?
>
> I have never really got very friendly with exceptions, I tend to
> consider them as something exceptional which "should not" happen,
> whereas the fact that the database does not contain a particular key
> is in my opinion something quite ordinary and not by any means
> "exceptional".
>
> Or maybe I am misunderstanding roally here?
>
> Joakim
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How to delete objects whose id is stored in a session when it ends?

2010-04-09 Thread laser_cg
Hello Tom, thank you for answering so quickly.

1. OK, so if a user closes the browser, the session is not deleted
because there is no way to notice that. However, when I use the admin
that Django provides and I logout, I can check that the session record
in the django_session table from the db is not deleted, even doing the
logout explicitly. I do not know what can be wrong. Have you got any
idea?

2. In short I will try the option of running a python script which
deletes the session information periodically through Django Celery. I
will comment how that worked.

Thank you.

On 9 abr, 11:04, Tom Evans  wrote:
> On Fri, Apr 9, 2010 at 4:17 AM, laser_cg  wrote:
> > Hello everybody!
>
> > I am working with sessions with the database backend in an e-commerce
> > shop. I store the cart ID, the number of items in the cart and the
> > total prize in the session. But actually have two problems.
>
> > 1. I set the SESSION_EXPIRE_AT_BROWSER_CLOSE = True, but Django does
> > not delete the session from the relation django_session when the
> > browser is closed. Why is that? Is that normal?
>
> > 2. How can I erase the shopping cart whose ID is in the session, when
> > the session ends at browser close?
> > I guess I should execute some code similar to the following, but I do
> > not know where exactly:
>
> > cart = Cart.objects.get(request.session[cart_id])  # This code is
> > assuming that this is in a view
> > cart.delete()
>
> > Thank you so much. Replies will be wellcome.
>
> 1) Yes, the browser does not send a special signal to your website
> saying the user has closed their browser. There is no way to detect
> precisely when a user terminates their session.
>
> 2) If you want to erase carts from expired sessions, then you need to
> periodically (every hour, 30 minutes) purge your sessions. This
> (realistically) has to happen from outside of the webserver (google:
> django celery), and should find session objects whose expiry time has
> been reached, look inside the session for carts and remove the cart if
> there, before finally deleting the session object.
>
> Cheers
>
> Tom

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



Re: How to delete objects whose id is stored in a session when it ends?

2010-04-09 Thread laser_cg
Hello Tom, thank you for answering so quickly.

OK, so if a user closes the browser the session is not deleted because
there is no way to notice that. However, when I use the admin that
Django provides and I logout, I can check that the session record in
the django_session is not deleted, even doing the logout explicitly. I
do not know what can be wrong.

I

On 9 abr, 11:04, Tom Evans  wrote:
> On Fri, Apr 9, 2010 at 4:17 AM, laser_cg  wrote:
> > Hello everybody!
>
> > I am working with sessions with the database backend in an e-commerce
> > shop. I store the cart ID, the number of items in the cart and the
> > total prize in the session. But actually have two problems.
>
> > 1. I set the SESSION_EXPIRE_AT_BROWSER_CLOSE = True, but Django does
> > not delete the session from the relation django_session when the
> > browser is closed. Why is that? Is that normal?
>
> > 2. How can I erase the shopping cart whose ID is in the session, when
> > the session ends at browser close?
> > I guess I should execute some code similar to the following, but I do
> > not know where exactly:
>
> > cart = Cart.objects.get(request.session[cart_id])  # This code is
> > assuming that this is in a view
> > cart.delete()
>
> > Thank you so much. Replies will be wellcome.
>
> 1) Yes, the browser does not send a special signal to your website
> saying the user has closed their browser. There is no way to detect
> precisely when a user terminates their session.
>
> 2) If you want to erase carts from expired sessions, then you need to
> periodically (every hour, 30 minutes) purge your sessions. This
> (realistically) has to happen from outside of the webserver (google:
> django celery), and should find session objects whose expiry time has
> been reached, look inside the session for carts and remove the cart if
> there, before finally deleting the session object.
>
> Cheers
>
> Tom

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



Is the DoesNotExist exception the only way to check if an object exists?

2010-04-09 Thread Joakim Hove
Hello,

I have something I would presume was a very common pattern. I have a
view which gets a primary-key (from the user) as second argument:


def my_view( request , pk ):
 obj = Class.objects.get( pk = pk)
 # Do something with obj and return a suitable response.


Now, of course I would like to check whether the object identified by
'pk' is in the database, and return a suitable error message if that
fails; I was halfway expecting to find a "has_key() / exists() / ..."
method, but it seems the only way to handle this gracefully is by
catching the DoesNotExist exception?

I have never really got very friendly with exceptions, I tend to
consider them as something exceptional which "should not" happen,
whereas the fact that the database does not contain a particular key
is in my opinion something quite ordinary and not by any means
"exceptional".

Or maybe I am misunderstanding roally here?

Joakim


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



Test is context variable is set

2010-04-09 Thread Martin Lundberg
Hello,

In a unit test for django, how would I test if a context variable is
set? I tried self.assertTrue('products' in response.context) but it
fails even though in my views I set 'products' to be
Product.objects.all() and if I pprint response.context I can see that
it is set.

Thanks in advance!

-Martin Lundberg

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



Re: Why is django returning only naive datetimes?

2010-04-09 Thread Tom X. Tobin
On Fri, Apr 9, 2010 at 2:48 PM, Ramiro Morales  wrote:
> On Fri, Apr 9, 2010 at 3:20 PM, Tom X. Tobin  wrote:
>>
>> This reminds me that we need to open-source our time zone code.  We
>> track entertainment events across several time zones, and Django's
>> standard time handling can't cleanly deal with that.  Database
>> backends that store time zones as a UTC offset (e.g., PostgreSQL)
>> actually cause *more* trouble because UTC offsets are not the same
>> thing as time zones; it's always safest to store times as UTC and
>
> We've solved this particular hurdle in r12602 when fixing bug #1480
> but of course more work is needed for a full solution.

I've banged my head against time zone issues for long enough to have a
pretty good understanding of just how tricky time zones are.  We
shouldn't be handing PostgreSQL anything but UTC times in a timestamp
column, since Postgres operates in terms of UTC offsets rather than
actual time zones.  Storing a time with a UTC offset is worse than
useless, since it doesn't tell you *anything* about the actual time
zone in question; time zones are political (rather than rational)
beasts.


> We added this featur as an idea for this year GSoC program
>
> http://code.djangoproject.com/wiki/SummerOfCode2010#Multipletimezonesupportfordatetimerepresentation
>
> So far, no student expressed interest in it, maybe we can
> propose it as a feature for 1.3 when the time comes.

We've got working code for single-site multiple-time-zone support
that's been in production use for a good year now, and again, I'm
happy to push it up onto GitHub as soon as I get a chance to extract
it from our repository.  It doesn't require modifying Django, either;
you just use the new model fields and you're good.  Hopefully someone
else will find it useful once it gets polished and has docs.

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



Re: Why is django returning only naive datetimes?

2010-04-09 Thread Ramiro Morales
On Fri, Apr 9, 2010 at 3:20 PM, Tom X. Tobin  wrote:
>
> This reminds me that we need to open-source our time zone code.  We
> track entertainment events across several time zones, and Django's
> standard time handling can't cleanly deal with that.  Database
> backends that store time zones as a UTC offset (e.g., PostgreSQL)
> actually cause *more* trouble because UTC offsets are not the same
> thing as time zones; it's always safest to store times as UTC and

We've solved this particular hurdle in r12602 when fixing bug #1480
but of course more work is needed for a full solution.

>
> store the time zone separately.
>
> I'll try to push a rough cut of the time zone code to GitHub within
> the next 24 hours, and post the URL here; it's still going to need
> documentation and polishing.

We added this featur as an idea for this year GSoC program

http://code.djangoproject.com/wiki/SummerOfCode2010#Multipletimezonesupportfordatetimerepresentation

So far, no student expressed interest in it, maybe we can
propose it as a feature for 1.3 when the time comes.

Regards,

-- 
Ramiro Morales  |  http://rmorales.net

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



Re: Why is django returning only naive datetimes?

2010-04-09 Thread Paweł Roman
> This reminds me that we need to open-source our time zone code.  We
> track entertainment events across several time zones, and Django's
> standard time handling can't cleanly deal with that.  Database
> backends that store time zones as a UTC offset (e.g., PostgreSQL)
> actually cause *more* trouble because UTC offsets are not the same
> thing as time zones; it's always safest to store times as UTC and
> store the time zone separately.

That's exactly what I do. The only thing that you should do (in my
opinion) is to implement some basic tzinfo for UTC and optionally use
it when instantiating datetime value for a DateTime field.

e.g.

my_datetime = models.DateTimeField(utc_tzinfo = True, ... )

and when a model is fetched, this time field would no longer be
'naive', and could be easily converted to user's local time (using
pytz or other library). No extra tricks needed. It would solve the
problem for 99% people who deal with timezones, because I guess
everyone who wants it done properly, stores all times as UTC.

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



Re: Admin issues

2010-04-09 Thread Steven Elliott Jr
Have you looked at your db? are the tables there that you wrote in your models. 
Did you run 

python manage.py syncdb and did you see verification that your tables were 
created?

If you want to see that the sql is being created run

python manage.py sqlall app_name to make sure its generating the sql you want. 
If everything is correct the only explanation is that you don't actually have 
any tables set up in the database.

On Apr 9, 2010, at 1:23 PM, Sheena wrote:

> I uncommented 'django.contrib.sessions' to no avail, and everything
> else is correct.
> 
> I'm not getting any error messages at all, I'm just not given the
> option to do anything with my tables from the admin site. I've gone
> through three different tutorials on it and they all say the same
> thing so it doesn't look like I've left anything out. I'm not sure if
> this is a stoopid question or not but could Windows XP be screwing
> with it? I was warned by an aquaintance that it does strange things to
> Django but I wasn't given any specifics and everything has been
> behaving beautifully until now. I'm using Djanga v1.1.1
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: CMS based Website using Django

2010-04-09 Thread CLIFFORD ILKAY

On 04/09/2010 12:29 PM, Pankaj Singh wrote:

Getting error during installation  please help

Installed
/usr/local/lib/python2.6/dist-packages/django_page_cms-1.1.2-py2.6.egg
Processing dependencies for django-page-cms==1.1.2
Searching for django-mptt>0.2.1
Reading http://pypi.python.org/simple/django-mptt/
Reading http://code.google.com/p/django-mptt/
No local packages or download links found for django-mptt>0.2.1
error: Could not find suitable distribution for
Requirement.parse('django-mptt>0.2.1')


Install pip, whether it's using the package manager for your distro or 
via easy_install. Then:


pip install django-mptt

You should Google for using pip with virtualenv. While you're at it, 
read up on (and use) virtualenvwrapper.

--
Regards,

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


+1 416-410-3326

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



Re: Admin issues

2010-04-09 Thread backdoc
This may be bad advice.  But, since I'm a newbie myself running in a
non-production environment, what I do is restart Apache after making changes
to my model.py or settings.py.  It might be worth restarting your web
server, if you can.

I figure there's a better approach.  I just haven't gotten far enough along
in my learning to be concerned with finding a better way, yet.

On Fri, Apr 9, 2010 at 7:44 AM, Sheena  wrote:

> Hey hey. I'm a little new to Django so I've been following through the
> Django Book v2 and I'm having trouble adding my models to the admin
> site. I'm pretty sure I've followed instructions correctly, I've also
> tried following some random advice I found to no avail. Any help would
> be greatly appreciated. Below are some code snippets:
>
> from models.py:
> class Publisher(models.Model):
>name = models.CharField(max_length=30)
>address = models.CharField(max_length=50)
>city = models.CharField(max_length=60)
>state_province = models.CharField(max_length=30)
>country = models.CharField(max_length=50)
>website = models.URLField()
>
>def __unicode__(self):
>return self.name
>
>class admin:
>pass
> the last two lines don't seem to change anything.
>
> form settings.py
> INSTALLED_APPS = (
>'django.contrib.auth',
>'django.contrib.contenttypes',
>#'django.contrib.sessions',
>'django.contrib.admin',
>#'django.contrib.comments',
>#'django.contrib.sites',
>'newProj.books',
> )
> MIDDLEWARE_CLASSES = (
>'django.middleware.common.CommonMiddleware',
>'django.contrib.sessions.middleware.SessionMiddleware',
>'django.contrib.auth.middleware.AuthenticationMiddleware',
> )
>
> DATABASE_ENGINE = 'sqlite3'
> DATABASE_NAME =
> os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
> DATABASE_USER = '' # Not used with sqlite3.
> DATABASE_PASSWORD = '' # Not used with sqlite3.
> DATABASE_HOST = '' # Not used with sqlite3.
> DATABASE_PORT = '' # Set to empty string for default. Not
> used
>
> And finally from admin.py
> class AuthorAdmin(admin.ModelAdmin):
>pass
> admin.site.register(Author, AuthorAdmin)
> admin.site.register(Publisher)
> admin.site.register(Book)
>
> Any help would be greatly appreciated
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Why is django returning only naive datetimes?

2010-04-09 Thread Tom X. Tobin
On Fri, Apr 9, 2010 at 1:05 PM, Paweł Roman  wrote:
> I've noticed that django always fetches 'naive' datetimes from the
> database. Tzinfo property on a datetime object is always set to null,
> even if the database stores a value WITH a timezone.
>
> This is a bit tedious because such datetime cannot be later converted
> to any timezone. Each time I want to display a datetime on the screen
> (converted to user's time zone) I have to copy it applying UTC as a
> tzinfo (this is how it is stored in the database) and then convert to
> relevant timezone with astimezone(). OK, that's one line of code :)
> but I have a feeling that this line should be somewhere inside in the
> django code.

This reminds me that we need to open-source our time zone code.  We
track entertainment events across several time zones, and Django's
standard time handling can't cleanly deal with that.  Database
backends that store time zones as a UTC offset (e.g., PostgreSQL)
actually cause *more* trouble because UTC offsets are not the same
thing as time zones; it's always safest to store times as UTC and
store the time zone separately.

I'll try to push a rough cut of the time zone code to GitHub within
the next 24 hours, and post the URL here; it's still going to need
documentation and polishing.

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



Why is django returning only naive datetimes?

2010-04-09 Thread Paweł Roman
I've noticed that django always fetches 'naive' datetimes from the
database. Tzinfo property on a datetime object is always set to null,
even if the database stores a value WITH a timezone.

This is a bit tedious because such datetime cannot be later converted
to any timezone. Each time I want to display a datetime on the screen
(converted to user's time zone) I have to copy it applying UTC as a
tzinfo (this is how it is stored in the database) and then convert to
relevant timezone with astimezone(). OK, that's one line of code :)
but I have a feeling that this line should be somewhere inside in the
django 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: another many-to-many filtering question

2010-04-09 Thread Nuno Maltez
Hi,

On Wed, Apr 7, 2010 at 9:35 PM, Jim N  wrote:
> I want to get Questions that a given User has not asked yet.  That
> is,  Questions where there is no Asking record for a given User.  I
> have the User's id.

Well, you can use the exclude() method. In a ManyToMany, the "user"
field is like a User with the additional properties defined in the
"through" model, so I think you can just do:

Question.objects.exclude(user__id=my_user__id)

Just see the examples the documentation provides:
http://www.djangoproject.com/documentation/models/many_to_many/


> Models look like:
>
> class Question(models.Model):
>     text = models.TextField()
>     question_type = models.ForeignKey('QuestionType')
>     user = models.ManyToManyField(User, through='Asking', null=True)
>
> class Asking(models.Model):
>     user = models.ForeignKey(User)
>     question = models.ForeignKey(Question)
>     is_primary_asker = models.BooleanField()
>
> User is the built-in django.contrib.auth.models User.
>
> Thanks!  Maybe this is simple and I just am not seeing it.
>
> -Jim
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Admin issues

2010-04-09 Thread Karen Tracey
On Fri, Apr 9, 2010 at 1:23 PM, Sheena  wrote:

> I uncommented 'django.contrib.sessions' to no avail, and everything
> else is correct.
>

Did you run manage.py syncdb after uncommenting sessions?



> I'm not getting any error messages at all, I'm just not given the
> option to do anything with my tables from the admin site.
>

So what, exactly, do you get? A blank page? A page saying you don't have
permission to edit anything?



> I've gone
> through three different tutorials on it and they all say the same
> thing so it doesn't look like I've left anything out. I'm not sure if
> this is a stoopid question or not but could Windows XP be screwing
> with it? I was warned by an aquaintance that it does strange things to
> Django but I wasn't given any specifics and everything has been
> behaving beautifully until now. I'm using Djanga v1.1.1
>

No, Django runs fine on Windows XP.

In your original note you mention having a "class admin" in your models --
that's an extremely old (and no longer functional) way of enabling admin. As
you note, it has no effect when using Django 1.1.1. But the fact that
something prompted you to even add it makes me think that you may be running
into trouble due to working off of doc for a mixture of different versions.

What I'd suggest is starting fresh by working through the tutorial:

http://docs.djangoproject.com/en/1.1/intro/tutorial01/#intro-tutorial01

(Note you want to stick with the one that matches the version you have
installed.) Perhaps by working through a fresh project and successfully
getting the admin working there it will become clear to you what piece is
missing/different in your own project.

Karen

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



Re: Problem with RSS feed. (Long Post)

2010-04-09 Thread Nuno Maltez
> Exception Type: ImproperlyConfigured at /feeds/latest/
> Exception Value: Give your Entry class a get_absolute_url() method, or
> define an item_link() method in your Feed class.

Have you tried the obvious - do what the Exception tells you and add a
"get_absolute_url" method to the model of the objects published on the
feed, or an item_link in your Feed class?

from http://docs.djangoproject.com/en/dev/ref/contrib/syndication/
"""
To specify the contents of , you have two options. For each item
in items(), Django first tries calling the item_link() method on the
Feed class. In a similar way to the title and description, it is
passed it a single parameter, item. If that method doesn't exist,
Django tries executing a get_absolute_url() method on that object.
Both get_absolute_url() and item_link() should return the item's URL
as a normal Python string. As with get_absolute_url(), the result of
item_link() will be included directly in the URL, so you are
responsible for doing all necessary URL quoting and conversion to
ASCII inside the method itself.
"""

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



Re: Admin issues

2010-04-09 Thread Sheena
I uncommented 'django.contrib.sessions' to no avail, and everything
else is correct.

I'm not getting any error messages at all, I'm just not given the
option to do anything with my tables from the admin site. I've gone
through three different tutorials on it and they all say the same
thing so it doesn't look like I've left anything out. I'm not sure if
this is a stoopid question or not but could Windows XP be screwing
with it? I was warned by an aquaintance that it does strange things to
Django but I wasn't given any specifics and everything has been
behaving beautifully until now. I'm using Djanga v1.1.1

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



Problem with RSS feed. (Long Post)

2010-04-09 Thread rbetzen
Been working on this one for three days now. I'm stumped.
I've created my rss feed  from the example listed in The Definitive
Guide to Django: Web Development Done Right.
Unfortunately, I'm getting an ImproperlyConfigured error. I've been
looknig on the Djangoproject.com site and searching Google for a
solution, but so far I've been coming up empty.

Heres the error message:

Environment:

Request Method: GET
Request URL: http://localhost:/feeds/latest/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'frenchmerchants.blog']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/syndication/
views.py" in feed
  19. feedgen = f(slug, request).get_feed(param)
File "/usr/lib/pymodules/python2.6/django/contrib/syndication/
feeds.py" in get_feed
  131. link = add_domain(current_site.domain,
self.__get_dynamic_attr('item_link', item))
File "/usr/lib/pymodules/python2.6/django/contrib/syndication/
feeds.py" in __get_dynamic_attr
  58. return attr(obj)
File "/usr/lib/pymodules/python2.6/django/contrib/syndication/
feeds.py" in item_link
  41. raise ImproperlyConfigured, "Give your %s class a
get_absolute_url() method, or define an item_link() method in your
Feed class." % item.__class__.__name__

Exception Type: ImproperlyConfigured at /feeds/latest/
Exception Value: Give your Entry class a get_absolute_url() method, or
define an item_link() method in your Feed class.

I'm thinking I'm neglecting to put something in my feed class, but
everything in the book is already there.  I did pull out the feed by
category, but I get the same error with or without it.
If this question and a solution have already been provided, please
accept my apologies.  I ran a search but haven't found anything here.

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



Re: Giving up PHP. ...Can't decide between Django & Rails

2010-04-09 Thread Steven Elliott Jr
I think it largely boils down (as many have said) to a python vs ruby debate.

I personally hate Ruby... I think its perl with a nice syntax, its very obtuse 
and just downright hard to maintain as projects get bigger (IMHO, others I;m 
sure disagree).

As far was what is better about Django for me is the lack of "Magic" that rails 
developers love. I just find the whole monolithic approach very confusing and 
ugly in Rails. ALso I hate the way it handles views but thats just my opinion. 
I love that in django I can store my templates anywhere and reuse them from 
other apps if need be... anyway, at the end of the day the best thing you can 
do is try both and just make a decision. THe more time you spend deliberating 
about these things is more wasted time that you could have been writing an app. 
I came from PHP and never looked back... oh yeah and the Python and Django 
communities are just friendlier and more helpful (again IMHO).

CHeck this out if you want to see a great talk about Django.
http://blog.fluther.com/going-for-a-trot-on-the-django-pony/


On Apr 9, 2010, at 12:06 PM, UnclaimedBaggage wrote:

> Hi folks,
> 
> I'm a long-term (8 years) PHP developer who's recently started
> dabbling with Rails & Django. I REALLY like what I've seen from both
> frameworks and quite frankly, am a little miffed I didn't jump on the
> bandwagon earlier.
> 
> I'm trying to decide between the two frameworks, but I'm
> struggling to get out of stalemate. If anyone can offer advice, I'd be
> very appreciative. Here are my current thoughts:
> 
> WHAT I LIKE ABOUT DJANGO
> * I LOVE django-admin . For the sort of work I do, which is a lot of
> customised cart/cms stuff, this would save a lot of time.
> * Code reusability seems superior. Opinions?
> * Better perfomance?
> * I've half-built a shopping cart app in Django that I'm happy with. A
> quick dabble in Rails made this task seem a little more time-
> consuming, and I'm not comfortable with drop-in solutions
> * Server seems more stable. Using the rails dev server on a local
> linux box twice threw errors I couldn't trace, then worked fine again
> the next time I restarted my computer (having previously restarted the
> server with no result). Is this a common problem?
> 
> WHAT I LIKE ABOUT RAILS
> * I prefer the syntax
> * There seems to be a lot more work for rails...with better pay
> * "Agile Rails" is a damn fantastic book. I haven't found much Django
> documentation I've enjoyed as much
> * Seems to be a little simpler
> * Seems to have a greater depth of features
> * Better AJAX integration from what I've seen
> 
> 
> Obviously I expect some django-tilted opinions here, but if anyone
> with
> experience in both can offer a balanced perspective on pros-n-cons of
> each it would be a big help.
> 
> Cheers.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: CMS based Website using Django

2010-04-09 Thread Bill Freeman
Yeah, I don't think that they're quite set up to just easy_install.
It took a bit of reading,
but there was enough information on their home page to know what else you had to
install, If I recall correctly (it's been a while).   You may want to
also include
django-tinymce so that your client can have somewhat WYSIWYG experience.

On Fri, Apr 9, 2010 at 12:29 PM, Pankaj Singh
 wrote:
> Getting error during installation  please help
> Installed
> /usr/local/lib/python2.6/dist-packages/django_page_cms-1.1.2-py2.6.egg
> Processing dependencies for django-page-cms==1.1.2
> Searching for django-mptt>0.2.1
> Reading http://pypi.python.org/simple/django-mptt/
> Reading http://code.google.com/p/django-mptt/
> No local packages or download links found for django-mptt>0.2.1
> error: Could not find suitable distribution for
> Requirement.parse('django-mptt>0.2.1')
>
>
> thanks
> Pankaj
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Setting up Django on snow leopard

2010-04-09 Thread Steven Elliott Jr
Its also a good idea to install the Developer Tools ... You should check which 
version of Python you are using too. I think be default OS X uses 2.6.1

This is what I get when I type "python" into the terminal:
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 


On Apr 9, 2010, at 11:38 AM, Lee Hinde wrote:

> 
> 
> On Apr 8, 1:50 pm, CG  wrote:
>> I have successfully setup django, although I am not sure how I did
>> it.  Now I am trying to setup MySQLdb  but keep getting the error
>>   File "setup.py", line 5, in 
>> from setuptools import setup, Extension
>> ImportError: No module named setuptools
>> 
>> On Apr 8, 12:45 pm, CG  wrote:
>> 
>>> Nothing happens, I just get a >
>> 
>>> On Apr 8, 12:39 pm, Tim Shaffer  wrote:
>> 
 Very strange. What happens if you open a new Terminal window and run
 the following?
>> 
 python -c "import sys; print sys.path"
> 
> Google is your friend. There are a bunch of posts that will take you
> through the process.
> 
> Django & mysql are actually the easy steps. You should google 'django
> and snow leopard' for support with those and other topics.
> 
> I'm not suggesting you shouldn't ask questions here, just saying there
> are resources out there to help get you started.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Setting up Django on snow leopard

2010-04-09 Thread Steven Elliott Jr
Are you running the install as superuser?

I am running leopard too and ran into the same problem but once you run it as:

sudo python setup.py install it should work..

Also, dumb question but do you have mysql installed? Its also a good idea to 
put this:

# mysql path
PATH=${PATH}:/usr/local/mysql/bin

in your .bash_profile as well... for later use.

On Apr 9, 2010, at 11:38 AM, Lee Hinde wrote:

> 
> 
> On Apr 8, 1:50 pm, CG  wrote:
>> I have successfully setup django, although I am not sure how I did
>> it.  Now I am trying to setup MySQLdb  but keep getting the error
>>   File "setup.py", line 5, in 
>> from setuptools import setup, Extension
>> ImportError: No module named setuptools
>> 
>> On Apr 8, 12:45 pm, CG  wrote:
>> 
>>> Nothing happens, I just get a >
>> 
>>> On Apr 8, 12:39 pm, Tim Shaffer  wrote:
>> 
 Very strange. What happens if you open a new Terminal window and run
 the following?
>> 
 python -c "import sys; print sys.path"
> 
> Google is your friend. There are a bunch of posts that will take you
> through the process.
> 
> Django & mysql are actually the easy steps. You should google 'django
> and snow leopard' for support with those and other topics.
> 
> I'm not suggesting you shouldn't ask questions here, just saying there
> are resources out there to help get you started.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Giving up PHP. ...Can't decide between Django & Rails

2010-04-09 Thread Javier Guerra Giraldez
On Fri, Apr 9, 2010 at 11:13 AM, UnclaimedBaggage  wrote:
> Ooops - forgot one other thing:
>
> I'm a little concerned by django error handling. The tracer stack
> seems to miss the relevant file a lot of the time, and I often find
> little help from the error pages even when it does get the right page
> (eg an error comes up with a useful file/line # in the debug page, but
> the cause is on another page and I'm struggling for indications as to
> where the bad code actually came from). This could, of course, just be
> my inexperience with the language, but do more experienced developers
> regularly find themselves having to "guess and hunt" exceptions/
> errors?
>
> Secondly, typoed template variables don't seem to throw exceptions. Is
> there a way of changing this? I haven't seen much in the way of
> getters/setters in example code, and I'm concerned that may make
> typoed variable/list/dictionary declarations more difficult to hunt
> down.
>
> Cheers again. ;-)


this comments are mostly about Python, not Django.  from this (and
your mention that like Rails syntax better than Django's), i can guess
you like Ruby more than Python, or at least, you're more familiar with
it.   if that's right, then you should first choose between learning
Python or staying with Ruby.  after that, your framework choice is
more than obvious.


of course, syntax preferences are subjective and very visceral.  i'm
not a big fan of Python's syntax; but there are very few languages
that i find more hideous than Ruby.  :-)

total bliss for me would be a Django-like ORM for Lua...


-- 
Javier

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



Re: CMS based Website using Django

2010-04-09 Thread Pankaj Singh
Getting error during installation  please help

Installed
/usr/local/lib/python2.6/dist-packages/django_page_cms-1.1.2-py2.6.egg
Processing dependencies for django-page-cms==1.1.2
Searching for django-mptt>0.2.1
Reading http://pypi.python.org/simple/django-mptt/
Reading http://code.google.com/p/django-mptt/
No local packages or download links found for django-mptt>0.2.1
error: Could not find suitable distribution for
Requirement.parse('django-mptt>0.2.1')



thanks
Pankaj

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



Re: Giving up PHP. ...Can't decide between Django & Rails

2010-04-09 Thread UnclaimedBaggage
Ooops - forgot one other thing:

I'm a little concerned by django error handling. The tracer stack
seems to miss the relevant file a lot of the time, and I often find
little help from the error pages even when it does get the right page
(eg an error comes up with a useful file/line # in the debug page, but
the cause is on another page and I'm struggling for indications as to
where the bad code actually came from). This could, of course, just be
my inexperience with the language, but do more experienced developers
regularly find themselves having to "guess and hunt" exceptions/
errors?

Secondly, typoed template variables don't seem to throw exceptions. Is
there a way of changing this? I haven't seen much in the way of
getters/setters in example code, and I'm concerned that may make
typoed variable/list/dictionary declarations more difficult to hunt
down.

Cheers again. ;-)

On Apr 9, 9:06 pm, UnclaimedBaggage  wrote:
> Hi folks,
>
> I'm a long-term (8 years) PHP developer who's recently started
> dabbling with Rails & Django. I REALLY like what I've seen from both
> frameworks and quite frankly, am a little miffed I didn't jump on the
> bandwagon earlier.
>
> I'm trying to decide between the two frameworks, but I'm
> struggling to get out of stalemate. If anyone can offer advice, I'd be
> very appreciative. Here are my current thoughts:
>
> WHAT I LIKE ABOUT DJANGO
> * I LOVE django-admin . For the sort of work I do, which is a lot of
> customised cart/cms stuff, this would save a lot of time.
> * Code reusability seems superior. Opinions?
> * Better perfomance?
> * I've half-built a shopping cart app in Django that I'm happy with. A
> quick dabble in Rails made this task seem a little more time-
> consuming, and I'm not comfortable with drop-in solutions
> * Server seems more stable. Using the rails dev server on a local
> linux box twice threw errors I couldn't trace, then worked fine again
> the next time I restarted my computer (having previously restarted the
> server with no result). Is this a common problem?
>
> WHAT I LIKE ABOUT RAILS
> * I prefer the syntax
> * There seems to be a lot more work for rails...with better pay
> * "Agile Rails" is a damn fantastic book. I haven't found much Django
> documentation I've enjoyed as much
> * Seems to be a little simpler
> * Seems to have a greater depth of features
> * Better AJAX integration from what I've seen
>
> Obviously I expect some django-tilted opinions here, but if anyone
> with
> experience in both can offer a balanced perspective on pros-n-cons of
> each it would be a big help.
>
> Cheers.

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



Giving up PHP. ...Can't decide between Django & Rails

2010-04-09 Thread UnclaimedBaggage
Hi folks,

I'm a long-term (8 years) PHP developer who's recently started
dabbling with Rails & Django. I REALLY like what I've seen from both
frameworks and quite frankly, am a little miffed I didn't jump on the
bandwagon earlier.

I'm trying to decide between the two frameworks, but I'm
struggling to get out of stalemate. If anyone can offer advice, I'd be
very appreciative. Here are my current thoughts:

WHAT I LIKE ABOUT DJANGO
* I LOVE django-admin . For the sort of work I do, which is a lot of
customised cart/cms stuff, this would save a lot of time.
* Code reusability seems superior. Opinions?
* Better perfomance?
* I've half-built a shopping cart app in Django that I'm happy with. A
quick dabble in Rails made this task seem a little more time-
consuming, and I'm not comfortable with drop-in solutions
* Server seems more stable. Using the rails dev server on a local
linux box twice threw errors I couldn't trace, then worked fine again
the next time I restarted my computer (having previously restarted the
server with no result). Is this a common problem?

WHAT I LIKE ABOUT RAILS
* I prefer the syntax
* There seems to be a lot more work for rails...with better pay
* "Agile Rails" is a damn fantastic book. I haven't found much Django
documentation I've enjoyed as much
* Seems to be a little simpler
* Seems to have a greater depth of features
* Better AJAX integration from what I've seen


Obviously I expect some django-tilted opinions here, but if anyone
with
experience in both can offer a balanced perspective on pros-n-cons of
each it would be a big help.

Cheers.

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



Re: CMS based Website using Django

2010-04-09 Thread Bill Freeman
The django-pages-cms app works pretty well.

On Fri, Apr 9, 2010 at 11:34 AM, Pankaj Singh
 wrote:
> Hi, I am a student. I have designed CMS websites using PHP and MySQL . I
> want to complete my new project using Django ( excited about it).
> I wanted to know the basic steps that I should follow. I need to do design a
> website for a new startup at IIT Kharagpur. I will use CMS because that
> person ( for whom I will be working) does not know web designing.
> I have read Django Tutorials from Internet.
>
> --
> --
> --
> Thanking You,
>
> Pankaj Kumar Singh,
> 2nd Year Undergraduate Student,
> Department of Agricultural and Food Engineering,
> Indian Institute of Technology,
> Kharagpur
>
> Mobile - (+91) 8001231685
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Setting up Django on snow leopard

2010-04-09 Thread Lee Hinde


On Apr 8, 1:50 pm, CG  wrote:
> I have successfully setup django, although I am not sure how I did
> it.  Now I am trying to setup MySQLdb  but keep getting the error
>   File "setup.py", line 5, in 
>     from setuptools import setup, Extension
> ImportError: No module named setuptools
>
> On Apr 8, 12:45 pm, CG  wrote:
>
> > Nothing happens, I just get a >
>
> > On Apr 8, 12:39 pm, Tim Shaffer  wrote:
>
> > > Very strange. What happens if you open a new Terminal window and run
> > > the following?
>
> > > python -c "import sys; print sys.path"

Google is your friend. There are a bunch of posts that will take you
through the process.

Django & mysql are actually the easy steps. You should google 'django
and snow leopard' for support with those and other topics.

I'm not suggesting you shouldn't ask questions here, just saying there
are resources out there to help get you started.

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



CMS based Website using Django

2010-04-09 Thread Pankaj Singh
Hi, I am a student. I have designed CMS websites using PHP and MySQL . I
want to complete my new project using Django ( excited about it).
I wanted to know the basic steps that I should follow. I need to do design a
website for a new startup at IIT Kharagpur. I will use CMS because that
person ( for whom I will be working) does not know web designing.
I have read Django Tutorials from Internet.

-- 
-- 
--
Thanking You,

Pankaj Kumar Singh,
2nd Year Undergraduate Student,
Department of Agricultural and Food Engineering,
Indian Institute of Technology,
Kharagpur

Mobile - (+91) 8001231685

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



Re: Double arrays in models django

2010-04-09 Thread Bill Freeman
Will there be more than one matrix?  Or are you using "Name" to indicate
matrix membership, as opposed to column names and row names?  If
so, a foreign key on a matrix table will be more storage efficient, since
matrix names will only need to be stored once.

Also, doesn't a select to do a lookup of a data item always need to join
on all three tables?  If you want to go this route, then you only really need
one table, though, if there are multiple named matrices, a second table
to hold the matrix name would be more efficient.

Let's say, for the sake of argument, that are numbering your matrices,
rows, and columns, rather than naming them, and avoid the extra table(s)
and join(s).

create table Data
(
  id int primary key,
  matrix int not null,
  row int not null,
  col int not null,
  data float not null
)

You can query this for an exact data item by specifying all of matrix, row, and
col in your where clause.   Or you can just specify matrix and row and get
all of a col (perhaps order by col) to get one row.  Similar for
getting a column.


In my initial scheme, the Data table items, which greatly outnumber any of
the other table's items, were slightly smaller each, having an id, a col int,
and a data (of whatever type).  This has the cost that Data must be joined
on Row, in turn joined on Matrix if matrices have a name, and getting one
column is a more expensive operation (but still done in one where clause).

The speed versus space tradoff is yours to make.


Also, while it may be easier for you to think in terms of SQL, to wire this to
Django, you should probably write it as a model rather than as create
table SQL, so that you will see when  you are going somewhere difficult.

For my first scheme above (remember, id is automatic):

class Data(models.Model):
matrix = models.IntegerField()
row = models.IntegerField()
col = models.IntegerField()
data = models.FloatField()

Now you can, for instance, do something like:

  for d in Data.objects.filter(matrix=m, row=r).order_by('col'):

to iterate over a row in order (leave off the order_by if order doesn't matter),
and:

   d = Data.objects.get(matrix=m, row-r, col=c)

to get an individual data object, which you can update using:

d.data = new_value
d.save()

use filter instead of get if you want to allow a matrix to be sparse.

I'll leave the three (or two, if matrices are numbered) table scheme as
an exercise for you.

Bill

On Fri, Apr 9, 2010 at 3:50 AM, zimberlman  wrote:
> create table Rows
> (
>  Id int primary key,
>  Name text(255) not null
> )
> create table Cols
> (
>  Id int primary key,
>  Name text(255) not null
> )
>
> create table Data
> (
>  RowId int not null foreign key references Rows(Id),
>    ColId int not null foreign key references Cols(Id),
>    Data
> )
>
> On 8 апр, 02:32, Bill Freeman  wrote:
>> You need one matrix table, having a row for each matrix.
>>
>> You need one matrix_row table, having a row for each row of any matrix, 
>> mostly
>> containing a foreign key on the matrix table, showing of which matrix the 
>> row is
>> part, plus it's row number in that table.
>>
>> And you need one matrix_row_values table, having a foreign key on the
>> matrix_row,
>> indicating of which row it is a part, plus it's column number, and the value.
>>
>> There is no run time table creation involved, and this can all be done
>> with direct
>> django models, and on any database the ORM supports (maybe not NoSQL
>> databases, I'll have to think about that).  The access syntax wouldn't look 
>> like
>> 2D array access, but you could fix that with a wrapper.
>>
>>
>>
>> On Wed, Apr 7, 2010 at 4:20 PM, zimberlman  wrote:
>> > No, no.
>> > I need to store the matrix and dual array is ideal for this would come
>> > up.
>> > The problem is that the matrix will grow in size, thousands of entries
>> > only on i, and where that same number of j.
>> > create table is not an option.
>>
>> > only if the matrix transform and drive the table. and my question is,
>> > if you can not define arrays in the model, how can I convert a
>> > matrix.
>> > example is the matrix
>> > a   b   c   d  e
>> > 1   2   3   4  5
>> > 11 22 33 44 55
>> > converted into
>> > a 1
>> > a 11
>> > b 2
>> > b 22
>> > c 3
>> > c 33
>> > d 4
>> > d 44
>> > e 5
>> > e 55
>>
>> > this is for example, how do I implement this in the model? course in
>> > the class will have to use functions, but is it possible?
>>
>> > On 8 апр, 01:28, pmains  wrote:
>> >> If there is no Django model field for this, then one option would be
>> >> to create your own model field (http://docs.djangoproject.com/en/dev/
>> >> howto/custom-model-fields/). Of course, it would not be compatible
>> >> with most SQL Database types.
>>
>> >> Of course, it may be easier to just rethink your data model. Would it
>> >> be possible to create one or more additional tables to avoid using an
>> >> unusual DB 

Re: MySQLdb setup on snow leopard help

2010-04-09 Thread jmswen
Out of curiosity, are you using a version of Python that you installed
(i.e., not the out-of-the-box version that comes with Snow Leopard)?

You are missing the setuptools package in your installation of
Python.  Visit http://pypi.python.org/pypi/setuptools and read the
download/installation instructions.

I fear that if you are using Python 2.6, you may run into another,
separate problem once you get setuptools working.  After "installing"
MySQLdb and subsequently importing it, you may run into this error:

ImportError: dynamic module does not define init function (init_mysql)

If you do, come back to this thread and I'll help you through that. :)

On Apr 8, 6:17 pm, CG  wrote:
> I have successfully setup django, although I am not sure how I did
> it.  Now I am trying to setup MySQLdb  but keep getting the error
>   File "setup.py", line 5, in 
>     from setuptools import setup, Extension
> ImportError: No module named setuptools

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



Populating fields using views from django admin

2010-04-09 Thread Daxal
Hi Guys,

I am trying to populate fields for a template using views from the
admin section of the site. The admin section is already setup and I
got my models to show up there and I can add and delete properly so it
works fine.

What remains is to populate those fields in views to render them onto
the template. I do not know how to setup that view.

What I have so far is basically a url linked to view:

def cvdetails(request, id):

the url is also setup fine it all works. I am just wondering how to
setup this population. The fields I am populating are many to many
fields. The models below will explain it well:

class cvdb(models.Model):
  user = models.ForeignKey(User)
  language = models.ManyToManyField(Language,
db_table='cm_cvdb_language', verbose_name="languages")
  profdesgn = models.ManyToManyField(ProfDesgn,
db_table='cm_cvdb_profdesgn', verbose_name="professional designation",
blank=True)
  practice = models.ManyToManyField(Practice,
db_table='cm_cvdb_practice', verbose_name="Practice", blank=True)
  sector = models.ManyToManyField(Sector, db_table='cm_cvdb_sector',
verbose_name="Sector", blank=True)
  profession = models.ManyToManyField(Profession,
db_table='cm_cvdb_profession', verbose_name="Profession", blank=True)
  country = models.ManyToManyField(Country,
db_table='cm_cvdb_country', verbose_name="Country", blank=True)

I am a newbie here but know a little bit to setup basic forms. I am
stuck on this one. Help please   if you can:)

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



Re: Admin issues

2010-04-09 Thread Steven Elliott Jr
Uncomment:  #'django.contrib.sessions',

make sure to import admin from django.contrib and turn admin.autodiscover()

and yes, error messages would be helpful... if any.


On Apr 9, 2010, at 10:32 AM, Stuart wrote:

> What you have looks about right. What result are you getting? An error
> message?
> 
> 
> --Stuart
> 
> On Apr 9, 7:44 am, Sheena  wrote:
>> Hey hey. I'm a little new to Django so I've been following through the
>> Django Book v2 and I'm having trouble adding my models to the admin
>> site. I'm pretty sure I've followed instructions correctly, I've also
>> tried following some random advice I found to no avail. Any help would
>> be greatly appreciated. Below are some code snippets:
>> 
>> from models.py:
>> class Publisher(models.Model):
>> name = models.CharField(max_length=30)
>> address = models.CharField(max_length=50)
>> city = models.CharField(max_length=60)
>> state_province = models.CharField(max_length=30)
>> country = models.CharField(max_length=50)
>> website = models.URLField()
>> 
>> def __unicode__(self):
>> return self.name
>> 
>> class admin:
>> pass
>> the last two lines don't seem to change anything.
>> 
>> form settings.py
>> INSTALLED_APPS = (
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> #'django.contrib.sessions',
>> 'django.contrib.admin',
>> #'django.contrib.comments',
>> #'django.contrib.sites',
>> 'newProj.books',
>> )
>> MIDDLEWARE_CLASSES = (
>> 'django.middleware.common.CommonMiddleware',
>> 'django.contrib.sessions.middleware.SessionMiddleware',
>> 'django.contrib.auth.middleware.AuthenticationMiddleware',
>> )
>> 
>> DATABASE_ENGINE = 'sqlite3'
>> DATABASE_NAME =
>> os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
>> DATABASE_USER = '' # Not used with sqlite3.
>> DATABASE_PASSWORD = '' # Not used with sqlite3.
>> DATABASE_HOST = '' # Not used with sqlite3.
>> DATABASE_PORT = '' # Set to empty string for default. Not
>> used
>> 
>> And finally from admin.py
>> class AuthorAdmin(admin.ModelAdmin):
>> pass
>> admin.site.register(Author, AuthorAdmin)
>> admin.site.register(Publisher)
>> admin.site.register(Book)
>> 
>> Any help would be greatly appreciated
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Admin issues

2010-04-09 Thread Stuart
What you have looks about right. What result are you getting? An error
message?


--Stuart

On Apr 9, 7:44 am, Sheena  wrote:
> Hey hey. I'm a little new to Django so I've been following through the
> Django Book v2 and I'm having trouble adding my models to the admin
> site. I'm pretty sure I've followed instructions correctly, I've also
> tried following some random advice I found to no avail. Any help would
> be greatly appreciated. Below are some code snippets:
>
> from models.py:
> class Publisher(models.Model):
>     name = models.CharField(max_length=30)
>     address = models.CharField(max_length=50)
>     city = models.CharField(max_length=60)
>     state_province = models.CharField(max_length=30)
>     country = models.CharField(max_length=50)
>     website = models.URLField()
>
>     def __unicode__(self):
>         return self.name
>
>     class admin:
>         pass
> the last two lines don't seem to change anything.
>
> form settings.py
> INSTALLED_APPS = (
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     #'django.contrib.sessions',
>     'django.contrib.admin',
>     #'django.contrib.comments',
>     #'django.contrib.sites',
>     'newProj.books',
> )
> MIDDLEWARE_CLASSES = (
>     'django.middleware.common.CommonMiddleware',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
> )
>
> DATABASE_ENGINE = 'sqlite3'
> DATABASE_NAME =
> os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
> DATABASE_USER = ''             # Not used with sqlite3.
> DATABASE_PASSWORD = ''         # Not used with sqlite3.
> DATABASE_HOST = ''             # Not used with sqlite3.
> DATABASE_PORT = ''             # Set to empty string for default. Not
> used
>
> And finally from admin.py
> class AuthorAdmin(admin.ModelAdmin):
>     pass
> admin.site.register(Author, AuthorAdmin)
> admin.site.register(Publisher)
> admin.site.register(Book)
>
> Any help would be greatly appreciated

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



Re: dumpdata doesn't seem to respect database routers

2010-04-09 Thread Francis Gulotta
Thank you Russ!

I'm glad I'm not crazy.

I must say that the django project and community have been a joy to get
acquainted with. Not only were you friendly and fast to respond but I see
you already fixed it!

Good day!
-Francis

---
Francis Gulotta
wiz...@roborooter.com


On Thu, Apr 8, 2010 at 10:42 PM, Russell Keith-Magee  wrote:

> On Fri, Apr 9, 2010 at 2:34 AM, wizard_2  wrote:
> > Hi everyone,
> > Mange dumpdata seems to be ignoring my database router and failing on
> > a model thats in a different db.
> >
> > I have two databases, default (mysql db named knothedashboard) and
> > bluecherry (mssql database named dataKNOT). Here's my router. (Should
> > I be using dpaste.com?)
> >
> >def db_for_read(self, model, **hints):
> >if model._meta.db_table == u'ZZOSHPRH':
> >return 'bluecherry'
> >return None
> >
> >def db_for_write(self, model, **hints):
> >if model._meta.db_table == u'ZZOSHPRH':
> >return False
> >return None
> >
> >def allow_syncdb(self, db, model):
> >if model._meta.db_table == u'ZZOSHPRH':
> >return False
> >return None
> >
> >
> > I'm not convinced I'm using my router properly. I think I'm OK with
> > checking the db_table, but I don't know how to check the model name.
> > (I'm new to python and django.) I have allow_syncdb return false for
> > the model, and the second db for read and write - but I don't know why
> > it wouldn’t be respected during the dump.
> >
> > I tried using --database to specify only to dump the default db but it
> > still tried to dump the offending model.
> >
> > django.db.utils.DatabaseError: (1146, "Table
> > 'knothedashboard.zzoshprh' doesn't exist")
> >
> > Is this a bug or am I missing something?
>
> This looks like a bug. dumpdata isn't using routing information at all
> at present, which looks to me like an oversight on my part from the
> introduction of routers.
>
> I've opened ticket #13308 to track the problem; the fix should be
> fairly trivial.
>
> http://code.djangoproject.com/ticket/13308
>
> Thanks for the report!
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Adding information to error reports

2010-04-09 Thread Steve Holden
What's easiest way to ensure that further data is displayed as a part of
the emails sent after a server error? Some of the data would be present
in all requests, some might only be available for particular requests.

regards
 Steve

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



Re: Admin issues

2010-04-09 Thread Steven Elliott Jr
@Sheena,

sorry -- I didnt read all of your email -- I think if you've got it all in 
admin.py make sure you're importing admin from django.contrib.

To activate the admin interface though you need to do:

1. Add 'django.contrib.admin' to the INSTALLED_APPS setting (which you did)
2. Make sure INSTALLED_APPS contains 'django.contrib.auth, contettypes, and 
sessions  (I see sessions is commented out on yours.
3. Middle ware classes needs to contain 
'django.middleware.common.CommomMiddleware, 
'django.contrib.sessions.middlewarae.SessionMiddleWare, and 
django.contrib.auth.middleware.AuthenticationMiddleware.

run python manage.py syncdb

then make sure that you have this in urls.py file:

from django.contrib import admin
admin.autodiscover()

#include this URLPattern...
urlpatterns = patterns(' ',
# ...
(r'^admin/', include(admin.site.urls)),
# ...
)

Hope this helps!



but you will still need to make sure that you have
On Apr 9, 2010, at 9:13 AM, Steven Elliott Jr wrote:

> In your urls. py make sure you have:
> 
> from django.contrib import admin
> admin.autodiscover()
> 
> and
> 
> that you've uncommented the (r'^admin/', include(admin.site.urls)), 
> 
> in the tuple: urlpatterns = patterns.
> 
> On Apr 9, 2010, at 8:44 AM, Sheena wrote:
> 
>> Hey hey. I'm a little new to Django so I've been following through the
>> Django Book v2 and I'm having trouble adding my models to the admin
>> site. I'm pretty sure I've followed instructions correctly, I've also
>> tried following some random advice I found to no avail. Any help would
>> be greatly appreciated. Below are some code snippets:
>> 
>> from models.py:
>> class Publisher(models.Model):
>>name = models.CharField(max_length=30)
>>address = models.CharField(max_length=50)
>>city = models.CharField(max_length=60)
>>state_province = models.CharField(max_length=30)
>>country = models.CharField(max_length=50)
>>website = models.URLField()
>> 
>>def __unicode__(self):
>>return self.name
>> 
>>class admin:
>>pass
>> the last two lines don't seem to change anything.
>> 
>> form settings.py
>> INSTALLED_APPS = (
>>'django.contrib.auth',
>>'django.contrib.contenttypes',
>>#'django.contrib.sessions',
>>'django.contrib.admin',
>>#'django.contrib.comments',
>>#'django.contrib.sites',
>>'newProj.books',
>> )
>> MIDDLEWARE_CLASSES = (
>>'django.middleware.common.CommonMiddleware',
>>'django.contrib.sessions.middleware.SessionMiddleware',
>>'django.contrib.auth.middleware.AuthenticationMiddleware',
>> )
>> 
>> DATABASE_ENGINE = 'sqlite3'
>> DATABASE_NAME =
>> os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
>> DATABASE_USER = '' # Not used with sqlite3.
>> DATABASE_PASSWORD = '' # Not used with sqlite3.
>> DATABASE_HOST = '' # Not used with sqlite3.
>> DATABASE_PORT = '' # Set to empty string for default. Not
>> used
>> 
>> And finally from admin.py
>> class AuthorAdmin(admin.ModelAdmin):
>>pass
>> admin.site.register(Author, AuthorAdmin)
>> admin.site.register(Publisher)
>> admin.site.register(Book)
>> 
>> Any help would be greatly appreciated
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: How to concatenate a list of Q objects?

2010-04-09 Thread dfolland
If you are looking for "OR" then use the "Q object".

see 
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

On Apr 7, 11:39 am, Daniel  wrote:
> Hi,
>
> Thank you for your help everyone.  I know that I need to learn python
> better, and I did read those articles.  What is still a bit unclear to
> me, though, is how could I add an "OR" or "AND" separator between Q
> objects?
>
> So I have a list of qobjects like [qObj1, qObj2, qObj3].
>
> What I want is something like Sample.objects.filter((qObj1 | qObj2),
> qObj3)
>
> I know that the default is for all Q objects to be "ANDed" together.
> I think the join operation is not going to work here, nor is
> concatenation, but is there something obvious that I'm missing?
>
> THANK YOU :>
>
> On Apr 6, 7:14 am, Vinicius Mendes  wrote:
>
> > I recommend you to read more documentation about python. It's a basic python
> > feature. You can read more about it here:
>
> >http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-...
>
> > Try this:
>
> > Sample.objects.filter(*qObjects)
>
> > __
> > Vinícius Mendes
> > Solucione Sistemashttp://solucione.info/
>
> > On Tue, Apr 6, 2010 at 2:54 AM, Aaron  wrote:
> > > Sample.objects.filter(*qObjects)
>
> > > On Apr 6, 1:10 am, Daniel  wrote:
> > > > Hi, I think that this must be super easy, but I'm kind of stumped.
>
> > > > I have a list qObjects = [qObject1, qObject2, qObject3]
> > > > What I'd like is to form this query:  Sample.objects.filter(qObject1,
> > > > qObject2, qObject3)
>
> > > > How would I accomplish what I need?  Thanks!
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Admin issues

2010-04-09 Thread Steven Elliott Jr
In your urls. py make sure you have:

from django.contrib import admin
admin.autodiscover()

and

that you've uncommented the (r'^admin/', include(admin.site.urls)), 

in the tuple: urlpatterns = patterns.

On Apr 9, 2010, at 8:44 AM, Sheena wrote:

> Hey hey. I'm a little new to Django so I've been following through the
> Django Book v2 and I'm having trouble adding my models to the admin
> site. I'm pretty sure I've followed instructions correctly, I've also
> tried following some random advice I found to no avail. Any help would
> be greatly appreciated. Below are some code snippets:
> 
> from models.py:
> class Publisher(models.Model):
>name = models.CharField(max_length=30)
>address = models.CharField(max_length=50)
>city = models.CharField(max_length=60)
>state_province = models.CharField(max_length=30)
>country = models.CharField(max_length=50)
>website = models.URLField()
> 
>def __unicode__(self):
>return self.name
> 
>class admin:
>pass
> the last two lines don't seem to change anything.
> 
> form settings.py
> INSTALLED_APPS = (
>'django.contrib.auth',
>'django.contrib.contenttypes',
>#'django.contrib.sessions',
>'django.contrib.admin',
>#'django.contrib.comments',
>#'django.contrib.sites',
>'newProj.books',
> )
> MIDDLEWARE_CLASSES = (
>'django.middleware.common.CommonMiddleware',
>'django.contrib.sessions.middleware.SessionMiddleware',
>'django.contrib.auth.middleware.AuthenticationMiddleware',
> )
> 
> DATABASE_ENGINE = 'sqlite3'
> DATABASE_NAME =
> os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
> DATABASE_USER = '' # Not used with sqlite3.
> DATABASE_PASSWORD = '' # Not used with sqlite3.
> DATABASE_HOST = '' # Not used with sqlite3.
> DATABASE_PORT = '' # Set to empty string for default. Not
> used
> 
> And finally from admin.py
> class AuthorAdmin(admin.ModelAdmin):
>pass
> admin.site.register(Author, AuthorAdmin)
> admin.site.register(Publisher)
> admin.site.register(Book)
> 
> Any help would be greatly appreciated
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: checking an IP range

2010-04-09 Thread Tom Evans
On Fri, Apr 9, 2010 at 1:41 PM, Ken Lacey  wrote:
> Hi
>
> I am trying to check an IP so some information will/will not be
> displayed based on the first 8 digites of the remote IP address.
>
> I have a vairable ip_address which contains the remote address and a
> vairable accept_ip with a value "192.168." but when I carry out the
> following it is not working correctly.
>
> {% ifequal ip_address|slice:"8" accept_ip %}
>   do something
> {% endifequal %}
>
>
> I have also tried
> {% ifequal ip_address|slice:"8" "192.168." %}
>   do something
> {% endifequal %}
>
> and
> {% ifequal ip_address|slice:"8"|stringformat:"s" "192.168." %}
>   do something
> {% endifequal %}
>
> the same results appaear whether the ip_address is 192.168. or any
> other range.
>
> Thanks
>
> Ken
>

You shouldn't do logic like this in the template - as you can see, it
is quite hard!

The simplest option is to calculate whether that IP is in the correct
range in the view and set a variable in the context to indicate that.
If you are iterating through a list of things, you would probably want
to write a templatetag to do the comparison for you.

PS:
Treating IP addresses as strings, and performing string manipulation
to test belonging is poor form. I would recommend the netaddr library,
and write code like this:

>>> import netaddr
>>> range = netaddr.IPNetwork('192.168.0.0/16')
>>> addr = netaddr.IPAddress('192.168.12.4')
>>> addr in range
True


Cheers

Tom

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



Admin issues

2010-04-09 Thread Sheena
Hey hey. I'm a little new to Django so I've been following through the
Django Book v2 and I'm having trouble adding my models to the admin
site. I'm pretty sure I've followed instructions correctly, I've also
tried following some random advice I found to no avail. Any help would
be greatly appreciated. Below are some code snippets:

from models.py:
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

def __unicode__(self):
return self.name

class admin:
pass
the last two lines don't seem to change anything.

form settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.sessions',
'django.contrib.admin',
#'django.contrib.comments',
#'django.contrib.sites',
'newProj.books',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME =
os.path.join(os.path.dirname(__file__),'testDB').replace('\\','/')
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not
used

And finally from admin.py
class AuthorAdmin(admin.ModelAdmin):
pass
admin.site.register(Author, AuthorAdmin)
admin.site.register(Publisher)
admin.site.register(Book)

Any help would be greatly appreciated

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



checking an IP range

2010-04-09 Thread Ken Lacey
Hi

I am trying to check an IP so some information will/will not be
displayed based on the first 8 digites of the remote IP address.

I have a vairable ip_address which contains the remote address and a
vairable accept_ip with a value "192.168." but when I carry out the
following it is not working correctly.

{% ifequal ip_address|slice:"8" accept_ip %}
   do something
{% endifequal %}


I have also tried
{% ifequal ip_address|slice:"8" "192.168." %}
   do something
{% endifequal %}

and
{% ifequal ip_address|slice:"8"|stringformat:"s" "192.168." %}
   do something
{% endifequal %}

the same results appaear whether the ip_address is 192.168. or any
other range.

Thanks

Ken

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



Re: Inline for model causes problem during save

2010-04-09 Thread Nuno Maltez
On Thu, Apr 8, 2010 at 7:42 PM, onorua  wrote:
> I'm using 1.1.1
> On the development server on my laptop - it doesn't happen, on
> production - happen every time.
> How can I debug why this happen?

I have no idea :-P Any other differences between the 2 environments?
Database server?

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



Saving ForeignKey and ManyToManyField fields¶

2010-04-09 Thread dm-tlt
on the page http://docs.djangoproject.com/en/dev/topics/db/queries/
writed:
cheese_blog = Blog.objects.get(name="Cheddar Talk")
>>> entry.blog = cheese_blog
>>> entry.save()

But it's not work, when i try i get error '1048' column 'blog_id'
cannot be null

how can i right save manytomany fields?

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



how to achieve the break tag in django template

2010-04-09 Thread CCC
now i have a finished template which wrote by j2ee,like this:
<#list  dailyStarList as dailyS>
   class="list_color_w"<#else>class="list_color"><#list
chatAvatarList as cal>
<#if dailyS.avatarid == cal.id>
${(cal.name[0..1])!''}之星
<#break>

<#if (dailyMemberList)??>
<#list  dailyMemberList as dm>
<#if dailyS.idx == dm.idx>
${(dm.myname)!''}
<#break>


${(dailyS.dailyNum)?c!''}
   


And Now i want to changeit,write by django,anyone know how to achieve
the "<#break>"
in this tenplate
thanks!

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



Re: make the traceback silent in django

2010-04-09 Thread mouadino
thank you it's worked

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



Re: make the traceback silent in django

2010-04-09 Thread mouadino
thank you it's worked

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



Re: make the traceback silent in django

2010-04-09 Thread Tom Evans
On Fri, Apr 9, 2010 at 11:56 AM, mouadino  wrote:
> hello Everybody .
>
> my probelem is that i want to make the traceback disappear when an
> exception is raised .
>  I'm using the module logging with Django and i 'm  redirecting the
> output to a file and this file must contain only feedback to the
> developer , and with the traceback it's not readable at all .
>
> so i tried in every exception to print a readable message but i have
> always the traceback how print as well
> example :
>
> try
>        price = decimal.Decimal(extracted_tags.get("PRICE", "0"))
>        if price:
>            product.list_price = price
>
>    except Exception, e:
>        logging.exception('Unable to convert the followin price : ' +
> extracted_tags.get("PRICE"))
>
> and in my log file i have :
>
>  Unable to convert the followin price : " 445,54"
> Traceback (most recent call last):
> ...
>
> can someone help me please and thanks for everything .
>

I don't think its a good idea, but replace your logging.exception()
call with something like:

  logging.warning('Unable to convert price: %s   error: %s" %
(extracted_tags.get('PRICE'), e))

Cheers

Tom

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



make the traceback silent in django

2010-04-09 Thread mouadino
hello Everybody .

my probelem is that i want to make the traceback disappear when an
exception is raised .
 I'm using the module logging with Django and i 'm  redirecting the
output to a file and this file must contain only feedback to the
developer , and with the traceback it's not readable at all .

so i tried in every exception to print a readable message but i have
always the traceback how print as well
example :

try
price = decimal.Decimal(extracted_tags.get("PRICE", "0"))
if price:
product.list_price = price

except Exception, e:
logging.exception('Unable to convert the followin price : ' +
extracted_tags.get("PRICE"))

and in my log file i have :

  Unable to convert the followin price : " 445,54"
Traceback (most recent call last):
...

can someone help me please and thanks for everything .

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



Re: creating basic view for a modelmultiplechoicefield

2010-04-09 Thread Daxal
Hi Daniel,

Thank you very much for your reply. That cleared quite a lot of stuff
for me. I was wondering if you have any links on how to populate
models through the admin interface. I would like to have it editable
from admin (makes it much easier to handle). If you have any links or
ideas on how to do this please let me know.

I already setup the admin backend so that I can add the six different
fields defined in the model (country, language, practice, profdesgn,
sector and profession) <-- the manytomany fields in models.

Thanks for your help! :)

Daxal

On Apr 9, 5:46 am, Daniel Roseman  wrote:
> On Apr 9, 9:42 am, Daxal  wrote:
>
>
>
> > Basically, I am starting to create a view called "cvdetails" and it is
> > linked to "cvdetails.html" link for template.
>
> > The form is supposed to use is:
>
> > class cvForm(forms.Form):
> >   Language =
> > forms.ModelMultipleChoiceField(queryset=C.Language.objects.all())
> >   ProfDesgn =
> > forms.ModelMultipleChoiceField(queryset=C.ProfDesgn.objects.all(),
> > required=False)
> >   Practice =
> > forms.ModelMultipleChoiceField(queryset=C.Practice.objects.all(),
> > required=False)
> >   Sector =
> > forms.ModelMultipleChoiceField(queryset=C.Sector.objects.all(),
> > required=False)
> >   Profession =
> > forms.ModelMultipleChoiceField(queryset=C.Profession.objects.all(),
> > required=False)
> >   Country =
> > forms.ModelMultipleChoiceField(queryset=C.Country.objects.all(),
> > required=False)
>
> > and the model for this form is:
>
> > class ProfDesgn(models.Model):
> >   Name = models.CharField(max_length=15)
> >   def __unicode__(self):
> >     return self.Name
>
> > class Practice(models.Model):
> >   Name = models.CharField(max_length=50)
> >   def __unicode__(self):
> >     return self.Name
>
> > class Sector(models.Model):
> >   Name = models.CharField(max_length=30)
> >   def __unicode__(self):
> >     return self.Name
>
> > class Profession(models.Model):
> >   Name = models.CharField(max_length=80)
> >   def __unicode__(self):
> >     return self.Name
>
> > class Country(models.Model):
> >   Name = models.CharField(max_length=40)
> >   def __unicode__(self):
> >     return self.Name
>
> > class Language(models.Model):
> >   Language = models.CharField(max_length=30)
> >   def __unicode__(self):
> >     return self.Language
>
> > class cvdb(models.Model):
> >   user = models.ForeignKey(User)
> >   language_set = models.ManyToManyField(Language,
> > db_table='cm_cvdb_language', verbose_name="languages")
> >   profdesgn_set = models.ManyToManyField(ProfDesgn,
> > db_table='cm_cvdb_profdesgn', verbose_name="professional designation",
> > blank=True)
> >   practice_set = models.ManyToManyField(Practice,
> > db_table='cm_cvdb_practice', verbose_name="Practice", blank=True)
> >   sector_set = models.ManyToManyField(Sector,
> > db_table='cm_cvdb_sector', verbose_name="Sector", blank=True)
> >   profession_set = models.ManyToManyField(Profession,
> > db_table='cm_cvdb_profession', verbose_name="Profession", blank=True)
> >   country_set = models.ManyToManyField(Country,
> > db_table='cm_cvdb_country', verbose_name="Country", blank=True)
>
> > Now I am wondering how do I start off the view for a
> > modelmultiplechoice fields. I would imagine they require some populate
> > definition using the MySQLdb library in pythong but should it be
> > defined under forms or views? I am completely lost as to how to
> > approach this. I searched and searched but I cannot find information
> > on it at all (even in the django references)
>
> > Thanks in advance!   (:
>
> It's not really clear what you are asking. What view do you mean?
> Fields don't have views, views are for displaying information on the
> front end.
>
> If you want to populate your models, an easy way would be via the
> admin interface - or you can do it programmatically, or define your
> own views with forms.
>
> A couple of tips: you probably want to use a modelform, not a plain
> form. Also you shouldn't use '_set' in the names, that's used for
> reverse relations in foreign keys and is likely to get confusing.
> --
> DR.

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



Re: Considering Django: How simple is customising django-admin?

2010-04-09 Thread UnclaimedBaggage
Many thanks, folks - very helpful replies. I've googled a lot of the
information mentioned above and it seems Django is quite easily
capable of almost everything I've mentioned above.  After another
night juggling Django & Rails I've decided my PHP days are certainly
over - I just need to decide between those two.

My preference is tilting towards Django, but from what I've seen there
seems to be more freelance work available for rails. ...Decisions,
decisions.

Cheers,
   - JB

On Apr 9, 2:00 am, Jon  wrote:
> 1. 
> Inlineshttp://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> 2. Form mediahttp://docs.djangoproject.com/en/dev/topics/forms/media/
>
> 3. Your example does not require custom template overrides for the
> admin HTML, it is possible to simply include a function from your
> Model in 
> 'list_display'.http://docs.djangoproject.com/en/dev/intro/tutorial02/#customize-the-...
> ... In your example the function must return the HTML for the
> thumbnail image, and it must escape it and allow tags so that the HTML
> shows correctly in the admin.  Example (from django-imagekit):
>
>
>
> >    def admin_thumbnail_view(self):
> >        if not self._imgfield:
> >            return None
> >        prop = getattr(self, self._ik.admin_thumbnail_spec, None)
> >        if prop is None:
> >            return 'An "%s" image spec has not been defined.' % \
> >              self._ik.admin_thumbnail_spec
> >        else:
> >            if hasattr(self, 'get_absolute_url'):
> >                return u'' % \
> >                    (escape(self.get_absolute_url()), escape(prop.url))
> >            else:
> >                return u'' % \
> >                    (escape(self._imgfield.url), escape(prop.url))
> >    admin_thumbnail_view.short_description = _('Thumbnail')
> >    admin_thumbnail_view.allow_tags = True
>
> You would then include 'admin_thumbnail_view' in 'list_display' in
> your Model's admin.
>
> 4. As for the thumbnail question, you can look at 'sorl-thumbnail' or
> 'django-imagekit'. I use my own amalgamation of both, for their
> different features.
>
> As for the rest of the question, you can add onto the admin app all
> you want with your own views, templates, etc. by hijacking the URL
> routing in urls.py to look for '/admin/my-report-page' and route that
> to your own app.  To integrate this into the admin you can simply edit
> the template for the main index, or use 'django-admin-tools' which
> gives you a much nicer way of adding onto the admin with your own
> dashboard links and modules.  Or you may watch out for 'django-
> grappelli' to soon integrate 'django-admin-tools' into its already
> existing body of work, like their Navigation sidebar which lets you
> add your own links to the admin index, and Bookmarks which appear at
> the top of every admin page. (The latest work is still not quite
> usable but still very impressive)
>
> 5. I've pondered on both examples myself, but haven't really gone
> anywhere with those ideas, so I can't tell you for sure whether it's
> possible or not. But my bet's on it being possible, because in the
> first example you're simply filtering out child categories based on
> the parent category selection, so this would be doable completely with
> JS it seems.  The second example seems doable as well, though I
> haven't tried it myself.
>
> On Apr 8, 6:15 am, UnclaimedBaggage  wrote:
>
>
>
> > Hi folks,
>
> > Long-time PHP/Zend user here who'd LOVE to switch to Python/Django for
> > webdev work. I've just spent a few hours snooping around Django and
> > really like what I see, but before I invest any real time in it I'd
> > really appreciate some advice on if (or how easily) a few things can
> > be done. My main concern is the flexibility of django-admin. I LOVE
> > the feature, but I'm a little concerned about flexibility. Any
> > suggestions on the following would be very appreciated:
>
> > #1.) For usability's sake, I'd like to have foreign key models
> > embedded in the same admin form as the model they're referencing. For
> > example, if there's a "products" model with a one-to-many relationship
> > to "product options", I'd like to add "product options" from within
> > the "product" admin form. (Eg javascript adds another field each time
> > all existing "product option" fields are filled out...or something).
> > Anything that will help (or hurt)  me in trying to add this sort of
> > functionality? Is this commonly done?
>
> > #2.) Adding javascript to individual admin forms. Simple?
>
> > #3.) Customising the HTML (not CSS) output of django-admin. For
> > example, putting a thumbnailed image next to each product in the
> > Admin-->Products table list. Simple?
>
> > #4.) A lot of what I do is basic (but custom) e-commerce & CMS stuff.
> > Django's CMS potential looks very solid, although I'm wondering if
> > tacking on basic e-commerce features to django-admin could be a little
> > cumbersome. 

Re: creating basic view for a modelmultiplechoicefield

2010-04-09 Thread Daniel Roseman
On Apr 9, 9:42 am, Daxal  wrote:
> Basically, I am starting to create a view called "cvdetails" and it is
> linked to "cvdetails.html" link for template.
>
> The form is supposed to use is:
>
> class cvForm(forms.Form):
>   Language =
> forms.ModelMultipleChoiceField(queryset=C.Language.objects.all())
>   ProfDesgn =
> forms.ModelMultipleChoiceField(queryset=C.ProfDesgn.objects.all(),
> required=False)
>   Practice =
> forms.ModelMultipleChoiceField(queryset=C.Practice.objects.all(),
> required=False)
>   Sector =
> forms.ModelMultipleChoiceField(queryset=C.Sector.objects.all(),
> required=False)
>   Profession =
> forms.ModelMultipleChoiceField(queryset=C.Profession.objects.all(),
> required=False)
>   Country =
> forms.ModelMultipleChoiceField(queryset=C.Country.objects.all(),
> required=False)
>
> and the model for this form is:
>
> class ProfDesgn(models.Model):
>   Name = models.CharField(max_length=15)
>   def __unicode__(self):
>     return self.Name
>
> class Practice(models.Model):
>   Name = models.CharField(max_length=50)
>   def __unicode__(self):
>     return self.Name
>
> class Sector(models.Model):
>   Name = models.CharField(max_length=30)
>   def __unicode__(self):
>     return self.Name
>
> class Profession(models.Model):
>   Name = models.CharField(max_length=80)
>   def __unicode__(self):
>     return self.Name
>
> class Country(models.Model):
>   Name = models.CharField(max_length=40)
>   def __unicode__(self):
>     return self.Name
>
> class Language(models.Model):
>   Language = models.CharField(max_length=30)
>   def __unicode__(self):
>     return self.Language
>
> class cvdb(models.Model):
>   user = models.ForeignKey(User)
>   language_set = models.ManyToManyField(Language,
> db_table='cm_cvdb_language', verbose_name="languages")
>   profdesgn_set = models.ManyToManyField(ProfDesgn,
> db_table='cm_cvdb_profdesgn', verbose_name="professional designation",
> blank=True)
>   practice_set = models.ManyToManyField(Practice,
> db_table='cm_cvdb_practice', verbose_name="Practice", blank=True)
>   sector_set = models.ManyToManyField(Sector,
> db_table='cm_cvdb_sector', verbose_name="Sector", blank=True)
>   profession_set = models.ManyToManyField(Profession,
> db_table='cm_cvdb_profession', verbose_name="Profession", blank=True)
>   country_set = models.ManyToManyField(Country,
> db_table='cm_cvdb_country', verbose_name="Country", blank=True)
>
> Now I am wondering how do I start off the view for a
> modelmultiplechoice fields. I would imagine they require some populate
> definition using the MySQLdb library in pythong but should it be
> defined under forms or views? I am completely lost as to how to
> approach this. I searched and searched but I cannot find information
> on it at all (even in the django references)
>
> Thanks in advance!   (:

It's not really clear what you are asking. What view do you mean?
Fields don't have views, views are for displaying information on the
front end.

If you want to populate your models, an easy way would be via the
admin interface - or you can do it programmatically, or define your
own views with forms.

A couple of tips: you probably want to use a modelform, not a plain
form. Also you shouldn't use '_set' in the names, that's used for
reverse relations in foreign keys and is likely to get confusing.
--
DR.

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



Re: How to concatenate a list of Q objects?

2010-04-09 Thread Tom Evans
On Thu, Apr 8, 2010 at 6:02 PM, Daniel  wrote:
> Thank you, Tom.  I understand now.  I come from java and I was not
> aware that such a syntax is allowed.  I got the Q objects part of my
> app working thanks to you guys.
>

Just to clarify:

python:
a = c if b else d

java:
a = b ? c : d;

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



Re: How to delete objects whose id is stored in a session when it ends?

2010-04-09 Thread Tom Evans
On Fri, Apr 9, 2010 at 4:17 AM, laser_cg  wrote:
> Hello everybody!
>
> I am working with sessions with the database backend in an e-commerce
> shop. I store the cart ID, the number of items in the cart and the
> total prize in the session. But actually have two problems.
>
> 1. I set the SESSION_EXPIRE_AT_BROWSER_CLOSE = True, but Django does
> not delete the session from the relation django_session when the
> browser is closed. Why is that? Is that normal?
>
> 2. How can I erase the shopping cart whose ID is in the session, when
> the session ends at browser close?
> I guess I should execute some code similar to the following, but I do
> not know where exactly:
>
> cart = Cart.objects.get(request.session[cart_id])  # This code is
> assuming that this is in a view
> cart.delete()
>
> Thank you so much. Replies will be wellcome.
>

1) Yes, the browser does not send a special signal to your website
saying the user has closed their browser. There is no way to detect
precisely when a user terminates their session.

2) If you want to erase carts from expired sessions, then you need to
periodically (every hour, 30 minutes) purge your sessions. This
(realistically) has to happen from outside of the webserver (google:
django celery), and should find session objects whose expiry time has
been reached, look inside the session for carts and remove the cart if
there, before finally deleting the session object.

Cheers

Tom

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



Inline formset customization

2010-04-09 Thread pinco
Hi Guys,

I'm try to figure out how add some customized functionalities to an
inline formset. What I would implement are the two following features:
- ability to delete a record by pressing a submit button assigned to
each row (instead of checking the delete box and submitting the
overall form)
- ability to preserve the extra forms number and order after the
submission

To better explain the second point, suppose there are 3 records on the
db and the user adds 3 extra forms (using eg. the technique described
here: 
http://www.falconhat.com/tutorials/django-adding-inline-formset-rows-without-javascript/).
The user then decides to delete the second record.
I would that, after the submission, the form has 2 records and 3
extra, blank forms. Additionally, if the user fills partially one or
more of the additional forms, I would the filled forms to keep the new
content.

Can somebody give me some hints on how to implement these
functionalities?
By the way, while the above functionalities seem to be easy to
implement using JavaScript, I'm keen to avoid to use it.


Many thanks for your invaluable help.


Cheers,

Paolo

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



sorting by date – problem handling/ordering null v alues

2010-04-09 Thread ARie
hi all,

i have basically the same problem as this guy on stackoverflow:
http://stackoverflow.com/questions/151195/possible-to-use-sql-to-sort-by-date-but-put-null-dates-at-the-back-of-the-results

i have a ticket-application where tickets have a deadline (which is
optional an can therefore be null) and when i display my tickets the
ones with no deadline should show up last. but mysql puts null-values
first.

i was looking at django's documentation of extra() to see if i can
adapt the solution presented on stack overflow but i am unsure if it
is really possible? at least the given examples for order_by are less
complex.

this is what looks like a solution in mysql's sql syntax:

ORDER BY CASE WHEN myDeadline IS NULL THEN 1 ELSE 0 END, myDeadline;

or is there even an easier way to accomplish what i want using
django's orm?
or is my best approach to create a calculated field which i update "on
save" and then use this for sorting?

thanks!
andreas

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



creating basic view for a modelmultiplechoicefield

2010-04-09 Thread Daxal
Basically, I am starting to create a view called "cvdetails" and it is
linked to "cvdetails.html" link for template.

The form is supposed to use is:

class cvForm(forms.Form):
  Language =
forms.ModelMultipleChoiceField(queryset=C.Language.objects.all())
  ProfDesgn =
forms.ModelMultipleChoiceField(queryset=C.ProfDesgn.objects.all(),
required=False)
  Practice =
forms.ModelMultipleChoiceField(queryset=C.Practice.objects.all(),
required=False)
  Sector =
forms.ModelMultipleChoiceField(queryset=C.Sector.objects.all(),
required=False)
  Profession =
forms.ModelMultipleChoiceField(queryset=C.Profession.objects.all(),
required=False)
  Country =
forms.ModelMultipleChoiceField(queryset=C.Country.objects.all(),
required=False)

and the model for this form is:

class ProfDesgn(models.Model):
  Name = models.CharField(max_length=15)
  def __unicode__(self):
return self.Name

class Practice(models.Model):
  Name = models.CharField(max_length=50)
  def __unicode__(self):
return self.Name

class Sector(models.Model):
  Name = models.CharField(max_length=30)
  def __unicode__(self):
return self.Name

class Profession(models.Model):
  Name = models.CharField(max_length=80)
  def __unicode__(self):
return self.Name

class Country(models.Model):
  Name = models.CharField(max_length=40)
  def __unicode__(self):
return self.Name

class Language(models.Model):
  Language = models.CharField(max_length=30)
  def __unicode__(self):
return self.Language

class cvdb(models.Model):
  user = models.ForeignKey(User)
  language_set = models.ManyToManyField(Language,
db_table='cm_cvdb_language', verbose_name="languages")
  profdesgn_set = models.ManyToManyField(ProfDesgn,
db_table='cm_cvdb_profdesgn', verbose_name="professional designation",
blank=True)
  practice_set = models.ManyToManyField(Practice,
db_table='cm_cvdb_practice', verbose_name="Practice", blank=True)
  sector_set = models.ManyToManyField(Sector,
db_table='cm_cvdb_sector', verbose_name="Sector", blank=True)
  profession_set = models.ManyToManyField(Profession,
db_table='cm_cvdb_profession', verbose_name="Profession", blank=True)
  country_set = models.ManyToManyField(Country,
db_table='cm_cvdb_country', verbose_name="Country", blank=True)

Now I am wondering how do I start off the view for a
modelmultiplechoice fields. I would imagine they require some populate
definition using the MySQLdb library in pythong but should it be
defined under forms or views? I am completely lost as to how to
approach this. I searched and searched but I cannot find information
on it at all (even in the django references)

Thanks in advance!   (:

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



hotmail contacts api + python but no django

2010-04-09 Thread karthi
how to write the script hotmail contacts api + python but no
django ,how this can be achieved ,can anybody give me some idea for
this.

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



Re: Double arrays in models django

2010-04-09 Thread zimberlman
create table Rows
(
  Id int primary key,
  Name text(255) not null
)
create table Cols
(
  Id int primary key,
  Name text(255) not null
)

create table Data
(
  RowId int not null foreign key references Rows(Id),
ColId int not null foreign key references Cols(Id),
Data
)

On 8 апр, 02:32, Bill Freeman  wrote:
> You need one matrix table, having a row for each matrix.
>
> You need one matrix_row table, having a row for each row of any matrix, mostly
> containing a foreign key on the matrix table, showing of which matrix the row 
> is
> part, plus it's row number in that table.
>
> And you need one matrix_row_values table, having a foreign key on the
> matrix_row,
> indicating of which row it is a part, plus it's column number, and the value.
>
> There is no run time table creation involved, and this can all be done
> with direct
> django models, and on any database the ORM supports (maybe not NoSQL
> databases, I'll have to think about that).  The access syntax wouldn't look 
> like
> 2D array access, but you could fix that with a wrapper.
>
>
>
> On Wed, Apr 7, 2010 at 4:20 PM, zimberlman  wrote:
> > No, no.
> > I need to store the matrix and dual array is ideal for this would come
> > up.
> > The problem is that the matrix will grow in size, thousands of entries
> > only on i, and where that same number of j.
> > create table is not an option.
>
> > only if the matrix transform and drive the table. and my question is,
> > if you can not define arrays in the model, how can I convert a
> > matrix.
> > example is the matrix
> > a   b   c   d  e
> > 1   2   3   4  5
> > 11 22 33 44 55
> > converted into
> > a 1
> > a 11
> > b 2
> > b 22
> > c 3
> > c 33
> > d 4
> > d 44
> > e 5
> > e 55
>
> > this is for example, how do I implement this in the model? course in
> > the class will have to use functions, but is it possible?
>
> > On 8 апр, 01:28, pmains  wrote:
> >> If there is no Django model field for this, then one option would be
> >> to create your own model field (http://docs.djangoproject.com/en/dev/
> >> howto/custom-model-fields/). Of course, it would not be compatible
> >> with most SQL Database types.
>
> >> Of course, it may be easier to just rethink your data model. Would it
> >> be possible to create one or more additional tables to avoid using an
> >> unusual DB construct like a 2D array?
>
> >> Could you explain the problem in a little more detail? Saying that you
> >> want a 2-dimensional array is very abstract, but if we understand what
> >> problem you are trying to solve, what data you are attempting to
> >> model, it will be easier to give you useful suggestions.
>
> > double array that I want to keep count, it is ideally suited for the
> > incidence matrix of the graph.
> > required to store the connection to the knowledge base of question-
> > answering system.
> > which will lie on j IDs leading questions, and i will lie on
> > identifiers answers emerging from a set of leading questions.
> > and a double array is an ideal way to store data.
> > but I probably need to write your own model of the array for django in
> > this case, it is the only big problem at this time.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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