Re: explanation of: {{ action.action_time|date:_("DATETIME_FORMAT") }}

2009-08-18 Thread Ali Rıza Keleş

Please look up at the top of your codes, i think you'll see something
like this:

from django.utils.translation import ugettext_lazy as _

That's it!..

--
Ali Rıza

On Tue, 2009-08-18 at 15:08 -0700, Margie Roginski wrote:
> I was trying to figure out how to run the date filter, using
> SETTINGS.DATETIME_FORMAT as an argument.
> 
> When I grepped in the admin app I found this in object_history.html:
> 
> {{ action.action_time|date:_("DATETIME_FORMAT") }}
> 
> Can anyone give me a pointer as to how this works?  What is '_' in
> this case, and where is it defined?  I see {% load il8n %}, but it is
> very hard to grep for '_', can seem to see where it is being defined
> there.
> 
> Margie
> 
> 
> > 


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



Form upload passed to ftp method

2009-08-18 Thread Jonathan

I am trying to write a view that will take a file uploaded via form,
pass it to an ftp method and save it on an ftp server.  However I am
running into problems when with the file object that gets passed to
the ftp method.

This is my view:

def order_prints(request, object_id):
p = get_object_or_404(Project, pk=object_id)
d = datetime.now()

def ftp_upload(file, ftp):
CONTENT_TYPES = ['text']
t = file.content_type.split('/')[0]
if t in CONTENT_TYPES:
ftp.storlines("STOR", file, open(file))
else:
ftp.storbinary("STOR", file, open(file, "rb"), 1024)

if not request.method =="POST":
form = ReproOrderForm()
return render_to_response(
'projects/printorderform.html',
{'form': form, "p": p},
context_instance = RequestContext(request, object_id),
)

form = ReproOrderForm(request.POST, request.FILES)
if not form.is_valid():
pass

if form.is_valid():
file = request.FILES["file"]
filename = file.name
description = request.POST["description"]
delivery = request.POST["delivery"]
reprofirm = request.POST["reprofirm"]
due_by = request.POST["due_by"]
rf = ReproFirm.objects.get(id=reprofirm)
ftp = ftplib.FTP(rf.ftp_server, rf.ftp_username, 
rf.ftp_password)
ftp_upload(file, ftp)
f = ReproOrder(project=p, user=request.user, filename=filename,
reprofirm=reprofirm, due_by=due_by,
pub_date=datetime.now())
f.save()
ftp.quit()
return HttpResponseRedirect('/projects/%s/' % object_id)

So when I run this, I get:

Exception Value: coercing to Unicode: need string or buffer,
InMemoryUploadedFile found

Which leads me to believe that I need to modify the file object before
I pass it to the ftp method.  Unfortunately, I am stuck.  Any pointers?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Transactions in Django

2009-08-18 Thread Lokesh Maremalla
It seems that we have to mention both the calls (commit & rollback) for
every @transaction.commit_manually decorator. One single function call won't
be sufficient to perform the operation.

On Tue, Aug 18, 2009 at 11:08 PM, Lokesh  wrote:

>
> Hi,
>
> Verified the flow of statements for the posted code. Still the problem
> exists.
>
> Code works fine when I handled the transactions in general functions
> but not with the views.
>
> Could someone please clarify me on these
>
> 1. Can I use the transaction decorators(@transaction.commit_manually)
> for the views?
> 2. Do I need to do any further settings in settings file before using
> the transactions?
> 3. As per the Doc link "http://docs.djangoproject.com/en/dev/topics/db/
> transactions/#topics-db-transactions"
> we can use the transaction
> decorators in views but, I am not able to achieve the output . Please
> correct me if I missing anything.
>
> Thanks for your time.
>
> Regards,
> Lokesh
>
> On Aug 18, 8:07 pm, TiNo  wrote:
> > On Tue, Aug 18, 2009 at 16:19, Lokesh  wrote:
> >
> > > Hi,
> >
> > > Unable to perform rollback the transactions. Ended up with the
> > > following error
> > > "Transaction managed block ended with pending COMMIT/ROLLBACK"
> >
> > > Can I rollback the db changes even if the code doesn't raise any
> > > excceptions?
> >
> > > Here is the code:
> > > from django.db import transaction
> > > @transaction.commit_manually
> > > def view(request):
> > >if request.method== "POST" :
> > >print "in post"
> > >new_user = User.objects.create_user(username="testing",
> > > email="l...@lokesh.com", password="lokesh")
> > >print "return value new user = %s" % new_user
> > >transaction.rollback()
> > >return render_to_response("templates/listuser.html",
> > >  context_instance=RequestContext
> > > (request))
> > >else:
> > >print "in else"
> > >return render_to_response("templates/listu.html",
> > >  context_instance=RequestContext
> > > (request))
> >
> > You probably get this message when you are in the else block. There your
> > method ends without a commit() or rollback(), so django complains :D
> >
>


-- 
Thanks & Regards,
Lokesh.
lokeshmarema...@gmail.com

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



Re: render_to_response fails with TemplateSyntaxError: too many values to unpack

2009-08-18 Thread girzel
On Wed, Aug 19, 2009 at 8:30 AM, Janne Peltola wrote:

>
> Template rendering fails when both form data and a tuple are passed to
> render_to_response.
>
> Python: 2.6.2; Django: 1.1; Environment: Windows + built-in dev server
>
> I use the standard django.contrib.auth.models.User and .Group models.
>
> View:
>
> class FuksiForm(forms.Form):
>ryhmat = forms.ModelChoiceField(queryset=Group.objects.none(),
> empty_label = "Ei saapunut")
>
>def __init__ (self, qset):
>super(FuksiForm, self).__init__(qset)
>self.fields["ryhmat"].queryset = qset


Janne, I was able to recreate your error with a test app, and made it go
away by *not* passing qset to the super call to __init__ (which is not
expecting a qset argument).


>
>
> def fuksit(request, ohjelma_id):
>if request.method == 'POST': # If the form has been submitted...
>form = FuksiForm(request.POST) # A form bound to the POST
> data
>if form.is_valid(): # All validation rules pass
>msg = 'meh'
>return HttpResponse(msg)
>
>else:
>users =
> User.objects.filter(ryhma__nimi__startswith=ohjelma_id)
>
>groups = Group.objects.filter(name__startswith=ohjelma_id)
>
>form = FuksiForm(qset = groups)
>d = {'form': form, 'pf': users}
>
>
> Template:
>
> 
> {% for u in pf %}
>
>{{ u.first_name }} {{ u.last_name }}
>{{ u.username }}
>{{ form.ryhmat.errors }}  for="id_ryhmat">Ryhma
> {{ form.ryhmat }}
>
> {% endfor %}
> 


I would also expect that instantiating a single form and then repeating it
for each user in users may cause you difficulties when you start submitting
those forms, but I'm not sure about that...

Hope that helps,
Eric


>
>
> This produces: http://users.tkk.fi/jjpelto3/exception.html
>
> When either form or pf are removed from the dictionary, the program
> works fine. However, everything seems to be fine until
> render_to_response when I do debugging in the shell.
>
> I suspect a bug in the rendering handler, since people on #django were
> unable to help either. There are no documented similar cases.
>
> I am utterly perplexed. Please help. :)
>
> >
>

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



Error in setting up psycopg2

2009-08-18 Thread Simon Lee

I am trying to set up a simple test website in the Apache Server that
comes with OSX 10.5.8 and continuously ran into errors that
complainted about not able to import something in pscycopg2. The site
works if I ran with the django development server. When I port to
Apache, it did not work. Can someone tell me what I am missing?



The set up is as followed:
Python
- version: 2.6
- installed location: /Library/Frameworks/Python.framework/Versions/
2.6/

Psycopg2
- version: 2.0.12
- installed location: /Library/Frameworks/Python.framework/Versions/
2.6/lib/python2.6/site-packages/psycopg2

Other installed components:
mod_wsgi-3.0c4



My test site stuff is in "/Users/myname/mysite3"

Inside "/Users/myname/mysite3", the following files and directories
exist:
- __init__.py
- manage.py
- settings.py
- urls.py
- apache (folder)
  - myapp.wsgi
- blog (django app folder)
  - __init__.py
  - models.py (empty)
  - views.py
- django (folder, symbolic link to the django directory)

--

The content of /mysite3/settings.py is as followed:
DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'djangodb'
DATABASE_USER = 'postgres'
DATABASE_PASSWORD = 'myname'
DATABASE_HOST = 'localhost'
DATABASE_PORT = '5432'

ROOT_URLCONF = 'mysite3.urls'

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite3.blog',
)

The rest of the settings are the default



The url address www.test-mysite.com is bind to /mysite3/apache/
myapp.wsgi with the following settings:

In "/etc/apache2/http.conf":
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

In "/private/etc/apache2/extra/httpd-vhosts.conf":

ServerName www.test-mysite.com
ServerAdmin webmas...@test-mysite.com
DocumentRoot "/Users/myname/wsgi/documents"
ServerAlias test-mysite.com
ErrorLog "/private/var/log/apache2/mysite.com-error_log"
CustomLog "/private/var/log/apache2/mysite.com-access_log" common


  Order allow,deny
  Allow from all



Order deny,allow
Allow from all


WSGIScriptAlias / /Users/myname/mysite3/apache/myapp.wsgi





The content of /mysite3/apache/myapp.wsgi is as followed:

import os, sys
sys.path.append('/Users/simonlee')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite3.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

---

When I entered www.test-mysite.com into the browser, it gave me the
following error message:

Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request

The following error was logged in my error log file:

[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=120): Exception occurred processing WSGI script '/Users/myname/
mysite3/apache/myapp.wsgi'.
[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1] Traceback (most
recent call last):
[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1]   File "/Users/
myname/mysite3/django/core/handlers/wsgi.py", line 239, in __call__
[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1]   File "/Users/
myname/mysite3/django/core/handlers/base.py", line 67, in get_response
[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1]   File "/Users/
myname/mysite3/django/contrib/sessions/middleware.py", line 9, in
process_request
[Wed Aug 19 11:00:26 2009] [error] [client 127.0.0.1] ImportError: No
module named db

--

I tried everything that I found on the web but nothing seems to work.
Any suggestion would be much appreciated.

Simon

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



Re: PIL & imagefield validation

2009-08-18 Thread Malcolm MacKinnon
For what it's worth, here's what helped me about a month ago. The PIL
installation process is a mess, and I had to follow these instructions, step
by step.
I think I've fixed the problem. It had to so with  PIL not being installed
correctly. Check out this link:
http://www.answermysearches.com/fixing-pil-ioerror-decoder-jpeg-not-available/320/
for
a possible solution. Now, jpeg images are uploaded and saved.

On Mon, Aug 17, 2009 at 11:24 AM, zayatzz  wrote:

>
> Hello
>
> On sunday i had problems with python when i installed stackless
> python. Now i have compiled and installed :
> setuptools & python-mysqldb and i got my django project up and running
> again. (i also reinstalled django-1.1),
> Then i compiled and installed, jpeg, freetyp2 and PIL. I also started
> using mod_wsgi instead of mod_python.
>
> But when uploading imagefield in form i  get validationerror:
> Upload a valid image. The file you uploaded was either not an image or
> a corrupted image.
>
> Searchmonkey shows that it comes from field.py imagefield validation.
> before raising this error it imports Image from PIL, opens file and
> verfies it. I tried importing PIL from python prompt manually - it
> worked just fine. Same with Image.open and Image.verify.
>
> So what could by causing this problem?
>
> Alan
> >
>

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



Re: PIL & imagefield validation

2009-08-18 Thread Michael
On Tue, Aug 18, 2009 at 4:44 PM, zayatzz  wrote:

>
> Buh... well instructions for installing & compiling ship with the
> software. Can you tell me how to uninstall those modules?
>

Not a clue. You can start in site-packages or go into the shell and
type import PIL PIL.__file__ to see where that file might be. You'll
also want to check anywhere in your sys path. I cannot take
responsibility if you break anything though.

I am grasping FYI. I really have no idea what is going on, nor have you
given too much information.

Sorry I can't be more helpful,

Michael

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



Re: Raw Strings with Variables

2009-08-18 Thread WilsonOfCanada

However, when I send the list over as a dictionary for HTML:

d["places"] = arrPlaces

return render_to_response('rentSearch.html', d)

the HTML using Django has:

{{ places }} but returns ['C:\\moo', 'C:\\supermoo']

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



render_to_response fails with TemplateSyntaxError: too many values to unpack

2009-08-18 Thread Janne Peltola

Template rendering fails when both form data and a tuple are passed to
render_to_response.

Python: 2.6.2; Django: 1.1; Environment: Windows + built-in dev server

I use the standard django.contrib.auth.models.User and .Group models.

View:

class FuksiForm(forms.Form):
ryhmat = forms.ModelChoiceField(queryset=Group.objects.none(),
empty_label = "Ei saapunut")

def __init__ (self, qset):
super(FuksiForm, self).__init__(qset)
self.fields["ryhmat"].queryset = qset

def fuksit(request, ohjelma_id):
if request.method == 'POST': # If the form has been submitted...
form = FuksiForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
msg = 'meh'
return HttpResponse(msg)

else:
users = User.objects.filter(ryhma__nimi__startswith=ohjelma_id)

groups = Group.objects.filter(name__startswith=ohjelma_id)

form = FuksiForm(qset = groups)
d = {'form': form, 'pf': users}


Template:


{% for u in pf %}

{{ u.first_name }} {{ u.last_name }}
{{ u.username }}
{{ form.ryhmat.errors }} Ryhma
{{ form.ryhmat }}

{% endfor %}


This produces: http://users.tkk.fi/jjpelto3/exception.html

When either form or pf are removed from the dictionary, the program
works fine. However, everything seems to be fine until
render_to_response when I do debugging in the shell.

I suspect a bug in the rendering handler, since people on #django were
unable to help either. There are no documented similar cases.

I am utterly perplexed. Please help. :)

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



Re: Database design question

2009-08-18 Thread ringemup


Well, I'm trying to implement parent / child aliases, but I'm running
into problems with class declaration order because I need to reference
the Alias class from within the Account class as well as referencing
Account from Alias for validation purposes -- and not just in
ForeignKey declarations and such.

Since one will always have to be declared before the other, is there
any way to do this?


On Aug 18, 7:02 pm, Joshua Russo  wrote:
> Yup, that could work too. Let me know what you end up with.
>
> On Tue, Aug 18, 2009 at 9:58 PM, ringemup  wrote:
>
> > Yes, I think that does make sense.  Thank you!
>
> > While pondering this, I also came up with a third option, which is to
> > make the alias data part of the Account model, and allow Accounts to
> > have parent accounts; then only accounts with no parents are permitted
> > to be assigned to users.  (Also prohibiting accounts with parents from
> > having children to prevent deeply nested trees.)  I suppose the same
> > could be done with the Aliases having parents / children instead of
> > the accounts, so as not to have to duplicate other account data.
>
> > On Aug 18, 6:30 pm, Joshua Russo  wrote:
> > > On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:
>
> > > > I have accounts that can have multiple aliases, but each account must
> > > > have a primary alias.  I can think of two ways to institute this, but
> > > > they both have problems:
>
> > > > 1) reference the primary alias from the account:
>
> > > > class Account(models.Model):
> > > >  ...
> > > >  primary_alias = models.OneToOneField('Alias',
> > > > related_name='accout_if_primary')
>
> > > > class Alias(models.Model):
> > > >  name = models.CharField(max_length=50, primary_key=True)
> > > >  account = models.ForeignKey(Account)
>
> > > > The trouble with this approach is that basically you can't create an
> > > > account without an alias, and you can't create an alias without an
> > > > account because of what amount to circular references, so you
> > > > essentially can't add any data.
>
> > > > 2) Assign primary status to the alias:
>
> > > > class Account(models.Model):
> > > >  ...
>
> > > > class Alias(models.Model):
> > > >  name = models.CharField(max_length=50, primary_key=True)
> > > >  account = models.ForeignKey(Account)
> > > >  is_primary = models.BooleanField(default=False)
>
> > > > The trouble here is that it is a real pain to enforce that each
> > > > account has a primary alias (in fact you have to initially create an
> > > > account with no aliases and then create aliases and add them to it).
> > > > Additionally, enforcing a limit on the number of aliases is
> > > > problematic.  Finally, even if you do enforce these constraints
> > > > programmatically, it doesn't seem to be feasible to relay error
> > > > messages to contrib.admin.
>
> > > > Has anyone else encountered this design problem, and how did you go
> > > > about addressing it?
>
> > > I have experienced this situation a couple of times and I would recommend
> > > the second option you discussed. Circular referenced like your first
> > option
> > > can become very problematic and are not recommended from a database
> > design
> > > perspective.
>
> > > What I would recommend is to create an Alias record automatically when a
> > new
> > > Account is created. You can do this in the save of the Account model or
> > with
> > > signals.
> >http://docs.djangoproject.com/en/dev/ref/models/instances/http://docs...
>
> > > Then in the save of the Alias you can manage the primary flag. I just
> > check
> > > to see if the current record being saved has primary set, if so then I
> > reset
> > > all others for (in your case) the account to not primary. The only other
> > > case is if the current alias isn't set as primary, check to see if there
> > are
> > > any primary aliases yet and if not automatically set the current one as
> > > primary.
>
> > > Ya, it's a little tricky but it's worth not having the headache of the
> > > circular reference.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and CouchDB

2009-08-18 Thread Russell Keith-Magee

On Tue, Aug 18, 2009 at 11:12 PM, sjtirtha wrote:
> Yes,
>
> I do have interest to help on Object non-Relational Mapper.
> Does Django has a kind of interfaces, where I can implement my own Object
> non-Relational Mapper and inject it to Django?

I don't want to seem rude, but this is one of those cases where if you
need to ask the question, you're probably not going to be able to do
it yourself. The interfaces aren't hard to find, and while some of the
internals are complex, the gross structure can be easily discovered
with a little bit of poking around.

Yes, the interfaces exist. No, they aren't documented - up till now,
they haven't needed to be documented. That's OK, though - this isn't
something that we expect most end-users to be concerned with. The
interfaces may also require some refinement and tweaking to suit the
particular needs of a particular non-relational store. The discussion
on django-dev is trying to establish what these modifications are.

If you still want to help out, start poking around the code and read
up on the history of discussion on django-dev.

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



Re: Why using ForeignKey and not OneToOne to extend the user profile?

2009-08-18 Thread Kenneth Gonsalves

On Tuesday 18 Aug 2009 7:27:58 pm Léon Dignòn wrote:
> Why should I use a ForeignKey if I want my user profile extended? If
> the reverse side will return a single object, I could spare a little
>
> bit of code, if I just write:
> >>> "User.objects.get(username='Leon').avatar"
>
> instead of
>
> >>> "u = User.objects.get(username='Leon')"
> >>> "UserProfileExtension.objects.get(user=u).avatar"

I think the reason is partially historical - at one stage the one2one field was 
going to be abolished and was quirky - so unique foreign key was a workaround. 
Possibly that does not hold now.
-- 
regards
kg
http://lawgon.livejournal.com

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



Re: Database design question

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:

>
> I have accounts that can have multiple aliases, but each account must
> have a primary alias.  I can think of two ways to institute this, but
> they both have problems:
>
> 1) reference the primary alias from the account:
>
> class Account(models.Model):
>  ...
>  primary_alias = models.OneToOneField('Alias',
> related_name='accout_if_primary')
>
> class Alias(models.Model):
>  name = models.CharField(max_length=50, primary_key=True)
>  account = models.ForeignKey(Account)
>
> The trouble with this approach is that basically you can't create an
> account without an alias, and you can't create an alias without an
> account because of what amount to circular references, so you
> essentially can't add any data.
>
> 2) Assign primary status to the alias:
>
> class Account(models.Model):
>  ...
>
> class Alias(models.Model):
>  name = models.CharField(max_length=50, primary_key=True)
>  account = models.ForeignKey(Account)
>  is_primary = models.BooleanField(default=False)
>
> The trouble here is that it is a real pain to enforce that each
> account has a primary alias (in fact you have to initially create an
> account with no aliases and then create aliases and add them to it).
> Additionally, enforcing a limit on the number of aliases is
> problematic.  Finally, even if you do enforce these constraints
> programmatically, it doesn't seem to be feasible to relay error
> messages to contrib.admin.
>
> Has anyone else encountered this design problem, and how did you go
> about addressing it?
>

I have experienced this situation a couple of times and I would recommend
the second option you discussed. Circular referenced like your first option
can become very problematic and are not recommended from a database design
perspective.

What I would recommend is to create an Alias record automatically when a new
Account is created. You can do this in the save of the Account model or with
signals.
http://docs.djangoproject.com/en/dev/ref/models/instances/
http://docs.djangoproject.com/en/dev/ref/signals/

Then in the save of the Alias you can manage the primary flag. I just check
to see if the current record being saved has primary set, if so then I reset
all others for (in your case) the account to not primary. The only other
case is if the current alias isn't set as primary, check to see if there are
any primary aliases yet and if not automatically set the current one as
primary.

Ya, it's a little tricky but it's worth not having the headache of the
circular reference.

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



Re: How do you remove a manytomany relationship in django?

2009-08-18 Thread Daniel Roseman

On Aug 18, 9:49 pm, Ray  wrote:
> I know in the backend, a manytomany relationship is essentially a join
> table, but there seems to be no easy way to delete relationships from
> it. The only remove option is made only for ForeignKey relationships.
> Is there a workaround? Why would django design a relationship that you
> can only add but not delete?

The wording in the documentation here:
http://docs.djangoproject.com/en/dev/ref/models/relations/
is potentially confusing. The top of the page clearly states that the
methods are available both for foreignkeys and many-to-many
relationships. However, remove() and clear() state that they are "only
available on ForeignKeys where null=True". I believe this should just
read "for FKs, these methods are only available where null=True" - in
other words, they are available as you would expect for ManyToMany.
--
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: explanation of: {{ action.action_time|date:_("DATETIME_FORMAT") }}

2009-08-18 Thread Ramiro Morales

On Tue, Aug 18, 2009 at 7:08 PM, Margie
Roginski wrote:
>
> I was trying to figure out how to run the date filter, using
> SETTINGS.DATETIME_FORMAT as an argument.
>
> When I grepped in the admin app I found this in object_history.html:
>
> {{ action.action_time|date:_("DATETIME_FORMAT") }}
>
> Can anyone give me a pointer as to how this works?  What is '_' in
> this case, and where is it defined?  I see {% load il8n %}, but it is
> very hard to grep for '_', can seem to see where it is being defined
> there.

Sure, the "DATETIME_FORMAT" literal is what we call a technical
message: A clever idea to give translators a way to determine
a few local-dependant info bits (usually date/time output formatting)
using the same infrastructure and tools used for translations
(hence the _()):

http://docs.djangoproject.com/en/dev/topics/i18n/#id2

(last item in the list).

If I understand things correctly, if/when Marc's GSoC work on this
front gets merged, in 1.2 this will be replaced by similar but
more explicit ways to specify the same info.

HTH

-- 
Ramiro Morales
http://rmorales.net

PyCon 2009 Argentina - Vie 4 y Sab 5 Setiembre
Buenos Aires, Argentina
http://ar.pycon.org/2009/about/

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



Re: i18n javascript problem

2009-08-18 Thread Antoni Aloy

2009/8/18 caiobos :
>
> Hello!
> My project is alredy working with i18n, but the i18n js doesnt work.
> I have created my dir locale at the root of the project, have run
> makemessages and it create the djangojs.po correcty. With compile
> messages I get the djangojs.mo ok.
> The problem is how i confgure it in URLconf, if i make:
>
> js_info_dict = {
>    'packages': ('project',),
> }
> urlpatterns += patterns('',
>    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
> js_info_dict),
> )
>
> It doesnt work, but if I do:
> js_info_dict = {
>    'packages': ('django.conf',),
> }
>
> I get the traduction from the django package(but I dont want it, I
> want my package).
> So how i get it? How can it works with my traduction?
>
> Thanks a lot.
> Caio
>
>
project is the name of your project, isn't it? You have to remember to
include the url for the translation javascript as 

the documentatios is well explained.


On the other hand, I have experienced some problems getting the
javascript keys from the templates. The workarround I have found is to
have all the javascript (or nearly all) in external js files, a best
practice anyway.


-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

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



Re: Database design question

2009-08-18 Thread Joshua Russo
Yup, that could work too. Let me know what you end up with.

On Tue, Aug 18, 2009 at 9:58 PM, ringemup  wrote:

>
>
> Yes, I think that does make sense.  Thank you!
>
> While pondering this, I also came up with a third option, which is to
> make the alias data part of the Account model, and allow Accounts to
> have parent accounts; then only accounts with no parents are permitted
> to be assigned to users.  (Also prohibiting accounts with parents from
> having children to prevent deeply nested trees.)  I suppose the same
> could be done with the Aliases having parents / children instead of
> the accounts, so as not to have to duplicate other account data.
>
>
> On Aug 18, 6:30 pm, Joshua Russo  wrote:
> > On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:
> >
> > > I have accounts that can have multiple aliases, but each account must
> > > have a primary alias.  I can think of two ways to institute this, but
> > > they both have problems:
> >
> > > 1) reference the primary alias from the account:
> >
> > > class Account(models.Model):
> > >  ...
> > >  primary_alias = models.OneToOneField('Alias',
> > > related_name='accout_if_primary')
> >
> > > class Alias(models.Model):
> > >  name = models.CharField(max_length=50, primary_key=True)
> > >  account = models.ForeignKey(Account)
> >
> > > The trouble with this approach is that basically you can't create an
> > > account without an alias, and you can't create an alias without an
> > > account because of what amount to circular references, so you
> > > essentially can't add any data.
> >
> > > 2) Assign primary status to the alias:
> >
> > > class Account(models.Model):
> > >  ...
> >
> > > class Alias(models.Model):
> > >  name = models.CharField(max_length=50, primary_key=True)
> > >  account = models.ForeignKey(Account)
> > >  is_primary = models.BooleanField(default=False)
> >
> > > The trouble here is that it is a real pain to enforce that each
> > > account has a primary alias (in fact you have to initially create an
> > > account with no aliases and then create aliases and add them to it).
> > > Additionally, enforcing a limit on the number of aliases is
> > > problematic.  Finally, even if you do enforce these constraints
> > > programmatically, it doesn't seem to be feasible to relay error
> > > messages to contrib.admin.
> >
> > > Has anyone else encountered this design problem, and how did you go
> > > about addressing it?
> >
> > I have experienced this situation a couple of times and I would recommend
> > the second option you discussed. Circular referenced like your first
> option
> > can become very problematic and are not recommended from a database
> design
> > perspective.
> >
> > What I would recommend is to create an Alias record automatically when a
> new
> > Account is created. You can do this in the save of the Account model or
> with
> > signals.
> http://docs.djangoproject.com/en/dev/ref/models/instances/http://docs.djangoproject.com/en/dev/ref/signals/
> >
> > Then in the save of the Alias you can manage the primary flag. I just
> check
> > to see if the current record being saved has primary set, if so then I
> reset
> > all others for (in your case) the account to not primary. The only other
> > case is if the current alias isn't set as primary, check to see if there
> are
> > any primary aliases yet and if not automatically set the current one as
> > primary.
> >
> > Ya, it's a little tricky but it's worth not having the headache of the
> > circular reference.
> >
>

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



Re: How do you remove a manytomany relationship in django?

2009-08-18 Thread Daniel Roseman

On Aug 18, 9:49 pm, Ray  wrote:
> I know in the backend, a manytomany relationship is essentially a join
> table, but there seems to be no easy way to delete relationships from
> it. The only remove option is made only for ForeignKey relationships.
> Is there a workaround? Why would django design a relationship that you
> can only add but not delete?

The wording in the documentation here:
http://docs.djangoproject.com/en/dev/ref/models/relations/
is potentially confusing. The top of the page clearly states that the
methods are available both for foreignkeys and many-to-many
relationships. However, remove() and clear() state that they are "only
available on ForeignKeys where null=True". I believe this should just
read "for FKs, these methods are only available where null=True" - in
other words, they are available as you would expect for ManyToMany.
--
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpages - what am I missing to make these work (advice, please)?

2009-08-18 Thread alain31

I just had the same problem, because my site.id was not 1 but 2 as I
discovered with
the shell...

On 18 août, 22:24, gegard  wrote:
> > I cannot get flatpages to work on my site
>
> ... which, I should have said, is in Django 1.1.
>
> Geoff
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem with "Cancel" button

2009-08-18 Thread David

Hello,

I have a "Cancel" button on one of my Webpages. The button sometimes
works as expected, sometimes it does not. After the button has been
clicked, it is supposed that the webpage is re-directed to another
page. However, this re-direction seems not work all the time.
Following is my script.

In my urls.py:


 (r'^cancel/$', cancel),
.

In my view.py:

def save_view(request):

if request.POST:
action = request.POST['action']

if action == 'Cancel':
url = '/cancel/'
#this_url = reverse('cancel')
#return HttpResponseRedirect(this_url)
return HttpResponseRedirect(url)

And my "cancel" view is really simple. It is

def cancel(request):
return render_to_response('cancel.html')


I even tried "reverse", however problem did not get fixed. (see the
commented code).

Anybody knows how to fix this?

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



Re: Using fixtures in tests

2009-08-18 Thread marekw2143

Yes, you're right. I just assumed that if the info about loading
initial_data is printed that there will be printed info for non-
initial-data fixtures too.

On Aug 17, 11:53 am, Karen Tracey  wrote:
> On Mon, Aug 17, 2009 at 11:10 AM, Marek Wawrzyczek 
> wrote:
>
>
>
>
>
> > Hi,
>
> > I've got an application called myapp
>
> > In the main folder of django project there is initial_data.json file
> > containing initial data for the application
> > I also have file "simplefix.json" situated in myapp/fixtures
> > containing initial data for tests
>
> > Then after calling: python manage.py test myapp:
>
> > the following output is shown:
>
> > (...creating tables and indexes)
>
> > Installing json fixture 'initial_data' from absolute path.
> > Installed 114 object(s) from 1 fixture(s)
> > hello
>
> > myapp/tests.py has the following content:
>
> > from django.test import TestCase
>
> > class SimpleTestCase(TestCase):
>
> >    fixtures = ['simplefix.json']
>
> >    def testOne(self):
> >        print 'hello'
>
> > How can I load database during tests from defined fixture? I tried
> > putting simplefix.json in myapp/ in main project folder, in fixtures
> > directory in main project folder and none of that worked
>
> What you have shown (with simplefix.json in your app's fixtures directory)
> should be working.  How are you determining that it isn't?  Note there is no
> feedback printed for non-initial-data fixtures loaded during testing, so you
> won't see a message for simplefix.json as you do for the initial data
> fixture.
>
> If you are determining that it isn't working because your test code can't
> access data that should have been loaded, then I'd suspect a typo in the
> file name somewhere.  Unfortunately there is also no feedback for this case,
> so double check that you've got the file with the right name, and specified
> the right name in the TestCase fixtures attribute.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to use inlineformset with a manytomany relationship

2009-08-18 Thread Andew Gee

Hi,

Is there a way to create an inlineformset for two models with
manytomany relationship. I have created:

class Person(models.Model):
  name = models.CharField
  phone= models.ManyToMany(Phone)

class Phone(models.Model):
 PHONE_CHOICES(('H','Home'),('W",'Work'),('M','Mobile'))
 phone= models.CharField(max_length=10)
 phoneType = models.CharField(max_length=1,
choices=PHONE_CHOICES)

In my view I have
 PhoneFormSet = inlineformset_factory(Person, Phone)

but when I access the view I get the following error
  has no foreignkey to 

Is there something I have missed or do I need to setup my models
differently?

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



explanation of: {{ action.action_time|date:_("DATETIME_FORMAT") }}

2009-08-18 Thread Margie Roginski

I was trying to figure out how to run the date filter, using
SETTINGS.DATETIME_FORMAT as an argument.

When I grepped in the admin app I found this in object_history.html:

{{ action.action_time|date:_("DATETIME_FORMAT") }}

Can anyone give me a pointer as to how this works?  What is '_' in
this case, and where is it defined?  I see {% load il8n %}, but it is
very hard to grep for '_', can seem to see where it is being defined
there.

Margie


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



Re: error message in admin

2009-08-18 Thread Marek Palatinus

On Tue, Aug 18, 2009 at 4:45 PM, Marek Palatinus wrote:
> On Tue, Aug 18, 2009 at 4:36 PM, Joshua Russo wrote:
>> On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus  wrote:
>>>
>>> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo
>>> wrote:
>>> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus 
>>> > wrote:
>>> >>
>>> >> Hello,
>>> >>
>>> >> Im doing some validation in ModelAdmin.save_model(). I can cancel
>>> >> operation (just dont call parent method), but I also need to show some
>>> >> error message to user. Im able to call self.message_user() and show
>>> >> INFO message, but how to send ERROR message and maybe show form back
>>> >> and force user to correct inputs?
>>> >>
>>> >> I need validation on level of whole formset, not on field level, so I
>>> >> cannot use some custom field to achieve that.
>>> >
>>> > What you want is to override the ModelAdmin.form with a custom form and
>>> > handle the clean_xxx() methods there. Django form validation is done in
>>> > the
>>> > form objects/classes.
>>> > Create a ModelForm
>>> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then
>>> > set
>>> > your ModelAdmin.form to your new ModelForm.
>>> >
>>>
>>> Joshua, thanks a lot!
>>>
>>> to others: there also exists clean() which have available all fields
>>> from form at one place.

Im sending working code for others:

class SlugModelForm(ModelForm):
def clean_slug(self, *args):
if not self.instance.allow_slug_slashes and
self.data['slug'].find('/') != -1:
msg = _("Slash '/' is not allowed here.")
self.errors['slug'] = ErrorList([msg])
return self.data['slug']

class BaseModuleAdmin(admin.ModelAdmin):
list_editable = ('enabled',)
exclude = ('site', )
form = SlugModelForm
 
Im using slug as universal identifier across tens modules inside
application, but in some rare cases I want to allow slashes inside
slugs (=full urls). Construction above is logic for showing error
message to user, when he write slash to module's slug,  which have
disabled this feature.

Regards,
Marek

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



Re: Database design question

2009-08-18 Thread ringemup


Yes, I think that does make sense.  Thank you!

While pondering this, I also came up with a third option, which is to
make the alias data part of the Account model, and allow Accounts to
have parent accounts; then only accounts with no parents are permitted
to be assigned to users.  (Also prohibiting accounts with parents from
having children to prevent deeply nested trees.)  I suppose the same
could be done with the Aliases having parents / children instead of
the accounts, so as not to have to duplicate other account data.


On Aug 18, 6:30 pm, Joshua Russo  wrote:
> On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:
>
> > I have accounts that can have multiple aliases, but each account must
> > have a primary alias.  I can think of two ways to institute this, but
> > they both have problems:
>
> > 1) reference the primary alias from the account:
>
> > class Account(models.Model):
> >  ...
> >  primary_alias = models.OneToOneField('Alias',
> > related_name='accout_if_primary')
>
> > class Alias(models.Model):
> >  name = models.CharField(max_length=50, primary_key=True)
> >  account = models.ForeignKey(Account)
>
> > The trouble with this approach is that basically you can't create an
> > account without an alias, and you can't create an alias without an
> > account because of what amount to circular references, so you
> > essentially can't add any data.
>
> > 2) Assign primary status to the alias:
>
> > class Account(models.Model):
> >  ...
>
> > class Alias(models.Model):
> >  name = models.CharField(max_length=50, primary_key=True)
> >  account = models.ForeignKey(Account)
> >  is_primary = models.BooleanField(default=False)
>
> > The trouble here is that it is a real pain to enforce that each
> > account has a primary alias (in fact you have to initially create an
> > account with no aliases and then create aliases and add them to it).
> > Additionally, enforcing a limit on the number of aliases is
> > problematic.  Finally, even if you do enforce these constraints
> > programmatically, it doesn't seem to be feasible to relay error
> > messages to contrib.admin.
>
> > Has anyone else encountered this design problem, and how did you go
> > about addressing it?
>
> I have experienced this situation a couple of times and I would recommend
> the second option you discussed. Circular referenced like your first option
> can become very problematic and are not recommended from a database design
> perspective.
>
> What I would recommend is to create an Alias record automatically when a new
> Account is created. You can do this in the save of the Account model or with
> signals.http://docs.djangoproject.com/en/dev/ref/models/instances/http://docs.djangoproject.com/en/dev/ref/signals/
>
> Then in the save of the Alias you can manage the primary flag. I just check
> to see if the current record being saved has primary set, if so then I reset
> all others for (in your case) the account to not primary. The only other
> case is if the current alias isn't set as primary, check to see if there are
> any primary aliases yet and if not automatically set the current one as
> primary.
>
> Ya, it's a little tricky but it's worth not having the headache of the
> circular reference.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to access ForeignKey models properties?

2009-08-18 Thread onoxo

this is my model.py:

class Event(models.Model):
title = models.CharField('Event Name', max_length=300)
photo_set = models.ForeignKey(PhotoSet, blank=True, null=True)

class PhotoSet(models.Model):
title = models.CharField(max_length=300)
slug = models.CharField(max_length=300)


and this is my views.py

def getProgrammAsXML(request):
entries = Event.objects.filter(start_time__year=2009)
for item in entries:
print item.title
print item.photo_set
# this one gets the error:
print item.photo_set.title

i'm getting this error when i try to access item.photo_set.title.
'NoneType' object has no attribute 'title'

when i try item.photo_set, then i get the name of that object so i
think that reference to object is ok...
what am i doing wrong here? or do i have to do that some other way?

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



How do you remove a manytomany relationship in django?

2009-08-18 Thread Ray

I know in the backend, a manytomany relationship is essentially a join
table, but there seems to be no easy way to delete relationships from
it. The only remove option is made only for ForeignKey relationships.
Is there a workaround? Why would django design a relationship that you
can only add but not delete?

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



Re: PIL & imagefield validation

2009-08-18 Thread zayatzz

Buh... well instructions for installing & compiling ship with the
software. Can you tell me how to uninstall those modules?

Alan.

On Aug 18, 11:40 pm, Michael  wrote:
> On Tue, Aug 18, 2009 at 4:37 PM, zayatzz  wrote:
>
> > Nobody knows? Any wild guesses? Cause im all out of ideas.
>
> > Alan.
>
> > On Aug 17, 9:24 pm, zayatzz  wrote:
> > > Hello
>
> > > On sunday i had problems with python when i installed stackless
> > > python. Now i have compiled and installed :
> > > setuptools & python-mysqldb and i got my django project up and running
> > > again. (i also reinstalled django-1.1),
> > > Then i compiled and installed, jpeg, freetyp2 and PIL. I also started
> > > using mod_wsgi instead of mod_python.
>
> > > But when uploading imagefield in form i  get validationerror:
> > > Upload a valid image. The file you uploaded was either not an image or
> > > a corrupted image.
>
> > > Searchmonkey shows that it comes from field.py imagefield validation.
> > > before raising this error it imports Image from PIL, opens file and
> > > verfies it. I tried importing PIL from python prompt manually - it
> > > worked just fine. Same with Image.open and Image.verify.
>
> > > So what could by causing this problem?
>
> > > Alan
>
> Unistall PIL. Make sure you can't import PIL or Image, Reinstall PIL. I had
> a similar issue recently and that fixed it. Also all the supporting
> libraries. PIL has some really strange pathing and Django relies on just
> one, so if you messed it up, things won't work.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Check server type at runtime?

2009-08-18 Thread ringemup

Is there any way to check at runtime whether Django is running on the
development server?

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



Database design question

2009-08-18 Thread ringemup

I have accounts that can have multiple aliases, but each account must
have a primary alias.  I can think of two ways to institute this, but
they both have problems:

1) reference the primary alias from the account:

class Account(models.Model):
  ...
  primary_alias = models.OneToOneField('Alias',
related_name='accout_if_primary')

class Alias(models.Model):
  name = models.CharField(max_length=50, primary_key=True)
  account = models.ForeignKey(Account)

The trouble with this approach is that basically you can't create an
account without an alias, and you can't create an alias without an
account because of what amount to circular references, so you
essentially can't add any data.

2) Assign primary status to the alias:

class Account(models.Model):
  ...

class Alias(models.Model):
  name = models.CharField(max_length=50, primary_key=True)
  account = models.ForeignKey(Account)
  is_primary = models.BooleanField(default=False)

The trouble here is that it is a real pain to enforce that each
account has a primary alias (in fact you have to initially create an
account with no aliases and then create aliases and add them to it).
Additionally, enforcing a limit on the number of aliases is
problematic.  Finally, even if you do enforce these constraints
programmatically, it doesn't seem to be feasible to relay error
messages to contrib.admin.

Has anyone else encountered this design problem, and how did you go
about addressing it?

Thanks!


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



Multiple pagination on a sinle page.

2009-08-18 Thread Sonal Breed

Hi all,

In my application, I want to have pagination for multiple objects
(Friends, Stories) on a single page. Problem is if I click next on one
of the paginated objects, all the paginated objects on the page move
to next page. How do I accomplish individual pagination on a single
page for multiple objects.


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



Re: PIL & imagefield validation

2009-08-18 Thread Michael
On Tue, Aug 18, 2009 at 4:37 PM, zayatzz  wrote:

>
> Nobody knows? Any wild guesses? Cause im all out of ideas.
>
> Alan.
>
> On Aug 17, 9:24 pm, zayatzz  wrote:
> > Hello
> >
> > On sunday i had problems with python when i installed stackless
> > python. Now i have compiled and installed :
> > setuptools & python-mysqldb and i got my django project up and running
> > again. (i also reinstalled django-1.1),
> > Then i compiled and installed, jpeg, freetyp2 and PIL. I also started
> > using mod_wsgi instead of mod_python.
> >
> > But when uploading imagefield in form i  get validationerror:
> > Upload a valid image. The file you uploaded was either not an image or
> > a corrupted image.
> >
> > Searchmonkey shows that it comes from field.py imagefield validation.
> > before raising this error it imports Image from PIL, opens file and
> > verfies it. I tried importing PIL from python prompt manually - it
> > worked just fine. Same with Image.open and Image.verify.
> >
> > So what could by causing this problem?
> >
> > Alan


Unistall PIL. Make sure you can't import PIL or Image, Reinstall PIL. I had
a similar issue recently and that fixed it. Also all the supporting
libraries. PIL has some really strange pathing and Django relies on just
one, so if you messed it up, things won't work.

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



Re: PIL & imagefield validation

2009-08-18 Thread zayatzz

Nobody knows? Any wild guesses? Cause im all out of ideas.

Alan.

On Aug 17, 9:24 pm, zayatzz  wrote:
> Hello
>
> On sunday i had problems with python when i installed stackless
> python. Now i have compiled and installed :
> setuptools & python-mysqldb and i got my django project up and running
> again. (i also reinstalled django-1.1),
> Then i compiled and installed, jpeg, freetyp2 and PIL. I also started
> using mod_wsgi instead of mod_python.
>
> But when uploading imagefield in form i  get validationerror:
> Upload a valid image. The file you uploaded was either not an image or
> a corrupted image.
>
> Searchmonkey shows that it comes from field.py imagefield validation.
> before raising this error it imports Image from PIL, opens file and
> verfies it. I tried importing PIL from python prompt manually - it
> worked just fine. Same with Image.open and Image.verify.
>
> So what could by causing this problem?
>
> Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpages - what am I missing to make these work (advice, please)?

2009-08-18 Thread gegard

> I cannot get flatpages to work on my site
... which, I should have said, is in Django 1.1.

Geoff

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



Re: Creating apps that can be easily migrated to subdirectories

2009-08-18 Thread Javier Guerra

On Tue, Aug 18, 2009 at 1:14 PM, Sydney Weidman wrote:
>
> On Aug 18, 11:57 am, Javier Guerra  wrote:
>> On Tue, Aug 18, 2009 at 11:49 AM, Sydney Weidman wrote:
>> > I'm moving some Django applications that used to be served from the
>> > root of the site to a sub-URL like /apps. Do I have to change every
>> > template that contains a reference to /app1/blah to /apps/app1/blah in
>> > every template? Is there a centralized/better/prescribed way to do
>> > this?

it's there in Django 1.1:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls
and http://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces

for previous releases, i think there's a non-pretty way to do it with
{%url ...%}, but if not, i'd try either a custom template tag, or
maybe stuffing a simple dict/function in the context would at least
centralize the problem.

but are you going to change the URL to the admin app?

-- 
Javier

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



Re: Get results from query depending on another query

2009-08-18 Thread Jonas Obrist

course = Course.objects.filter(group__user=request.user)


Chris McComas wrote:
> I have a model that has a FK to django.contrib.auth.models Group. I
> run a query that gets all the groups that a user is a member of:
>
> groups = Group.objects.filter(user=request.user)
>
> Then I want to run a query for that model that gets and entries in
> that model where the group FK is one of the groups in the groups
> query. So like:
>
> course = Course.objects.filter(group=groups)
>
> How can I do 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get results from query depending on another query

2009-08-18 Thread Daniel Roseman

On Aug 18, 8:28 pm, Chris McComas  wrote:
> I have a model that has a FK to django.contrib.auth.models Group. I
> run a query that gets all the groups that a user is a member of:
>
> groups = Group.objects.filter(user=request.user)
>
> Then I want to run a query for that model that gets and entries in
> that model where the group FK is one of the groups in the groups
> query. So like:
>
> course = Course.objects.filter(group=groups)
>
> How can I do this?

Like this:

course = Course.objects.filter(group__in=groups)

However, you can do the whole thing in one query:

course = Course.objects.filter(group__user=request.user)

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



Re: template syntax

2009-08-18 Thread Margie

I would convert your dictionary to a list of tuples.  IE, in your
views.py code

studentTuples = [(student, dictionary.student.id) for student in
students]

Now in your template, to print out lines containing:
 student name: student id

you can do this:

{% for studentTuple in studentTuples %}
  {{studentTuple.0}} {{studentTuple.1}}
{% endfor %}


  Margie

On Aug 18, 8:48 am, elminio  wrote:
> I iterate through all students and have distionary containing students
> ids as key and for example grade as a value. I pass this dictionary to
> the view and then while iterating through all students I though that
> it would be simple to get appropriate value for current student. I
> dont know how I could make it simplier in template :/ If You think so
> maybe any ideas? but please with sample code
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Get results from query depending on another query

2009-08-18 Thread Chris McComas

I have a model that has a FK to django.contrib.auth.models Group. I
run a query that gets all the groups that a user is a member of:

groups = Group.objects.filter(user=request.user)

Then I want to run a query for that model that gets and entries in
that model where the group FK is one of the groups in the groups
query. So like:

course = Course.objects.filter(group=groups)

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



Re: Exception in transaction block hidden by "InternalError: transaction aborted ..." exception

2009-08-18 Thread Darren

any thoughts on this?

thanks,
darren

On Aug 17, 2:57 pm, Darren  wrote:
> Hi
>
> My app saves data in a method with "@transaction.commit_manually".
>
> My code had a bug - a field in a model was the wrong datatype for what
> was passed in, so I got a DataError exception back.
>
> However, the only exception that was displayed to me was
> "psycopg2.InternalError: current transaction is aborted, commands
> ignored until end of transaction block".
>
> I had to comment out "@transaction.commit_manually" in order to get
> the real DataError exception to show.
>
> My code looks like this:
>
>     @transaction.commit_manually
>     def save(self):
>         try:
>             # save data here
>         except BaseException as e:
>             traceback.print_exc()       # prints
> psycopg2.InternalError traceback
>             transaction.rollback()
>         else:
>             transaction.commit()
>
> I'm sure there's a way to get the original, DataError, exception...
> can anyone help?
>
> Thanks,
> Darren
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Why using ForeignKey and not OneToOne to extend the user profile?

2009-08-18 Thread Alex Gaynor

On Tue, Aug 18, 2009 at 8:57 AM, Léon Dignòn wrote:
>
> Hello,
>
> in the authentication documentation is written that the user profile
> should be extended with a foreign key.
>
> - 
> http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
>
> "If you'd like to store additional information related to your users,
> Django provides a method to specify a site-specific related model --
> termed a "user profile" -- for this purpose.
>
> To make use of this feature, define a model with fields for the
> additional information you'd like to store […] and also add a
> ForeignKey from your model to the User model, specified with
> unique=True to ensure only one instance of your model can be created
> for each User."
>
>
>
> If you look at the model documentation you can find this extract from
> the text.
>
> - http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields
>
> "A one-to-one relationship. Conceptually, this is similar to a
> ForeignKey with unique=True, but the 'reverse' side of the relation
> will directly return a single object.
>
> This is most useful as the primary key of a model which "extends"
> another model in some way […]"
>
>
>
> Why should I use a ForeignKey if I want my user profile extended? If
> the reverse side will return a single object, I could spare a little
> bit of code, if I just write:
 "User.objects.get(username='Leon').avatar"
> instead of
 "u = User.objects.get(username='Leon')"
 "UserProfileExtension.objects.get(user=u).avatar"
>
>
>
> Comments are welcome!
>
> -ld
> >
>

Personally I always use a 1-1 field, for both the reasons you mention,
and some automatic caching stuff I have only works automatically with
1-1 fields :)

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



Re: Problem installing Django 1.1 on XP

2009-08-18 Thread Alex Gaynor

2009/8/18 Nikola Smiljanić :
>
> I installed Django 1.1 on my Windows 7 machine with 64bit Python 2.6.2
> without any problems, but now I tried to install it on Windows XP with
> Python 2.6.2 and here is what I get:
>
> D:\Django-1.1>python setup.py install
> Traceback (most recent call last):
>  File "setup.py", line 69, in 
>    version = __import__('django').get_version()
>  File "D:\Django-1.1\django\__init__.py", line 12, in get_version
>    from django.utils.version import get_svn_revision
>  File "D:\Django-1.1\django\utils\__init__.py", line 1
>    Django-1.1/of the Lawrence Journal-World newspaper in Lawrence,
> Kansas.
>                           ^
> SyntaxError: invalid syntax
>
> Any ideas?
>
> >
>

Your download got messed up somehow, that content does'nt exist in
django/utils/__init__.py, I'd try redownloading and unpacking.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



Re: Creating apps that can be easily migrated to subdirectories

2009-08-18 Thread Sydney Weidman

On Aug 18, 11:57 am, Javier Guerra  wrote:
> On Tue, Aug 18, 2009 at 11:49 AM, Sydney Weidman wrote:
> > I'm moving some Django applications that used to be served from the
> > root of the site to a sub-URL like /apps. Do I have to change every
> > template that contains a reference to /app1/blah to /apps/app1/blah in
> > every template? Is there a centralized/better/prescribed way to do
> > this?
>
> there shouldn't be any URL inthe templates, either use {% url ... %}
> for linking to views, or {{MEDIA_URL}}/relative/path for media
> content.
>
> --
> Javier

Thanks for the suggestion. That does seem like the right way to do
things and it does work for most of my links. However, when I have a
view defined in my urls that I would like to link to the admin
interface like so:

from django.contrib import admin
...
(r'^admin/(.*)', admin.site.root),

if I try putting a tag in like:

Admin

Django complains that there is no reverse match because the matching
view has parameters and I'm not passing the url tag any arguments. How
would I pass the (.*) group using the url template tag? Or should I be
passing something else?

Thanks again for your help.

- syd


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



i18n javascript problem

2009-08-18 Thread caiobos

Hello!
My project is alredy working with i18n, but the i18n js doesnt work.
I have created my dir locale at the root of the project, have run
makemessages and it create the djangojs.po correcty. With compile
messages I get the djangojs.mo ok.
The problem is how i confgure it in URLconf, if i make:

js_info_dict = {
'packages': ('project',),
}
urlpatterns += patterns('',
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
js_info_dict),
)

It doesnt work, but if I do:
js_info_dict = {
'packages': ('django.conf',),
}

I get the traduction from the django package(but I dont want it, I
want my package).
So how i get it? How can it works with my traduction?

Thanks a lot.
Caio


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



Re: Transactions in Django

2009-08-18 Thread Lokesh

Hi,

Verified the flow of statements for the posted code. Still the problem
exists.

Code works fine when I handled the transactions in general functions
but not with the views.

Could someone please clarify me on these

1. Can I use the transaction decorators(@transaction.commit_manually)
for the views?
2. Do I need to do any further settings in settings file before using
the transactions?
3. As per the Doc link "http://docs.djangoproject.com/en/dev/topics/db/
transactions/#topics-db-transactions" we can use the transaction
decorators in views but, I am not able to achieve the output . Please
correct me if I missing anything.

Thanks for your time.

Regards,
Lokesh

On Aug 18, 8:07 pm, TiNo  wrote:
> On Tue, Aug 18, 2009 at 16:19, Lokesh  wrote:
>
> > Hi,
>
> > Unable to perform rollback the transactions. Ended up with the
> > following error
> > "Transaction managed block ended with pending COMMIT/ROLLBACK"
>
> > Can I rollback the db changes even if the code doesn't raise any
> > excceptions?
>
> > Here is the code:
> > from django.db import transaction
> > @transaction.commit_manually
> > def view(request):
> >    if request.method== "POST" :
> >        print "in post"
> >        new_user = User.objects.create_user(username="testing",
> > email="l...@lokesh.com", password="lokesh")
> >        print "return value new user = %s" % new_user
> >        transaction.rollback()
> >        return render_to_response("templates/listuser.html",
> >                                      context_instance=RequestContext
> > (request))
> >    else:
> >        print "in else"
> >        return render_to_response("templates/listu.html",
> >                                  context_instance=RequestContext
> > (request))
>
> You probably get this message when you are in the else block. There your
> method ends without a commit() or rollback(), so django complains :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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Flatpages - what am I missing to make these work (advice, please)?

2009-08-18 Thread gegard

I cannot get flatpages to work on my site, although I have done all
that I can see in the documentation, and would like guidance.

I give a 6-step short description of what I've done and what happened,
in case anyone recognizes a glaring mistake or lack in what I've done.
Step 6 is it just 'not working'. I can get static pages working Ok.

Thank you for any help that you can give me.

Regards,
Geoff

1) Create settings for flatpages in settings.py

settings.py
---

...
SITE_ID = 1
...

MIDDLEWARE_CLASSES = (
...
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

INSTALLED_APPS = (
...
'django.contrib.sites',
'django.contrib.flatpages',
)

2) Create a template for flatpages in flatpages/default.html

templates/flatpages/default.html

http://www.w3.org/TR/REC-html40/loose.dtd;>

  
 {{ flatpage.title }} 
  
  
 {{ flatpage.content }} 
  


3) Create a path for flatpages in urls.py
(this is not specified in the documentation but would seem to be
needed as shown in the cwiw site.
I've tried it with and without, and the without just means that all
other paths are tried first during DEBUG)

urls.py
---
urlpatterns = patterns('',
...
(r'', include('django.contrib.flatpages.urls')),
)

4) Create a flatpage in the admin console

browse to:
  http://mysite/admin/flatpages/flatpage/1/

create
  URL: /info/
  Title: Information
  Content: Some Info

and
  Sites: mysite

5) Test that an arbitrary URL creates a 404.

browse to:
  http://mysite/in/
I get a genuine 404 error. In DEBUG mode it says "No FlatPage
matches the given query."

6) Test that the info URL creates works (IT DOESN'T!)

browse to:
  http://mysite/info/
I again get a genuine 404 error. In DEBUG mode it again says "No
FlatPage matches the given query."
I would expect that my flatpage would now show.



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



Re: Creating apps that can be easily migrated to subdirectories

2009-08-18 Thread Javier Guerra

On Tue, Aug 18, 2009 at 11:49 AM, Sydney Weidman wrote:
> I'm moving some Django applications that used to be served from the
> root of the site to a sub-URL like /apps. Do I have to change every
> template that contains a reference to /app1/blah to /apps/app1/blah in
> every template? Is there a centralized/better/prescribed way to do
> this?

there shouldn't be any URL inthe templates, either use {% url ... %}
for linking to views, or {{MEDIA_URL}}/relative/path for media
content.

-- 
Javier

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



Creating apps that can be easily migrated to subdirectories

2009-08-18 Thread Sydney Weidman

Hi!

I'm moving some Django applications that used to be served from the
root of the site to a sub-URL like /apps. Do I have to change every
template that contains a reference to /app1/blah to /apps/app1/blah in
every template? Is there a centralized/better/prescribed way to do
this?

- Syd

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



Re: template syntax

2009-08-18 Thread mettwoch

See this:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

There's an example of iterating over key, value pairs

Marc

On Aug 18, 5:48 pm, elminio  wrote:
> I iterate through all students and have distionary containing students
> ids as key and for example grade as a value. I pass this dictionary to
> the view and then while iterating through all students I though that
> it would be simple to get appropriate value for current student. I
> dont know how I could make it simplier in template :/ If You think so
> maybe any ideas? but please with sample code
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: site and username unique together

2009-08-18 Thread Fredde

I have solved this. If anyone is interested, this is how I did...
Instead of having username and site as two separate fields, I combined
them. This will make the username unique for each site. The username
field will look like this ":". Since this isn't
very nice to display I wrote some methods in the User proxy SiteUser
that will extract the username and the site.

Here are the classes i wrote to make this work:

class SiteUserManager(UserManager):
def create_user(self, username, email, password=None):
return super(SiteUserManager, self).create_user('%d:%s' %
(settings.SITE_ID, username), email, password)

def get_query_set(self):
return super(SiteUserManager, self).get_query_set().filter
(username__startswith = '%d:' % settings.SITE_ID)

class SiteUser(User):
objects = SiteUserManager()

def get_site_id(self):
return int(self.username.split(USERNAME_SEPARATOR, 1)[0])

def get_site(self):
return Site.objects.get(pk = self.get_site_id())

def get_local_username(self):
return self.username.split(':', 1)[1]

def get_global_username(self):
return '%...@%s' % (self.get_local_username(), 
self.get_site().domain)

def __unicode__(self):
return self.get_global_username()

class Meta:
proxy = True

class Backend(ModelBackend):
def authenticate(self, username=None, password=None):
try:
user = User.objects.get(username='%d:%s' % 
(settings.SITE_ID,
username))
if user.check_password(password):
return user
except User.DoesNotExist:
return None

def get_user(self, user_id):
try:
return SiteUser.objects.get(pk=user_id)
except SiteUser.DoesNotExist:
return None

/Fredrik

On 17 Aug, 10:31, Fredde  wrote:
> Hi!
>
> I am working on a project with multiple sites and are using the
> contrib.site app to separate them from eachother. The number of sites
> will be high and changing often, so I don't want to modify the Apache
> config and create a new VirtualHost/Location for each new site. I have
> solved this by writing a middleware that parses the url and changes
> the settings.SITE_ID based on that. Similar 
> tohttp://www.djangosnippets.org/snippets/1099/
>
> I'm planing to use contrib.auth for user login on each site, but I
> want to make the username unique together with the site. I tried
> something like this:
>
> class SiteUser(User):
>         site = ForeignKey(Site)
>
>         class Meta:
>                 unique_together = (('site', 'username'),)
>
> But this will not work so well, since the username field has to be in
> the same model as the unique_together meta attribute, and the username
> field is still unique across the sites. So I tried to make the User
> model abstract and removing the unique flag:
>
> User._meta.abstract = True
> User._meta.get_field('username')._unique = False
>
> But now the ManyToMany fields in User will complain that it's a
> abstract class, wich makes sence. And I guess you shouldn't modify en
> existing model anyway. Is it possible to do what I am trying to do
> without writing a new auth app? Are there any other problems with the
> multi site approach?
>
> /Fredrik
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



OK to put app_directories before filesystem template loader?

2009-08-18 Thread ke1g

I find myself wanting to place the app_directories template loader
before the filesystem template loader in
settings.TEMPLATE_LOADERS, so that when I clone an app to, among other
things, modifiy its templates, I get mine instead of the default.

I'm wondering if anyone knows of reasons not to change the order?

[I'm actually using pinax, but this seems like a general Django
question.]

Bill

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



Re: template syntax

2009-08-18 Thread elminio

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



Re: template syntax

2009-08-18 Thread elminio

I iterate through all students and have distionary containing students
ids as key and for example grade as a value. I pass this dictionary to
the view and then while iterating through all students I though that
it would be simple to get appropriate value for current student. I
dont know how I could make it simplier in template :/ If You think so
maybe any ideas? but please with sample code


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



Re: template syntax

2009-08-18 Thread Michael
On Tue, Aug 18, 2009 at 11:16 AM, elminio  wrote:

>
> Thanks for such a quick reply
>
> and what is i iterate through for example students
>
> {% for student in students %}
>  {{ dictionary.student.id }}
> {% endfor %}
>
> I want to have student.id as a key and in the way I did it above it
> doesnt work because dicttionary wants student as a key :)
>
> thanks for help


Not recommended: You either have to write a template tag (check google it
has been done before).

Recommended: Make the changes in the view and pass it to the templates
prepared. That is what views are for. This kind of logic should stay out of
the templates.

Hope that helps,

Michael

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



Re: Seamless integration of customized forms in my project

2009-08-18 Thread Thierry

You sold me on "this construction is unclear" and the "happy
debugging" is scaringly convincing.
I will stick with different classnames approach, with maintenance and
portability (reusing apps) in mind.
Thank you for your 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OT: Drawing lines in the browser

2009-08-18 Thread Chris McCormick

On Tue, Aug 18, 2009 at 07:40:00AM -0700, Ian McDowall wrote:
> On Aug 18, 8:53 am, Thomas Guettler  wrote:
> > Hi,
> >
> > this is offtopic: How can you draw lines in a (django) web application?
> >
> > I think you need to use flash or java to do it. I googled for it, but found 
> > only beta
> > quality projects.
> >
> > Has anyone experience with this?
> 
> Depends on what type of line.  It is technically possible to use SVG.
> You can embed an SVG image in HTML and then draw lines (or circles
> etc.) in it. The SVG is just XMl and Django's templating works fine
> for that.  There are some technical catches about the type of the
> document and namespaces but I can provide a worked example. The
> drawback is that not all browsers support SVG well. This appears to
> work well in recent versions of Firefox but not well in IE.

Even better is the  element and it has good coverage on recent browsers
with the help of explorercanvas  for
Internet Explorer, although the drawing must be done dynamically with
javascript.   is an example of a library which
uses the  element to draw graphs.

Chris.

---
http://mccormick.cx

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



Re: template syntax

2009-08-18 Thread elminio

Thanks for such a quick reply

and what is i iterate through for example students

{% for student in students %}
  {{ dictionary.student.id }}
{% endfor %}

I want to have student.id as a key and in the way I did it above it
doesnt work because dicttionary wants student as a key :)

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



Re: Django and CouchDB

2009-08-18 Thread sjtirtha
Yes,

I do have interest to help on Object non-Relational Mapper.
Does Django has a kind of interfaces, where I can implement my own Object
non-Relational Mapper and inject it to Django?

Regards,
Steve



On Tue, Aug 18, 2009 at 3:17 PM, Russell Keith-Magee  wrote:

>
> On Tue, Aug 18, 2009 at 7:40 PM, Joshua Partogi
> wrote:
> >
> >
> > On Tue, Aug 18, 2009 at 8:17 PM, sjtirtha  wrote:
> >>
> >> Hi,
> >>
> >> i found some Python API to access couchDB.
> >> I'm asking here for experience.
> >
> > Django model is really tight to RDBMS. You are going to have a hard time
> > making django model work with non-RDBMS
>
> This isn't entirely correct. Django's ORM is in no way tied to
> relational databases. Look at the public API for the ORM - the
> interface that is provided is object based, not relational. You don't
> call "SELECT * FROM table", you call Model.objects.all()
>
> Django's ORM doesn't currently have any non-relational
> implementations, so in practice, for newcomers (such as the original
> poster), this means that it isn't currently trivial to use a
> non-relational store with Django's ORM.
>
> The key word in that sentence is _currently_. The ORM has been
> specifically designed to accommodate non-relational data stores. There
> have been several recent discussions on adding a Google AppEngine or
> Amazon SimpleDB 'database backend'. CouchDB could also fall under this
> umbrella.
>
> Building these backends won't be trivial, and may require some minor
> modifications to the existing Django code, but they are certainly
> possible in the gross framework that has been provided. If you want to
> help out Django and you have interest and expertise in a particular
> non-relational datastore, this would be a great way to get involved.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Ordering a django change list page via jQuery?

2009-08-18 Thread Niall Mccormack
I would like to be able to reorder lists of Models via a jQuery script.

I already have reordering within inLines on the Model update page, but  
I'd like to add it to the change_list page aswell?

Is this possible? I'm using Django 1.1 so have access to action  
sheets, if that makes things easier...

Any information would be appreciated.



Cheers

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



Re: Transactions in Django

2009-08-18 Thread TiNo
On Tue, Aug 18, 2009 at 16:19, Lokesh  wrote:

>
> Hi,
>
> Unable to perform rollback the transactions. Ended up with the
> following error
> "Transaction managed block ended with pending COMMIT/ROLLBACK"
>
> Can I rollback the db changes even if the code doesn't raise any
> excceptions?
>
> Here is the code:
> from django.db import transaction
> @transaction.commit_manually
> def view(request):
>if request.method== "POST" :
>print "in post"
>new_user = User.objects.create_user(username="testing",
> email="l...@lokesh.com", password="lokesh")
>print "return value new user = %s" % new_user
>transaction.rollback()
>return render_to_response("templates/listuser.html",
>  context_instance=RequestContext
> (request))
>else:
>print "in else"
>return render_to_response("templates/listu.html",
>  context_instance=RequestContext
> (request))


You probably get this message when you are in the else block. There your
method ends without a commit() or rollback(), so django complains :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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template syntax

2009-08-18 Thread mettwoch

Use:

{% name_of_your_dictionary.key_you_want_to_access %}

Remember that templates use the '.' (dot) to access keys, attributes,
indexes ...

Kindly Yours
Marc

On Aug 18, 4:55 pm, elminio  wrote:
> Hi,
>
> Im passing to the template dictionary and I would like to get by key
> to the value of that dictionary and if the key doesnt exist in it
> insert blank field into html
>
> thank You very much for help
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template syntax

2009-08-18 Thread Michael
On Tue, Aug 18, 2009 at 10:55 AM, elminio  wrote:

>
> Hi,
>
> Im passing to the template dictionary and I would like to get by key
> to the value of that dictionary and if the key doesnt exist in it
> insert blank field into html
>
> thank You very much for help



The template language is purposefully simple. So try:

{{ dict.key }}

This will give you the value if the key exists and by default will be blank
if it does not.

Simple,

Hope that helps,

Michael

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



template syntax

2009-08-18 Thread elminio

Hi,

Im passing to the template dictionary and I would like to get by key
to the value of that dictionary and if the key doesnt exist in it
insert blank field into html

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



Problem with Django/Jython and Postgres backend

2009-08-18 Thread Brandon Taylor

Hi everyone,

I'm getting this exception with the latest Django-Jython and
Jython2.5:

wks-btaylor:test_project btaylor$ jython manage.py runserver
Validating models...
Unhandled exception in thread started by 
Traceback (most recent call last):
  File "/Users/btaylor/jython2.5.0/Lib/site-packages/django/core/
management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
  File "/Users/btaylor/jython2.5.0/Lib/site-packages/django/core/
management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
  File "/Users/btaylor/jython2.5.0/Lib/site-packages/django/core/
management/validation.py", line 22, in get_validation_errors
from django.db import models, connection
  File "/Users/btaylor/jython2.5.0/Lib/site-packages/django/db/
__init__.py", line 50, in 
connection = backend.DatabaseWrapper({
  File "/Users/btaylor/jython2.5.0/Lib/site-packages/doj/backends/
zxjdbc/postgresql/base.py", line 54, in __init__
self.client = DatabaseClient()
TypeError: __init__() takes exactly 2 arguments (1 given)


Anyone able to get Django running on Jython on OS X 10.5.x ? I'd
appreciate some pointers!
TIA,
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Aggregation on expressions

2009-08-18 Thread mettwoch

The whole thing behind that it is: I'm developing an invoicing/
inventory application and I run into performance problems that might
require using raw SQL and admittedly I'm not an SQL expert and I
dislike the idea of doing so.

I thought more on an approach of "SQL view" than denormalisation or a
pseudoattribute. I've also read a little about F() and the extra()
function to inject SQL, but that's to be done for every query while
I'm more interested on having the calculation (business rule) defined
once in the model.

I could also access a view in PostGres where 'total' is defined as
'price*quantity' but as far as I know (and my SQL knowledge is rather
poor), views are not updatable.

The example was a quick and dirty draft and should read:

from django.db import models

class InvoiceLine(models.Model):
price = models.DecimalField()
quantity = models.DecimalField()
total = models.ExpressionField('price * quantity')

The SQL looks something like this for InvoiceLine.objects.all():

SELECT price, quantity, price * quantity AS total FROM invoiceline;

Marc

On Aug 18, 4:08 pm, Russell Keith-Magee 
wrote:
> On Tue, Aug 18, 2009 at 9:21 PM, mettwoch wrote:
>
> > Hi,
>
> > Some time ago I asked if there is a way to aggregate on an expression
> > and I was told that it's not possible at the moment. I managed to use
> > a mix of aggregation and some arithmetics to reduce processing time by
> > a factor of 20 in critical areas of my application. While doing so, I
> > felt that some kind of a new field-type could be useful and perhaps
> > lead to make aggregation on expressions possible. Something like an
> > ExpressionField (or SQLField or whatever ...) that does some SQL
> > processing directly on the database and that could be used like this:
>
> > class InvoiceLine():
> >    price = DecimalField()
> >    quantity = DecimalField()
> >    total = ExpressionField('price*quantity')
> >    invoice = ForeignKey(Invoice)
>
> > One could do:
>
> > invoice.invoiceline_set.objects.aggregate(Sum('total'))
>
> > Is this a reasonable approach
>
> At this point you haven't really explained what the approach _is_. To
> pick just one aspect - what does "ExpressionField" do?. It could be a
> denormalization - that is, a column that is stored in the database
> that is automatically updated with as 'price' and 'quantity' are
> updated. It could be part of turning InvoiceLine from a SQL table to a
> SQL view. It could be a pseudoattribute that only appears in Django's
> ORM and is computed on request from the current value of price and
> quantity.
>
> You haven't really given a proposal. You've given a example usage of
> an API which is either ambiguous or buggy - InvoiceLine doesn't have a
> base class; the 'objects' manager is being used on a related _set
> object for no apparent reason. You also haven't explained how that API
> you have proposed would be interpreted as SQL.
>
> > and is it perhaps already in the
> > timeline?
>
> The idea of adding denormalization fields has been discussed in the
> past. Some code has been written, but nothing has been committed to
> trunk. Search the archives for the discussion.
>
> There have also been proposals to allow F() objects inside aggregates,
> and to allow annotation of data that isn't an aggregate onto a model.
> I suspect these may be closer to what you are trying to achieve. These
> ideas have open tickets, but I'm not aware of anyone actively working
> on these topics at the moment.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: error message in admin

2009-08-18 Thread Marek Palatinus

On Tue, Aug 18, 2009 at 4:36 PM, Joshua Russo wrote:
> On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus  wrote:
>>
>> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo
>> wrote:
>> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus 
>> > wrote:
>> >>
>> >> Hello,
>> >>
>> >> Im doing some validation in ModelAdmin.save_model(). I can cancel
>> >> operation (just dont call parent method), but I also need to show some
>> >> error message to user. Im able to call self.message_user() and show
>> >> INFO message, but how to send ERROR message and maybe show form back
>> >> and force user to correct inputs?
>> >>
>> >> I need validation on level of whole formset, not on field level, so I
>> >> cannot use some custom field to achieve that.
>> >
>> > What you want is to override the ModelAdmin.form with a custom form and
>> > handle the clean_xxx() methods there. Django form validation is done in
>> > the
>> > form objects/classes.
>> > Create a ModelForm
>> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then
>> > set
>> > your ModelAdmin.form to your new ModelForm.
>> >
>>
>> Joshua, thanks a lot!
>>
>> to others: there also exists clean() which have available all fields
>> from form at one place.
>
> I often also place checks in the save of a model (like you were doing) to
> help catch scenarios when using the models in your own code (outside of the
> admin app).

Yes, I know that and Im using model validation, but I need check human
input and print errors to admin interface. When I have validation only
in model, there is no chance to print error message (because it can be
called outside admin).

Marek

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



Re: OT: Drawing lines in the browser

2009-08-18 Thread Ian McDowall



On Aug 18, 8:53 am, Thomas Guettler  wrote:
> Hi,
>
> this is offtopic: How can you draw lines in a (django) web application?
>
> I think you need to use flash or java to do it. I googled for it, but found 
> only beta
> quality projects.
>
> Has anyone experience with this?
>
>   Thomas
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de

Depends on what type of line.  It is technically possible to use SVG.
You can embed an SVG image in HTML and then draw lines (or circles
etc.) in it. The SVG is just XMl and Django's templating works fine
for that.  There are some technical catches about the type of the
document and namespaces but I can provide a worked example. The
drawback is that not all browsers support SVG well. This appears to
work well in recent versions of Firefox but not well in IE.

Ian McDowall

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



Re: The admin interface - this used to work?

2009-08-18 Thread Marek Palatinus

>  1. I have moved to the production server, and django is invoked with
> apache & mod_wsgi (previously used the dev server).

When using dev server, django serve all admin static files for you. Im
not absolutely sure, but when you switch from dev server to another
(im using fastcgi), you have to configure webserver to serve static
files instead of django _OR_ configure django to serve static files
(which have performance impact).

I solved the same issue before few days and because Im still in dev
phase, I added this line to urls.py to let django serve my static
files:
url(r'^admin-media/(?P.*)$', 'django.views.static.serve',
{'document_root': '/opt/django-1.1/django/contrib/admin/media'}),

You have to change admin-media to your MEDIA PATH and document root to
place, where you have admin media files.

Hope this helps.

Regards,
Marek

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



Re: The admin interface - this used to work?

2009-08-18 Thread Sean Kemplay

I had a similar problem after updating the django version.  I had custom
admin templates based on the previous version.  Copying the latest
versions accross fixed it for me.

Regards,
Sean

On Tue, 2009-08-18 at 07:18 -0700, Joakim Hove wrote:
> Hello,
> 
> I am slowly building up a site with django - it feels very good.
> 
> About two months ago I tried the admin interface; with nearly zero
> effort (basically uncomment a couple of lines from the default files)
> I got a very nice and functional interface up and running - great!
> 
> Now I have done some changes, and can not get the interface to work
> any longer. What I have done is:
> 
>   1. I have moved to the production server, and django is invoked with
> apache & mod_wsgi (previously used the dev server).
>   2. I have upgraded django to the latest svn release (I had latest
> svn in june as well).
>   3. I have not installed any admin.py files.
> 
> When I now go to the admin url I can log in with the django super user
> account, but:
> 
>   1. The interface is damn basic - maybe some stylesheets / templates
> are missing?
>   2. The interface does not seem to contain any information about my
> site anymore.
> 
> Any tips?
> 
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: error message in admin

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus  wrote:

>
> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo
> wrote:
> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus 
> wrote:
> >>
> >> Hello,
> >>
> >> Im doing some validation in ModelAdmin.save_model(). I can cancel
> >> operation (just dont call parent method), but I also need to show some
> >> error message to user. Im able to call self.message_user() and show
> >> INFO message, but how to send ERROR message and maybe show form back
> >> and force user to correct inputs?
> >>
> >> I need validation on level of whole formset, not on field level, so I
> >> cannot use some custom field to achieve that.
> >
> > What you want is to override the ModelAdmin.form with a custom form and
> > handle the clean_xxx() methods there. Django form validation is done in
> the
> > form objects/classes.
> > Create a ModelForm
> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then
> set
> > your ModelAdmin.form to your new ModelForm.
> >
>
> Joshua, thanks a lot!
>
> to others: there also exists clean() which have available all fields
> from form at one place.


I often also place checks in the save of a model (like you were doing) to
help catch scenarios when using the models in your own code (outside of the
admin app).

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



Re: Seamless integration of customized forms in my project

2009-08-18 Thread Marek Palatinus

On Tue, Aug 18, 2009 at 4:14 PM, Thierry wrote:
> Should I stick with custom class names and refer to them throughout my
> project instead?
> Thanks for any feedback,
> Thierry.
>

Hi,

from side of python syntax, it is possible. See this example:

mar...@kraksna:~/$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Test(object):
... def test1method(self):
... print "test1method"
...
>>> class Test(Test):
... def test2method(self):
... print "test2method"
...
>>> mytest = Test()
>>> mytest.test1method()
test1method
>>> mytest.test2method()
test2method

My opinion is that this construction is unclear and hard to read
(because other code readers expect, that SomeClass which they know has
common interface). You also have to import new class definition before
every attempt of class usage, because when not, python dont print any
warning/error, but maybe use generic class with old behaviour. Happy
debugging ;).

Regards,
Marek

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



Re: error message in admin

2009-08-18 Thread Marek Palatinus

On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo wrote:
> On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus  wrote:
>>
>> Hello,
>>
>> Im doing some validation in ModelAdmin.save_model(). I can cancel
>> operation (just dont call parent method), but I also need to show some
>> error message to user. Im able to call self.message_user() and show
>> INFO message, but how to send ERROR message and maybe show form back
>> and force user to correct inputs?
>>
>> I need validation on level of whole formset, not on field level, so I
>> cannot use some custom field to achieve that.
>
> What you want is to override the ModelAdmin.form with a custom form and
> handle the clean_xxx() methods there. Django form validation is done in the
> form objects/classes.
> Create a ModelForm
> (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then set
> your ModelAdmin.form to your new ModelForm.
>

Joshua, thanks a lot!

to others: there also exists clean() which have available all fields
from form at one place.

Regards,
Marek

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



Problem installing Django 1.1 on XP

2009-08-18 Thread Nikola Smiljanić

I installed Django 1.1 on my Windows 7 machine with 64bit Python 2.6.2
without any problems, but now I tried to install it on Windows XP with
Python 2.6.2 and here is what I get:

D:\Django-1.1>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 69, in 
version = __import__('django').get_version()
  File "D:\Django-1.1\django\__init__.py", line 12, in get_version
from django.utils.version import get_svn_revision
  File "D:\Django-1.1\django\utils\__init__.py", line 1
Django-1.1/of the Lawrence Journal-World newspaper in Lawrence,
Kansas.
   ^
SyntaxError: invalid syntax

Any ideas?

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



Transactions in Django

2009-08-18 Thread Lokesh

Hi,

Unable to perform rollback the transactions. Ended up with the
following error
"Transaction managed block ended with pending COMMIT/ROLLBACK"

Can I rollback the db changes even if the code doesn't raise any
excceptions?

Here is the code:
from django.db import transaction
@transaction.commit_manually
def view(request):
if request.method== "POST" :
print "in post"
new_user = User.objects.create_user(username="testing",
email="l...@lokesh.com", password="lokesh")
print "return value new user = %s" % new_user
transaction.rollback()
return render_to_response("templates/listuser.html",
  context_instance=RequestContext
(request))
else:
print "in else"
return render_to_response("templates/listu.html",
  context_instance=RequestContext
(request))


Thanks for your time.

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



The admin interface - this used to work?

2009-08-18 Thread Joakim Hove

Hello,

I am slowly building up a site with django - it feels very good.

About two months ago I tried the admin interface; with nearly zero
effort (basically uncomment a couple of lines from the default files)
I got a very nice and functional interface up and running - great!

Now I have done some changes, and can not get the interface to work
any longer. What I have done is:

  1. I have moved to the production server, and django is invoked with
apache & mod_wsgi (previously used the dev server).
  2. I have upgraded django to the latest svn release (I had latest
svn in june as well).
  3. I have not installed any admin.py files.

When I now go to the admin url I can log in with the django super user
account, but:

  1. The interface is damn basic - maybe some stylesheets / templates
are missing?
  2. The interface does not seem to contain any information about my
site anymore.

Any tips?

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



Seamless integration of customized forms in my project

2009-08-18 Thread Thierry

(Please excuse my meaningless title as English is not my natural
language).

I would like some advice on how pythonic/heretic my approach is.

What I am trying to do is:
- subclass standard Form class (e.g to add new rendering methods)
- subclass some fields and widgets (e.g to add custom CSS attributes)
- replace all import statements "from django import forms" with "from
my_project import forms"
And that's all! Class names referred in my project (Form, RadioSelect,
DateField...) should not change.

I came up with the following module excerpt (myproject/forms.py):
from django.forms import *
class Form(Form):
  def my_rendering_method(self):
(...)

See my issue? To guarantee transparency between my own custom 'forms'
module and the standard one, I am subclassing but keeping the same
name, though I am not sure whether this is sane or not in Python...

Should I stick with custom class names and refer to them throughout my
project instead?
Thanks for any feedback,
Thierry.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Aggregation on expressions

2009-08-18 Thread Russell Keith-Magee

On Tue, Aug 18, 2009 at 9:21 PM, mettwoch wrote:
>
> Hi,
>
> Some time ago I asked if there is a way to aggregate on an expression
> and I was told that it's not possible at the moment. I managed to use
> a mix of aggregation and some arithmetics to reduce processing time by
> a factor of 20 in critical areas of my application. While doing so, I
> felt that some kind of a new field-type could be useful and perhaps
> lead to make aggregation on expressions possible. Something like an
> ExpressionField (or SQLField or whatever ...) that does some SQL
> processing directly on the database and that could be used like this:
>
> class InvoiceLine():
>    price = DecimalField()
>    quantity = DecimalField()
>    total = ExpressionField('price*quantity')
>    invoice = ForeignKey(Invoice)
>
> One could do:
>
> invoice.invoiceline_set.objects.aggregate(Sum('total'))
>
> Is this a reasonable approach

At this point you haven't really explained what the approach _is_. To
pick just one aspect - what does "ExpressionField" do?. It could be a
denormalization - that is, a column that is stored in the database
that is automatically updated with as 'price' and 'quantity' are
updated. It could be part of turning InvoiceLine from a SQL table to a
SQL view. It could be a pseudoattribute that only appears in Django's
ORM and is computed on request from the current value of price and
quantity.

You haven't really given a proposal. You've given a example usage of
an API which is either ambiguous or buggy - InvoiceLine doesn't have a
base class; the 'objects' manager is being used on a related _set
object for no apparent reason. You also haven't explained how that API
you have proposed would be interpreted as SQL.

> and is it perhaps already in the
> timeline?

The idea of adding denormalization fields has been discussed in the
past. Some code has been written, but nothing has been committed to
trunk. Search the archives for the discussion.

There have also been proposals to allow F() objects inside aggregates,
and to allow annotation of data that isn't an aggregate onto a model.
I suspect these may be closer to what you are trying to achieve. These
ideas have open tickets, but I'm not aware of anyone actively working
on these topics at the moment.

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



Why using ForeignKey and not OneToOne to extend the user profile?

2009-08-18 Thread Léon Dignòn

Hello,

in the authentication documentation is written that the user profile
should be extended with a foreign key.

- 
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

"If you'd like to store additional information related to your users,
Django provides a method to specify a site-specific related model --
termed a "user profile" -- for this purpose.

To make use of this feature, define a model with fields for the
additional information you'd like to store […] and also add a
ForeignKey from your model to the User model, specified with
unique=True to ensure only one instance of your model can be created
for each User."



If you look at the model documentation you can find this extract from
the text.

- http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields

"A one-to-one relationship. Conceptually, this is similar to a
ForeignKey with unique=True, but the 'reverse' side of the relation
will directly return a single object.

This is most useful as the primary key of a model which "extends"
another model in some way […]"



Why should I use a ForeignKey if I want my user profile extended? If
the reverse side will return a single object, I could spare a little
bit of code, if I just write:
>>> "User.objects.get(username='Leon').avatar"
instead of
>>> "u = User.objects.get(username='Leon')"
>>> "UserProfileExtension.objects.get(user=u).avatar"



Comments are welcome!

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



RichTextEditor

2009-08-18 Thread chinny

hai,

can anyone sugget me how to work on RichTexEditor.

I actually i tried but couldn't get the excat thing what i want.
i have downloaded the richtext app from google and i put in my project
folder and i'm extending the fileds from there to my models.py

In my models.py

from richtext.fields import AdminRichTextField,RichTextField
from richtext.custom_widgets import RichTextWidget

Class newsarticle(models.Model):
 content=AdminRichTextField()

But this field looks like normal text area. And i did ntot install
Photolouge.
I need an editor in that i can put even the html code or i can upload
images. Where i need exactly like kuppu editor ( Plone Editor)

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



Re: programmatically changing language problem

2009-08-18 Thread stanleyxu2005

I have solved this problem myself.

I have to declare the following variable:
LANGUAGES = (
  ('de', 'German (Deutsch)'),
  ('en', 'English'),
)

And then include the middleware
"django.middleware.locale.LocaleMiddleware"



On Aug 18, 11:20 am, stanleyxu2005  wrote:
> Hi All,
>
> after reading the django documentation, I still have problem with
> changing a language.
> I have create two languages: en_US and de_DE
>
> If I declare LANGUAGE_CODE='de_DE' in settings.py (without the
> middleware django.middleware.locale.LocaleMiddleware), my project will
> be translated into German.
> if I declare LANGUAGE_CODE='en_EN' (or leave it undeclared), my
> project will be translated into English.
>
> Now, I try to change the language setting in index page.
> def index(request)
>   request.session['django_language') = "de_DE"
>   from django.conf import settings
>   settings.LANGUAGE_CODE = "de_DE"
>
>   C = Context()
>   C['am'] = _("AM")
>   # and so on
>   f = open('template/overview.tpl')
>   t = Template(f.read())
>   f.close()
>   return HttpResponse(t.render(C))
> # end-def
>
> However, the index page looks always in English.
>
> What is the problem? 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to extend Auth/User in admin view?

2009-08-18 Thread Léon Dignòn

Forget my previous post. Now that I got it working I have one more
question! (btw, I needed to restart the server for the changes to take
effect)

This is my code:

from django.contrib import admin
from myproject.myapp.models import Car, Manufacturer, UserProfile
from django.contrib.auth.admin import User, UserAdmin
from django.utils.translation import ugettext, ugettext_lazy as _

admin.site.register(Manufacturer)
admin.site.register(Car)

class UserProfileAdmin(UserAdmin):
list_display = ('username', 'email', 'first_name', 'last_name',
'is_staff')

admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)


I can add my UserProfile to the user admin form. But I'm not able to
add for example UserProfile.user_is_public to the list_display.

I get:
ImproperlyConfigured at /admin/auth/user/
UserProfileAdmin.list_display[5], 'user_is_public' is not a callable
or an attribute of 'UserProfileAdmin' or found in the model 'User'.


Please help :o)

-LD



On Aug 18, 11:16 am, Léon Dignòn  wrote:
> Hi Daniel,
>
> I have trouble doing this:
>
> 1. admin.site.unregister(User) does not remove User from the admin
> interface. It is still visible. I removed all code and used only this
> line and the import... line. Nothing happens.
>
> 2. Is this code correct?
>
> from django.contrib import admin
> from myproject.myapp.models import Car, Manufacturer, UserProfile
> #UserProfile ist the extended Profile
> from django.contrib.auth.admin import UserAdmin
>
> admin.site.register(Manufacturer)
> admin.site.register(Aeroplane)
>
> class MyUserAdmin(UserAdmin):
>     model = UserProfile
>
> try:
>     admin.site.unregister(User)
> except admin.sites.NotRegistered:
>     pass
> admin.site.register(User, MyUserAdmin)
>
> -LD
>
> On Aug 17, 10:04 am, Daniel Roseman  wrote:
>
>
>
> > On Aug 17, 8:06 am, Léon Dignòn  wrote:
>
> > > Hello,
>
> > > I use an extendedUserModel and like to display these fields in the
> > >adminview at Auth/User. Can anybody show me how this works?
>
> > > Thanks
>
> > > -LD
>
> > Create your ownadminclass for your extendedUsermodel, inheriting
> > from the one in contrib.auth.admin. Then unregister the default one
> > and register yours:
>
> > from django.contrib.auth.adminimport UserAdmin
>
> > class MyUserAdmin(UserAdmin(UserAdmin):
> >     extended attributes here ...
>
> > try:
> >    admin.site.unregister(User)
> > except exceptadmin.sites.NotRegistered:
> >     passadmin.site.register(User, MyUserAdmin)
>
> > --
> > DR.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Aggregation on expressions

2009-08-18 Thread mettwoch

Hi,

Some time ago I asked if there is a way to aggregate on an expression
and I was told that it's not possible at the moment. I managed to use
a mix of aggregation and some arithmetics to reduce processing time by
a factor of 20 in critical areas of my application. While doing so, I
felt that some kind of a new field-type could be useful and perhaps
lead to make aggregation on expressions possible. Something like an
ExpressionField (or SQLField or whatever ...) that does some SQL
processing directly on the database and that could be used like this:

class InvoiceLine():
price = DecimalField()
quantity = DecimalField()
total = ExpressionField('price*quantity')
invoice = ForeignKey(Invoice)

One could do:

invoice.invoiceline_set.objects.aggregate(Sum('total'))

Is this a reasonable approach and is it perhaps already in the
timeline?

Marc


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



Re: Django and CouchDB

2009-08-18 Thread Russell Keith-Magee

On Tue, Aug 18, 2009 at 7:40 PM, Joshua Partogi wrote:
>
>
> On Tue, Aug 18, 2009 at 8:17 PM, sjtirtha  wrote:
>>
>> Hi,
>>
>> i found some Python API to access couchDB.
>> I'm asking here for experience.
>
> Django model is really tight to RDBMS. You are going to have a hard time
> making django model work with non-RDBMS

This isn't entirely correct. Django's ORM is in no way tied to
relational databases. Look at the public API for the ORM - the
interface that is provided is object based, not relational. You don't
call "SELECT * FROM table", you call Model.objects.all()

Django's ORM doesn't currently have any non-relational
implementations, so in practice, for newcomers (such as the original
poster), this means that it isn't currently trivial to use a
non-relational store with Django's ORM.

The key word in that sentence is _currently_. The ORM has been
specifically designed to accommodate non-relational data stores. There
have been several recent discussions on adding a Google AppEngine or
Amazon SimpleDB 'database backend'. CouchDB could also fall under this
umbrella.

Building these backends won't be trivial, and may require some minor
modifications to the existing Django code, but they are certainly
possible in the gross framework that has been provided. If you want to
help out Django and you have interest and expertise in a particular
non-relational datastore, this would be a great way to get involved.

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



Re: Model instance refreshing

2009-08-18 Thread mettwoch

Oooh, obvious! It requires alot of changes, but I think I'll do it.

Thanks Colin

Marc

On Aug 17, 10:43 pm, Colin Bean  wrote:
> On Mon, Aug 17, 2009 at 1:31 PM, mettwoch wrote:
>
> > Hi,
>
> > I use a session to store several instances of different models coming
> > from a:
>
> > some_model.objects.get(pk = some_pk)
>
> > When the data in the db changes the model instances in the session
> > still contain the old data. What would be a good strategy to make
> > shure that all objects in a session get fresh data on every request?
>
> > Marc
>
> > PS: Hopefully going live in 2 weeks ... to be continued
>
> I would only store the PK in the session and use it to get a new
> instance of the model with every request.
>
> Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Clarification required on one-to-one save method

2009-08-18 Thread bvemu

Hi All


To maintain a 1-1 relation with User table I have defined the
following in my models


class UserDetails(models.Model):
user_id = models.OneToOneField(User, primary_key=True,
parent_link=True)
choices= models.PositiveSmallIntegerField(null=False,
blank=False, choices=menu_filler(choice_list))

My query is : Inorder to enforce/ensure that a one to one relation
w.r.t UserDetails/User records exists
which of the following is a better practise and why

1.) Override the Save method in Class UserDetails:
like

def save():
   #create the user
   #create the userdetails

2.) Write a method in extendedmanager of UserDetails
like

class MyManager()
   # create the user
   # create the record


class UserDetails():
objects=MyManager()


Thanks in advance

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



Re: Admin add / list / etc links broken?

2009-08-18 Thread ringemup

Ah - thank you!  I knew I was doing something stupid.

On Aug 17, 10:16 pm, Ramiro Morales  wrote:
> On Mon, Aug 17, 2009 at 8:39 PM, ringemup wrote:
>
> > I'm sure I'm doing something wrong, but I can't figure out what.  The
> > list, add, and change links on the admin index all point to the
> > correct URLs, but all URLs under /admin are returning the admin index
> > page rather than the appropriate views.
>
> > Using the following urls.py under Django 1.1:
>
> > from django.conf.urls.defaults import *
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns('',
>
> ># Uncomment the next line to enable the admin:
> >(r'^admin/(.*)', include(admin.site.urls)),
> > )
>
> > Interestingly, using admin.site.root instead of include
> > (admin.site.urls) works, but my understanding is that the older use is
> > now deprecated, so I'd like to get this working.
>
> > Any suggestions on what I've screwed up, or how to debug this?
>
> Thast's because you are mixing strategies for specifying the admin entry
> on the URL map. Compare the relevant highlighted lines in the urlpatterns
> variable assignment in the following documentation code excerpts:
>
> http://docs.djangoproject.com/en/1.0/intro/tutorial02/#activate-the-a...
> (Django < 
> 1.1)http://docs.djangoproject.com/en/dev/intro/tutorial02/#activate-the-a...
> (Django 1.1)
>
> --
> Ramiro Moraleshttp://rmorales.net
>
> PyCon 2009 Argentina - Vie 4 y Sab 5 Setiembre
> Buenos Aires, Argentinahttp://ar.pycon.org/2009/about/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and CouchDB

2009-08-18 Thread Sam Lai

Would be easy enough if you just wanted to use the routing, views and
template parts of Django though.

Sorry, no experience though something that I've been wanting to try
for a while. Unfortunately, the current project doesn't call for that
kind of db.

2009/8/18 Joshua Partogi :
>
>
> On Tue, Aug 18, 2009 at 8:17 PM, sjtirtha  wrote:
>>
>> Hi,
>>
>> i found some Python API to access couchDB.
>> I'm asking here for experience.
>
> Django model is really tight to RDBMS. You are going to have a hard time
> making django model work with non-RDBMS
>
>
>
> --
> http://blog.scrum8.com
> http://twitter.com/scrum8
>
> >
>

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



Re: Django and CouchDB

2009-08-18 Thread Joshua Partogi
On Tue, Aug 18, 2009 at 8:17 PM, sjtirtha  wrote:

> Hi,
>
> i found some Python API to access couchDB.
> I'm asking here for experience.
>

Django model is really tight to RDBMS. You are going to have a hard time
making django model work with non-RDBMS



-- 
http://blog.scrum8.com
http://twitter.com/scrum8

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



Re: model get_absolute_url strange behaviour

2009-08-18 Thread andreas schmid

Daniel Roseman wrote:
> On Aug 18, 11:08 am, andreas schmid  wrote:
>   
>> hi to all,
>>
>> i have a weird problem with my urls.
>>
>> my model has a get_absolute_url like this:
>>* def get_absolute_url(self):
>> return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*
>>
>> and the url conf is this one:
>>  *(r'^(?P\d{4})/(?P[-\w]+)/$',
>> 'myapp.views.projects.project_detail', ),
>> *
>> which works fine... my projects urlconf setup is:
>> *(r'^projects/', include('myapp.urls.projects')),
>>
>> *i set up a form template to add projects without touching the admin
>> interface which works fine too but when i save and it should direct to
>> the project detail view it sets up the url in the wrong way.
>>
>> *return HttpResponseRedirect(new_project.get_absolute_url())
>>
>> *the return above is in my add function but it redirects from
>> *http://mysite.com/add/*to *http://mysite.com/add/2009/slug/*which
>> obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
>> *which works.
>>
>> any help?
>> 
>
> The string returned from your get_absolute_url method would be
> something like "2009/slug/". Because it doesn't start with a slash,
> browsers interpret it as relative to the current URL, so if you start
> on "/add/" it will just add the slug on to that, ending up with "/add/
> 2009/slug/".
>
> Easy to fix - just make sure get_absolute_url starts with a slash:
> return "/%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )
>
>   
if i put the trailing slash it does not add the projects/ prefix i added
in the include of my projects urls.py ... the problem of the wrong
absolute url is only when i add or edit a project and it doesnt redirect
right... i postet it wrong before, it tryes to redirect at
http://127.0.0.1:8000/projects/add/2009/slug/ without trailing slash in
in the get_absolute_url but every other absolute url in the templates
works fine.
if i put the trailing slash the url is wrong everywhere and links to
http://127.0.0.1:8000/2009/slug/

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



Re: model get_absolute_url strange behaviour

2009-08-18 Thread Daniel Roseman

On Aug 18, 11:08 am, andreas schmid  wrote:
> hi to all,
>
> i have a weird problem with my urls.
>
> my model has a get_absolute_url like this:
>    * def get_absolute_url(self):
>         return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*
>
> and the url conf is this one:
>  *(r'^(?P\d{4})/(?P[-\w]+)/$',
> 'myapp.views.projects.project_detail', ),
> *
> which works fine... my projects urlconf setup is:
>     *(r'^projects/', include('myapp.urls.projects')),
>
> *i set up a form template to add projects without touching the admin
> interface which works fine too but when i save and it should direct to
> the project detail view it sets up the url in the wrong way.
>
> *return HttpResponseRedirect(new_project.get_absolute_url())
>
> *the return above is in my add function but it redirects from
> *http://mysite.com/add/*to *http://mysite.com/add/2009/slug/*which
> obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
> *which works.
>
> any help?

The string returned from your get_absolute_url method would be
something like "2009/slug/". Because it doesn't start with a slash,
browsers interpret it as relative to the current URL, so if you start
on "/add/" it will just add the slug on to that, ending up with "/add/
2009/slug/".

Easy to fix - just make sure get_absolute_url starts with a slash:
return "/%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )

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



Re: error message in admin

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus  wrote:

>
> Hello,
>
> Im doing some validation in ModelAdmin.save_model(). I can cancel
> operation (just dont call parent method), but I also need to show some
> error message to user. Im able to call self.message_user() and show
> INFO message, but how to send ERROR message and maybe show form back
> and force user to correct inputs?
>
> I need validation on level of whole formset, not on field level, so I
> cannot use some custom field to achieve that.
>

What you want is to override the ModelAdmin.form with a custom form and
handle the clean_xxx() methods there. Django form validation is done in the
form objects/classes.

Create a ModelForm (
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then set
your ModelAdmin.form to your new ModelForm.

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



Re: Django and CouchDB

2009-08-18 Thread sjtirtha
Hi,

i found some Python API to access couchDB.
I'm asking here for experience.

Regards,
Steve

On Tue, Aug 18, 2009 at 5:08 AM, 邓超  wrote:

> You can google it. I have read once, but forget the link address now.
>
> 2009/8/18 sjtirtha 
>
> Hi,
>>
>> can some body share about his experience using Django and CouchDB?
>> I found some python API that can be used to access CouchDB, which one is
>> the best and suitable to Django Framework.
>>
>> Regards,
>> STeve
>>
>>
>>
>
>
> --
> Deng Chao
>
> >
>

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



model get_absolute_url strange behaviour

2009-08-18 Thread andreas schmid

hi to all,

i have a weird problem with my urls.

my model has a get_absolute_url like this:
   * def get_absolute_url(self):
return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*

and the url conf is this one:
 *(r'^(?P\d{4})/(?P[-\w]+)/$',
'myapp.views.projects.project_detail', ),
*
which works fine... my projects urlconf setup is:
*(r'^projects/', include('myapp.urls.projects')),

*i set up a form template to add projects without touching the admin
interface which works fine too but when i save and it should direct to
the project detail view it sets up the url in the wrong way.

*return HttpResponseRedirect(new_project.get_absolute_url())

*the return above is in my add function but it redirects from
*http://mysite.com/add/* to *http://mysite.com/add/2009/slug/* which
obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
*which works.

any help?


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



error message in admin

2009-08-18 Thread Marek Palatinus

Hello,

Im doing some validation in ModelAdmin.save_model(). I can cancel
operation (just dont call parent method), but I also need to show some
error message to user. Im able to call self.message_user() and show
INFO message, but how to send ERROR message and maybe show form back
and force user to correct inputs?

I need validation on level of whole formset, not on field level, so I
cannot use some custom field to achieve that.

Thanks,
Marek

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



programmatically changing language problem

2009-08-18 Thread stanleyxu2005

Hi All,

after reading the django documentation, I still have problem with
changing a language.
I have create two languages: en_US and de_DE

If I declare LANGUAGE_CODE='de_DE' in settings.py (without the
middleware django.middleware.locale.LocaleMiddleware), my project will
be translated into German.
if I declare LANGUAGE_CODE='en_EN' (or leave it undeclared), my
project will be translated into English.

Now, I try to change the language setting in index page.
def index(request)
  request.session['django_language') = "de_DE"
  from django.conf import settings
  settings.LANGUAGE_CODE = "de_DE"

  C = Context()
  C['am'] = _("AM")
  # and so on
  f = open('template/overview.tpl')
  t = Template(f.read())
  f.close()
  return HttpResponse(t.render(C))
# end-def

However, the index page looks always in English.

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



Re: ways to implement a user - profile page

2009-08-18 Thread Berislav Lopac



On Aug 18, 2:49 am, Nicolas Aggelidis  wrote:
> Thank you for your comments!
>
> > First, there is no need to have the username in the URL if this page
> > is visible only to the logged-in user. Instead, use the request.user
> > object inside your view (and, if necessary, the template).
>
> The idea is that the profile page(what i have in my mind at least) is
> visible to all, but according to if you
> are logged in , it is your profile-home page. Or your friend's and you
> can leave comments,
> for example...

In that case it's best if you set two urls, one with the username for
everyone (loggedin users and others) and one without the username for
loggedinusers only.

> but then where do you use custom tags?

Tags and filters are used to display stuff, not to retrieve it. Think
of custom tags as custom functions for your templates -- when you need
to implement some element(s) on a number of views. Then you put that
element into a custom tag and call it whenever you need it. E.g. I
have implemented a navigation menu as a custom tag.

Note that in many cases custom tags are an overkill and you can
accomplish the same with a simple included template. But with tags you
can do a lot of logic-crunching behind the curtain, which you can0t
with included templates, so chose what fits your situation better.

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



Re: Logging mechanism in Django

2009-08-18 Thread slafs

Hi!

Found this about django-logging also...

http://ericholscher.com/blog/2008/aug/29/screencast-2-logging-fun-and-profit/

Regards

On Aug 18, 12:30 am, Rafael Ferreira  wrote:
> the problem is that logging to a file is not going to work in a multiprocess
> environment. I'm using the logging library configured to log to syslog with
> fcgi and it is working out quite well.
>
> On Mon, Aug 17, 2009 at 11:10 AM, Mike Ramirez  wrote:
> > On Monday 17 August 2009 10:24:18 am Lokesh Maremalla wrote:
> > > Hi,
>
> > > Included django-logging as described in the link.
>
> > > From the django-logging I can view the log messages on the screen at run
> > > time. But, I am not sure on saving the log messages from django-logging.
> > > Can I capture the log messages into my log file on a daily basis instead
> > of
> > > redirecting to screen.
>
> > > Regards,
> > > Lokesh
>
> > you would set up the file access similar to using the python logging module
> > [1]
>
> > import logging
> > logging.FileHandler('myfile')
>
> > Mike
>
> > [1]
>
> >http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Pytho...
>
> > This is also linked on django-logging's overview page.
>
> > --
> > "Hard work now leads to less work full stop"
>
> >        - Alan Cox
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OT: Drawing lines in the browser

2009-08-18 Thread Chris Withers

Thomas Guettler wrote:
> Hi,
> 
> this is offtopic: How can you draw lines in a (django) web application?
> 
> I think you need to use flash or java to do it. I googled for it, but found 
> only beta
> quality projects.
> 
> Has anyone experience with this?

Depends on why you want to draw lines... If it's for graphs and the 
like, just use matplotlib and generate the graphs on the server as .png 
or .pdf :-)

Chris

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

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



Re: How to extend Auth/User in admin view?

2009-08-18 Thread Léon Dignòn

Hi Daniel,

I have trouble doing this:

1. admin.site.unregister(User) does not remove User from the admin
interface. It is still visible. I removed all code and used only this
line and the import... line. Nothing happens.


2. Is this code correct?

from django.contrib import admin
from myproject.myapp.models import Car, Manufacturer, UserProfile
#UserProfile ist the extended Profile
from django.contrib.auth.admin import UserAdmin

admin.site.register(Manufacturer)
admin.site.register(Aeroplane)

class MyUserAdmin(UserAdmin):
model = UserProfile

try:
admin.site.unregister(User)
except admin.sites.NotRegistered:
pass
admin.site.register(User, MyUserAdmin)


-LD


On Aug 17, 10:04 am, Daniel Roseman  wrote:
> On Aug 17, 8:06 am, Léon Dignòn  wrote:
>
> > Hello,
>
> > I use an extendedUserModel and like to display these fields in the
> >adminview at Auth/User. Can anybody show me how this works?
>
> > Thanks
>
> > -LD
>
> Create your ownadminclass for your extendedUsermodel, inheriting
> from the one in contrib.auth.admin. Then unregister the default one
> and register yours:
>
> from django.contrib.auth.adminimport UserAdmin
>
> class MyUserAdmin(UserAdmin(UserAdmin):
>     extended attributes here ...
>
> try:
>    admin.site.unregister(User)
> except exceptadmin.sites.NotRegistered:
>     passadmin.site.register(User, MyUserAdmin)
>
> --
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django model register for admin section

2009-08-18 Thread vijay kumar
Hi,
   I tried it but ended up with some problem .
   Let me try it once again

with Thanks
Ajay

On Tue, Aug 18, 2009 at 1:59 PM, Alex Gaynor  wrote:

>
> On Tue, Aug 18, 2009 at 3:28 AM, ajay wrote:
> >
> > Hi ,
> >   To register model in admin section we need to Register individual
> > class
> >   Example:
> >  admin.site.register(Poll)
> >  admin.site.register(Choice)
> > admin.site.register(Vote)
> >
> > Is there other way to register all class by single register call  like
> > this
> >admin.site.register(Poll,Choice,Vote)
> >
> > with thanks
> > Ajay
> > >
> >
>
> Yep,
> admin.site.register([Model1, Moel2, Model3])
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
>
> >
>

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



  1   2   >