Re: How to call an API? (django-dynamicresponse)

2011-11-08 Thread Benjamin Buch
Found the answer while reading the piston documentation:

curl -H "Accept: application/json" http://127.0.0.1:8000/api/";

The -H option allows to pass a custom header to the server.

Best,
Benjamin

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



How to call an API? (django-dynamicresponse)

2011-11-08 Thread Benjamin Buch
I'm new to APIs and played around with 
https://github.com/funkbit/django-dynamicresponse
today.
I get no errors, but it seems that I'm not able to call the API
correctly.

I configured the URLs so that the view available under 
http://127.0.0.1:8000/api/
returns SerializeOrRender.
But when I call the URL in the browser, I just get the HTML template
rendered instead of a JSON response.

The dynamicresponse doc says:

"The framework provides two response classes; SerializeOrRender and
SerializeOrRedirect.

As the names imply, these response classes serialize the supplied
context as JSON for API requests, and renders a template or redirects
to a URL for normal requests."

So it seems like typing the URL into the browser would be a "normal
requst".
How should an API request look like in comparison?

Best,
Benjamin

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



Strange query string/doubled value?

2010-09-19 Thread Benjamin Buch
Hi,

I'm getting the following value-error on a production site (extract from the 
error message):

Traceback (most recent call last):

 File "/.../django/core/handlers/base.py", line 100, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/.../work/views.py", line 23, in artwork
   pictures.insert(0, pictures.pop(int(request.GET['picture']) -1))

ValueError: invalid literal for int(): 4?picture=5
...
'HTTP_HOST': 'dorthegoeden.de',
...
'QUERY_STRING': 'picture=4?picture=5',
'REDIRECT_STATUS': '200',
'REDIRECT_URI': 
'/django.fcgi/arbeiten/raumbezogene-arbeiten/horch-was-waechst/?picture=4?picture=5',
...
'REQUEST_METHOD': 'GET',
'REQUEST_URI': 
'/arbeiten/raumbezogene-arbeiten/horch-was-waechst/?picture=4?picture=5',
...

Here is the code in question:

views.py:

def artwork(request, category, artwork):
artworks = Artwork.objects.filter(category__slug=category)
artwork = get_object_or_404(Artwork, slug=artwork)
pictures = list(artwork.picture_set.all())
for picture in pictures:
picture.position = pictures.index(picture) + 1
if 'picture' in request.GET:
try:
pictures.insert(0, pictures.pop(int(request.GET['picture']) -1))
except IndexError:
pass
context = {'artwork': artwork, 'artworks': artworks, 'pictures': pictures}
return render_to_response('work/artwork.html', context, 
context_instance=RequestContext(request))

artwork.html:

{% for picture in pictures %}
{% if forloop.first %}

{% else %}

{% endif %}
{% endfor %}

I understand that I get a ValueError if the value that I pass int() is 
something like '4?picture=5'...

But how comes that from that code a URL like 
'http://dorthegoeden.de/arbeiten/raumbezogene-arbeiten/horch-was-waechst/?picture=4?picture=5'
 can be constructed by a user clicking around that page in the first place?
Or is this perhaps a bot's work?

I can think of two possible solutions for that problem:

1: Pass the ValueError like this:

if 'picture' in request.GET:
try:
pictures.insert(0, pictures.pop(int(request.GET['picture']) -1))
except IndexError:
pass
except ValueError:
pass

2: Construct the URL differently like this:



By attaching '&' to the 'picture'-value, the strangely constructed URLs would 
look like this, which I think would work:
'http://dorthegoeden.de/arbeiten/raumbezogene-arbeiten/horch-was-waechst/?picture=4?&picture=5&;'

Thanks for any hints on what's best or other advice,

Benjamin


  



-- 
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: Sports app?

2010-04-14 Thread Benjamin Buch



there is one for golf, but that is not a sport - it is a vocation ;-)


Do you mean Django Golf Handicap Tracker by David Grant?
http://www.davidgrant.ca/django_golf_handicap_tracker

That's the only one i came up with after a quick search...



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



Sports app?

2010-04-14 Thread Benjamin Buch

Hi,

I was wondering if there is a django app to manage sports teams and  
scores out there...


Found some posts on the list concerning questions about writing your  
own, but the only project I found is

http://code.google.com/p/sports-org/
, which has no updates since 1 1/2 years.

Best,
Benjamin


--
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: Peepcode like screencasts for Django

2009-09-30 Thread Benjamin Buch

I especially enjoyed Eric Florenzano's excellent screencast series  
'Django From the Ground Up'.

You'll find it here:
http://thisweekindjango.com/screencasts/

There are no screencasts on http://djangodose yet,
but I think this is a good place to look out for screencasts in the  
future.

-benjamin

Am 01.10.2009 um 06:47 schrieb hrishy:

> Hi
>
> Rails programmers have many screencasts like http://railscasts.com/  
> to bring newbie programmers upto speed is there anything like tahat  
> available for Django
>
> regards


--~--~-~--~~~---~--~~
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: Editors of choice

2009-09-09 Thread Benjamin Buch


I second that.

>
> Vim
>


--~--~-~--~~~---~--~~
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: Deployment on same server: Conflict staging/production

2009-09-08 Thread Benjamin Buch


Hi Mike,

that actually helped!

Putting the staging project folder in a folder of its own
and changing server relevant settings did the trick.

-benjamin

Am 08.09.2009 um 15:29 schrieb Mike Ramirez:

> I do something similar one site, but both have parent directory that  
> holds
> misc data and the project dir, example:
>
> staging/
>   apache/
>   apache scripts and custom conf files specific to this deployment
>   myproject/
>   ...
>   misc_stuff/
>   scripts specific to this deployment
> live/
>   apache/
>   scripts and custom conf files specific to this deployment
>   myproject/
>   ...
>   misc_stuff/
>   scripts specific to this deployment
>
> Both are checked out from the same svn (instead of git) repo.   
> Staging of
> course is where I edit and make changes to the code for live and  
> commits are
> from stage. While live is a read only checkout.
>

> Hope this helps,
>
> Mike


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



Deployment on same server: Conflict staging/production

2009-09-08 Thread Benjamin Buch

Hi,

I'm working on a small project
trying to get used to the development/staging/production setup.

I develop on my local machine,
push to a git repo
and pull from there to staging and then finally to production.

My problem here is that the staging and the production projects are  
deployed on the same server.
Thus, the project folders can't have the same names -
the production folder is called say 'myproject', so the staging folder  
has to be called different, say 'myproject_staging'.

Of course I run into conflicts here -
many imports in my code plus settings.py (INSTALLED_APPS, ROOT_URLCONF)
refer to 'myproject' - and not to 'myproject_staging'.

How can I work around this?
Is it time for me to have a look at virualenv?

-benjamin


--~--~-~--~~~---~--~~
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: pagination

2009-03-30 Thread Benjamin Buch

django-pagination makes use of the Djangos' built in pagination,
so it's more like a wrapper on top but no distinct 'engine'.

If you have a need for some special customized pagination,
I would recommend Djangos' own pagination,
but if you want easy setup and some more generic pagination funcionality
I would use django-pagination.

As Jakob mentioned,
it's really easy and well written and should cover most use cases.

Benjamin

Am 30.03.2009 um 12:36 schrieb Konstantin S:

> Hello!
>
> I noticed that there are two paginations 'engines' available for
> django. The first one is in django distribution itself
> (http://docs.djangoproject.com/en/1.0/topics/pagination/), and the
> second one I found at code.google.com. (Url is
> http://code.google.com/p/django-pagination/). Which one would you
> recommend ?


--~--~-~--~~~---~--~~
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: Strip empty lines in rendered templates?

2009-03-16 Thread Benjamin Buch

Yes, you're right.

But as the SpacelessMiddleware uses djangos' strip_spaces_between_tags,
which strips all whitespace between tags and not just empty lines,
I think it would have been fiddly to adapt it without touching django  
internals.
In this case it seemed easier for me to use StripWhitespaceMiddleware,  
which did what I wanted.

benjamin

Am 16.03.2009 um 17:37 schrieb Dougal Matthews:

> You could adapt that middlewear to make it only stop blank lines I'm  
> sure.
>
> I use it for one website and its only used in the production  
> version, in my settings for the dev version it doesn't include that  
> middlewear so it doesn't effect any front end development.
>
> Only thing to be aware of is it messes up some tags, like   
> and 
>
> Dougal

--~--~-~--~~~---~--~~
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: Strip empty lines in rendered templates?

2009-03-16 Thread Benjamin Buch

Thank you for your replies!

What I essentially want to do is:
1: Keep the template output readable for the frontend coder I'm  
working with
2: Keep the templates readable for me.

@Dougal:
I think the solution you suggested is great when someone wants to keep  
the size of the rendered template to a minimum.
But as it strips really all whitespace, all linebreaks and everything,  
the result is perfectly machine readable
but nothing that would make my frontend coder be happy.

@Tim:
This solution would give me the desired output, but the templates get  
less readable for me this way.

What I figured out:

I gave the StripWhitespaceMiddleware I mentioned a try,
and it works reasonably well.
It just strips empty lines but keeps the indentation the tags have in  
the template,
so you've got reasonable control over how the rendered templates look  
like.

The downsides I see so far are:
- You can't add empty lines to structure the rendered template
- Multiline output from template variables are not indented (e.g.  
something like {{ entry.body|markdown }})

I have no solution for the add-empty-line-problem,
but I wrote a template tag that indents the output of a multiline  
variable.
It's not perfect (it destroys all indentation that is output by  
markdown..) but it works for me:

class IndentNode(Node):
 def __init__(self, nodelist, indent_level):
 self.indent_level = indent_level
 self.nodelist = nodelist

 def render(self, context):
 rendered = self.nodelist.render(context)
 lines = rendered.split('\n')
 for i in range(len(lines)):
 if lines[i]:
 lines[i] = ' ' * int(self.indent_level) +  
lines[i].strip(' ')
 rendered = ''
 for line in lines:
 rendered += line + '\n'
 return rendered

def do_indent(parser, token):
 bits = token.contents.split()
 try:
 indent_level = bits[1]
 except IndexError:
 indent_level = 0
 nodelist = parser.parse(('endindent',))
 parser.delete_first_token()
 return IndentNode(nodelist, indent_level)

You would use it like this:

{% indent 8 %}
{{ entry.body|markdown }}
{% endindent %}

An other solution I tried but rejected was to use Beatiful Soups  
'prettify'-method in a middleware:

class BeautifulSoupMiddleware:
 def process_response(self, request, response):
 new_content = BeautifulSoup(response.content).prettify()
 response.content = new_content
 return response

But the output was a little to shaky, so I can't recommend it.


benjamin





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



Strip empty lines in rendered templates?

2009-03-15 Thread Benjamin Buch

Hi,

is there a way to tighten up the output that Django renders?
Especially, remove the empty lines?

This template code:


{% for entry in entries %}
{{ entry.title }}
{% endfor %}


looks like this when rendered:



Title 1

Title 1

Title 1



I stumbled upon this middleware,
http://code.djangoproject.com/wiki/StripWhitespaceMiddleware,
but the discussion around it is somewhat dated,
and even the author states that there are some problems with it.
http://code.djangoproject.com/wiki/ContributedMiddleware

Is there any other way to handle it?

benjamin

--~--~-~--~~~---~--~~
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: docs: Problem with 'make html'

2009-02-02 Thread Benjamin Buch

Thanks for ointing me in the right direction!
I had the sphinx version from macports installes, which was something  
about 0.1.6 or something...
Installed 0.5.1 via easy_install (which didn't work quite well, but  
did...)

Now it works.

benjamin

Am 01.02.2009 um 12:40 schrieb Ramiro Morales:

>
> On Sat, Jan 31, 2009 at 8:48 AM, Benjamin Buch   
> wrote:
>>
>> Hi,
>>
>> if I do 'make html' in my django-trunk/docs directory, I get this  
>> error:
>>
>> [...]
>>
>> Traceback (most recent call last):
>>  File "/opt/local/lib/python2.5/site-packages/sphinx/__init__.py",
>> line 114, in main
>>confoverrides, status, sys.stderr, freshenv)
>>  File "/opt/local/lib/python2.5/site-packages/sphinx/
>> application.py", line 81, in __init__
>>self.setup_extension(extension)
>>  File "/opt/local/lib/python2.5/site-packages/sphinx/
>> application.py", line 120, in setup_extension
>>mod.setup(self)
>>  File "/Users/benjamin/Code/django/django-trunk/docs/_ext/
>> djangodocs.py", line 15, in setup
>>app.add_crossref_type(
>> AttributeError: 'Sphinx' object has no attribute 'add_crossref_type'
>>
>> I'm using a recent version of django.
>
> Which version of Sphinx are you using?.
>
> -- 
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem with contenttype/renaming of an app

2009-02-02 Thread Benjamin Buch
I think I've got it now.
I didn't dump the data of the seperate apps, but everything.
So I dumped some auth tables too.

Strangely, some tables of 'stanza' were not installed, but ./manage.py  
syncdb fixed this.

Got to get accustomed to SQL some more... ;-)

benjamin

Am 24.01.2009 um 21:38 schrieb felix:

>
> look in auth_permission
>
> I would just rename them by hand or by sql
>
>
> http://crucial-systems.com
>
>
>
> On Sat, Jan 24, 2009 at 8:19 PM, Benjamin Buch   
> wrote:
>
> Hi,
>
> during development, I messed around with an app name.
> First it was called 'body copies' (no native speaker!), then I renamed
> it to 'stanza', which I liked better.
> No problem there: As there was no data in the db, I deleted the tables
> and created them again, with other names.
>
> Then I deployed the project.
> I transfered the data via manage.py dumpdata/loaddata.
> Still no problems when I'm logged in as admin.
>
> But:
> When I create a new user group and want to give permissions, there's
> still 'body copy' instead of 'stanza'.
> ('bodyopies | body copy | Can add static content' and so on...)
>
> If I give the bodycopy permissions and log in as a user with those
> permissions, I'm not able to edit 'stanza'.
> The 'stanza'-area won't even show up in the admin panel, neither does
> 'bodycopies'.
>
> I took a look at the database, and in the table 'django_content_type'
> I found some entries refering to 'bodycopies':
>
> id |name   |  app_label | model
> ---+---++---
> 09 | body copy | bodycopies | bodycopy
>
> I renamed them to the according 'stanza' labels.
> After that, in the group permissions on the group page 'stanza' showed
> up instead of 'bodycopies',
> but I still was not able to edit 'stanza' as non-admin-user.
>
> Any ideas?
>
> Benjamin
>
>
>
>
>
>
> >


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



docs: Problem with 'make html'

2009-02-01 Thread Benjamin Buch

Hi,

if I do 'make html' in my django-trunk/docs directory, I get this error:

mkdir -p _build/html _build/doctrees
sphinx-build -b html -d _build/doctrees   . _build/html
Exception occurred:
   File "/Users/benjamin/Code/django/django-trunk/docs/_ext/ 
djangodocs.py", line 15, in setup
 app.add_crossref_type(
AttributeError: 'Sphinx' object has no attribute 'add_crossref_type'
The full traceback has been saved in /var/folders/Yb/ 
YbJi1xdnH98ZWGMLUVZ5GU+++TI/-Tmp-/sphinx-err-SPVwHe.log, if you want  
to report the issue to the author.
Please also report this if it was a user error, so that a better error  
message can be provided next time.
Send reports to ge...@python.org. Thanks!
make: *** [html] Error 1

This is the full traceback:

Traceback (most recent call last):
   File "/opt/local/lib/python2.5/site-packages/sphinx/__init__.py",  
line 114, in main
 confoverrides, status, sys.stderr, freshenv)
   File "/opt/local/lib/python2.5/site-packages/sphinx/ 
application.py", line 81, in __init__
 self.setup_extension(extension)
   File "/opt/local/lib/python2.5/site-packages/sphinx/ 
application.py", line 120, in setup_extension
 mod.setup(self)
   File "/Users/benjamin/Code/django/django-trunk/docs/_ext/ 
djangodocs.py", line 15, in setup
 app.add_crossref_type(
AttributeError: 'Sphinx' object has no attribute 'add_crossref_type'

I'm using a recent version of django.

Any ideas?


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



Problem with contenttype/renaming of an app

2009-01-24 Thread Benjamin Buch

Hi,

during development, I messed around with an app name.
First it was called 'body copies' (no native speaker!), then I renamed  
it to 'stanza', which I liked better.
No problem there: As there was no data in the db, I deleted the tables  
and created them again, with other names.

Then I deployed the project.
I transfered the data via manage.py dumpdata/loaddata.
Still no problems when I'm logged in as admin.

But:
When I create a new user group and want to give permissions, there's  
still 'body copy' instead of 'stanza'.
('bodyopies | body copy | Can add static content' and so on...)

If I give the bodycopy permissions and log in as a user with those  
permissions, I'm not able to edit 'stanza'.
The 'stanza'-area won't even show up in the admin panel, neither does  
'bodycopies'.

I took a look at the database, and in the table 'django_content_type'  
I found some entries refering to 'bodycopies':

id |name   |  app_label | model
---+---++---
09 | body copy | bodycopies | bodycopy

I renamed them to the according 'stanza' labels.
After that, in the group permissions on the group page 'stanza' showed  
up instead of 'bodycopies',
but I still was not able to edit 'stanza' as non-admin-user.

Any ideas?

Benjamin



--~--~-~--~~~---~--~~
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: Problems with InlineModelAdmin: Date hierarchy?

2009-01-21 Thread Benjamin Buch
All right, I think I've got it:

1: I tried to use InlineModelAdmin with a ManyToMany-Field.
You can do this, but you've got to do it as described here I guess:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models
 
.

2: I confused the model which has the foreign key  with the other one.
If class a has a foreign key to class b, it's class a which inherits  
from TabularInline, not the other way around like I did.

3: You don't have to register Inline classes, as Karen said in her  
mail (which I got while I'm writing this one...Thanks Karen!)

Here's the working example:

from django.db import models

class a(models.Model):
 title = models.CharField(max_length=50)

 def __unicode__(self):
 return self.title

class b(models.Model):
 title = models.CharField(max_length=50)
 other_model = models.ForeignKey('a')

 def __unicode__(self):
 return self.title

admin.py:

from myproject.myapp.models import a, b
from django.contrib import admin

class bInline(admin.TabularInline):
 model = b

class aAdmin(admin.ModelAdmin):
 inlines = [bInline]

admin.site.register(a, aAdmin)

Thanks!
Benjamin


Am 21.01.2009 um 17:36 schrieb Benjamin Buch:

> I simplified the models a bit for better demonstration.
> Here's the model:
>
> from django.db import models
>
> class a(models.Model):
> title = models.CharField(max_length=50)
> other_model = models.ManyToManyField('b')
>
> def __unicode__(self):
> return self.title
>
> class b(models.Model):
> title = models.CharField(max_length=50)
>
> def __unicode__(self):
> return self.title
>
> Here's admin.py:
>
> from myproject.myapp.models import a, b
> from django.contrib import admin
>
> class bInline(admin.TabularInline):
> model = b
>
> class aAdmin(admin.ModelAdmin):
> inlines = [bInline]
>
> admin.site.register(b, bInline)
> admin.site.register(a, aAdmin)
>
> Now, when I'm trying to acess the admin in the browser, I get this  
> error thrown (Traceback):
>
> Traceback:
> File "/Library/Python/2.5/site-packages/django/core/handlers/ 
> base.py" in get_response
>   77. request.path_info)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in resolve
>   181. for pattern in self.url_patterns:
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in _get_url_patterns
>   205. patterns = getattr(self.urlconf_module,  
> "urlpatterns", self.urlconf_module)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in _get_urlconf_module
>   200. self._urlconf_module =  
> __import__(self.urlconf_name, {}, {}, [''])
> File "/Users/benjamin/Code/django/myproject/../myproject/urls.py" in  
> 
>   6. admin.autodiscover()
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> __init__.py" in autodiscover
>   54. __import__("%s.admin" % app)
> File "/Users/benjamin/Code/django/myproject/../myproject/myapp/ 
> admin.py" in 
>   10. admin.site.register(b, bInline)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> sites.py" in register
>   76. validate(admin_class, model)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> validation.py" in validate
>   72. if cls.date_hierarchy:
>
> Exception Type: AttributeError at /admin/
> Exception Value: type object 'bInline' has no attribute  
> 'date_hierarchy'
>
> Thanks,
> Benjamin
>
> Am 21.01.2009 um 17:19 schrieb Karen Tracey:
>
>> On Wed, Jan 21, 2009 at 10:53 AM, Benjamin Buch   
>> wrote:
>>
>> Hi,
>>
>> I'm trying to use InlineModelAdmins, but get a strange error  
>> thrown...
>>
>> You get this error raised when you do what, exactly?  Also the full  
>> traceback might provide a clue of what is going on.
>>
>> Karen
>
> >


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



Re: Problems with InlineModelAdmin: Date hierarchy?

2009-01-21 Thread Benjamin Buch
I simplified the models a bit for better demonstration.
Here's the model:

from django.db import models

class a(models.Model):
 title = models.CharField(max_length=50)
 other_model = models.ManyToManyField('b')

 def __unicode__(self):
 return self.title

class b(models.Model):
 title = models.CharField(max_length=50)

 def __unicode__(self):
 return self.title

Here's admin.py:

from myproject.myapp.models import a, b
from django.contrib import admin

class bInline(admin.TabularInline):
 model = b

class aAdmin(admin.ModelAdmin):
 inlines = [bInline]

admin.site.register(b, bInline)
admin.site.register(a, aAdmin)

Now, when I'm trying to acess the admin in the browser, I get this  
error thrown (Traceback):

Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"  
in get_response
   77. request.path_info)
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
in resolve
   181. for pattern in self.url_patterns:
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
in _get_url_patterns
   205. patterns = getattr(self.urlconf_module, "urlpatterns",  
self.urlconf_module)
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
in _get_urlconf_module
   200. self._urlconf_module =  
__import__(self.urlconf_name, {}, {}, [''])
File "/Users/benjamin/Code/django/myproject/../myproject/urls.py" in  

   6. admin.autodiscover()
File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
__init__.py" in autodiscover
   54. __import__("%s.admin" % app)
File "/Users/benjamin/Code/django/myproject/../myproject/myapp/ 
admin.py" in 
   10. admin.site.register(b, bInline)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py"  
in register
   76. validate(admin_class, model)
File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
validation.py" in validate
   72. if cls.date_hierarchy:

Exception Type: AttributeError at /admin/
Exception Value: type object 'bInline' has no attribute 'date_hierarchy'

Thanks,
Benjamin

Am 21.01.2009 um 17:19 schrieb Karen Tracey:

> On Wed, Jan 21, 2009 at 10:53 AM, Benjamin Buch   
> wrote:
>
> Hi,
>
> I'm trying to use InlineModelAdmins, but get a strange error thrown...
>
> You get this error raised when you do what, exactly?  Also the full  
> traceback might provide a clue of what is going on.
>
> Karen

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



Problems with InlineModelAdmin: Date hierarchy?

2009-01-21 Thread Benjamin Buch

Hi,

I'm trying to use InlineModelAdmins, but get a strange error thrown...

Here's admin.py:

from mysite.showroom.models import Project, ProjectImage, Client,  
Service
from django.contrib import admin
from filebrowser import fb_settings

class ProjectImageInline(admin.TabularInline):
 model = ProjectImage
 class Media:
 js = [fb_settings.URL_FILEBROWSER_MEDIA + '/js/ 
AddFileBrowser.js']

class ProjectAdmin(admin.ModelAdmin):
 inlines = [ProjectImageInline,]
 prepopulated_fields = {'slug': ('title',)}
 class Media:
 js = [fb_settings.URL_FILEBROWSER_MEDIA + '/js/ 
AddFileBrowser.js']

class ClientAdmin(admin.ModelAdmin):
 prepopulated_fields = {'slug': ('name',)}
 class Media:
 js = [fb_settings.URL_FILEBROWSER_MEDIA + '/js/ 
AddFileBrowser.js']

class ServiceAdmin(admin.ModelAdmin):
 pass

admin.site.register(ProjectImage, ProjectImageInline)
admin.site.register(Project, ProjectAdmin)
admin.site.register(Client, ClientAdmin)
admin.site.register(Service, ServiceAdmin)

The error says

type object 'ProjectImageInline' has no attribute 'date_hierarchy'

What is this about a 'date hirarchy'?

The model ProjectImage has not date:

class ProjectImage(models.Model):
 """One or more images for the project model"""
 title = models.CharField(max_length=100, help_text='The title is  
also used as the alt tag of the image.')
 image = FileBrowseField(max_length=250,
 initial_directory='/showroom/projects/',
 extensions_allowed=['.jpg', '.jpeg',  
'.gif', '.png', '.tif', '.tiff'])

 def __unicode__(self):
 return self.title

What could be wrong here?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: FileBrowser: Easy access to generated images from the template?

2009-01-19 Thread Benjamin Buch

Thank you!

I guess I'll wait...

Benjamin

Am 19.01.2009 um 10:30 schrieb patrickk:

>
> you could either use a templatetag or a custom-method.
>
> that said, we are just working on integrating this with the  
> filebrowse-
> field. so, if you wait a couple of days it´ll be there.
>
> here´s more information: 
> http://code.google.com/p/django-filebrowser/issues/detail?id=63
>
> patrick.
>
>
> On Jan 18, 1:52 pm, Benjamin Buch  wrote:
>> I'm using django-filebrowser(http://code.google.com/p/django-filebrowser/
>> ) to upload and manage files within my project.
>> And it's working great!Filebrowseris a great app.
>>
>> The only problem I'm having is this:
>> I coupledfilebrowserwith on of my models ('News') and use the
>> FileBrowse-Field for this 
>> (http://code.google.com/p/django-filebrowser/wiki/installationfilebrow 
>> ...
>> ),
>> and I like filebrowsers' image generator and want to use it.
>>
>> But how can I access the generated images from the template?
>> Say I have the template variable 'news_report' in my template and  
>> want
>> to display the image, I would write
>>
>> 
>>
>> That would give me the original image, not the processed one.
>> The url for the original image is something like
>>
>> '/media/uploads/news/DSC04678.JPG',
>>
>> and the url to the processed version would be something like
>>
>> '/media/uploads/news/dsc04678_jpg_versions/cropped_DSC04678.JPG'
>>
>> Is there a way to access the url to the processed image from the
>> template?
>>
>> Benjamin
> 

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



FileBrowser: Easy access to generated images from the template?

2009-01-18 Thread Benjamin Buch

I'm using django-filebrowser (http://code.google.com/p/django-filebrowser/ 
) to upload and manage files within my project.
And it's working great! Filebrowser is a great app.

The only problem I'm having is this:
I coupled filebrowser with on of my models ('News') and use the  
FileBrowse-Field for this 
(http://code.google.com/p/django-filebrowser/wiki/installationfilebrowsefield 
),
and I like filebrowsers' image generator and want to use it.

But how can I access the generated images from the template?
Say I have the template variable 'news_report' in my template and want  
to display the image, I would write



That would give me the original image, not the processed one.
The url for the original image is something like

'/media/uploads/news/DSC04678.JPG',

and the url to the processed version would be something like

'/media/uploads/news/dsc04678_jpg_versions/cropped_DSC04678.JPG'

Is there a way to access the url to the processed image from the  
template?

Benjamin


--~--~-~--~~~---~--~~
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: Do you recommend "Practical Django Projects"?

2009-01-05 Thread Benjamin Buch

I agree, Practical Django Projects is a great book!
Altough I would only recommend it if you've read the docs and worked  
you way through the tutorial (which are both excellent as someone  
mentioned earlier...)
It's full of best practices and a lot of bits and pieces that are not  
covered by the tutorial.
Which is good by the way because the tutorial is clearly for  
beginners, and Practical Django Projects is more towards the  
intermediate djangonaut I would say.
As brad says, it gives you more of the big picture.

I've learned a lot from it!

So if you've got some time, wait a few months, if you are to eager or  
to curious to learn django, just go and get it.
Altough it's a little bit outdated, the biggest part of it (especially  
best practices) is still up to date.
If you know some django, you will recognize the parts where it's  
behind django 1.0.2.

benjamin

Am 05.01.2009 um 15:42 schrieb brad:

>
>
> On Jan 5, 2:21 am, HB  wrote:
>> Do you recommend "Practical Django Projects" instead?
>
> I got this book as soon as it came out, and very soon after Django hit
> 1.0.  It's a good book, and I learned a few "big picture" ideas from
> the sample apps, but I really had to read the docs to figure out how
> to do the specifics.
>
> If you're looking for the "big picture", grab it from a library or
> borrow it from a friend.. otherwise, wait for the next edition or just
> read the docs (which are very excellent, btw).


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



Re: How to randomize a sliced query set?

2008-12-02 Thread Benjamin Buch

Worked like a charm...

Thanks!

>
>> coupon_items = Item.objects.all()[:25]
>> random.shuffle(coupon_items)
>>
>> doesn't word because a QuerySet object does not support item
>> assignment, which is used by random.shuffle.
>
> You might be able to cast the queryset as a list and then use
> random.shuffle:
>
>   coupon_items = list(Item.objects.all()[:25])
>   random.shuffle(coupon_items)
>
> -tim


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to randomize a sliced query set?

2008-12-02 Thread Benjamin Buch

Hi,

I'd like to have a sliced query set in random order.

I tried

coupon_items = Item.objects.order_by('?')[:25]

,it seemed to work first but than I noticed that coupon_items consists  
of doubled items (although all Item objects are distinct).

coupon_items = Item.objects.all()[:25].order_by('?')

doesn't work because you can't reorder a queryset once a slice has  
been taken.

coupon_items = Item.objects.all()[:25]
random.shuffle(coupon_items)

doesn't word because a QuerySet object does not support item  
assignment, which is used by random.shuffle.

The problem was also adressed by this thread
http://groups.google.com/group/django-users/browse_thread/thread/1364d04127caff99
but I didn't get the answer...

Regards,
Benjamin




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django's decoupling apps but template should couple them together, right?

2008-11-03 Thread Benjamin Buch


Am 03.11.2008 um 02:33 schrieb ilmarik:

> It's just simple amazing that I waste another night to figure out how
> to glue two and more apps together inside one template.
> I read about custom tags and I thing it isn't (or at least it
> shouldn't be) the way of doing it. too much fuss imho.
>
> Example:
> I have home page with menu on one side, news on other side, greetings
> article inside, footer menu on bottom and a survey somewere else.
> everything on one page of course.
>
> Walking with the idea of decoupled apps, I should create News app,
> Survey app, Menu app and so on...

There are several ways to get data from apps into templates:

Views:
-
With views you have the ability to tailor the data you want to display  
to the needs of a specific page.
Views are not necessarily coupled to apps;
most apps have them, but then the views deal with the pages that are  
tied to the app.
Say, if you have a news app, it's most likely that the app contains  
some views to display the news on some specific pages like 'mysite/ 
news/', 'mysite/news/2008/11/' , 'mysite/news/2008/11/03/super-duper- 
great-news/'.
If you would like to have the news displayed on other not-tied-to-the- 
news-app pages like your homepage, you wouldn't do this in the  
views.py file of the news app but in a more global file like the  
views.py in your project directory (at least this is how I do it...).
In this file, you could wirte a view that gathers all the data you  
want to display on your home page, for example like this:

def index(request):

news = News.objects.all()
surveys = Survey.objects.all()
menu_items = MenuItem.objects.all()

return render_to_response('home.html',
{
'news': news,
'surveys': surveys,
'menu_items': menu_items,   
},
context_instance=RequestContext(request))

So views are a good thing if it comes to specific pages, but there are  
better ways if you have something you want to display on every page.

Custom Tags:
---
Custom tags are often tied to apps as well, wich makes sense.
With custom tags, you can filter the app's data and provide this  
filtered data directly to the template, without wire up some views for  
it, and in the same step add functionality to the template language.
You can do some other pretty sophisticated things with custom tags  
besides of just pulling data...
Their main use case is in my oppinion to seperate business logic from  
presentation logic.
With custom tags, the programmer can provide some special  
functionality for the template author.
For example you could write a custom tag for your news app that is  
used in the template like this:

{% get_news 4 1 as newslist %},

which would then be 'give me the four latest news items, but only if  
they are not older then one month, and make them available in the  
template as newslist'.

So you could use custom tags when you have some things that you want  
to display on every page, but if you want to do only this, then you  
are right:
It's a little bit to much fuss for such a simple task, custom tags can  
be used for much more complex things.


Context processors:
---
I think context processors the best way when it comes to just  
displaying some data on every single of your projects' pages.
They are easy to write, and they do just one thing:
Add some data to the context which gets passed to all templates.

A (simple) example would be:

def get_news(request):
latest_news = News.objects.all()[:4]
return {'lates_news': latest_news}

And voilà, from now on 'latest_news' is available in every temlate,  
and you can do things like this:

{% for news in latest_news %}
Do some stuff with your news
{% endfor %}

Docs and tipps on context processors:
http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put signals?

2008-10-29 Thread Benjamin Buch

Hi Adi,

Radov proposed the same, I just answered to his reply...
It works like you two guys said!

Danke!

benjamin

Am 29.10.2008 um 17:04 schrieb Adi Jörg Sieker:

>
> On 29.10.2008 12:49 Uhr, Benjamin Buch wrote:
>>
>>
>> Why do I have to set an environment variable for this?
>> Django never complained about this before.
>>
>>
> you can't put it in the projects __init__.py since that is imported
> before django can initialize itself.
>
> I sometimes just create a module named core in the project directory  
> and
> place stuf I need in various place there.
> how about creating an app called global put the signals.py in there  
> and
> in the __init__.py do an import signals.
>
>> @adi:
>> What do you mean by 'whatever pleases you'?
>>
> naja, es ist egal wohin du die signals tust so lange es für dich passt
> und es im Rahmen
> der Django Vorgaben bleibt.
>
> adi


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put signals?

2008-10-29 Thread Benjamin Buch

Hi Radovan,

thanks for your reply!

Am 29.10.2008 um 13:07 schrieb urukay:

> Benjamin, i did't have to use singnals so far, but when something is  
> needed
> in various app (models), i create new app and put it there (e.g.
> signals.py).
> And you don't have to bother with cross imports exceptions, can change
> everything in one place for each model etc.
>
>
> Radovan


I started a new app (./manage.py startapp) named 'utilities'
and put signals.py in it like this:

-project
-__init__.py
-settings.py
-urls.py
-utilities
-__init__.py
-signals.py

Then I added 'project.utilities' to INSTALLED_APPS in settings.py.

This way it did not work yet, I had to do what Adi proposed in an  
earlier reply:
I had to import signals.py in the app's __init__.py.

benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put signals?

2008-10-29 Thread Benjamin Buch

The thing is, I don't want to tie the comments signals to a specific  
application.
It's more of a project-wide thing.

So I did put the code into signals.py, stuffed it into my project root  
(not in an app)
and imported it in my project's __init__.py.

Now I get this Error if I try to ./manage.py runserver:

Traceback (most recent call last):
   File "./manage.py", line 11, in 
 execute_manager(settings)
   File "/Library/Python/2.5/site-packages/django/core/management/ 
__init__.py", line 338, in execute_manager
 setup_environ(settings_mod)
   File "/Library/Python/2.5/site-packages/django/core/management/ 
__init__.py", line 316, in setup_environ
 project_module = __import__(project_name, {}, {}, [''])
   File "/Users/benjamin/Code/django/kassette/../kassette/ 
__init__.py", line 1, in 
 import signals.py
   File "/Users/benjamin/Code/django/kassette/../kassette/signals.py",  
line 1, in 
 from django.contrib.comments.models import Comment
   File "/Library/Python/2.5/site-packages/django/contrib/comments/ 
models.py", line 2, in 
 from django.contrib.auth.models import User
   File "/Library/Python/2.5/site-packages/django/contrib/auth/ 
models.py", line 6, in 
 from django.db import models
   File "/Library/Python/2.5/site-packages/django/db/__init__.py",  
line 9, in 
 if not settings.DATABASE_ENGINE:
   File "/Library/Python/2.5/site-packages/django/conf/__init__.py",  
line 28, in __getattr__
 self._import_settings()
   File "/Library/Python/2.5/site-packages/django/conf/__init__.py",  
line 57, in _import_settings
 raise ImportError("Settings cannot be imported, because  
environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable  
DJANGO_SETTINGS_MODULE is undefined.

Why do I have to set an environment variable for this?
Django never complained about this before.

@adi:
What do you mean by 'whatever pleases you'?

I understand that I can create any arbitrary .py-file with code that I  
want and than import this file,
but I'm not quite sure from which file I should import it.
As seen above, importing from __init__.py results in quite some trouble.
But thanks for the reply!

benjamin

Am 29.10.2008 um 12:09 schrieb Adi Jörg Sieker:

>
> Since a django application is a normal python module you
> could create a signals.py  and import it in your applications  
> __init__.py
> or whatever pleases you.
> a django application can contain whatever new files modules you want.
> It has to respect somethings so that django recognises it as an  
> application
> but other than that you are free to create whatever you want.
>
> Gruß
>   adi
>
> On 29.10.2008 9:17 Uhr, Benjamin Buch wrote:
>> Hi,
>>
>> short summary for all who didn't follow or don't remember (it's  
>> been a
>> while since the last reply...):
>>
>> I have signals wired up for comments (email-notification on  
>> commenting).
>> Users are allowed to comment on three different models.
>> Where should the code live?
>>
>> Am 29.09.2008 um 14:36 schrieb Benjamin Buch:
>>
>>> I should write the code first, and then say something about it I
>>> guess... ;-)
>>> I'll get back when I did so.
>>> benjamin
>>
>> I wrote the code now.
>> Here it is:
>>
>> from django.contrib.comments.models import Comment
>> from django.core.mail import mail_managers
>> from django.contrib.comments.signals import comment_was_posted
>>
>> def mail_on_posted_comment(sender, comment, request, **kwargs):
>>name = comment.user_name
>>email = comment_user_email
>>comment_body = comment.comment
>>ct = comment.content_type
>>ct_name = ct.name
>>ct_object = ct.get_object_for_this_type(pk=comment.object_pk)
>>domain = comment.site.domain
>>url_read = domain + ct_object.get_absolute_url()
>>url_edit = domain + '/admin/comments/comment/' + str(comment.id)
>>
>>email_body = '''Ein neuer Kommentar wurde erstellt:
>> von: %s
>> E-mail: %s
>> zu: %s %s
>> Kommentar: %s
>>
>> Kommentar lesen: %s
>> Kommentar bearbeiten: %s''' % (name, email, ct_name, ct_object,
>> comment_body, url_read, url_edit)
>>email_subject = 'Neuer Kommentar'
>>mail_managers(email_subject, email_body)
>>
>> comment_was_posted.connect(mail_on_posted_comment, sender=Comment)
>>
>> So the question is: Where should this code live?
>>
>> As Erik said, it's more of a

Re: Where to put signals?

2008-10-29 Thread Benjamin Buch
Hi,

short summary for all who didn't follow or don't remember (it's been a  
while since the last reply...):

I have signals wired up for comments (email-notification on commenting).
Users are allowed to comment on three different models.
Where should the code live?

Am 29.09.2008 um 14:36 schrieb Benjamin Buch:

> I should write the code first, and then say something about it I  
> guess... ;-)
> I'll get back when I did so.
> benjamin

I wrote the code now.
Here it is:

from django.contrib.comments.models import Comment
from django.core.mail import mail_managers
from django.contrib.comments.signals import comment_was_posted

def mail_on_posted_comment(sender, comment, request, **kwargs):
 name = comment.user_name
 email = comment_user_email
 comment_body = comment.comment
 ct = comment.content_type
 ct_name = ct.name
 ct_object = ct.get_object_for_this_type(pk=comment.object_pk)
 domain = comment.site.domain
 url_read = domain + ct_object.get_absolute_url()
 url_edit = domain + '/admin/comments/comment/' + str(comment.id)

 email_body = '''Ein neuer Kommentar wurde erstellt:
von: %s
E-mail: %s
zu: %s %s
Kommentar: %s

Kommentar lesen: %s
Kommentar bearbeiten: %s''' % (name, email, ct_name, ct_object,  
comment_body, url_read, url_edit)
 email_subject = 'Neuer Kommentar'
 mail_managers(email_subject, email_body)

comment_was_posted.connect(mail_on_posted_comment, sender=Comment)

So the question is: Where should this code live?

As Erik said, it's more of a project related thing (because you can  
comment on three different models),
so I think it would be a bad idea to tie the code to one particular  
model and put it in some models.py.

Other places I could think of but considered them as 'not so good':
__init__.py:Who would think that there are signals here? I guess  
nobody.
views.py: signals in views? I don't think so. Let's keep things  
separated.
urls.py: urls.py is for wiring up urls, not signals.

@Erik:
What exactly do you mean by 'put them somewhere in the project'?

benjamin

>>>
>>> Am 28.09.2008 um 17:14 schrieb Erik Allik:
>>>
>>>> The way I see it is that your comment notification is not tied to  
>>>> any particular application that has commentable models but  
>>>> instead is more like a project related thing. So depending on  
>>>> your source layout, I'd put them somewhere in the project.  
>>>> Basically this relates to the application reuse topic -- when you  
>>>> connect the handler to the comment signal, is it something you  
>>>> want to reuse in the future or it's just a one time thing for the  
>>>> current project?
>>>>
>>>> Erik
>>>>
>>>> On 28.09.2008, at 14:58, Benjamin Buch wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I'm using the new comments framework, and I'd like to get  
>>>>> notified by mail when someone posts a comment.
>>>>> How to di it I think I know, but I'm not quite sure where the  
>>>>> code should live.
>>>>> The website has several kinds of entries where users can comment  
>>>>> on, so it would feel a little odd to put the comments' signal- 
>>>>> code in just one models.py.
>>>>> As I have even more signals, I thought it would be great to have  
>>>>> a file signals.py, where all signal handling is done.
>>>>>
>>>>> But where should signals.py live?
>>>>> Documentation says to signals:
>>>>> "Where should this code live?
>>>>> You can put signal handling and registration code anywhere you  
>>>>> like. However, you'll need to make sure that the module it's in  
>>>>> gets imported early on so that the signal handling gets  
>>>>> registered before any signals need to be sent. This makes your  
>>>>> app's models.py a good place to put registration of signal  
>>>>> handlers."
>>>>> What means "the module it's in gets imported early"?
>>>>> I suppose it's not enough to put my signals.py right there in my  
>>>>> projects' root folder?
>>>>> -benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: random quote help

2008-10-08 Thread Benjamin Buch


Am 08.10.2008 um 10:33 schrieb David Reynolds:

> On 8 Oct 2008, at 4:05 am, Bobby Roberts wrote:
>
>> Yeah i know the randomization needs to be in the view and then pushed
>> back to the template.  How would I call the view on each page in the
>> website?
>
>
> Use a template tag.
>
> Oh and Quote.objects.order_by('?')[0] is probably what you want
>
> --  
> David Reynolds

If you want the quotes on every page, you could also use a custom  
context processor.
http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors

-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Hosting Survey

2008-10-07 Thread Benjamin Buch


Am 07.10.2008 um 15:49 schrieb Gour:

> Benjamin> I can recommend djangohosting (http://djangohosting.ch), at
> Benjamin> least if you're looking for a host in europe...

> Heh, nice to hear...I'm also considering to take it...
>
> Is it OK for production site as well?

I'm only hosting personal stuff there, so not much traffic...
As Jarek said, perhaps it's better to go with dedicated hosting if you  
plan to have loads of traffic.

But you can always ask the folks at djangohosting what they think of  
it directly, they are quite nice and answer quickly.

benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Hosting Survey

2008-10-07 Thread Benjamin Buch


Am 06.10.2008 um 19:30 schrieb Jeff:

> I am about to begin a new Django project and I am currently evaluating
> hosting options.

I can recommend djangohosting (http://djangohosting.ch), at least if  
you're looking for a host in europe...
It doesn't seem like you do, but I thought I should mention it anyway...

It's great for personal stuff, didn't do something big there (60MB  
RAM, 1GB storage, 4€ per month, easy setup...)

benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-06 Thread Benjamin Buch

I found a way!

Am 04.10.2008 um 18:28 schrieb Ulises:
> Anyway, I still think that the heavy lifting should be done in a view
> and that the template should be in charge of just displaying what has
> been sent to it.

And I did it in the view...

models.py:
def get_monthly_expenses(self, user):
 expenses = Expense.objects.filter(date__month =  
datetime.date.today().month).filter(user__username =  
user.username).filter(category = self)
 return expenses

def get_monthly_total(self, user):
 monthly_total = 0.0
 expenses = self.get_monthly_expenses(user)
 for expense in expenses:
 monthly_total += expense.expense
 return monthly_total

views.py:
categories = []
cats = Category.objects.all()
for cat in cats:
 expenses = cat.get_monthly_expenses(request.user)
 total = cat.get_monthly_total(request.user)
 categories.append({'category': cat, 'expenses': expenses,  
'total': total})

template:
{% if categories %}
{% for category in categories %}
{% if category.expenses %}
{{ category.category }}
{% for expense in category.expenses %}
{{ expense.date }}: {{ expense.expense }}
{% endfor %}
{{ category.total }}
{% endif %}
{% endfor %}
{% endif %}

Thanks!
-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Benjamin Buch

Am 04.10.2008 um 18:53 schrieb Vovk D:

>
>
> 2008/10/4, Benjamin Buch <[EMAIL PROTECTED]>:
>
> Category1:
> expense1:   3.5
> expense2:   3.5
> total:  7.0
>
> Category2:
> expense1:   2
> expense2:   3
> total:  5
>
> First, i think smth like sum you can do easy with JavaScript on the  
> client-side, if cant do it on the server-side.
> Second, logic like aggregation you must do in the View.
> Third, it's a bad idea to do smth like this in a Model :)

Na, I think this has to work without JavaScript.
But you are right, that's nothing for the model and should be handled  
in the view.
-benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Benjamin Buch

If I would do this in the view, I couldn't do something like this in  
the template:

{% for category in categories %}
{% for expense in category.get_monthly_expenses %}
...
{% endfor %}
{% endfor %}

If I do it in the view, the only way I can think of it could be  
accomplished by stuffing categories in dictionaries, appending the  
expenses...
Is this normal to do so?

But thanks anyway!
-benjamin

Am 04.10.2008 um 17:52 schrieb Ulises:

>
>> Accessing the user from within the model seems somehow like a bad
>> idea, but I can't see an other way to do this.
>
> How about doing it in a view where you have access to the user object?
> I reckon this is the type of stuff you normally do in views?
>
> U


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Access logged in user in models?

2008-10-04 Thread Benjamin Buch

It sounds like a strange question, but I'll ask it...

Is it possible to access the currently logged in user in a model?

This question is related to the following problem:
I have the models 'expense' and 'category' to keep track of my monthly  
expenses:

class Category(models.Model):
 category = models.CharField(max_length=100)
 slug = models.CharField(max_length=100)

class Expense(models.Model):
 category = models.ForeignKey(Category)
 date = models.DateField(default=datetime.date.today)
 description = models.TextField(blank=True)
 expense = models.FloatField()
 user = models.ForeignKey(User)

I'd now like to have a page where a logged in user can see his  
expenses for the actual month in the following way:

Category1:
expense1:   3.5
expense2:   3.5
total:  7.0

Category2:
expense1:   2
expense2:   3
total:  5

So I have to limit the query set by user and date (actual month), sort  
them somehow into the categories and sum up all expenses within one  
category.
I first tried to solve this problem in the template.
I queried for expenses and limited it by user and date like this:
expenses = Expense.objects.filter(user__username =  
user.username).filter(date__month = today.month).order_by('category')
Then I did this in the template:
{% if expenses %}

{% for expense in expenses %}
{% ifchanged %}{{ expense.category }}{% endifchanged  
%}

{{ expense.date }}
{{ expense.expense }}

{% endfor %}

{% endif %}
But as you can see there's no sum at the and, and I couldn't think of  
a way to do this.

Second attempt was to do it from within the model.
I came up with the following methods, attached to the model 'Category':

def get_monthly_expenses(self):
 expenses = Expense.objects.filter(date__month =  
datetime.date.today().month)
 return expenses

def get_monthly_total(self):
 monthly_total = 0.0
 expenses = self.get_monthly_expenses()
 for expense in expenses:
 monthly_total += expense.expense
 return monthly_total

I would then pass Category.objects.all() to the template.
The problem here is that I have no possibility to filter the expenses  
by logged in user beause I can't access the user from within the model.

Accessing the user from within the model seems somehow like a bad  
idea, but I can't see an other way to do this.

-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SQL: Migration How To?

2008-10-04 Thread Benjamin Buch

Thanks James and Russel for your replies.

Am 04.10.2008 um 07:22 schrieb Russell Keith-Magee:
>
> On Sat, Oct 4, 2008 at 12:36 PM, Benjamin Buch <[EMAIL PROTECTED]>  
> wrote:
>>
>> Is there somewhere a place in the documentation where SQL migration
>> strategies are explained a little?
>> I think I remember a paragraph in the pre-1.0-documentation that
>> described what you have to do with your database when you'd like to
>> add a column to your model, but I can't find it anymore.
>
> This isn't the sort of thing that Django can document easily (and I
> certainly can't recall it ever being mentioned in the Django docs).
> The problem is that is isn't as simple as 'the SQL statement you need
> to run' - every database does it quite differently.

Yes, documenting the whole thing would not be easy, you're absolutely  
right.

But some hints on strategy would be very helpful I guess.
Not in the sense of written SQL statements for every database, and not  
for every problem which could propably emerge when the models evolve.
But I think there are some common patterns - like adding a field to a  
model - that could be described in a way that would be sufficient as  
an entry point to learning SQL.
When I remember it right, then the paragraph I mentioned (I think it  
was in the tutorial...) was something like
- alter your model
- use manage.py sql altered_app to output the SQL statements you would  
use to create the table
- alter the table along the lines of those statements

At least this was a hint what to do...

Or possibly another hint could be something like
- dump the database tables you want to alter
- put in the changes manually
- delete the (now old) tables in your db
- import the altered dump

(I don't know if this works, but I will try...)

So I'm not looking for a full-feldged documentation, just for some  
hints on strategy or some examples as a starting point to dive in  
deeper.

>> Working with django for some weeks now, I find it quite common to  
>> want
>> to add or modify a column after the db is synced and some (valuable)
>> data is put in.
>> Since it will propably take some time that the three great migration
>> apps will merge(?) somehow and find their way into trunk (at least
>> that's the way I understood it when watching the video from django
>> con...),
>> I dicided to do migration by hand.
>
> Merging Django Evolution, South and dmigrations is certainly something
> that the three of us have discussed. We hope to be able to make some
> public announcements about this in the near future.

I'm looking forward to this! I liked the talk on django con...

> In the meantime, any of the three migration projects are usable as-is.
>
>> I don't know SQL, and I find it quite hard to search for  
>> documentation
>> (although there is good documentation about SQL out there...), think
>> about migration strategies and tinker with differences between  
>> sqlite3
>> and mysql.
>> So is there anywhere a short explanation of SQL from a django point  
>> of
>> view out there?
>
> Your best source of documentation will be the SQL manual for your
> database of choice, and/or the tutorials around the web for the same.
> There's almost nothing Django specific about migrations at the SQL
> level, other than knowing what you need your database to look like at
> the end of the process (which you can find out using ./manage sqlall).

As James said, I should stop and learn some SQL.
Thanks for the tip on manage.py, it is quite useful.
At least it shows how SQL statements should look...

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



SQL: Migration How To?

2008-10-03 Thread Benjamin Buch

Is there somewhere a place in the documentation where SQL migration  
strategies are explained a little?
I think I remember a paragraph in the pre-1.0-documentation that  
described what you have to do with your database when you'd like to  
add a column to your model, but I can't find it anymore.

Working with django for some weeks now, I find it quite common to want  
to add or modify a column after the db is synced and some (valuable)  
data is put in.
Since it will propably take some time that the three great migration  
apps will merge(?) somehow and find their way into trunk (at least  
that's the way I understood it when watching the video from django  
con...),
I dicided to do migration by hand.

I don't know SQL, and I find it quite hard to search for documentation  
(although there is good documentation about SQL out there...), think  
about migration strategies and tinker with differences between sqlite3  
and mysql.
So is there anywhere a short explanation of SQL from a django point of  
view out there?

My concrete problem at the moment is this:

I had the very bad idea to use models.IntegerField to store phone  
numbers (noob!).
Now I realize that some people want to put in characters like -,  
( or ), and some numbers are definitely longer than 11 digits, which  
seems to be the default with MySQL.
So I have to change the database column from

"contact_phone" integer NULL

to

"contact_phone" varchar(15) NOT NULL

As there are some entries in the database yet, even some NULLs, I have  
to think about a way to not lose this data, perhaps convert it from  
int to char (I don't know how MySQL handles data types internally) and  
replace all the NULLs with "", because NULL is no good with char fields.

Thanks for any hints,
benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Subscribe to all feeds on the community page at once?

2008-10-01 Thread Benjamin Buch

Okay, I've got it.
There's just no seperate rss link or button or something.
You can subscribe to the page as whole...
This is, just put "http://www.djangoproject.com/community"; into your  
favourite newsreader...

(Found it while browsing the source of djangoproject.com)

-benjamin

Am 01.10.2008 um 12:02 schrieb Benjamin Buch:

>
> Hi,
>
> is there a feed for all the items on http://www.djangoproject.com/community/
> ,
> or do I have to subscribe to every single feed seperatly?
>
> -benjamin
>
> 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Subscribe to all feeds on the community page at once?

2008-10-01 Thread Benjamin Buch

Hi,

is there a feed for all the items on http://www.djangoproject.com/community/ 
,
or do I have to subscribe to every single feed seperatly?

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put signals?

2008-09-29 Thread Benjamin Buch
No, I think you've got it right.
I should write the code first, and then say something about it I  
guess... ;-)
I'll get back when I did so.

Thanks for your reply,
benjamin


Am 28.09.2008 um 18:27 schrieb Erik Allik:

> But you only have a single comment model to wire to, unless I'm  
> missing something.
>
> Erik
>
> On 28.09.2008, at 19:03, Benjamin Buch wrote:
>
>> Hi Erik,
>>
>> thanks for your reply.
>> You are right, the comments are not tied to a particular model, but  
>> to three of them.
>> Instead of wiring up all three models, I thought I could do this in  
>> one place.
>> As I write this reply, I realize that it is perhaps not such a good  
>> idea to do so.
>> It would be good to have some information in the mail that says on  
>> exactly which model instance the comment was made on,
>> so it will be better to  wire up each model.
>>
>> Thanks again anyway,
>> benjamin
>>
>> Am 28.09.2008 um 17:14 schrieb Erik Allik:
>>
>>> The way I see it is that your comment notification is not tied to  
>>> any particular application that has commentable models but instead  
>>> is more like a project related thing. So depending on your source  
>>> layout, I'd put them somewhere in the project. Basically this  
>>> relates to the application reuse topic -- when you connect the  
>>> handler to the comment signal, is it something you want to reuse  
>>> in the future or it's just a one time thing for the current project?
>>>
>>> Erik
>>>
>>> On 28.09.2008, at 14:58, Benjamin Buch wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm using the new comments framework, and I'd like to get  
>>>> notified by mail when someone posts a comment.
>>>> How to di it I think I know, but I'm not quite sure where the  
>>>> code should live.
>>>> The website has several kinds of entries where users can comment  
>>>> on, so it would feel a little odd to put the comments' signal- 
>>>> code in just one models.py.
>>>> As I have even more signals, I thought it would be great to have  
>>>> a file signals.py, where all signal handling is done.
>>>>
>>>> But where should signals.py live?
>>>> Documentation says to signals:
>>>> "Where should this code live?
>>>> You can put signal handling and registration code anywhere you  
>>>> like. However, you'll need to make sure that the module it's in  
>>>> gets imported early on so that the signal handling gets  
>>>> registered before any signals need to be sent. This makes your  
>>>> app's models.py a good place to put registration of signal  
>>>> handlers."
>>>> What means "the module it's in gets imported early"?
>>>> I suppose it's not enough to put my signals.py right there in my  
>>>> projects' root folder?
>>>> -benjamin
>>>>
>>>>
>>>>
>>
>>
>>
>>
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put signals?

2008-09-28 Thread Benjamin Buch
Hi Erik,

thanks for your reply.
You are right, the comments are not tied to a particular model, but to  
three of them.
Instead of wiring up all three models, I thought I could do this in  
one place.
As I write this reply, I realize that it is perhaps not such a good  
idea to do so.
It would be good to have some information in the mail that says on  
exactly which model instance the comment was made on,
so it will be better to  wire up each model.

Thanks again anyway,
benjamin

Am 28.09.2008 um 17:14 schrieb Erik Allik:

> The way I see it is that your comment notification is not tied to  
> any particular application that has commentable models but instead  
> is more like a project related thing. So depending on your source  
> layout, I'd put them somewhere in the project. Basically this  
> relates to the application reuse topic -- when you connect the  
> handler to the comment signal, is it something you want to reuse in  
> the future or it's just a one time thing for the current project?
>
> Erik
>
> On 28.09.2008, at 14:58, Benjamin Buch wrote:
>
>> Hi,
>>
>> I'm using the new comments framework, and I'd like to get notified  
>> by mail when someone posts a comment.
>> How to di it I think I know, but I'm not quite sure where the code  
>> should live.
>> The website has several kinds of entries where users can comment  
>> on, so it would feel a little odd to put the comments' signal-code  
>> in just one models.py.
>> As I have even more signals, I thought it would be great to have a  
>> file signals.py, where all signal handling is done.
>>
>> But where should signals.py live?
>> Documentation says to signals:
>> "Where should this code live?
>> You can put signal handling and registration code anywhere you  
>> like. However, you'll need to make sure that the module it's in  
>> gets imported early on so that the signal handling gets registered  
>> before any signals need to be sent. This makes your app's models.py  
>> a good place to put registration of signal handlers."
>> What means "the module it's in gets imported early"?
>> I suppose it's not enough to put my signals.py right there in my  
>> projects' root folder?
>> -benjamin
>>
>>
>>


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Where to put signals?

2008-09-28 Thread Benjamin Buch
Hi,

I'm using the new comments framework, and I'd like to get notified by  
mail when someone posts a comment.
How to di it I think I know, but I'm not quite sure where the code  
should live.
The website has several kinds of entries where users can comment on,  
so it would feel a little odd to put the comments' signal-code in just  
one models.py.
As I have even more signals, I thought it would be great to have a  
file signals.py, where all signal handling is done.

But where should signals.py live?
Documentation says to signals:
"Where should this code live?
You can put signal handling and registration code anywhere you like.  
However, you'll need to make sure that the module it's in gets  
imported early on so that the signal handling gets registered before  
any signals need to be sent. This makes your app's models.py a good  
place to put registration of signal handlers."
What means "the module it's in gets imported early"?
I suppose it's not enough to put my signals.py right there in my  
projects' root folder?
-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problems with signals accessing kwargs

2008-09-15 Thread Benjamin Buch


Thanks!

I've got it working now:

def mail_on_create_intro(sender, instance, created, **kwargs):
 if created:
 email_body =  'A new Intro at' + instance.url
 email_subject = 'New Intro'
 else:
 email_body = 'An intro has changed at' + instance.url
 email_subject = 'Changed Intro'
 mail_managers(email_subject, email_body)

It wasn't quite clear to me from the documentation at 
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save
 
  that you actually have to pass the arguments 'instance' and 'created'.
-benjamin


> Or:
>
> def mail_on_create_intro(sender, created=None, **kwargs):
> if created:
> email_body = 'A new intro at ' + instance.url
> email_subject = 'New intro'
> else:
> email_body = 'An intro has changed at ' + instance.url
> email_subject = 'Changed Intro'
> mail_managers(email_subject, email_body)

>>
>> Try:
>>
>> if 'created' in kwargs:
>>   if kwargs['created']:
>># Send email


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problems with signals accessing kwargs

2008-09-14 Thread Benjamin Buch

Hi,

I have this code in myapp.intros.models to send a mail to the managers  
each time an intro gets saved:

from django.db.models.signals import post_save
from django.core.mail import mail_managers

def mail_on_create_intro(sender, **kwargs):
 if created:
 email_body = 'A new intro at ' + instance.url
 email_subject = 'New intro'
 else:
 email_body = 'An intro has changed at ' + instance.url
 email_subject = 'Changed Intro'
 mail_managers(email_subject, email_body)

post_save.connect(mail_on_create_intro, sender=Intro)

This doesn't work, here's the last part of the traceback:

  File "/home/benni/kassette/../kassette/intros/models.py", line 20,  
in mail_on_create_intro
if created:

NameError: global name 'created' is not defined

How comes that?
The documentation at 
http://docs.djangoproject.com/en/dev/ref/signals/#post-save 
  says there should be an argument named 'created'...
If I replace 'created' with 'True' for example, the error says that  
'global name 'instance' is not defined'.

I suspect I'm writing bad syntax?

-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: [solved] Problems with mails and django-contact-form

2008-09-14 Thread Benjamin Buch


Forget about it. Everything works fine.

I just didn't check the spam filter...

-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: New Comments: Bad Magic Number Error

2008-09-11 Thread Benjamin Buch



> More generally, whenever there's a major refactor (or even a minor  
> one if it involves renaming or deleting files), it's a good idea to  
> delete .pyc files before updating from svn.  The .pyc files are not  
> stored in svn, so they won't be deleted by update even when the  
> corresponding source file is deleted. Leaving the outdated .pyc  
> files hanging around can cause problems as they get loaded when they  
> really shouldn't be any more, plus deletion of directories by svn  
> update won't happen since the delete is 'obstructed' by what svn  
> sees as locally-modified files.  (If you are not updating from svn  
> but rather using a standard install, it's best to first remove all  
> traces of the old code...the install won't do that either.)
>
> Karen

I had some problems with old .pyc-files after upgrading too.
I found those helpful commands to delete all .pyc-files in a certain  
directory at once:

Find all .pyc-files (just to be sure what you will delete in the next  
step):

find /path/to/the/directory/ -type f -name "*.pyc" -exec ls -f {} \;

Then delete all .pyc-files (just replace ls with rm):

find /path/to/the/directory/ -type f -name "*.pyc" -exec rm -f {} \;

Use it with caution, I'm no wizard with the terminal, just wanted to  
share this because it's been useful to me.
I found it somewhere on the net, can't find it again, so no link to  
the original post...

-benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Limit results of Q objects?

2008-09-05 Thread Benjamin Buch

Hi all,

1.0 is there, great! Congratulations for the people who made it  
possible!

Now my problem:

I have a model 'Gig' which includes a date field, and I need a query  
that results in the five latest passed gigs and the 10 closest  
forthcoming gigs.
Sorry for my bad english, I hope it's understandable...

I tried Something like this:

today = datetime.date.today()
gigs = Gig.objects.filter(Q(date__gt=today)[:5]|Q(date__lte=today)[:5])

But this results in the following error (shell):

Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'Q' object is unsubscriptable

So limiting QuerySets with [:n] syntax seems not to be allowed on Q  
objects...

I even tried
gigs = Gig.objects.filter(date__gt=today)[:5])
gigs += Gig.objects.filter(Q(date__lte=today)[:5]

No luck. + is not defined on QuerySets...

Any suggestions?

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using subclass of RequestContext in generic views?

2008-09-01 Thread Benjamin Buch

Hi Tim,

> I've been trying to figure out how to use a custom subclased
> RequestContext[1] object in my generic views.  Looking at the
> code of django/views/generic/*.py it looks like this class is
> hard-coded in each of the views.
>
>
> Ideally, I'd be able to set something in the settings.py to
> specify my default RequestContext class, but I don't readily see
> a way to go about that short of hacking the
> django.templates.context module.

Generic views are using RequestContext by default;
that's what's 'hardcoded' into generic views.

To 'sublclass' Context, you just write a simple method somewhere in  
your code and give it request as an argument.
Like this:

from myproject.myapp import SomeObject

def get_someobjects_(request):
 someobjects = SomeObject.aobjects.all()
 return {'someobjects': someobjects}

Put this in the file myproject/mycomtextprocessor.py for example.
Then you have to tell django that this is a context processor.
You do it in the settings:

TEMPLATE_CONTEXT_PROCESSORS = (
 'myproject.myapp.mycontextprocessor.get_someobjects',
)

Now every view that has RequestContext(request) as contex_instance like

def some_view(request):
#...
return render_to_response('mytemplate.html',
mydata,

context_instance=RequestContext(request))

will automatically include {'someobjects': someobjects}, and you can  
use {{ for someobject in someobjects }} in your templates.

I hope I understood the question right...

-benjamin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: photologue or: how to not escape html in the admin?

2008-08-30 Thread Benjamin Buch
Okay, I've got it!

> I've installed photologue recently, and it's a great app.
> Works like a charm...
>
> The only thing that doesn't is the thumbnail preview in the admin.
> I think photologue spits out the correct html:
>
>  src="http://127.0.0.1:8000/site_media/photologue/photos/cache/DSC04668_admin_thumbnail.JPG
>  
> ">
>
> But the admin interface escapes it, so I don't see any nice  
> thumbnails, just html...
>
> How can I change this?

The 'list_display' string in question is a method of a model, those  
are automatically escaped by django.
But you can set it to allow tags like this:

admin_thumbnail.allow_tags = True

See here: http://www.djangoproject.com/documentation/admin/#list-display

-benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



photologue or: how to not escape html in the admin?

2008-08-30 Thread Benjamin Buch
Hi,

I've installed photologue recently, and it's a great app.
Works like a charm...

The only thing that doesn't is the thumbnail preview in the admin.
I think photologue spits out the correct html:

http://127.0.0.1:8000/site_media/photologue/photos/cache/DSC04668_admin_thumbnail.JPG
 
">

But the admin interface escapes it, so I don't see any nice  
thumbnails, just html...

How can I change this?

-benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Getting things into entries

2008-08-29 Thread Benjamin Buch

Clumsy subject, I know...

I know there was a recent discussion about this, but I lost it, so  
sorry for asking again.
So here's the question:

How can you allow your users to add something like pictures into  
something like blog posts?
Not just below or above (this could be achieved by a simple foreignkey  
I guess...), but at positions they want to?

Antoher related question would be if it's possible to include tags and  
variables ({{ somevariable }}) into text I enter into the admin?

-benjamin




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Get all available urls as select box?

2008-08-29 Thread Benjamin Buch

Hi,

in my project I want to give the users the possibility to put in some  
content (some sort of page intro...) into a text field and than choose  
on which page the content gets displayed.
Perhaps a very common problem while building cmssy projects...

I thought I could achieve this by displaying a simple select box wich  
contains all urls specified by the url confs...
But how can I get all available urls?

Another alternative would be to let the user copy the link of the page  
he wants the content to be displayed on directly from the addressbar  
of the browser.
But than the question is: How would I hook this up into django? I  
think it sould not be the best idea to place something like

content = Intro.objects.get(path=request.path)

in every view I wrote. Not very dry...

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problems with photologue installation

2008-08-29 Thread Benjamin Buch


Am 26.08.2008 um 15:56 schrieb Karen Tracey:

> The traceback shows the sequence of calls made.  So runserver.py on  
> line 47 called self.validate... which wound up on line 122 of  
> base.py calling get_validation_errors, etc. until you get to line  
> 139 of base.py caling contribute_to_class on value, which apparently  
> takes you into your fields.py under Prog/django/birchcove/ 
> taggingonly you say that no longer exists?
>
> Are you sure you deleted Prog entirely or just the source .py files  
> under it?  I've seen tracebacks referring to non-existent files only  
> when the compiled Python files (.pyc) created for them still exist.   
> Solution is usually to delete all .pyc files from the tree to make  
> sure all the old stuff is really gone.
>
> Karen

Thanks Karen!

Yes, I'm sure Prog isn't there any more, because I renamed the entire  
directory. And deleted the files that are referenced by the traceback.
But I think I found the mistake.
I did a grep on my whole django directory, and those were the results:

benjamin-buchs-macbook:~ benjamin$ egrep -rni -e "/Users/benjamin/Prog/ 
django/birchcove/tagging" /Users/benjamin/Code/django/
Binary file /Users/benjamin/Code/django/apps/tagging/__init__.pyc  
matches
Binary file /Users/benjamin/Code/django/apps/tagging/fields.pyc matches
Binary file /Users/benjamin/Code/django/apps/tagging/managers.pyc  
matches
Binary file /Users/benjamin/Code/django/pps/tagging/models.pyc matches
Binary file /Users/benjamin/Code/django/apps/tagging/settings.pyc  
matches
Binary file /Users/benjamin/Code/django/apps/tagging/templatetags/ 
__init__.pyc matches
Binary file /Users/benjamin/Code/django/apps/tagging/templatetags/ 
tagging_tags.pyc matches
Binary file /Users/benjamin/Code/django/apps/tagging/utils.pyc matches
Binary file /Users/benjamin/Code/django/apps/tagging/validators.pyc  
matches

I removed the files, no problem with photologue any more...

-benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bug in django/contrib/gis/geos?

2008-08-29 Thread Benjamin Buch

Seems like something in django/contrib/gis/geos broke the python help  
system:

benjamin-buchs-macbook:~ benjamin$ python
Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> help()

Welcome to Python 2.5!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given  
word
such as "spam", type "modules spam".

help> modules

Please wait a moment while I gather a list of all available modules...

Traceback (most recent call last):
   File "", line 1, in 
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site.py", line 348, in __call__
 return pydoc.help(*args, **kwds)
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pydoc.py", line 1647, in __call__
 self.interact()
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pydoc.py", line 1665, in interact
 self.help(request)
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pydoc.py", line 1681, in help
 elif request == 'modules': self.listmodules()
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pydoc.py", line 1802, in listmodules
 ModuleScanner().run(callback)
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pydoc.py", line 1853, in run
 for importer, modname, ispkg in pkgutil.walk_packages():
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pkgutil.py", line 125, in walk_packages
 for item in walk_packages(path, name+'.', onerror):
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pkgutil.py", line 125, in walk_packages
 for item in walk_packages(path, name+'.', onerror):
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pkgutil.py", line 125, in walk_packages
 for item in walk_packages(path, name+'.', onerror):
   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/pkgutil.py", line 110, in walk_packages
 __import__(name)
   File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/ 
__init__.py", line 31, in 
 from django.contrib.gis.geos.base import GEOSGeometry, wkt_regex,  
hex_regex
   File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/ 
base.py", line 11, in 
 from django.contrib.gis.geos.coordseq import GEOSCoordSeq
   File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/ 
coordseq.py", line 9, in 
 from django.contrib.gis.geos.libgeos import CS_PTR, HAS_NUMPY
   File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/ 
libgeos.py", line 52, in 
 '", "'.join(lib_names))
django.contrib.gis.geos.error.GEOSException: Could not find the GEOS  
library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your  
settings.
 >>>

Django-version is 1.0 beta 2.
Did I unintentionally break something (although I didn't mess with  
gis...) or is this a bug?
-benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problems with photologue installation

2008-08-25 Thread Benjamin Buch

Hi,

I'm working with the most recent versions of both django and photologue.
When I add photologue to the INSTALLED_APPS, the testserver stops  
working and I get this traceback:

Validating models...
Unhandled exception in thread started by 
Traceback (most recent call last):
   File "/Library/Python/2.5/site-packages/django/core/management/ 
commands/runserver.py", line 47, in inner_run
 self.validate(display_num_errors=True)
   File "/Library/Python/2.5/site-packages/django/core/management/ 
base.py", line 122, in validate
 num_errors = get_validation_errors(s, app)
   File "/Library/Python/2.5/site-packages/django/core/management/ 
validation.py", line 28, in get_validation_errors
 for (app_name, error) in get_app_errors().items():
   File "/Library/Python/2.5/site-packages/django/db/models/ 
loading.py", line 128, in get_app_errors
 self._populate()
   File "/Library/Python/2.5/site-packages/django/db/models/ 
loading.py", line 57, in _populate
 self.load_app(app_name, True)
   File "/Library/Python/2.5/site-packages/django/db/models/ 
loading.py", line 72, in load_app
 mod = __import__(app_name, {}, {}, ['models'])
   File "/Users/benjamin/Code/django/apps/photologue/models.py", line  
119, in 
 class Gallery(models.Model):
   File "/Library/Python/2.5/site-packages/django/db/models/base.py",  
line 88, in __new__
 new_class.add_to_class(obj_name, obj)
   File "/Library/Python/2.5/site-packages/django/db/models/base.py",  
line 139, in add_to_class
 value.contribute_to_class(cls, name)
   File "/Users/benjamin/Prog/django/birchcove/tagging/fields.py",  
line 33, in contribute_to_class
AttributeError: 'module' object has no attribute 'connect'

The strange thing is that the directory 'Prog' doesn't exist any more,
so there is no file /Users/benjamin/Prog/django/birchcove/tagging/ 
fields.py.

Why is the traceback referring to a non-existent file?
And, as I'm fairly new to python and not even close to being familiar  
with tracebacks, could someone please tell me what's going on here in  
general?

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to filter FOO_set in templates?

2008-08-23 Thread Benjamin Buch

Am 22.08.2008 um 23:15 schrieb Garrett Garcia:

> How about:
>
> songs = Recording.objects.filter(song__title__startswith='R',  
> represents_song=True)
>
> http://www.djangoproject.com/documentation/db-api/#filter-kwargs
>
> "Multiple parameters are joined via AND in the underlying SQL  
> statement."
>
> - Garrett

The problem I still see with this is that this is a query set  
containing recordings, not songs.
Let's assume there can be several recordings that represent the song  
and thus can have "represents_song=True".
If you had the query from above,

songs = Recording.objects.filter(song__title__startswith='R',  
represents_song=True),

how would you display the songs in the template in a way that the  
songs and recordings would order like this:

song_1_title
   song_1_representative_recording_1
   song_1_representative_recording_2
   song_1_representative_recording_3

song_2_title
   song_2_representative_recording_1
   song_2_representative_recording_2

...

?

-benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to filter FOO_set in templates?

2008-08-23 Thread Benjamin Buch

Am 22.08.2008 um 23:15 schrieb Garrett Garcia:
> How about:
>
> songs = Recording.objects.filter(song__title__startswith='R',  
> represents_song=True)
>
> http://www.djangoproject.com/documentation/db-api/#filter-kwargs
>
> "Multiple parameters are joined via AND in the underlying SQL  
> statement."
>
> - Garrett

Hm, never thought about that. Thanks!

But still: It feels somehow like a workaround. I want to have songs in  
my query set, not recordings.
songs = Recording looks confusing to me. Songs are songs, and  
recordings are recordings.

And I still would have to acess the song via the recording in the  
template:
{{ recording.song.title }}

-benjamin
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Model method or manager?

2008-08-22 Thread Benjamin Buch

Hi,

I have a method in a class that filters related objects  
(get_representative_recording):

class Song(models.Model):
 title   = models.CharField(max_length=50)
 description = models.TextField(blank=True)

 def get_representative_recording(self):
 # There is always only one representative_recording, so I'm  
using get()
 representative_recording =  
self.recording_set.get(represents_song=True)
 return representative_recording

class Recording(models.Model):
 song= models.ForeignKey(Song)
 mp3 = models.FileField(upload_to='songs')
 description = models.TextField(blank=True)
 represents_song = models.BooleanField()

The method defines "row-level"-functionality for songs, but that's  
"table-wide" functionality for recordings...
See here: http://www.djangoproject.com/documentation/model-api/#model-methods

So should this stay a method or be transfered into a custom manager?
What would be preferable and why?

I have no idea how I could transfer the functionality into a manager  
anyway...
Someone knows how to do that?

I thought about somehow overriding recording_set...

-benjamin




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to filter FOO_set in templates?

2008-08-22 Thread Benjamin Buch



> I'm not sure i understand you question.  You can filter via the  
> attributes of a related object like this:
> Recording.objects.filter(song__artist="Ben Folds")

Yes, and that's perfectly all right when you are only interested only  
in the related objects.
But what do you do when you want to do something like:

"Give my all songs that start with the letter R AND limit the related  
recording_set to the recordings that have represents_song=True"?

You could do this with two queries:
songs = Song.objects.filter(title__startswith='R')
recordings = Recording.objects.filter(represents_song=True)

But then there would be no connection between songs and recordings.
Every song in songs would still have attached all recordings that  
belong to the song, not only the recordings with represents_song=True.

What I want is to filter objects and at the same time the FOO_sets of  
the single objects.
When I understand this right, with filters you can either filter the  
objects itself OR you can filter the related objects, but not both at  
the same time.

I think this can only be don via a custom manager or a custom method.

As I don't understand how custom managers work yet to well, I tried it  
with a custom method:

class Song(models.Model):
 title   = models.CharField(max_length=50)
 description = models.TextField(blank=True)

 def __unicode__(self):
 return self.title

 def get_representative_recording(self):
 representative_recording =  
self.recording_set.get(represents_song=True)
 return representative_recording

class Recording(models.Model):
 song= models.ForeignKey(Song)
 mp3 = models.FileField(upload_to='songs')
 represents_song = models.BooleanField()

I can now filter the songs in the view:

 songs = Song.objects.filter(filter_for_whatever_you_like_here)

And access the "representative recording" like this in the template:

 {{ song.get_representative_recording.mp3.url }}

I can't see how this could be done only by filtering, without a custom  
method or a custom manager.

-benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to filter FOO_set in templates?

2008-08-20 Thread Benjamin Buch


Hi Garret,

> How about sending the template something like:
>
> songs = Recording.objects.filter(represents_song=True)
>
> A custom manager seems like overkill for this situation (If I'm  
> understanding you right).
>
> - Garrett

this is indeed a plausible sollution.
I then had to access the songs' data via the recording in the template  
like

{% for recording in songs %}
{{ recording.song.title }}
{{ recording.song.description }}
{{ recording.mp3 }}
{% endfor %}

For my special case I think this should work, because every song has  
exact one recording that represents it.
And you are right, a custom manager seems like overkill in this case.
But out of interest, it turned out to be a more general question for me:

How to limit the query set of a related object?

I think this can only be done via a custom manager...

Thanks!

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem retrieving objects

2008-07-12 Thread Benjamin Buch
I'm trying to find my way round the django 'basic apps' to get to know  
django a little better.
http://playgroundblues.com/posts/2007/dec/2/django-basic-apps/

Installation of basic/blog went all right, I could save posts to the  
database (sqlite in this case) through the admin.

But if I try to edit a post in the admin, django throws this error:

'post object with primary key u'1' does not exist'

I checked the database, but the post with id=1 is there.
I even can't get any posts in the shell:

 >>>Post.objects.all()
[]

-benjamin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put stylesheets?

2008-07-09 Thread Benjamin Buch

Fixed it. Thanks for pointing me to the right place in the  
documentation.
Searched the docs, but overlooked 'Serving static/media files'.
Who thought that there would be something about where to put my css  
files?

Lame excuse, glad you helped me!

-benjamin

>
> meant to put this in there:
>
> http://www.djangoproject.com/documentation/static_files/
>
> On Jul 9, 2:59 pm, Benjamin Buch <[EMAIL PROTECTED]> wrote:
>>> Just to clarify what may be obvious...do you have the correct one
>>> of these:
>>
>>>  href=" {{ MEDIA_URL }}styles.css"  <- what you wrote
>>>  href="{{ MEDIA_URL }}styles.css" <- likely what you want
>>
>>> without the extra space?
>>
>>> -tim
>>
>> fixed it, but it still won't load...
>>
>> -benjamin
> 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where to put stylesheets?

2008-07-09 Thread Benjamin Buch


> Just to clarify what may be obvious...do you have the correct one
> of these:
>
>  href=" {{ MEDIA_URL }}styles.css"  <- what you wrote
>  href="{{ MEDIA_URL }}styles.css" <- likely what you want
>
> without the extra space?
>
> -tim

fixed it, but it still won't load...

-benjamin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Where to put stylesheets?

2008-07-09 Thread Benjamin Buch

Okay, I'll ask.
Perhaps it's a stupid supernoob-question, but I'll do it:

Where should my projects' stylesheets live?

I've made a 'media' directory beneath the projects' home folder, and I  
put that into settings.py:

MEDIA_ROOT = '/path/to/my/project/media'
MEDIA_URL = 'http://127.0.0.1:8000/media/'

(As you can see, I'm developing on a local machine.)

But when I put this in my base template:

 ,

'styles.css' won't load.

Any hints? For the noob?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---