Customize the admin look and feel

2011-01-02 Thread Daniel Roseman
The directions seem quite clear. What have you set TEMPLATE_DIRS to in 
settings.py? It goes in there. 
-- 
DR 

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



Re: merge 2 views?

2011-01-02 Thread bruno desthuilliers
On 1 jan, 18:42, Sam Lai  wrote:
> On 2 January 2011 00:56, bruno desthuilliers
>
>  wrote:
> > "simple_tag" is nothing new - it has been here since the 0.96 days
> > IIRC.
>
> But only the version in v1.3 has the ability to manipulate the context
> object (which is what's needed in the suggested alternative solution),
> thanks to the new takes_context parameter.

Indeed - but if you go the custom tag route, you can as well just
directly render the 'navigation.html' subtemplate from the custom tag
itself.

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



Re: Customize the admin look and feel

2011-01-02 Thread Anthony Pearce
"DjangoProjects/mysite/mytemplates/admin/"  but I created the
"mytemplates" and "admin" directories for this purpose.

What exactly is this supposed to do for me anyway? I thought it would
allow me to edit the "Django administration" bar at the top, but I
can't as of yet.

On Jan 2, 8:05 pm, Daniel Roseman  wrote:
> The directions seem quite clear. What have you set TEMPLATE_DIRS to in 
> settings.py? It goes in there.
> --
> DR

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



New to Django, sheet music organization site

2011-01-02 Thread Kyle
I am wanting to create an app that helps me organize sheet music. I
want to be able to sort by the artist. Every piece of sheet music I
have I want to be scanned in and uploaded as an image file, then when
I want to open a particular file, it opens as a PDF.

This would be my long terms goals. For now since I am new to Django, I
just want to simply organize my music and be able to easily sort.

I know I will need:

from django.db import models

class Artist(models.Model):
name = models.CharField(max_length=30)
genre = models.CharField(max_length=30)

class Song(models.Model):
name = models.CharField(max_length=30)
artist = models.ForeignKey(Artist)

What else can I do to help me get a start with this? I've gone through
the tutorial and I understand how Django works, its just a matter of
getting some hands on experience.

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



PageAdmin.fieldsets[0][1]['fields']' refers to field 'username' that is missing from the form.

2011-01-02 Thread Ground Zero
Hello,

I am trying to make a custom (extended) User, according to this:
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

So I created my own user called DashboardUser, made a link to django
User using models.OneToOneField and added several additional
attributes.

So far so good.

Now I wanted my administration to display attributes but also to
display regular User attributes (like 'username' or 'last_name') and
that's where I ran into trouble because admin (or autodiscover() for
that matter) seems to be unable to find these.

Here's my model:
http://pastebin.com/CqKHV8xf

And here's my attempt to customize admin view for my DashboardUser:
http://pastebin.com/MzPDF12S

If anyone knows where to go from here, I'd appreciate your input (I
tried #django on freenode but nobody knew).

I am using Django 1.2.3 with Python 2.6.6 on Gentoo x86.

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



Re: Customize the admin look and feel

2011-01-02 Thread Praveen Krishna R
Hi,

Your TEMPLATE_DIRS should contain a path to a folder where you want to keep
your templates. Say if your project is in *D:/myproject* then create a
folder named
template under *D:\myproject*, and in that folder create a folder named *admin
*and then copy and paste base_site.html into the admin folder.

 TEMPLATE_DIRS section should look like the below snippet in settings.py

*
TEMPLATE_DIRS = (
'D:/myproject /templates'
)


*
On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce  wrote:

> I have made it to the "Writing your first Django app, part 2" page
> down to "Customize the admin look and feel", at the bottom.  I'm stuck
> with this paragraph..
>
> Now copy the template admin/base_site.html from within the default
> Django admin template directory in the source code of Django itself
> (django/contrib/admin/templates) into an admin subdirectory of
> whichever directory you're using in TEMPLATE_DIRS. For example, if
> your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above,
> then copy django/contrib/admin/templates/admin/base_site.html to /home/
> my_username/mytemplates/admin/base_site.html. Don't forget that admin
> subdirectory.
>
> I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> templates/admin/base_site.html.
>
> I have no idea where this is supposed to be copied and pasted to.
>
> Any help please?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
*Praveen Krishna R*

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



Re: Customize the admin look and feel

2011-01-02 Thread Anthony Pearce
OK, this is  now what I have:

Project location. C:\DjangoProjects\mysite\
base_site.html locationC:\DjangoProjects\mysite\templates
\base_site.html
TEMPLATE_DIRS reads "C:/DjangoProjects/mysite/templates/"

There are no apparent errors, but I also do not see how this helps
me.

base_site.html reads as follows:

{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{%
endblock %}
{% block branding %}
{% trans 'Django Administration' %}
{% endblock %}
{% block nav-global %}{% endblock %}

What am I supposed to do with this to change the appearance?

btw, tyvm for your response  :)

On Jan 2, 4:36 pm, Praveen Krishna R 
wrote:
> Hi,
>
> Your TEMPLATE_DIRS should contain a path to a folder where you want to keep
> your templates. Say if your project is in *D:/myproject* then create a
> folder named
> template under *D:\myproject*, and in that folder create a folder named *admin
> *and then copy and paste base_site.html into the admin folder.
>
>  TEMPLATE_DIRS section should look like the below snippet in settings.py
>
> *
> TEMPLATE_DIRS = (
>     'D:/myproject /templates'
> )
>
> *
>
>
>
>
>
> On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce  wrote:
> > I have made it to the "Writing your first Django app, part 2" page
> > down to "Customize the admin look and feel", at the bottom.  I'm stuck
> > with this paragraph..
>
> > Now copy the template admin/base_site.html from within the default
> > Django admin template directory in the source code of Django itself
> > (django/contrib/admin/templates) into an admin subdirectory of
> > whichever directory you're using in TEMPLATE_DIRS. For example, if
> > your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above,
> > then copy django/contrib/admin/templates/admin/base_site.html to /home/
> > my_username/mytemplates/admin/base_site.html. Don't forget that admin
> > subdirectory.
>
> > I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> > templates/admin/base_site.html.
>
> > I have no idea where this is supposed to be copied and pasted to.
>
> > Any help please?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> *Praveen Krishna R*- 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Customize the admin look and feel

2011-01-02 Thread Anthony Pearce
TYVM for your response. My first reply does not show, so hopefully I'm
not double posting.

This is what I have so far:

TEMPLATE_DIRS   "C:/DjangoProjects/mysite/mytemplates/"
base_site.html location   C:\DjangoProjects\mysite\mytemplates

This is what base_site.html reads.
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{%
endblock %}
{% block branding %}
{% trans 'Django Administration' %}
{% endblock %}
{% block nav-global %}{% endblock %}

If this supposed to help me change the appearance?  I don't see how to
change anything here.


On Jan 2, 4:36 pm, Praveen Krishna R 
wrote:
> Hi,
>
> Your TEMPLATE_DIRS should contain a path to a folder where you want to keep
> your templates. Say if your project is in *D:/myproject* then create a
> folder named
> template under *D:\myproject*, and in that folder create a folder named *admin
> *and then copy and paste base_site.html into the admin folder.
>
>  TEMPLATE_DIRS section should look like the below snippet in settings.py
>
> *
> TEMPLATE_DIRS = (
>     'D:/myproject /templates'
> )
>
> *
>
>
>
>
>
> On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce  wrote:
> > I have made it to the "Writing your first Django app, part 2" page
> > down to "Customize the admin look and feel", at the bottom.  I'm stuck
> > with this paragraph..
>
> > Now copy the template admin/base_site.html from within the default
> > Django admin template directory in the source code of Django itself
> > (django/contrib/admin/templates) into an admin subdirectory of
> > whichever directory you're using in TEMPLATE_DIRS. For example, if
> > your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above,
> > then copy django/contrib/admin/templates/admin/base_site.html to /home/
> > my_username/mytemplates/admin/base_site.html. Don't forget that admin
> > subdirectory.
>
> > I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> > templates/admin/base_site.html.
>
> > I have no idea where this is supposed to be copied and pasted to.
>
> > Any help please?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> *Praveen Krishna R*- 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Customize the admin look and feel

2011-01-02 Thread Praveen Krishna R
Could you please try moving the base_site.html to
C:\DjangoProjects\mysite\mytemplates\admin
folder and Leave the TEMPLATE_DIRS as it is, which is "*
C:/DjangoProjects/mysite/mytemplates*" only. and please try removing the /
slash at the end.

On Sun, Jan 2, 2011 at 5:36 PM, Anthony Pearce  wrote:

> TYVM for your response. My first reply does not show, so hopefully I'm
> not double posting.
>
> This is what I have so far:
>
> TEMPLATE_DIRS   "C:/DjangoProjects/mysite/mytemplates/"
> base_site.html location   C:\DjangoProjects\mysite\mytemplates
>
> This is what base_site.html reads.
> {% extends "admin/base.html" %}
> {% load i18n %}
> {% block title %}{{ title }} | {% trans 'Django site admin' %}{%
> endblock %}
> {% block branding %}
> {% trans 'Django Administration' %}
> {% endblock %}
> {% block nav-global %}{% endblock %}
>
> If this supposed to help me change the appearance?  I don't see how to
> change anything here.
>
>
> On Jan 2, 4:36 pm, Praveen Krishna R 
> wrote:
> > Hi,
> >
> > Your TEMPLATE_DIRS should contain a path to a folder where you want to
> keep
> > your templates. Say if your project is in *D:/myproject* then create a
> > folder named
> > template under *D:\myproject*, and in that folder create a folder named
> *admin
> > *and then copy and paste base_site.html into the admin folder.
> >
> >  TEMPLATE_DIRS section should look like the below snippet in settings.py
> >
> > *
> > TEMPLATE_DIRS = (
> > 'D:/myproject /templates'
> > )
> >
> > *
> >
> >
> >
> >
> >
> > On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce 
> wrote:
> > > I have made it to the "Writing your first Django app, part 2" page
> > > down to "Customize the admin look and feel", at the bottom.  I'm stuck
> > > with this paragraph..
> >
> > > Now copy the template admin/base_site.html from within the default
> > > Django admin template directory in the source code of Django itself
> > > (django/contrib/admin/templates) into an admin subdirectory of
> > > whichever directory you're using in TEMPLATE_DIRS. For example, if
> > > your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above,
> > > then copy django/contrib/admin/templates/admin/base_site.html to /home/
> > > my_username/mytemplates/admin/base_site.html. Don't forget that admin
> > > subdirectory.
> >
> > > I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> > > templates/admin/base_site.html.
> >
> > > I have no idea where this is supposed to be copied and pasted to.
> >
> > > Any help please?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com
> 
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
> >
> > --
> > *Praveen Krishna R*- 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
*Praveen Krishna R*

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



Re: Customize the admin look and feel

2011-01-02 Thread Anthony Pearce
That has worked. Puzzling to me though since we left off the admin
directory in TEMPLATE_DIRS

None the less, thank you very much. I will continue with the tutorial
and see how much farther I can get.

On Jan 2, 11:46 pm, Praveen Krishna R 
wrote:
> Could you please try moving the base_site.html to
> C:\DjangoProjects\mysite\mytemplates\admin
> folder and Leave the TEMPLATE_DIRS as it is, which is "*
> C:/DjangoProjects/mysite/mytemplates*" only. and please try removing the /
> slash at the end.
>
>
>
>
>
> On Sun, Jan 2, 2011 at 5:36 PM, Anthony Pearce  wrote:
> > TYVM for your response. My first reply does not show, so hopefully I'm
> > not double posting.
>
> > This is what I have so far:
>
> > TEMPLATE_DIRS           "C:/DjangoProjects/mysite/mytemplates/"
> > base_site.html location   C:\DjangoProjects\mysite\mytemplates
>
> > This is what base_site.html reads.
> > {% extends "admin/base.html" %}
> > {% load i18n %}
> > {% block title %}{{ title }} | {% trans 'Django site admin' %}{%
> > endblock %}
> > {% block branding %}
> > {% trans 'Django Administration' %}
> > {% endblock %}
> > {% block nav-global %}{% endblock %}
>
> > If this supposed to help me change the appearance?  I don't see how to
> > change anything here.
>
> > On Jan 2, 4:36 pm, Praveen Krishna R 
> > wrote:
> > > Hi,
>
> > > Your TEMPLATE_DIRS should contain a path to a folder where you want to
> > keep
> > > your templates. Say if your project is in *D:/myproject* then create a
> > > folder named
> > > template under *D:\myproject*, and in that folder create a folder named
> > *admin
> > > *and then copy and paste base_site.html into the admin folder.
>
> > >  TEMPLATE_DIRS section should look like the below snippet in settings.py
>
> > > *
> > > TEMPLATE_DIRS = (
> > >     'D:/myproject /templates'
> > > )
>
> > > *
>
> > > On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce 
> > wrote:
> > > > I have made it to the "Writing your first Django app, part 2" page
> > > > down to "Customize the admin look and feel", at the bottom.  I'm stuck
> > > > with this paragraph..
>
> > > > Now copy the template admin/base_site.html from within the default
> > > > Django admin template directory in the source code of Django itself
> > > > (django/contrib/admin/templates) into an admin subdirectory of
> > > > whichever directory you're using in TEMPLATE_DIRS. For example, if
> > > > your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above,
> > > > then copy django/contrib/admin/templates/admin/base_site.html to /home/
> > > > my_username/mytemplates/admin/base_site.html. Don't forget that admin
> > > > subdirectory.
>
> > > > I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> > > > templates/admin/base_site.html.
>
> > > > I have no idea where this is supposed to be copied and pasted to.
>
> > > > Any help please?
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com
> > 
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > *Praveen Krishna R*- 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> *Praveen Krishna R*- 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Customize the admin look and feel

2011-01-02 Thread Praveen Krishna R
*Good to know that It worked. Good luck, anyways
*
On Sun, Jan 2, 2011 at 6:01 PM, Anthony Pearce  wrote:

> That has worked. Puzzling to me though since we left off the admin
> directory in TEMPLATE_DIRS
>
> None the less, thank you very much. I will continue with the tutorial
> and see how much farther I can get.
>
> On Jan 2, 11:46 pm, Praveen Krishna R 
> wrote:
> > Could you please try moving the base_site.html to
> > C:\DjangoProjects\mysite\mytemplates\admin
> > folder and Leave the TEMPLATE_DIRS as it is, which is "*
> > C:/DjangoProjects/mysite/mytemplates*" only. and please try removing the
> /
> > slash at the end.
> >
> >
> >
> >
> >
> > On Sun, Jan 2, 2011 at 5:36 PM, Anthony Pearce 
> wrote:
> > > TYVM for your response. My first reply does not show, so hopefully I'm
> > > not double posting.
> >
> > > This is what I have so far:
> >
> > > TEMPLATE_DIRS   "C:/DjangoProjects/mysite/mytemplates/"
> > > base_site.html location   C:\DjangoProjects\mysite\mytemplates
> >
> > > This is what base_site.html reads.
> > > {% extends "admin/base.html" %}
> > > {% load i18n %}
> > > {% block title %}{{ title }} | {% trans 'Django site admin' %}{%
> > > endblock %}
> > > {% block branding %}
> > > {% trans 'Django Administration' %}
> > > {% endblock %}
> > > {% block nav-global %}{% endblock %}
> >
> > > If this supposed to help me change the appearance?  I don't see how to
> > > change anything here.
> >
> > > On Jan 2, 4:36 pm, Praveen Krishna R 
> > > wrote:
> > > > Hi,
> >
> > > > Your TEMPLATE_DIRS should contain a path to a folder where you want
> to
> > > keep
> > > > your templates. Say if your project is in *D:/myproject* then create
> a
> > > > folder named
> > > > template under *D:\myproject*, and in that folder create a folder
> named
> > > *admin
> > > > *and then copy and paste base_site.html into the admin folder.
> >
> > > >  TEMPLATE_DIRS section should look like the below snippet in
> settings.py
> >
> > > > *
> > > > TEMPLATE_DIRS = (
> > > > 'D:/myproject /templates'
> > > > )
> >
> > > > *
> >
> > > > On Sun, Jan 2, 2011 at 10:04 AM, Anthony Pearce 
> > > wrote:
> > > > > I have made it to the "Writing your first Django app, part 2" page
> > > > > down to "Customize the admin look and feel", at the bottom.  I'm
> stuck
> > > > > with this paragraph..
> >
> > > > > Now copy the template admin/base_site.html from within the default
> > > > > Django admin template directory in the source code of Django itself
> > > > > (django/contrib/admin/templates) into an admin subdirectory of
> > > > > whichever directory you're using in TEMPLATE_DIRS. For example, if
> > > > > your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as
> above,
> > > > > then copy django/contrib/admin/templates/admin/base_site.html to
> /home/
> > > > > my_username/mytemplates/admin/base_site.html. Don't forget that
> admin
> > > > > subdirectory.
> >
> > > > > I found the "base_site" at C:/Django-1.2.4/django/contrib/admin/
> > > > > templates/admin/base_site.html.
> >
> > > > > I have no idea where this is supposed to be copied and pasted to.
> >
> > > > > Any help please?
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Django users" group.
> > > > > To post to this group, send email to django-users@googlegroups.com
> .
> > > > > To unsubscribe from this group, send email to
> > > > > django-users+unsubscr...@googlegroups.com
> 
> > > 
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/django-users?hl=en.
> >
> > > > --
> > > > *Praveen Krishna R*- 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-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com
> 
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
> >
> > --
> > *Praveen Krishna R*- 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
*Praveen Krishna R*

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



ImproperlyConfigured: 'SentAdmin.fields' refers to field 'dateSent' that is missing from the form.

2011-01-02 Thread gintare
I was changing models many times and deleting tables inbetween.
New tables were generated to improved models and admin site worked
perfectly.
Now smth happened that i am getting error:

ImproperlyConfigured: 'SentAdmin.fields' refers to field 'dateSent'
that is missing from the form.

'dateSent' is in the model and correctly described in admin.py

I did not added this field before generating new tables. It was
previously.
If i comment other fields gives the same error.

What can be the solution?
Should i make new project or there is a way to update forms (for
field 'dateSent' and orher fields that are missing from the form
according Django) ??

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



Re: Cant locate problem with trunk: 'ModelForm' object has no attribute '_meta'

2011-01-02 Thread Ramiro Morales
On Sun, Jan 2, 2011 at 3:36 AM, Martin  wrote:
> Hey,
>
> could someone have a look at this, I updated to Django trunk and face
> some problems.
>
> I get the error message ' 'ModelForm' object has no attribute
> '_meta''. But the traceback doesn't have any position of my own code
> inside. Only Django internal function calls. So I don't really know
> how to locate the issue.
>
>
> This is all I get when I load my site: http://dpaste.com/293197/
> Tried to reproduce it in the shell by importing all models, views,
> urls, etc. but nothing.
>
> Could someone point out where I should look at?

Could you please try again but rolling back your Django trunk  installation to
revision 14991?.

I've been seeing similar errors after the changes to template rendering
implemented in r14992 but I've been unable to point the exact reason and how
to solve them. an additional, independent case would be of help.

Thanks,

-- 
Ramiro Morales

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



Re: Ajax and SSL

2011-01-02 Thread andrewwatts
Would one of the following work?

1. Hardcore https in the VIEW1 template
2. Write response middleware that, if the request is secure, basically
does s/http/https/g on the response text (this obviously gets all
other URLs as well, which you may not want)
3. Add another MEDIA_URL like variable to settings: eg: AJAX_URL which
is absolute with https

If your template is used by more than one view you could also write a
context processor that, if the request is secure, changes AJAX_URL
accordingly to be http or https.

Hope that helps


On Jan 1, 11:17 am, Jakob H  wrote:
> Hi,
>
> I'm using Satchmo to build a store for a Django-powered webpage.
> Satchmo provides a convenient middleware
> ('satchmo_store.shop.SSLMiddleware.SSLRedirect') which allows me to
> add { 'SSL' : True } arguments to my view specifications (in urls.py).
> This forwards requests to using the HTTPS protocol when so specified.
> There are other middlewares that do roughly the same thing, so this is
> not necessarily Satchmo-specific.
>
> I have some views configured to be forwarded to using SSL (HTTPS
> protocol). However, I also have some general Ajax views configured.
> E.g. I have one that updates a progress bar on every page once that
> page has loaded.
>
> The problem is the following: consider me having the following
> (abstract) specification in urls.py:
>
> VIEW1[SSL=True]
> AJAX1[SSL=False]
>
> where a client-side call to AJAX1 is performed once the page has fully
> loaded as generated by VIEW1. The page generated by VIEW1 should call
> AJAX1 using the HTTPS protocol, but the convenient middleware will
> forward it to HTTP, as specified above, which will cause problems
> (i.e. it will not work). If I set AJAX1[SSL=True] I will get problems
> when I access views using the HTTP protocol.
>
> Is there a way to make use of the above-mentioned convenient
> declarative middleware (just adding { 'SSL' : True } in view-
> specifications), but get around these kinds of problems?
>
> What are some common design patterns for these kinds of problems?
>
> Thanks,
> Jakob

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



Re: ImproperlyConfigured: 'SentAdmin.fields' refers to field 'dateSent' that is missing from the form.

2011-01-02 Thread Ramiro Morales
On Sun, Jan 2, 2011 at 12:49 PM, gintare  wrote:
> I was changing models many times and deleting tables inbetween.
> New tables were generated to improved models and admin site worked
> perfectly.
> Now smth happened that i am getting error:
>
> ImproperlyConfigured: 'SentAdmin.fields' refers to field 'dateSent'
> that is missing from the form.
>
> 'dateSent' is in the model and correctly described in admin.py
>
> I did not added this field before generating new tables. It was
> previously.
> If i comment other fields gives the same error.
>
> What can be the solution?
> Should i make new project or there is a way to update forms (for
> field 'dateSent' and orher fields that are missing from the form
> according Django) ??

Post only the definitions of the model containing dateSent and
its ModelAdmin.

Also:
 Are you using dateSent somethwere else in the dmin.py?
 Remove the admin.pyc file.

-- 
Ramiro Morales

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



Re: Following "first app" tutorial -- admin site can't find css files

2011-01-02 Thread pedro.a.goncalves
Hi Arthur,

Thanks for your post. It was one of the first I found perfectly aligned with 
my current issue: showing the look & feel one would expect, while following 
the official django tutorial at 
http://docs.djangoproject.com/en/dev/intro/tutorial02/ using django's 
default *development server*.

After looking around for the replies on this post and other similar 
questions on the web, I was able to fix this with these 4 actions:

   1. Make sure you have the following lines in settings.py:
  - 
  - MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media")
  - MEDIA_URL = '/media/'
  - ADMIN_MEDIA_PREFIX = '/media/admin/'
   2. Add the following line to urls.py, as an extra parameter inside the *
   patterns* function call
   - 
  - # Required to make static serving work 
  - (r'^media/(?P.*)$', 'django.views.static.serve', 
  {'document_root': settings.MEDIA_ROOT}),
   3. Build a directory structure to the above settings
   
   
   

   4. And, finally, copy the default admin CSS files from the django 
   installation onto the above structure (in my case the django CSS files were 
   in *C:\django\django\contrib\admin\media\css*)
   

Also, it helped me a lot to read these posts in the web:

   - 
   
http://twigstechtips.blogspot.com/2009/08/django-how-to-serve-media-files-css.html
   - http://rob.cogit8.org/blog/2008/Jun/20/django-and-relativity/


Have fun,
Pedro

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



Django dev server issue

2011-01-02 Thread daniels
Hi,
I'm having a issue with Django's dev server. I did a "django-admin.py
startproject" then "manage.py startapp home", then added the app in
settings.py and in urls.py. The app only has  a index function in
views.py which is mapped to / and just renders a simple html template.
What happens is that sometimes(and this is often) when i load the page
in a broswer (tryed Chrome and Firefox) or refresh it, the page starts
loading but it never finishes. And if i hit the browser's stop button
i get this in the console



Exception happened during processing of request from ('127.0.0.1',
52495)
Traceback (most recent call last):
  File "C:\Python26\lib\SocketServer.py", line 283, in
_handle_request_noblock
self.process_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 309, in process_request
self.finish_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "C:\Python26\lib\site-packages\django\core\servers
\basehttp.py", line 562, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "C:\Python26\lib\SocketServer.py", line 618, in __init__
self.finish()
  File "C:\Python26\lib\SocketServer.py", line 661, in finish
self.wfile.flush()
  File "C:\Python26\lib\socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 10053] An established connection was aborted by the
software in your host machine



Any idea what's causing this? As it really cripples my dev time.
I'm on a Windows 7 32bit machine

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



Re: New to Django, sheet music organization site

2011-01-02 Thread Kyle
Ok I have a good start. I have run into a problem though. In my
database, I have an artist field. Most artists have a space in there
name. When creating my URLs, how can I ignore white space?

For example, take the artist Chris Tomlin. In my database, it will
show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
to access it, I want to type "music/christomlin" or "music/
chris_tomlin". How can I do this?

Thanks.

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



Re: New to Django, sheet music organization site

2011-01-02 Thread daniels
SlugField ?

On Jan 3, 12:56 am, Kyle  wrote:
> Ok I have a good start. I have run into a problem though. In my
> database, I have an artist field. Most artists have a space in there
> name. When creating my URLs, how can I ignore white space?
>
> For example, take the artist Chris Tomlin. In my database, it will
> show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
> to access it, I want to type "music/christomlin" or "music/
> chris_tomlin". How can I do this?
>
> Thanks.

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



Re: Django dev server issue

2011-01-02 Thread W. Craig Trader
The exception you're seeing is just a response to stopping the request in
the browser.  The real problem is that your view function is hanging.  Could
you post the source to the view (and the substantial parts of your
template)?  Very hard to offer suggestions without the right data.

- Craig -

On Sun, Jan 2, 2011 at 16:25, daniels  wrote:

> Hi,
> I'm having a issue with Django's dev server. I did a "django-admin.py
> startproject" then "manage.py startapp home", then added the app in
> settings.py and in urls.py. The app only has  a index function in
> views.py which is mapped to / and just renders a simple html template.
> What happens is that sometimes(and this is often) when i load the page
> in a broswer (tryed Chrome and Firefox) or refresh it, the page starts
> loading but it never finishes. And if i hit the browser's stop button
> i get this in the console
>
>
>
> Exception happened during processing of request from ('127.0.0.1',
> 52495)
> Traceback (most recent call last):
>  File "C:\Python26\lib\SocketServer.py", line 283, in
> _handle_request_noblock
>self.process_request(request, client_address)
>  File "C:\Python26\lib\SocketServer.py", line 309, in process_request
>self.finish_request(request, client_address)
>  File "C:\Python26\lib\SocketServer.py", line 322, in finish_request
>self.RequestHandlerClass(request, client_address, self)
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 562, in __init__
>BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
>  File "C:\Python26\lib\SocketServer.py", line 618, in __init__
>self.finish()
>  File "C:\Python26\lib\SocketServer.py", line 661, in finish
>self.wfile.flush()
>  File "C:\Python26\lib\socket.py", line 297, in flush
>self._sock.sendall(buffer(data, write_offset, buffer_size))
> error: [Errno 10053] An established connection was aborted by the
> software in your host machine
> 
>
>
> Any idea what's causing this? As it really cripples my dev time.
> I'm on a Windows 7 32bit machine
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django dev server issue

2011-01-02 Thread W. Craig Trader
You'll probably want to install the Django debug toolbar (
https://github.com/robhudson/django-debug-toolbar) at some point, though it
doesn't help much with views that hang or throw exceptions.

- Craig -

On Sun, Jan 2, 2011 at 16:25, daniels  wrote:

> Hi,
> I'm having a issue with Django's dev server. I did a "django-admin.py
> startproject" then "manage.py startapp home", then added the app in
> settings.py and in urls.py. The app only has  a index function in
> views.py which is mapped to / and just renders a simple html template.
> What happens is that sometimes(and this is often) when i load the page
> in a broswer (tryed Chrome and Firefox) or refresh it, the page starts
> loading but it never finishes. And if i hit the browser's stop button
> i get this in the console
>
>
>
> Exception happened during processing of request from ('127.0.0.1',
> 52495)
> Traceback (most recent call last):
>  File "C:\Python26\lib\SocketServer.py", line 283, in
> _handle_request_noblock
>self.process_request(request, client_address)
>  File "C:\Python26\lib\SocketServer.py", line 309, in process_request
>self.finish_request(request, client_address)
>  File "C:\Python26\lib\SocketServer.py", line 322, in finish_request
>self.RequestHandlerClass(request, client_address, self)
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 562, in __init__
>BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
>  File "C:\Python26\lib\SocketServer.py", line 618, in __init__
>self.finish()
>  File "C:\Python26\lib\SocketServer.py", line 661, in finish
>self.wfile.flush()
>  File "C:\Python26\lib\socket.py", line 297, in flush
>self._sock.sendall(buffer(data, write_offset, buffer_size))
> error: [Errno 10053] An established connection was aborted by the
> software in your host machine
> 
>
>
> Any idea what's causing this? As it really cripples my dev time.
> I'm on a Windows 7 32bit machine
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: New to Django, sheet music organization site

2011-01-02 Thread Mike Dewhirst

On 3/01/2011 9:56am, Kyle wrote:

Ok I have a good start. I have run into a problem though. In my
database, I have an artist field. Most artists have a space in there
name. When creating my URLs, how can I ignore white space?

For example, take the artist Chris Tomlin. In my database, it will
show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
to access it, I want to type "music/christomlin" or "music/
chris_tomlin". How can I do this?


Stick to Chris Tomlin everywhere in your database because that is the 
name you want. Most systems with people names split them into surname 
and given name columns but that doesn't seem to make sense in your case 
unless you think you will want to search millions of records by separate 
surname or given names.


The URL however is a different matter. You need to decide how you want 
to refer to the artists in a consistent way and put a decorated method 
in your artist model something like ...


@models.permalink
def get_absolute_url(self):
return "/music/artist/%s/" % self.slug

... where self.slug is a field on the artist model where you store the 
representation of the artist's name in exactly the way you want to type 
it in as a URL.


Note that I added /artist/ to your URL because you will probably want to 
do something similar for songs and the same principle applies.


If you did something like this in your artist model ...

slug = models.SlugField(unique=True)

... then the admin app would automatically create the slug for you with 
hyphens replacing spaces and everything lower-cased. But you need to 
specify in the admin app which field is the source for the slug.


Otherwise, you could write a method of your own on the artist model to 
massage the name as you prefer and populate the slug field when saving a 
record.


hth



Thanks.



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



Unable to import middleware class 'facebook.djangofb.FacebookMiddleware' with uncaught exception

2011-01-02 Thread PJ
Disclaimer: I'm new to Django and system administration, though a C++
developer.

following the tutorial on: 
http://uswaretech.com/blog/2009/02/how-to-build-a-facebook-app-in-django/
I get everything set up. In my settings.py, I have in my
MIDDLEWARE_CLASSES:
'facebook.djangofb.FacebookMiddleware',

When I run this, it renders:
"Unhandled Exception

An unhandled exception was thrown by the application.
"

my logs look like this (note "Error importing middleware" at the top
of the stack trace). Any idea how/why it cannot find this "middleware"
and why the exception would not be caught? Thank you in advance.

[Sun Jan 02 18:04:40 2011] [warn] FastCGI: (dynamic) server "/home/pj/
public_html/dispatch.fcgi" (pid 18148) terminated by calling exit with
status '0'
[Sun Jan 02 18:04:40 2011] [warn] FastCGI: (dynamic) server "/home/pj/
public_html/dispatch.fcgi" (pid 18148) termination signaled
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:
ImproperlyConfigured: Error importing middleware facebook.djangofb:
"No module named facebook.djangofb", referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr: raise
exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"'
% (mw_module, e)), referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:   File "/home/pj/
local/lib/python2.6/site-packages/django/core/handlers/base.py", line
47, in load_middleware, referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:
self.load_middleware(), referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:   File "/home/pj/
local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line
247, in __call__, referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr: result =
self.application(environ, start_response), referer: 
http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:   File "/home/pj/
local/lib/python2.6/site-packages/flup/server/fcgi_base.py", line
1118, in handler, referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:
protocolStatus, appStatus = self.server.handler(self), referer:
http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr:   File "/home/pj/
local/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 558,
in run, referer: http://apps.facebook.com/###/
[Sun Jan 02 18:04:40 2011] [error] [client 69.203.110.216] FastCGI:
server "/home/pj/public_html/dispatch.fcgi" stderr: Traceback (most
recent call last):, referer: http://apps.facebook.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: removable file field and other features

2011-01-02 Thread Daniel Carvalho
On 12/20/2010 12:55 AM, Daniel Carvalho wrote:
> Everybody knows the default django FileField doesn't allow to remove an
> existing file...
> 
> This is a good replacement. Just use RemovableFileField instead of
> FileField in your models:
> http://djangosnippets.org/snippets/636/
> 
> 
> I want to implement on it another feature- When there is a file being
> uploaded, but the form fails validation for other reason, I want to keep
> the file in the server, so no need to upload the file again. The next
> time the form is submit I would take the file and save it in the model.
> 
> 
> BUT this is not possible because there is (apparently) no way to acess
> the request object inside RemovableFileField nor from the widget...
> 
> SO I think I have to implement this in the ModelForm, or in the
> ModelAdmin, which is a more ugly solution.
> (any ideas???)
> 
> 


If anyone wants to use it, I implemented this solution.

Just use FilesModelAdmin for your models that have file or image fields.

1. A checkbox will be displayed, to remove the current value, if the
field supports blank values.
2. The uploaded files are stored in session variables for later use, in
case the form fails validation you don't need to upload then again.
3. It works for inline models also.

Problem:
if the user is editing two forms at the same time in the same session,
the uploaded files will be mixed...




# coding: utf-8
from django.contrib import admin
from django import forms
from django.utils.safestring import mark_safe

from django.utils.translation import ugettext, ugettext_lazy as _

import django.core.files
import re
import tempfile, shutil

from django.db import models

# if we have a field called "imagem", the associated checkbox for
deleting the file will be "imagem"  + REMOVE_SUFFIX,  "imagem__remove"
REMOVE_SUFFIX = "__remove"

# The session variable name we will use to store the uploaded files
SESSION_NAME = "save_uploaded_files"

import threading

# remember the request value
# so it can be accessed from any place in the thread
def set_current_request(request):
   global local
   local = threading.local()
   local.current_request = request

def get_current_request():
   global local
   return local.current_request


class FileWidget(forms.FileInput):
   # if this file accepts blanks or not
   # This will define if we put a checkbox for removing the file
   blank = False

   def render(self, name, value, attrs=None):

  output = []
  if value:
 # file has a current value

 if hasattr(value, "url"):
# the file value is the value stored in the model
output.append('%s %s %s ' % \
 (ugettext('Currently:'), value.url, value,
ugettext('Change:')))

 else:
# the file value is the file uploaded in the previous
request but not saved yet, because the form validation failed:
output.append('%s %s %s ' % \
 (ugettext('Not saved yet:'), value,
ugettext('Change:')))

 # If it has a current value, and the field accepts blanks,
 # we place a checkbox for removing it
 if self.blank:
request = get_current_request()

name_checkbox = name + REMOVE_SUFFIX

# This is important to remember the checkbox state,
# when the form is submited but fails validation, and is
displayed again
if request and name_checkbox in request.POST.keys():
   checked = 'checked="on"'
else:
   checked = ''

output.append(' %s ' % (name_checkbox, name, checked,
name, ugettext('Remove')))

  output.append(super(FileWidget, self).render(name, value, attrs))

  return mark_safe(u''.join(output))

# The same, but accepts blanks
class FileWidgetBlank(FileWidget):
   blank = True


# This ModelAdmin offers this funtionalities:
# For each file or image field, keeps uploaded files in the server even
if the form fails validation, so they dont need to be uploaded again.
When the form is saved, the uploaded files are also saved to the model.
# Put a checkbox for removing the file, it it accepts blanks.
# This also works for inline models, which have to be FilesStackedInline
class FilesModelAdmin(admin.ModelAdmin):

   def formfield_for_dbfield(self, db_field, **kwargs):
  # is it file or image?
  if type(db_field) in [ models.ImageField, models.FileField]:
 if db_field.blank:
# accept blank?
kwargs['widget'] = FileWidgetBlank
 else:
kwargs['widget'] = FileWidget
  return super(FilesModelAdmin,
self).formfield_for_dbfield(db_field,**kwargs)

   # This function is called before add_view and change_view
   # It saves the uploaded files, and at the same time restores previous
uploaded files.
   def manage_uploads(self, request):

  # this is for the request to be accessible from FileWidget

  # I could have implemented get_form doing this:
  #fo

Re: New to Django, sheet music organization site

2011-01-02 Thread Kyle
Thank you very much! You have been very helpful. I have, however, run
into another problem.

When I try to access my Object, I get an error "invalid literal for
int() with base 10". I know it has something to do with ForeignKeys,
but cannot find how to fix it.

**models.py**--

from django.db import models

# Create your models here.

class Artist(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(unique=True)

def __unicode__(self):
return self.name

class Album(models.Model):
name = models.CharField(max_length=200)
artist = models.ForeignKey(Artist)

def __unicode__(self):
return self.name

class Song(models.Model):
name = models.CharField(max_length=100)
artist = models.ForeignKey(Artist)
album = models.ForeignKey(Album)
date_added = models.DateField('date added')

def __unicode__(self):
return self.name

**views.py**--

from music.models import Song
from django.shortcuts import render_to_response

# Create your views here.

def index(request):
artist = Song.objects.all().order_by('name')
return render_to_response('music/index.html', {'artist': artist})

def artist(request, myartist):
myArgs = Song.objects.all().filter(artist=myartist)
return render_to_response('music/index.html', {'artist': myArgs})

-

Thanks

On Jan 2, 6:08 pm, Mike Dewhirst  wrote:
> On 3/01/2011 9:56am, Kyle wrote:
>
> > Ok I have a good start. I have run into a problem though. In my
> > database, I have an artist field. Most artists have a space in there
> > name. When creating my URLs, how can I ignore white space?
>
> > For example, take the artist Chris Tomlin. In my database, it will
> > show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
> > to access it, I want to type "music/christomlin" or "music/
> > chris_tomlin". How can I do this?
>
> Stick to Chris Tomlin everywhere in your database because that is the
> name you want. Most systems with people names split them into surname
> and given name columns but that doesn't seem to make sense in your case
> unless you think you will want to search millions of records by separate
> surname or given names.
>
> The URL however is a different matter. You need to decide how you want
> to refer to the artists in a consistent way and put a decorated method
> in your artist model something like ...
>
> @models.permalink
> def get_absolute_url(self):
>      return "/music/artist/%s/" % self.slug
>
> ... where self.slug is a field on the artist model where you store the
> representation of the artist's name in exactly the way you want to type
> it in as a URL.
>
> Note that I added /artist/ to your URL because you will probably want to
> do something similar for songs and the same principle applies.
>
> If you did something like this in your artist model ...
>
> slug = models.SlugField(unique=True)
>
> ... then the admin app would automatically create the slug for you with
> hyphens replacing spaces and everything lower-cased. But you need to
> specify in the admin app which field is the source for the slug.
>
> Otherwise, you could write a method of your own on the artist model to
> massage the name as you prefer and populate the slug field when saving a
> record.
>
> hth
>
>
>
>
>
>
>
>
>
> > Thanks.

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



Redirecting to last view after login.

2011-01-02 Thread keynesiandreamer
I have wrestled with this one for a bit and googled and looked through
documentation, so I guess its time to ask.

I am trying make my app redirect to the last viewed page after logging
in. I am running django 1.2.4 and have had no luck so far.

This Stack Overflow thread seemed like it would do the trick but I
have not had success with it:
http://stackoverflow.com/questions/806835/django-redirect-to-previous-page-after-login

Currently after logging in from any view I am redirected to:
http://localhost:1100/accounts/profile/

Currently I am trying this in settings.py:
"django.core.context_processors.request",

With this as my login button link:
login

I also made sure to import the RequestContext in my views.py file:
from django.template import RequestContext

Some how I get the impression this is not working. Also I noticed now
login URL has a partial next URL in it:
http://localhost:1100/accounts/login/?next=

Suggestions?

Thanks in advance!

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



Re: Show HTML in Labels for Model Choice Fields

2011-01-02 Thread Adi
I was able to find the solution to it myself.

The key was to
1. Create a custom field that extended ModelChoiceField.
2. Overwrite the label_from_instance method in the custom field.
3. Return a HTML string from the label_from_instance method, and
marking that as a safe_string.


from django.forms import ModelChoiceField
from django.utils.safestring import mark_safe

class ThemeChoiceField(ModelChoiceField):
def label_from_instance(self,obj):
return mark_safe("%s - Click here to see an example. \
 " \
% (obj.name, obj.pk, obj.pk, obj.image.url))

-Adi


On Dec 30 2010, 6:36 pm, Adi  wrote:
> Hi I have a situation like this
>
> class AppearanceThemesForm(forms.Form):
>     page_theme =
> forms.ModelChoiceField(widget=forms.RadioSelect(attrs={'title':'Select
> the appropriate theme for your pages.'}),
>
> queryset=Theme.objects.filter(section="1"),
>
> initial=Theme.objects.get(section="1",representation="").pk,
>                                         label="Page Theme")
>
> And my Theme model is like this:
>
> class Theme(models.Model):
>     name = models.CharField(max_length=32)
>     image = models.ImageField(upload_to="images/themes", null=True)
>
>     def __unicode__(self):
>         return "%s" % (self.name)
>
> When I render AppearanceThemesForm in my template, i would like to be
> able to show a link next to the label. If a user clicks the link, the
> webpage displays the image associated with Theme.
>
> I tried putting in a custom field that extends the ModelChoiceField,
> and in the label_from_instance method, tried to output the HTML, but
> that gets escaped.
>
> What is the proper way to achieve what i am trying to do?
>
> Alternatively, how do i get access the underlying model object behind
> the modelchoice field in my templates?

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



Too many items in my drowndown list

2011-01-02 Thread mongoose
Hi there,

I have a drowdown list in my inlines. The problem is that there are
over 3500 items which is making is difficult for people to use. Are
there eaiser ways perhaps to filter or search within the dropdownlist?


Thanks

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