Custom select_related()

2011-06-07 Thread mhulse
Hello,

I have a M2M field...

class A(models.Model):
foo1 = models.ManyToManyField('B', related_name='foo1_set' ...)
foo2 = models.ManyToManyField('B', related_name='foo2_set' ...)
...

When I run:

...foo.select_related()

I get all of the B entries related to A instance.

I would like to write a method similar to select_related() (I need to 
customize the query), but I am not sure how to implement such a query.

I have been hammering at this all day, and I gave up on the idea of writing 
my own select_related() method and I have most recently tried:

Failure #1:

Add the below method to class A:

def custom_select_related(self):
if self.foo1:
return self.foo1.select_related()
elif self.foo2:
return self.foo2.select_related()
else:
return None

Failure #2:

Added the similar method as above, except I replaced replaced 
select_related() with foo1/foo2_set.

...

What I really need is to implement similar functionality as 
select_related()... I am just not sure how or where. Is this a model 
manager?

Could someone kick me in the right direction here? :D

Please let me know if I can post more code and/or explain my situation 
better.

Thanks so much!

Cheers,
Micky 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/WGd5bnh1OEI3WlFK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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 Development Environments

2011-06-07 Thread Xavier Ordoquy
Hi,

> Xavier, could you point to any resources about using buildout with Django, 
> virtualenv and pip?  I'm assuming you're using it to deploy things into 
> production, right?

I usually use virtualenv / pip for early development as it requires almost no 
setup.
I prefer using buildout once the project start being mature and for production.

For buildout, I use djangorcecipe (http://pypi.python.org/pypi/djangorecipe) 
which will do most of the work for me ;)
Jacob Kaplan wrote a nice article about it 
(http://jacobian.org/writing/django-apps-with-buildout/)

As for virtualenv, you should instal virtual env wrappers that might help you: 
http://pypi.python.org/pypi/virtualenvwrapper/2.7.1
There's not much to say about it, basically it is create your env, activate it 
and pip install what you need and you are good to go.

Virtualenv is commonly used on production but I prefer buildout as all the 
paths troubles are automatically handled by the buildout. On my boxes, the 
server starts with:
 /myapp/bin/django run_gunicorn 127.0.0.1:myport --workers=howmanyyouwant
No extra path to set or configuration to make.

Regards,
Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Custom select_related()

2011-06-07 Thread Martin
Why not create a Manager?

Give it a method foo1_related() which then returns something like
self.foo1_set.filter( your filters ) and a similar method foo2_related (if
needed).

You can then call A.foo1_related() and get what you need.

Best regards,
Martin

On Tue, Jun 7, 2011 at 4:08 PM, mhulse  wrote:

> Hello,
>
> I have a M2M field...
>
> class A(models.Model):
> foo1 = models.ManyToManyField('B', related_name='foo1_set' ...)
> foo2 = models.ManyToManyField('B', related_name='foo2_set' ...)
> ...
>
> When I run:
>
> ...foo.select_related()
>
> I get all of the B entries related to A instance.
>
> I would like to write a method similar to select_related() (I need to
> customize the query), but I am not sure how to implement such a query.
>
> I have been hammering at this all day, and I gave up on the idea of writing
> my own select_related() method and I have most recently tried:
>
> Failure #1:
>
> Add the below method to class A:
>
> def custom_select_related(self):
> if self.foo1:
> return self.foo1.select_related()
> elif self.foo2:
> return self.foo2.select_related()
> else:
> return None
>
> Failure #2:
>
> Added the similar method as above, except I replaced replaced
> select_related() with foo1/foo2_set.
>
> ...
>
> What I really need is to implement similar functionality as
> select_related()... I am just not sure how or where. Is this a model
> manager?
>
> Could someone kick me in the right direction here? :D
>
> Please let me know if I can post more code and/or explain my situation
> better.
>
> Thanks so much!
>
> Cheers,
> Micky
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/WGd5bnh1OEI3WlFK.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



overriding admin/bashe.html block messages.

2011-06-07 Thread Marc Aymerich
HI
I'm trying to override the block messages in order to allow messages with
HTML in one of my model changelist pages.

After realizing that the tipical override with template extension seems that
doesn't work with messages block I go to the original django base.html admin
template to try the modifications there. But still doesn't work! how can be
possible if base.html is the only place where block messages is defined?

Is it a bug?

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



repr(request.session)

2011-06-07 Thread Henrik Genssen
Hi,

I try to add the content of my session to the error-mails.
I have written a middleware, overwriting the standard error mail.
But for:
repr(request.session)
I only get:


What am I doing wrong?

regards

Henrik

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

2011-06-07 Thread Mário Neto
Dev.
Mac OS X
PyCharm
Virtualenv
pip
Mercurial (Bitbucket)
debug-toolbar and extensions

Prod. 1
RedHat
Apache
mod_wsgi

Prod. 2
Debian
Cherokee
uwsgi

2011/6/7 Xavier Ordoquy 

> Hi,
>
> > Xavier, could you point to any resources about using buildout with
> Django, virtualenv and pip?  I'm assuming you're using it to deploy things
> into production, right?
>
> I usually use virtualenv / pip for early development as it requires almost
> no setup.
> I prefer using buildout once the project start being mature and for
> production.
>
> For buildout, I use djangorcecipe (
> http://pypi.python.org/pypi/djangorecipe) which will do most of the work
> for me ;)
> Jacob Kaplan wrote a nice article about it (
> http://jacobian.org/writing/django-apps-with-buildout/)
>
> As for virtualenv, you should instal virtual env wrappers that might help
> you: http://pypi.python.org/pypi/virtualenvwrapper/2.7.1
> There's not much to say about it, basically it is create your env, activate
> it and pip install what you need and you are good to go.
>
> Virtualenv is commonly used on production but I prefer buildout as all the
> paths troubles are automatically handled by the buildout. On my boxes, the
> server starts with:
>  /myapp/bin/django run_gunicorn 127.0.0.1:myport --workers=howmanyyouwant
> No extra path to set or configuration to make.
>
> Regards,
> Xavier.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Att. Mário A. Chaves Neto
Designer / U.I. Engineer
MBA - Design Digital

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

2011-06-07 Thread Bjarni Rúnar Einarsson
Dev:
 - Ubuntu 11.04 (netbook)
 - vim
 - git
 - in-memory mocks of user DB
 - bundled Django dev server + PageKite for testing & showing coworkers

Production:
 - debian stable (linode)
 - redis for replicated user DB / sqlite for rarely-changing site content
 - lighttpd + fastcgi/flup (hot pages cached to static files for lighttpd to
serve directly)
 - daemon wraps & restarts things that crash
 - yamon for black & white-box monitoring

I also have a staging setup which is just like the production one, except it
runs in a few local virtual machines which I expose them to the world (again
for collaboration with remote coworkers) using PageKite.  I'm pretty sure
this is a relatively unusual setup, as I'm heavily biased towards using my
own tools (eat your own dogfood, etc.). But it works for me! :-)

(Aside: The site is so low-volume still that I do not know whether (or when)
using SQLite this way will become a bottleneck. If anyone cares to enlighten
me, that would be most welcome. I like it because copying the entire website
around is super easy, making disaster recovery and off-line testing/curating
quite easy.)

-- 
Bjarni R. Einarsson
Founder, lead developer of PageKite.

Make localhost servers visible to the world: http://pagekite.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: files managing

2011-06-07 Thread Mateusz Marzantowicz
On Tue, Jun 7, 2011 at 5:15 AM, pankaj sharma wrote:

> hello everyone, i need some help;
> i want the users to download some files.. {say photos}
> and what setting do i have to take care using FileField. where all
> these photos will be stored and how can user download the photos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
Please read Django documentation first and then describe your problem.

* https://docs.djangoproject.com/en/dev/topics/http/file-uploads/
* https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield


Regards,
Mateusz

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



New to Django, need some help with tutorial

2011-06-07 Thread Dori Rutkevitz
Hi all,

I am new to programming in general and recently decided to pick up Django. 
Im reading bits of a book on Python, and im starting to stumble through the 
Djangoproject.com tutorial. My problem might be embarrassingly simple, but i 
could really use some help. 

I created my first project using django-admin.py startproject mysite , although 
this didnt work untill i manually added the  folder containing 
django-admin.py to my system path.

now, from within the new directory i created, i try to run python manage.py 
runserver 
and get the following message:

Python is not recognized as an internal or external command, operable 
program or batch file.

I dont know whats wrong. Im getting the sense that maybe i installed django 
wrong? i dont know why else i had to add something to my system path which 
was supposed to be there, and why now Python isnt recognized.

I did the tests on the djangoproject.com to see if it all installed 
correctly - that is, i import django without a problem. 

Can anyone give me some pointers here? I would really appreciate any help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dFdXZE42TjFhT3NK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: code 128 or code 39 barcode generation

2011-06-07 Thread Thomas Turner
see https://code.djangoproject.com/wiki/Barcodes

On Apr 18, 7:12 pm, Steven L Smith  wrote:
> There's a great wrapper you can use to generate these in PIL using a
> postscript library.http://pypi.python.org/pypi/elaphe/
>
> I did something similar with pyqrnative to generate QR Codes for a
> conference, basically just create a URL that wraps the output of the
> library in an HTTPResponse.
>
> On Apr 18, 1:58 pm, Bobby Roberts  wrote:
>
>
>
>
>
>
>
> > anyone know if there is a django module to generate code 128 or 39
> > barcodes for printing out on a webpage?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: New to Django, need some help with tutorial

2011-06-07 Thread Xavier Ordoquy

Le 7 juin 2011 à 07:59, Dori Rutkevitz a écrit :

> Hi all,
> 
> I am new to programming in general and recently decided to pick up Django. Im 
> reading bits of a book on Python, and im starting to stumble through the 
> Djangoproject.com tutorial. My problem might be embarrassingly simple, but i 
> could really use some help. 
> 
> I created my first project using django-admin.py startproject mysite , 
> although this didnt work untill i manually added the  folder containing 
> django-admin.py to my system path.
> 
> now, from within the new directory i created, i try to run python manage.py 
> runserver and get the following message:
> 
> Python is not recognized as an internal or external command, operable program 
> or batch file.
> 
> I dont know whats wrong. Im getting the sense that maybe i installed django 
> wrong? i dont know why else i had to add something to my system path which 
> was supposed to be there, and why now Python isnt recognized.
> 
> I did the tests on the djangoproject.com to see if it all installed correctly 
> - that is, i import django without a problem. 
> 
> Can anyone give me some pointers here? I would really appreciate any help.

Hi,

You seem to be on windows and it looks like the python.exe isn't in your 
standard path.
I don't know what the command is on windows but you should add python.exe in 
your path.
The equivalent command on unix is export PATH=yourpath:$PATH

Hope this will help,
Regards,
Xavier.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: repr(request.session)

2011-06-07 Thread Malcolm Box
n 7 June 2011 10:46, Henrik Genssen  wrote:

> I try to add the content of my session to the error-mails.
> I have written a middleware, overwriting the standard error mail.
> But for:
> repr(request.session)
> I only get:
> 
>
> What am I doing wrong?
>
> That is the how a session object displays. Depending what information you
want from the session, you'll need to explicitly extract and format that
into your email.

If you're not sure what you need to print, drop into the debugger in your
middleware and poke around in the request.session object to figure it out.

Do this by putting "import pdb; pdb.set_trace()" in your code  where you're
accessing the session.

Malcolm

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



Add custom html between two model fields in Django admin's change_form

2011-06-07 Thread mf
Let's say I've two models:

class Book(models.Model):
name = models.CharField(max_length=50)
library = models.ForeignKeyField('Library')

class Library(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=50)
tel = models.CharField(max_length=50)

Is there a nice way to add some html(a readonly input field) between
name and address in the Library change_form template?. I'm doing it
overriding [admin/includes/fieldset.html][1] but it's getting messy
and I can't find a way to display the html exactly where I want to.
For example, if I want to add html displaying the amount of books that
the library has below the name field I woul do this:

{% for field in line %}
...
{% if field.field.name == 'name' %}
{{ field.field }}


Total books:


   
{% else %}
{{ field.field }}
{% endif %}
...
{% endfor %}


  [1]: 
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/includes/fieldset.html

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



Users not logging out

2011-06-07 Thread jayhalleaux
I have the django auth system set correctly, my only problem is that
is if the user does not use the logout and just closes the browser,
they are still logged in.

Any suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Users not logging out

2011-06-07 Thread Tim Sawyer
Try putting:

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

in your settings.py file.

Tim.

> I have the django auth system set correctly, my only problem is that
> is if the user does not use the logout and just closes the browser,
> they are still logged in.
>
> Any suggestions?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


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



Re: Users not logging out

2011-06-07 Thread Shawn Milochik

On 06/07/2011 09:20 AM, jayhalleaux wrote:

I have the django auth system set correctly, my only problem is that
is if the user does not use the logout and just closes the browser,
they are still logged in.

Any suggestions?


Any suggestions for how to accomplish what?

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Users not logging out

2011-06-07 Thread jayhalleaux
works perfectly... thanks :)

On Jun 7, 9:29 am, "Tim Sawyer"  wrote:
> Try putting:
>
> SESSION_EXPIRE_AT_BROWSER_CLOSE = True
>
> in your settings.py file.
>
> Tim.
>
>
>
> > I have the django auth system set correctly, my only problem is that
> > is if the user does not use the logout and just closes the browser,
> > they are still logged in.
>
> > Any suggestions?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Users not logging out

2011-06-07 Thread jayhalleaux
i take that back.

If I log in and then I close the tab, I can go back and still use the
url to go to a login required page.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Users not logging out

2011-06-07 Thread christian.posta
so, is that what you wanted? sounds like when the user is done with
the session, and they navigate away (by closing the browser or closing
the tab which browser are you using btw, chrome?), then the
session closes as is indicated by the SESSION_EXPIRE_AT_BROWSER_CLOSE
setting. Isn't that what you're asking?

On Jun 7, 6:39 am, jayhalleaux  wrote:
> i take that back.
>
> If I log in and then I close the tab, I can go back and still use the
> url to go to a login required page.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: New to Django, need some help with tutorial

2011-06-07 Thread oneroler
Below is the information on adding python to your windows path from
the python website

http://docs.python.org/faq/windows.html

for windows 7 you just go into 'edit environment variables for your
account' under system in control panel and add your python path (e.g.
c:\python27) to the 'Path' field under 'System Variables'.  There will
be other paths in the field so just add to the end with a ;.

Regards,
Sam

On Jun 7, 4:05 am, Xavier Ordoquy  wrote:
> Le 7 juin 2011 à 07:59, Dori Rutkevitz a écrit :
>
> > Hi all,
>
> > I am new to programming in general and recently decided to pick up Django. 
> > Im reading bits of a book on Python, and im starting to stumble through the 
> > Djangoproject.com tutorial. My problem might be embarrassingly simple, but 
> > i could really use some help.
>
> > I created my first project using django-admin.py startproject mysite , 
> > although this didnt work untill i manually added the  folder containing 
> > django-admin.py to my system path.
>
> > now, from within the new directory i created, i try to run python manage.py 
> > runserver and get the following message:
>
> > Python is not recognized as an internal or external command, operable 
> > program or batch file.
>
> > I dont know whats wrong. Im getting the sense that maybe i installed django 
> > wrong? i dont know why else i had to add something to my system path which 
> > was supposed to be there, and why now Python isnt recognized.
>
> > I did the tests on the djangoproject.com to see if it all installed 
> > correctly - that is, i import django without a problem.
>
> > Can anyone give me some pointers here? I would really appreciate any help.
>
> Hi,
>
> You seem to be on windows and it looks like the python.exe isn't in your 
> standard path.
> I don't know what the command is on windows but you should add python.exe in 
> your path.
> The equivalent command on unix is export PATH=yourpath:$PATH
>
> Hope this will help,
> Regards,
> Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Accessing template name inside a template?

2011-06-07 Thread Derek
On Jun 6, 8:08 pm, Roy Smith  wrote:
> For diagnostic purposes, I want every one of my templates to emit an
> HTML comment showing the template name.  I was doing fine just
> dropping "", etc, in each template, until the first
> time I renamed a template and forgot to update the comment :-)
>
> Any way to automate this process so I can do ""?

I do not know if there is a tag  for this (if not, you could create
one), but one way to do this "manually" is to pass in the name of the
template file to the context variable.  If you are using locals(),
then you could store the template file name beforehand e.g.

def current_datetime(request):
current_date = datetime.datetime.now()
template_file = 'current_datetime.html'
return render_to_response(template_file, locals())

and have access to template_file as a variable (see
http://www.djangobook.com/en/2.0/chapter04/ )

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Add custom html between two model fields in Django admin's change_form

2011-06-07 Thread christian.posta
Create a different ModelForm that contains your readonly fields (and
populate them however you want) and set this on your ModelAdmin form.

See the ModelAdmin.form option in the docs.
https://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-options




On Jun 7, 6:01 am, mf  wrote:
> Let's say I've two models:
>
>     class Book(models.Model):
>         name = models.CharField(max_length=50)
>         library = models.ForeignKeyField('Library')
>
>     class Library(models.Model):
>         name = models.CharField(max_length=50)
>         address = models.CharField(max_length=50)
>         tel = models.CharField(max_length=50)
>
> Is there a nice way to add some html(a readonly input field) between
> name and address in the Library change_form template?. I'm doing it
> overriding [admin/includes/fieldset.html][1] but it's getting messy
> and I can't find a way to display the html exactly where I want to.
> For example, if I want to add html displaying the amount of books that
> the library has below the name field I woul do this:
>
>     {% for field in line %}
>         ...
>         {% if field.field.name == 'name' %}
>             {{ field.field }}
>             
>                 
>                     Total books:
>                      id="totbooks" readonly="readonly">
>                 
>            
>         {% else %}
>             {{ field.field }}
>         {% endif %}
>         ...
>     {% endfor %}
>
>   [1]:https://code.djangoproject.com/browser/django/trunk/django/contrib/ad...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Users not logging out

2011-06-07 Thread Derek
On Jun 7, 3:39 pm, jayhalleaux  wrote:
> i take that back.
>
> If I log in and then I close the tab, I can go back and still use the
> url to go to a login required page.

close_tab != CLOSE_BROWSER

(An interesting discussion on this type of problem:
http://www.thewebsqueeze.com/forum/PHP-f11/Logout-On-Browser-Close-t5342.html
)

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



django transactions.

2011-06-07 Thread Marc Aymerich
Hi,
I've activated the
'django.middleware.transaction.TransactionMiddleware' and I've
decorated one method with @transaction.commit_on_success
With this I expect that if the method raise an exception, django rolls
back any database operation executed by this method, even the
operations executed by submethods called by this main method, right?
So I got this exception but the changes made on the DB during the
method execution still there.

Django Version: 1.4 pre-alpha SVN-16332
Exception Type: TypeError
Exception Value: create() takes at least 3 non-keyword arguments (1 given)


I missed something?
Thanks!
--
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: Parsing feeds that are imported

2011-06-07 Thread Chris Lawlor


I've not used the django community aggregator, so I'm making some
assumptions about it's functionality. If that app were to emit a
signal for each feed entry that it processed, it would be fairly
simple to write a signal handler that would create the associations
that you want. With this approach, you wouldn't need another cron job,
your processing would be done at the same time as django community
aggregator's.

If you do need to do some manual feed parsing, you might try using the
Universal Feed Parser python module: http://feedparser.org/. It's
specifically designed for parsing RSS / Atom feeds, and so may be
somewhat more useful than BeautifulSoup.

On Jun 6, 10:59 pm, Chris McComas  wrote:
> Also, using the update_feeds that's part of the Django Community
> Aggregator worked initially, but I started over adding a m2m field on
> the Feed model for Sites. I'll have several "sites" as part of the
> Django app, like team1.mysite.com, team2.mysite.com, etc.
>
> When I added that field to the models and tried to run the
> update_feeds script it did nothing. It didn't import the feeds, didn't
> throw an error, etc.
>
> update_feeds:https://github.com/django/djangoproject.com/blob/master/django_websit...
> my models:http://dpaste.com/551322/
>
> Thanks,
>
> On Jun 6, 4:55 pm, Chris McComas  wrote:
>
>
>
>
>
>
>
> > This could be the wrong place to ask (maybe a BeautifulSoup)
> > question...
>
> > I have a Django app that is based around the Django Community
> > Aggregator, it gets feeds from various sites and displays them on my
> > site. What I am wanting to do, if possible, is when it gets a feed if
> > a certain zip code is the feed Title or Summary then I want to create
> > a entry for that zipcode with that feed?
>
> > I have a model for the zip codes, so the list to compare should be
> > pulled from that. There'd be a cron that'd run to do this, so for
> > example if one of the zip codes is 12345 and one of the feeds it gets
> > on the hourly cron has 12345 in the summary, then it'd go to the model
> > linking the two and create/save an entry.
>
> > Here are the pertinent models:http://dpaste.com/551223/
>
> > Thanks,

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



Re: Making a login/create user interface

2011-06-07 Thread imageguy
I would recommend django-registration as well.  Seems to handle all the 
machinery quite well.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VnRGWTd6ZDhLR3NK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Add custom html between two model fields in Django admin's change_form

2011-06-07 Thread mf
Thanks christian. I've followed your good advice but I don't know why
am I getting  this error: "PresupuestoAdmin.readonly_fields[1], 'name'
is not a callable or an attribute of 'PresupuestoAdmin' or found in
the model 'Presupuesto' ". It seems that the 'name' field is not added
to the form used by the admin.

class PresupuestoAdminForm(forms.ModelForm):
name = models.CharField(max_length=100)

class Meta:
model = Presupuesto

class PresupuestoAdmin(admin.ModelAdmin):
form = PresupuestoAdminForm

fieldsets = (
(None, {
'fields': (('id', 'fecha_emision', ), ('obra',
'num_pres_ext',),
'proveedor', 'descripcion', 'observaciones',
'importe_contratado',)
}),
)
readonly_fields = ('id', 'name',)

admin.site.register(Presupuesto, PresupuestoAdmin)



On 7 jun, 11:11, "christian.posta"  wrote:
> Create a different ModelForm that contains your readonly fields (and
> populate them however you want) and set this on your ModelAdmin form.
>
> See the ModelAdmin.form option in the 
> docs.https://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-o...
>
> On Jun 7, 6:01 am, mf  wrote:
>
>
>
>
>
>
>
> > Let's say I've two models:
>
> >     class Book(models.Model):
> >         name = models.CharField(max_length=50)
> >         library = models.ForeignKeyField('Library')
>
> >     class Library(models.Model):
> >         name = models.CharField(max_length=50)
> >         address = models.CharField(max_length=50)
> >         tel = models.CharField(max_length=50)
>
> > Is there a nice way to add some html(a readonly input field) between
> > name and address in the Library change_form template?. I'm doing it
> > overriding [admin/includes/fieldset.html][1] but it's getting messy
> > and I can't find a way to display the html exactly where I want to.
> > For example, if I want to add html displaying the amount of books that
> > the library has below the name field I woul do this:
>
> >     {% for field in line %}
> >         ...
> >         {% if field.field.name == 'name' %}
> >             {{ field.field }}
> >             
> >                 
> >                     Total books:
> >                      > id="totbooks" readonly="readonly">
> >                 
> >            
> >         {% else %}
> >             {{ field.field }}
> >         {% endif %}
> >         ...
> >     {% endfor %}
>
> >   
> > [1]:https://code.djangoproject.com/browser/django/trunk/django/contrib/ad...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Custom select_related()

2011-06-07 Thread Micky Hulse
Hi Martin! Thanks so much for the quick reply, I really appreciate your help. :)

On Tue, Jun 7, 2011 at 1:48 AM, Martin  wrote:
> Why not create a Manager?
> Give it a method foo1_related() which then returns something like
> self.foo1_set.filter( your filters ) and a similar method foo2_related (if
> needed).
> You can then call A.foo1_related() and get what you need.

That sounds good to me! I will definitely head that route.

The primary thing I like about select_related is that I can do this on
the template level (for example):

{% with object.file1.select_related as foo %}
...
{% endwith %}

Where the context of the field has already been accounted for.

This might sound silly, my goal is to:

1. Get the first related file in the related files M2M
2. Get everything but the first file in the related files M2M

For #1, I could use {% with object.file1.select_related|first as foo
%}... and for #2 I could say {% for ... %}{% if not forloop.first
%}... But I thought it would be nice to have a couple of functions
that I could call, from the template, that behaved like select_related
and worked on either file1/file2 without having to hard-code
file1/file2 into the methods.

But I think I just have very little experience with
managers/django/python, and I am betting that your suggestion of using
managers will end up being the optimal route for this situation. :)

Thanks for the kick, I really appreciate it!!!

Have an awesome day.

Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: New to Django, need some help with tutorial

2011-06-07 Thread Dori Rutkevitz
Alexy, Xavier and Sam thank you all very much - I am on windows and i just 
needed to add the python directory to my system path. thanks so much for the 
help, on with the tutorial : )

-Dori

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/aF9ZR3pHM1RkUllK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: ManyToManyField limit_choices_to that instance via Django admin.

2011-06-07 Thread Ryan
This is possible, but I'm not sure if you could do it via limit_choices_to.  
The admin docs shows how to accomplish this here: 
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_manytomany

Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ZlhkM0JHY3dkbTRK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: ManyToManyField limit_choices_to that instance via Django admin.

2011-06-07 Thread Micky Hulse
Hi Ryan! Thanks so much for the reply, I really appreciate the help. :)

On Tue, Jun 7, 2011 at 12:17 PM, Ryan  wrote:
> This is possible, but I'm not sure if you could do it via limit_choices_to.
> The admin docs shows how to accomplish this here:

Oooh, interesting. I will experiment with that solution. Thanks for
pointing me in the right direction.

I will post back here if I code something worth sharing. :D

Thanks again!

Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Excel dumps to Office 10

2011-06-07 Thread Marwan Al-Sabbagh
So what you are doing is producing HTML content, but send the user a file
with an xls extension. Before MS Excel used to open the xls file see that in
fact it doesn't have xls data in it but HTML and would try and take care of
it by converting the html to excel and presenting to the user. In more
recent versions like excel 2010 it correctly reports to the user that this
xls file does not have xls data in it but has html data. I suspect there
might have been security concerns with this.

you can use xlwt http://www.python-excel.org to build a proper xls file.
This is the more correct way of exporting to MS Excel. The approach you have
is kind of a hack that worked without complaint in older versions of MS
office.

Marwan

On Mon, Jun 6, 2011 at 6:40 PM, creecode  wrote:

> Hello Bobby,
>
> No answer just some thoughts.  Did the MIME type change for Excel between
> 2003 and 2010?
>
> If your file dump is in a text format and is delimited with tabs or commas,
> can you change your MIME type to a plain text one?  Although the apps may
> ask to convert when opening files that are in a text format, you'd need to
> test.
>
> Toodle-loo...
> creecode
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Y0ZUcERGMUpGbUVK.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Users not logging out

2011-06-07 Thread Malcolm Box
On 7 June 2011 15:14, Derek  wrote:

> On Jun 7, 3:39 pm, jayhalleaux  wrote:
> > i take that back.
> >
> > If I log in and then I close the tab, I can go back and still use the
> > url to go to a login required page.
>
> close_tab != CLOSE_BROWSER
>
> (An interesting discussion on this type of problem:
>
> http://www.thewebsqueeze.com/forum/PHP-f11/Logout-On-Browser-Close-t5342.html
> )
>
>
The fundamental problem is there is absolutely NO WAY for Django to know
that the user has closed their browser/gone away/been abducted by aliens,
and thus to know they should be logged out.

All else is just work-arounds for this fact:

- Browsers will clear cookies with no expiry time set when the browser exits
(maybe), so SESSION_EXPIRE_AT_BROWSER_
CLOSE uses such a cookie for the Django session cookie, so the browser might
delete it on exit.

- It's possible to add an inactivity timer on the server side, so that if
the user isn't seen for a while the session is expired. How to do this is
left as an exercise to the reader.

HTH,

Malcolm

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

2011-06-07 Thread Malcolm Box
n 7 June 2011 15:16, Marc Aymerich  wrote:

> Hi,
> I've activated the
> 'django.middleware.transaction.TransactionMiddleware' and I've
> decorated one method with @transaction.commit_on_success
> With this I expect that if the method raise an exception, django rolls
> back any database operation executed by this method, even the
> operations executed by submethods called by this main method, right?
> So I got this exception but the changes made on the DB during the
> method execution still there.
>
>
What database are you using? Does it support transactions?

Malcolm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Re: Odp: Re: signals pre_save vs model's save()

2011-06-07 Thread Malcolm Box
On 2 June 2011 23:37, Mateusz Harasymczuk  wrote:

> That was a very good and convincing post :}
> I am testing a solution with .clean(), which IMHO is a better place to
> clean data before save()
>
>
Glad to have been of help.

clean() is ideal for cleaning up stuff from forms, so could be a great fit
for your use case.

Malcolm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: Making a login/create user interface

2011-06-07 Thread raj
I got completely lost when looking at that. I don't even know how to
describe my confusion. I guess my issue is that I'm not seeing the big
picture when reading to the tutorial. And i'm, not familiar with the
django-registration thing described below. Is it possible that you can
create a very simple demo project that includes very simple login
interface and send it to me? Thank you.
-Raj

On Jun 6, 1:03 pm, Shawn Milochik  wrote:
> Most of the info you need is here:
>
> https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-in-...
>
> If you get stuck understanding any specific points in the docs then let
> us know (be as descriptive as possible) and you'll probably get 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 transactions.

2011-06-07 Thread Christophe Pettus

On Jun 7, 2011, at 7:16 AM, Marc Aymerich wrote:

> With this I expect that if the method raise an exception, django rolls
> back any database operation executed by this method, even the
> operations executed by submethods called by this main method, right?

That's correct.

> So I got this exception but the changes made on the DB during the
> method execution still there.

Which back-end are you using?

--
-- Christophe Pettus
   x...@thebuild.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: Making a login/create user interface

2011-06-07 Thread Martin
Are you kidding?

https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-in-web-requests


The docs are crystal clear. And if you don't want to implement your own
views, django-registration is as simple as it can get. It even has loads of
documentation:
http://readthedocs.org/docs/django-registration/latest/index.html

Work your
way through the docs and post your problems here. You can hardly expect
anyone here to do all the work for you.

Best regards,
Martin

On Wed, Jun 8, 2011 at 7:23 AM, raj  wrote:

> I got completely lost when looking at that. I don't even know how to
> describe my confusion. I guess my issue is that I'm not seeing the big
> picture when reading to the tutorial. And i'm, not familiar with the
> django-registration thing described below. Is it possible that you can
> create a very simple demo project that includes very simple login
> interface and send it to me? Thank you.
> -Raj
>
> On Jun 6, 1:03 pm, Shawn Milochik  wrote:
> > Most of the info you need is here:
> >
> > https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-in-...
> >
> > If you get stuck understanding any specific points in the docs then let
> > us know (be as descriptive as possible) and you'll probably get 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.
>
>

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



ANN: django-supervisor: easy integration between django and supervisord

2011-06-07 Thread Ryan Kelly

Hi All,


  I've just released a little experiment in combining the process
management awesomeness of supervisord with the convenience of Django's
management scripts.  It's called, funnily enough, django-supervisor:

  http://pypi.python.org/pypi/django-supervisor/
 

  The concept is simple:  instead of having supervisord in charge of
Django, why not put Django in charge of supervisord?

 
  If you've got a Django project that needs to keep several processes
running at once (e.g. celeryd or celerybeat) then this might be the app
for you.  You can:

   * manage all your processes with `python manage.py supervisor`.

   * keep your process definitions and configuration inside your
 Django project directory.

   * use Django's template system to construct the supervisord config
 file, interpolating environment variables or settings as you need.

   * merge pre-defined configuration files from all the INSTALLED_APPS,
 and tweak or override them on a per-project basis.

   * auto-reload all running processes when your code changes
(but only in debug mode of course)


  All comments, questions, feedback and criticism welcome.  I hope you
find it useful.


  Cheers,

  Ryan

-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part


VERY cheap django hosting?

2011-06-07 Thread raj
Hey guys,
Just wondering if you could give me some hosts that are very cheap for
django hosting? Is hostgator any good? I really don't know what to
look for in a host. A lot of people are recommending web faction, but
its around $9 bucks a month. I was looking in the $5 bucks a month
range. Any ideas? Thank you.
-Raj

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, 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: VERY cheap django hosting?

2011-06-07 Thread Maksymus007
megiteam.pl is 24PLN which is about 8usd a month:)

Pozdrawiam, Maksymilian Pawlak
08-06-2011 08:30 użytkownik "raj"  napisał:
> Hey guys,
> Just wondering if you could give me some hosts that are very cheap for
> django hosting? Is hostgator any good? I really don't know what to
> look for in a host. A lot of people are recommending web faction, but
> its around $9 bucks a month. I was looking in the $5 bucks a month
> range. Any ideas? Thank you.
> -Raj
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

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