If Statements inside For Loops

2010-01-10 Thread Dave Merwin
I have the following:

{% for group in user.groups.all %}
{{ group.name }}
{% ifequal group.name "subscribed" %}
I'm subscribed
{% else %}
{{ group.name }}
{% endifequal %}
{% endfor %}

The else part of the statement is not rendering. What am I missing?
Any help welcome.

Thanks,
Dave
-- 
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: Model Form crashing on Foreign Key

2010-01-10 Thread fest
I feel like I could jump out of the window... Just spent 4 hours of
debugging :/

Any idea which is the last revision which is not affected by this bug?




On 11 Janv., 07:02, Sontek  wrote:
> On Jan 10, 6:17 pm, Sontek  wrote:
>
> > On Jan 10, 12:23 pm, Sontek  wrote:
>
> > > So I'm trying to create a new feed within the Admin page and its
> > > crashing with the error  IntegrityError: lifestream_feed.lifestream_id
> > > may not be NULL, the call stack is... form['lifestream'] is set but
> > > form.instance.lifestream is not.  Here is the code:
>
> This is a bug in HEAD
-- 
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: Model Form crashing on Foreign Key

2010-01-10 Thread Sontek


On Jan 10, 6:17 pm, Sontek  wrote:
> On Jan 10, 12:23 pm, Sontek  wrote:
>
> > So I'm trying to create a new feed within the Admin page and its
> > crashing with the error  IntegrityError: lifestream_feed.lifestream_id
> > may not be NULL, the call stack is... form['lifestream'] is set but
> > form.instance.lifestream is not.  Here is the code:

This is a bug in HEAD
-- 
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.




Form Validation in Admin

2010-01-10 Thread Sasuke
Hi all,
I'm using the form's clean() method to do validation for models in admin. The 
validation we need to do is to make sure there are no more than a certain 
number of items totally submitted. So I calculate the total number of items in 
the clean() method and check whether it is in the given range. But the exact 
total number is difficult ot get because I don't know whether the newly 
submitted form'data is a modified item that is already submitted or it's a 
newly added item. So is there any way in the clean() method to know whether the 
form's data is a newly added item or a modified one?
Thanks to all.-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: django-tagging on shared hosting

2010-01-10 Thread flynnguy
Awesome, worked like a charm, Thank you!

You know, I *thought* I tried this but I think I didn't do something
right in importing the paths before so when I read it I thought well
let me try it once more. I was also half asleap last night trying to
get it to work... I should learn that coding while half asleap is
usually bad news.
-Chris

On Jan 10, 11:43 am, Daniel Roseman  wrote:
> On Jan 10, 3:28 pm, flynnguy  wrote:
>
>
>
> > So I'm trying to implement tagging on my website and I found the
> > django-tagging project and threw it in my app and it works great... on
> > my laptop. Go to put things up on the server (dreamhost using their
> > new passenger method) and started to run into some issues. I did easy
> > install using --prefix so I could install it in my home directory. My
> > structure looks something like this:
> > ~/django
> > |--applications
> > |   `-- pythonlib
> > |       `-- lib
> > |           `-- python2.4
> > |               `-- site-packages
> > |                   `-- django_tagging-0.3-py2.4.egg
> > |                       |-- EGG-INFO
> > |                       `-- tagging
> > |                           |-- templatetags
> > |                           `-- tests
> > |--projects
> > |--source
>
> > source is my copy of the Django source code and then projects is where
> > I keep my application souce code. Also, in order to get it to install,
> > I had to put the site-packages path in my PYTHONPATH in .bash_profile:
> > export PYTHONPATH=$PYTHONPATH:$HOME/django/source:$HOME/django/
> > projects:$HOME/django/applications/pythonlib/lib/python2.4/site-
> > packages
>
> > So far so good:
> > $ python manage.py shell
> > Python 2.4.4 (#2, Oct 22 2008, 20:20:22)
> > [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > (InteractiveConsole)>>> import tagging
> > >>> tagging.VERSION
>
> > (0, 3, 'pre')
>
> > I think great, that was pretty easy... I should be ready to go. Push
> > my code up to the server, run syncdb, it makes the tables and index...
> > but I get a 500 Internal Server Error. What's most frustrating is I
> > can't seem to get a debug error page, despite having Debug = True but
> > that just seems to be a quirk of using dreamhost.
>
> > So fearing maybe my code is borked, I undid my recent checkout...
> > sites fine again. If I put in 'tagging', into the INSTALLED_APPS, I
> > get the 500 Internal Server Error.
>
> > I realize this is probably due to the way dreamhost is setup. In my
> > passenger_wsgi.py script, I have a bunch of sys.path.inserts to add
> > the same folders in my PYTHONPATH, I'm just not understanding where
> > the disconnect it. If someone has some insight into why this might be
> > happening, I'd love to hear it. Both laptop and server are using
> > Django version 1.1.1. Is there something I'm missing with my paths?
> > I've spent more time trying to fix this than I have adding the tags. :-
> > (
>
> I'm not familiar with Dreamhost's setup particularly, but if you are
> already inserting paths into sys.path in your WSGI script, the answer
> is probably there. Instead of running setup.py to install django-
> tagging anywhere, just leave it where it is, and insert its path into
> sys.path along with all the others.
> --
> DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




World cities database

2010-01-10 Thread nameless
Hi at all,
I need a world cities database for registration form.
What is the best and most used ?


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




Inline Admin and ForeignKey

2010-01-10 Thread Igor
Hi,

I have a blog model and would like to be able to add an arbitrary
number of event dates to it (i.e. turn a blog post into an event
announcement). For that I use

class Event(models.Model):
entry = models.ForeignKey(Entry)
begin_date = models.DateTimeField(default=datetime.datetime.now)
end_date = models.DateTimeField(default=datetime.datetime.now)

I hope this is good so far.
What I would like to happen is to be able to add those events inline -
inside an Entry editing page in the admin interface:

class EventInline(generic.GenericTabularInline):
model = Event
max_num = 1   #TODO: Fix this


class EntryAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }
inlines = [ EventInline ]

But in the Entry admin page I see three blocks of begin_date and
end_date. No option to edit/delete them, or add a new one. The three
are basically static.

What am I doing wrong?

Thanks for 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-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: Model Form crashing on Foreign Key

2010-01-10 Thread Sontek

On Jan 10, 12:23 pm, Sontek  wrote:
> So I'm trying to create a new feed within the Admin page and its
> crashing with the error  IntegrityError: lifestream_feed.lifestream_id
> may not be NULL, the call stack is... form['lifestream'] is set but
> form.instance.lifestream is not.  Here is the code:
>

Its not returning the empty returns, its reaching the return
self.cleaned_data:

-> return self.cleaned_data
(Pdb) list
 85 self.cleaned_data['name'] = feed_info['title']
 86 self.instance.name = self.cleaned_data['name']
 87 self.cleaned_data['domain'] = get_url_domain(feed_url)
 88 self.instance.domain = self.cleaned_data['domain']
 89
 90  -> return self.cleaned_data
 91
 92 class FeedAdmin(admin.ModelAdmin):
 93 list_display= ('name', 'lifestream', 'domain',
'fetchable')
 94 list_filter = ('domain', 'lifestream')
 95 actions = ['make_fetchable', 'make_unfetchable']
(Pdb) self.cleaned_data
{'url': u'http://twitter.com/statuses/user_timeline/6166742.rss',
'domain': u'twitter.com', 'lifestream': , 'name':
u'Twitter / sontek', 'plugin_class_name':
u'lifestream.plugins.twitter.TwitterPlugin'}

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




Django with embedded python - module error

2010-01-10 Thread Wim De Hul
Dear members,

I'm trying to use Django in an embedded python app (main program is in C).
When I try to import the models from my Django app, I get the following error:

Traceback (most recent call last):
  File "/data/mytest/test.py", line 4, in 
from accounts import models
  File "/data/dj/accounts/models.py", line 1, in 
from django.db import models
  File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 41, in 

backend = load_backend(settings.DATABASE_ENGINE)
  File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 22, in 
load_backend
return import_module('.base', backend_name)
  File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in 
import_module
__import__(name)
ImportError: No module named mysql.base

This is my sys.path:

['/data/mytest', '/data/dj', '/data/dj', '/usr/lib/python2.6', 
'/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', 
'/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', 
'/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', 
'/usr/lib/pymodules/python2.6/gtk-2.0', 
'/usr/local/lib/python2.6/dist-packages']


And this is the mysql module:
r...@lab:/data# ls -l /usr/lib/pymodules/python2.6/django/db/backends/mysql/
total 40
lrwxrwxrwx 1 root root52 2009-12-27 15:12 base.py -> 
/usr/share/pyshared/django/db/backends/mysql/base.py
-rw-r--r-- 1 root root 12169 2009-12-27 15:13 base.pyc
lrwxrwxrwx 1 root root54 2009-12-27 15:12 client.py -> 
/usr/share/pyshared/django/db/backends/mysql/client.py
-rw-r--r-- 1 root root  1581 2009-12-27 15:13 client.pyc
lrwxrwxrwx 1 root root56 2009-12-27 15:12 creation.py -> 
/usr/share/pyshared/django/db/backends/mysql/creation.py
-rw-r--r-- 1 root root  2939 2009-12-27 15:13 creation.pyc
-rw-r--r-- 1 root root 0 2009-12-27 15:13 __init__.py
-rw-r--r-- 1 root root   152 2009-12-27 15:13 __init__.pyc
lrwxrwxrwx 1 root root61 2009-12-27 15:12 introspection.py -> 
/usr/share/pyshared/django/db/backends/mysql/introspection.py
-rw-r--r-- 1 root root  4699 2009-12-27 15:13 introspection.pyc
lrwxrwxrwx 1 root root58 2009-12-27 15:12 validation.py -> 
/usr/share/pyshared/django/db/backends/mysql/validation.py
-rw-r--r-- 1 root root  1901 2009-12-27 15:13 validation.pyc
r...@lab:/data#


Everything seems OK for me... Django runs from Apache.
Someone has an idea?

Thanks a lot!
-- 
  Wim
-- 
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: multidb - partitioning

2010-01-10 Thread Adrian Maier
On Sat, Jan 9, 2010 at 15:20, tom  wrote:

> Hi Adrian,
>
> thanks for your answer!
> The problem is, that i don't know how many projects will be created.
> Every user
> of the application can create and delete new projects.
> Maybe it's possible to execute some raw sql commands whenever a
> project is created or deleted (to create the new table and insert
> trigger).
> Do you think that's possible?
> Do you have any good tutorial about postgres and partitioning? I'm
> completly new to this topic.
>
>
One possibility is to have one child table for each existing project. And
one additional table for (all) the newly created projects (just as a
temporary
step until someone or a script creates the new tables).  Later, a midnight
script can check for new projects, create the needed new tables and
rewrite the trigger(s) . I see no reason why automating everything wouldn't
be possible .

By the way : how many projects do you expect to have in the database?
Thousands of projects means thousands of tables ,  and a huge insert
trigger that tries to determine where to insert each new record.  PostgreSQL
should be able to handle lots of tables,  but that trigger will become a
bottleneck at some point in future ...

On the other hand,  try to avoid being stuck into the partitioning idea:
maybe improving the performance for your database can be done
in other ways (maybe you are simply missing an index ! ) .


Sorry, I have no links about partitioning to suggest.

However,  i suggest you to join the pgsql-performance mailing list
and ask there for advice.  That is the PostgreSQL list for discussions
about specific performance issues. You'll find information about how
to subscribe on the postgresql website .

Just make sure that you post there enough information about your database:
the columns of the table,  the estimated number of rows , and a specific
select query that is executed too slowly . And of course the execution
plan of that query  ( explain analyse select .  from    where 
).
So, make sure that you are describing a concrete problem :  for example
you didn't mention what is actual the problem that you hope to solve through
partitioning.  Obviously, you are seeking for faster database response time.
But when exactly : when you insert data, or when you query the data ?
There are many postgres experts on pgsql-performance  ,  but you need
to describe well what are you trying to do;)



-- 
Adrian Maier
-- 

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: Possibility of recursive rendering

2010-01-10 Thread Ethan Jucovy
I think the easiest thing to do write two templates and use the {% include
%} tag like so:

# templates/number_of_comments.html
There are {{paragraph.comment_set.all.count}} comments.

# templates/display_all_paragraphs.html
{% for paragraph in paragraph_set %}
Paragraph: {{paragraph.name}}
{% include "templates/number_of_comments.html" %}
{% endfor %}

On Sun, Jan 10, 2010 at 4:42 AM, Amit Sethi wrote:

> Hi I wish  to know if it is possible to use recursive rendering ? . What I
> mean by that is that their is a template which renders no of comments on a
> paragraph . SInce their are many paragraphs what i wish to send is  a list
> of render_to_response calls for each paragraph. i.e send response messages
> from a loop etc ...
>
> --
> A-M-I-T S|S
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Handling Vector/Array Data in Forms

2010-01-10 Thread Frédéric Burlet
On Saturday 09 January 2010 17:17:26 Tomasz Zieliński wrote:
> On 9 Sty, 01:23, datta  wrote:
> > I am using Django for a scientific applicaition. If I have to
> > transport a vector/array 'to' a form, dismantle it and display the
> > relevant information, it is easy. But how I capture vectors/array
> > datatypes 'from' the HTML forms (submitted by the user) in the
> > view.class and work with them.
> >
> > i.e., i am asking if there is a efficient way of handling 'array' data
> > types in forms (other than using a single variable name in the (html)
> > form and doing a get_all from the (parent) request object)
> 
> I'm not sure what you are asking for, but request.POST['vector']
> contains
> list or tuple of values gathered from vector=1=2&(etc...) POST
> data.

Indeed, or have a look at QueryDict:

http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects

Frédéric Burlet.


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


Re: handle astronomically high number of users via the new BigIntegerField and contrib.auth.user

2010-01-10 Thread Eric Chamberlain
We used one of the UUID fields from djangosnippets.org 
.



On Jan 9, 2010, at 6:56 PM, G B Smith wrote:

> Eric, could you explain how this UUID implementation was achieved?
> Django doesn't have a built-in UUID, so I can only guess that you used
> a varchar field within Django. ?
> 
> On Jan 10, 2:29 am, Eric Chamberlain  wrote:
>> On Jan 9, 2010, at 8:59 AM, G B Smith wrote:
>> 
>>> Thanks, that is a good resource. So this is what I am going to do : -
>>> -- modify the contrib.auth.models.user to explicitly include id =
>>> models.BigIntegerField(primary_key=True)
>>> -- modify the contrib.auth.models.user.id field in the database using
>>> creecode's method above or via the mysql shell or phpmyadmin or other
>>> tools (still deciding)
>> 
>>> I am pretty sure this is going to have zero side-effects. If someone
>>> knows otherwise, would be helpful to have that information.
>> 
>> If your going to go to all that trouble, you may as well use a UUID field 
>> instead.  We went with UUID, because we didn't want membership counts to 
>> leak via an autoincrementing integer.
>> 
>> --
>> Eric Chamberlain, Founder
>> RF.com -http://RF.com/
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

-- 
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: Additional field in junction table

2010-01-10 Thread Benjamin W.
Guess I had some potatoes on my eyes.
Thank you!

On Jan 10, 7:24 pm, Daniel Roseman  wrote:
> On Jan 10, 5:48 pm, "Benjamin W."  wrote:
>
> > Hi,
>
> > I have a model with a ManyToManyField.
> > The junction table ist automatically created by django.
> > In my application it is needed to save additional information for
> > every relation that is created, so I would need an additional field in
> > the junction table.
>
> > It's difficult to explan, so I've created a screenshot, perhaps this
> > makes it more clear:http://doubleu-it.com/sample.jpg
>
> > Hopefully you understand what I mean ;)
> > Thank you very much,
> > greets ben
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
> --
> DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Model Form crashing on Foreign Key

2010-01-10 Thread Sontek
So I'm trying to create a new feed within the Admin page and its
crashing with the error  IntegrityError: lifestream_feed.lifestream_id
may not be NULL, the call stack is... form['lifestream'] is set but
form.instance.lifestream is not.  Here is the code:


class FeedCreationForm(forms.ModelForm):
class Meta:
model = Feed
exclude = ['name', 'domain', 'fetchable']

def parse_feed(self, feed_url):
feed = feedparser.parse(feed_url)

# Does the feed have errors
if feed['bozo']:
if feed['feed'].has_key("links"):
for link in feed['feed']['links']:
if link["type"] == "application/rss+xml":
feed = self.parse_feed(link['href'])
if not feed['bozo']:
return feed
else:
return feed

return None

def clean(self):
"""
Checks to make sure a feed url is valid and gets the feed
title
and domain.
"""
feed_url = self.cleaned_data.get('url')
if not feed_url:
# Feed url was not validated by the field validator
return
feed = self.parse_feed(feed_url)
if feed:
feed_url = feed['url']
self.cleaned_data['url'] = feed_url
else:
# the feed was not parsed correctly.
import logging

self._errors['url'] = ErrorList(["This is not a valid
feed: %s" % feed['bozo_exception']])
logging.error(feed['bozo_exception'])
# This field is no longer valid. Remove from cleaned_data
del self.cleaned_data['url']
return

# Check if the feed has a title field
feed_info = feed.get('feed')
if not feed_info.get('title'):
self._errors['url'] = ErrorList(["This is not a valid
feed: The feed is empty"])
# This field is no longer valid. Remove from cleaned_data
del self.cleaned_data['url']
return
self.cleaned_data['name'] = feed_info['title']
self.instance.name = self.cleaned_data['name']
self.cleaned_data['domain'] = get_url_domain(feed_url)
self.instance.domain = self.cleaned_data['domain']

return self.cleaned_data

class FeedAdmin(admin.ModelAdmin):
list_display= ('name', 'lifestream', 'domain', 'fetchable')
list_filter = ('domain', 'lifestream')
actions = ['make_fetchable', 'make_unfetchable']

add_form = FeedCreationForm
model = Feed

def make_unfetchable(self, request, queryset):
queryset.update(fetchable=False)
make_unfetchable.short_description = _(u"Mark as unfetchable")

def make_fetchable(self, request, queryset):
queryset.update(fetchable=True)
make_fetchable.short_description = _(u"Mark as fetchable")

def add_view(self, request):
if not self.has_change_permission(request):
raise PermissionDenied
if request.method == 'POST':
form = self.add_form(request.POST)
if form.is_valid():
new_feed = form.save()
msg = _('The %(name)s "%(obj)s" was added
successfully.') % {'name': 'user', 'obj': new_feed}
self.log_addition(request, new_feed)
if "_addanother" in request.POST:
request.user.message_set.create(message=msg)
return HttpResponseRedirect(request.path)
elif '_popup' in request.REQUEST:
return self.response_add(request, new_feed)
else:
request.user.message_set.create(message=msg + ' '
+ ugettext("You may edit it again below."))
# TODO: use reversed url
return HttpResponseRedirect('../%s/' %
new_feed.id)
else:
form = self.add_form()

return render_to_response('admin/lifestream/feed/
add_form.html', {
'title': _('Add feed'),
'form': form,
'is_popup': '_popup' in request.REQUEST,
'add': True,
'change': False,
'has_add_permission': True,
'has_delete_permission': False,
'has_change_permission': True,
'has_file_field': False,
'has_absolute_url': False,
'auto_populated_fields': (),
'opts': self.model._meta,
'save_as': False,
#'username_help_text': self.model._meta.get_field
('username').help_text,
'root_path': self.admin_site.root_path,
'app_label': self.model._meta.app_label,
}, context_instance=template.RequestContext(request))

def queryset(self, request):
return self.model.objects.feeds()

admin.site.register(Feed, FeedAdmin)


class Lifestream(models.Model):
"""
A lifestream. Lifestreams can be created per user.
"""
site = models.ForeignKey(Site, 

Re: Register signal on all objects

2010-01-10 Thread Matias

El 10/01/10 04:18, Ishwor Gurung escribió:

2010/1/10 Matias:
[...]

Thanks, this will do the trick...


Curious. Why doesn't overriding save(..) do for you?



Because I would have to override the save() method on all Model classes

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




Additional field in junction table

2010-01-10 Thread Benjamin W.
Hi,

I have a model with a ManyToManyField.
The junction table ist automatically created by django.
In my application it is needed to save additional information for
every relation that is created, so I would need an additional field in
the junction table.

It's difficult to explan, so I've created a screenshot, perhaps this
makes it more clear:
http://doubleu-it.com/sample.jpg


Hopefully you understand what I mean ;)
Thank you very much,
greets ben
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Why in import statement

2010-01-10 Thread Łukasz Balcerzak
Hi there,

Well, it is quite simple but let's break it down:

> to me the command "from myproject.myapp.models import Author" should
> be
> either
> 
>from myapp.models import Author
> or
>from models import Author # in the same folder as myapp.models.


1) If you use "from myapp.models import Author" then "myapp" is supposed to be 
pluggable app. If so, it should not be located within "myproject" as it is kind 
of library for django projects. On the other hand, as you write your apps you 
are not always sure if this should be pluggable or not, especially at the early 
stage. Most of the time it probably should but if you know about PYTHONPATH 
(and virtualenv maybe) you can figure it out on your own how to split your 
project/apps. Tutorial at Django website is aimed for people with little python 
knowledge, really. Just use "from someapp.package..." statements for external 
(from the point of view of your project) apps and "from 
myproject.projectapp..." statements for internal (not pluggable) apps.

2) Definitely "from models" is not a good idea - there should be clear 
statement about where are classes imported from. Adding "app_name" into import 
statement makes it very clear.

You may also read http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango - 
it has some references to import statements in django projects.


On Jan 10, 2010, at 3:04 PM, ruckus tak wrote:

> Hi,
> 
> +
> +
>  Does anyone know why the project-name included in the import
> statement?
> +
> +
> 
> One thing I cannot understand in Django is the  included
> in the import statement.
> For example from djangoproject admin document:
> 
>from django.contrib import admin
>from myproject.myapp.models import Author
> 
>class AuthorAdmin(admin.ModelAdmin):
>pass
>admin.site.register(Author, AuthorAdmin)
> 
> to me the command "from myproject.myapp.models import Author" should
> be
> either
> 
>from myapp.models import Author
> or
>from models import Author # in the same folder as myapp.models.
> 
> My view is project-name is a container, applications inside the
> container deal with other applications in the container or defined in
> the PYTHONPATH.
> 2nd if you would like to share the application with other project;
> then definitely the application should not refer to any project name
> -- an application can refer to other applications, but it should not
> refer to an application of other project which i might not have the
> right to access to it, but only the application.
> 
> Does anyone know why the project-name included in the import
> statement?
> 
> Thanks in advance.
> tak
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

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




Re: django-tagging on shared hosting

2010-01-10 Thread Daniel Roseman
On Jan 10, 3:28 pm, flynnguy  wrote:
> So I'm trying to implement tagging on my website and I found the
> django-tagging project and threw it in my app and it works great... on
> my laptop. Go to put things up on the server (dreamhost using their
> new passenger method) and started to run into some issues. I did easy
> install using --prefix so I could install it in my home directory. My
> structure looks something like this:
> ~/django
> |--applications
> |   `-- pythonlib
> |       `-- lib
> |           `-- python2.4
> |               `-- site-packages
> |                   `-- django_tagging-0.3-py2.4.egg
> |                       |-- EGG-INFO
> |                       `-- tagging
> |                           |-- templatetags
> |                           `-- tests
> |--projects
> |--source
>
> source is my copy of the Django source code and then projects is where
> I keep my application souce code. Also, in order to get it to install,
> I had to put the site-packages path in my PYTHONPATH in .bash_profile:
> export PYTHONPATH=$PYTHONPATH:$HOME/django/source:$HOME/django/
> projects:$HOME/django/applications/pythonlib/lib/python2.4/site-
> packages
>
> So far so good:
> $ python manage.py shell
> Python 2.4.4 (#2, Oct 22 2008, 20:20:22)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)>>> import tagging
> >>> tagging.VERSION
>
> (0, 3, 'pre')
>
> I think great, that was pretty easy... I should be ready to go. Push
> my code up to the server, run syncdb, it makes the tables and index...
> but I get a 500 Internal Server Error. What's most frustrating is I
> can't seem to get a debug error page, despite having Debug = True but
> that just seems to be a quirk of using dreamhost.
>
> So fearing maybe my code is borked, I undid my recent checkout...
> sites fine again. If I put in 'tagging', into the INSTALLED_APPS, I
> get the 500 Internal Server Error.
>
> I realize this is probably due to the way dreamhost is setup. In my
> passenger_wsgi.py script, I have a bunch of sys.path.inserts to add
> the same folders in my PYTHONPATH, I'm just not understanding where
> the disconnect it. If someone has some insight into why this might be
> happening, I'd love to hear it. Both laptop and server are using
> Django version 1.1.1. Is there something I'm missing with my paths?
> I've spent more time trying to fix this than I have adding the tags. :-
> (

I'm not familiar with Dreamhost's setup particularly, but if you are
already inserting paths into sys.path in your WSGI script, the answer
is probably there. Instead of running setup.py to install django-
tagging anywhere, just leave it where it is, and insert its path into
sys.path along with all the others.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




django-tagging on shared hosting

2010-01-10 Thread flynnguy
So I'm trying to implement tagging on my website and I found the
django-tagging project and threw it in my app and it works great... on
my laptop. Go to put things up on the server (dreamhost using their
new passenger method) and started to run into some issues. I did easy
install using --prefix so I could install it in my home directory. My
structure looks something like this:
~/django
|--applications
|   `-- pythonlib
|   `-- lib
|   `-- python2.4
|   `-- site-packages
|   `-- django_tagging-0.3-py2.4.egg
|   |-- EGG-INFO
|   `-- tagging
|   |-- templatetags
|   `-- tests
|--projects
|--source

source is my copy of the Django source code and then projects is where
I keep my application souce code. Also, in order to get it to install,
I had to put the site-packages path in my PYTHONPATH in .bash_profile:
export PYTHONPATH=$PYTHONPATH:$HOME/django/source:$HOME/django/
projects:$HOME/django/applications/pythonlib/lib/python2.4/site-
packages

So far so good:
$ python manage.py shell
Python 2.4.4 (#2, Oct 22 2008, 20:20:22)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import tagging
>>> tagging.VERSION
(0, 3, 'pre')

I think great, that was pretty easy... I should be ready to go. Push
my code up to the server, run syncdb, it makes the tables and index...
but I get a 500 Internal Server Error. What's most frustrating is I
can't seem to get a debug error page, despite having Debug = True but
that just seems to be a quirk of using dreamhost.

So fearing maybe my code is borked, I undid my recent checkout...
sites fine again. If I put in 'tagging', into the INSTALLED_APPS, I
get the 500 Internal Server Error.

I realize this is probably due to the way dreamhost is setup. In my
passenger_wsgi.py script, I have a bunch of sys.path.inserts to add
the same folders in my PYTHONPATH, I'm just not understanding where
the disconnect it. If someone has some insight into why this might be
happening, I'd love to hear it. Both laptop and server are using
Django version 1.1.1. Is there something I'm missing with my paths?
I've spent more time trying to fix this than I have adding the tags. :-
(
-- 
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: installing django application on non-django website.

2010-01-10 Thread flynnguy
It looks like what you've linked to is a full project.

In order to use any part of Django, you need to setup a Django
instance. You will need to go configure apache to pass requests going
to example.com/weblog/ to Django, specifically your project folder.
The url.py folder then handles the rest.
-Chris

On Jan 10, 8:57 am, gryzzly  wrote:
> I have a website that is a bunch of html files, deployed trhough
> apache. (let's say, example.com)
>
> What do I need to do in order to deploy one django application (let's
> sayhttp://github.com/vbabiy/django_blog) on example.com/weblog/?
>
> I know how to plug an application into existing django project, but
> what if all I want to use is the application?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Why in import statement

2010-01-10 Thread ruckus tak
Hi,

+
+
  Does anyone know why the project-name included in the import
statement?
+
+

One thing I cannot understand in Django is the  included
in the import statement.
For example from djangoproject admin document:

from django.contrib import admin
from myproject.myapp.models import Author

class AuthorAdmin(admin.ModelAdmin):
pass
admin.site.register(Author, AuthorAdmin)

to me the command "from myproject.myapp.models import Author" should
be
either

from myapp.models import Author
or
from models import Author # in the same folder as myapp.models.

My view is project-name is a container, applications inside the
container deal with other applications in the container or defined in
the PYTHONPATH.
2nd if you would like to share the application with other project;
then definitely the application should not refer to any project name
-- an application can refer to other applications, but it should not
refer to an application of other project which i might not have the
right to access to it, but only the application.

Does anyone know why the project-name included in the import
statement?

Thanks in advance.
tak


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




installing django application on non-django website.

2010-01-10 Thread gryzzly
I have a website that is a bunch of html files, deployed trhough
apache. (let's say, example.com)

What do I need to do in order to deploy one django application (let's
say http://github.com/vbabiy/django_blog) on example.com/weblog/?

I know how to plug an application into existing django project, but
what if all I want to use is the application?
-- 
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: handle astronomically high number of users via the new BigIntegerField and contrib.auth.user

2010-01-10 Thread Frank DiRocco
I assume you could checksum some form of the user's object or  
"cleaned" form values and store it as unique attribute of the users.  
You would prolly have to override the clean method and add in  
valudation of the uniqueness and generate using an alternate method if  
the first does not validate unique, the main issue I see is needing to  
get that value for the UUID unique every time. Could be as simple as  
salting the username with timestamp and checksumming the text. pad or  
trim to get the necessary length, but this doesnt seem necessary.  
Since your not using a base 10 character system anymore you can really  
increase the max number of users by alot without using a ton of space  
storing digits.


One impact may be lookup time and index storage/maintenance as your  
uuid field would probably benefit from an index to reduce search time.  
With an "astronomically high number of users" I imagine your  
production equipment would need to be pretty serious already.


On Jan 9, 2010, at 9:56 PM, G B Smith wrote:


Eric, could you explain how this UUID implementation was achieved?
Django doesn't have a built-in UUID, so I can only guess that you used
a varchar field within Django. ?

On Jan 10, 2:29 am, Eric Chamberlain  wrote:

On Jan 9, 2010, at 8:59 AM, G B Smith wrote:

Thanks, that is a good resource. So this is what I am going to  
do : -

-- modify the contrib.auth.models.user to explicitly include id =
models.BigIntegerField(primary_key=True)
-- modify the contrib.auth.models.user.id field in the database  
using
creecode's method above or via the mysql shell or phpmyadmin or  
other

tools (still deciding)



I am pretty sure this is going to have zero side-effects. If someone
knows otherwise, would be helpful to have that information.


If your going to go to all that trouble, you may as well use a UUID  
field instead.  We went with UUID, because we didn't want  
membership counts to leak via an autoincrementing integer.


--
Eric Chamberlain, Founder
RF.com -http://RF.com/

--
You received this message because you are subscribed to the Google  
Groups "Django users" group.

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





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




text in translation strings?

2010-01-10 Thread Andreas Pfrengle
Hello,

I'm having a template, where a link shall be inside a translation-
marked text. I see two ways how to accomplish this, but both don't
work:
1. {% trans "You need to login before
you can do anything" %}
I get an template syntax error: "Searching for value. Unexpected
end of string" (because of the quotes). Escaping the quotes or taking
single quotes also didn't work
2. {% blocktrans %}You need to login
before you can do anything {% endblocktrans %}
Again template syntax error: "'blocktrans' doesn't allow other
block tags (seen u'url login') inside it"

Is there a way with either of these tags to accomplish what I want? Of
course there would also be the possibility to mark each single part of
the text, like so:
3. {% trans "You need to " %}{% trans "login
 before you can do anything" %}
But I don't want to split the string in the middle of a sentence.
-- 
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: Possibility of recursive rendering

2010-01-10 Thread Andreas Pfrengle
On 10 Jan., 10:42, Amit Sethi  wrote:
> Hi I wish  to know if it is possible to use recursive rendering ? . What I
> mean by that is that their is a template which renders no of comments on a
> paragraph . SInce their are many paragraphs what i wish to send is  a list
> of render_to_response calls for each paragraph. i.e send response messages
> from a loop etc ...
>
> --
> A-M-I-T S|S

Do you mean you just want to add to your Context or RequestContext?
Sth. like that?

c = Context({})
for p in paragraphs:
c.update(p.comments) # assuming each paragraph p has a comments-
dict
return render_to_response('template.html', c)
-- 
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: users sessions logging

2010-01-10 Thread Казбек
In this case request.session.session_key and request.COOKIES
["sessionid"] contains different values. request.COOKIES["sessionid"]
contains old session id, request.session.session_key contains new
session id. To emplement correct logging, need to find session id from
request.COOKIES["sessionid"] in logs table, and replace it with
request.session_key.

On 7 янв, 14:51, Казбек  wrote:
> Good day. For sessions logging i use wrapper for django login and
> logout functions. I save session id from request, save session id to
> my table, and then pass request to django login function. but when the
> django's login function ends, user's session id in django changes. and
> my table and django's table contains different session id. 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Django Groups In Templates

2010-01-10 Thread G B Smith
If your users can belong to only one group, then check this out: -
http://stackoverflow.com/questions/1889607/django-middleware-to-determine-users-group-in-a-session

GBS.

On Jan 10, 1:21 pm, Dave Merwin  wrote:
> Brilliant!! That worked. Thanks.
>
> On Jan 10, 12:19 am, G B Smith  wrote:
>
> > user.groups.all returns not one but (possibly) many objects. Thus you
> > will have to do something like
>
> > {% for group in user.groups.all %}
> >     {% if group.name == 'subscribed' %}
> >        Hello
> >     {% endif %}
> > {% endfor %}
>
> > Regards,
> > GBS
>
> > On Jan 10, 1:12 pm, Dave Merwin  wrote:
>
> > > I'm trying to do something I thought was simple.
>
> > > {% ifequal user.groups "subscribed"  %}
> > >     Hello
> > > {% endifequal %}
>
> > > But it's not working...
>
> > > Any tips?
-- 
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: context processor var empty

2010-01-10 Thread Daniel Roseman
On Jan 10, 3:35 am, neridaj  wrote:
> I'm trying to use a context processor to make all of my blog entry
> titles available for an ajax autocomplete search box but for some
> reason the var returned from the context processor is empty.
>
> from blog.models import Entry
>
> # search/context_processors.py
>
> def search(request):
>         data = Entry.objects.all()
>         return { 'data': data }
>
> # settings.py
>
> TEMPLATE_CONTEXT_PROCESSORS = (
>     "django.core.context_processors.auth",
>     "django.core.context_processors.debug",
>     "django.core.context_processors.i18n",
>     "django.core.context_processors.media",
>     "search.context_processors.search",
> )
>
> # base.html
>
>     
>         $(document).ready(function(){
>             var data = "{{ data }}".split(":");
>             $("#id_q").autocomplete(data);
>         });
>     
>
> # base.html rendered
>
>  $(document).ready(function(){
>     var data = "".split(":");
>     $("#id_q").autocomplete(data);
>    });

It's not AJAX if you're hard-coding all the entries into the template,
it's just basic Javascript, but never mind.

You don't show how you're rendering that template, but I suspect that
you're not using RequestContext.

Bear in mind that the context processor is run for *every single view*
(again, as long as you use RequestContext), which may not be what you
want. I'd suggest a template tag for this use case. Or you could
actually make it Ajax, so it requests matching entries dynamically.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Possibility of recursive rendering

2010-01-10 Thread Amit Sethi
Hi I wish  to know if it is possible to use recursive rendering ? . What I
mean by that is that their is a template which renders no of comments on a
paragraph . SInce their are many paragraphs what i wish to send is  a list
of render_to_response calls for each paragraph. i.e send response messages
from a loop etc ...

-- 
A-M-I-T S|S
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Django Groups In Templates

2010-01-10 Thread Dave Merwin
Brilliant!! That worked. Thanks.

On Jan 10, 12:19 am, G B Smith  wrote:
> user.groups.all returns not one but (possibly) many objects. Thus you
> will have to do something like
>
> {% for group in user.groups.all %}
>     {% if group.name == 'subscribed' %}
>        Hello
>     {% endif %}
> {% endfor %}
>
> Regards,
> GBS
>
> On Jan 10, 1:12 pm, Dave Merwin  wrote:
>
> > I'm trying to do something I thought was simple.
>
> > {% ifequal user.groups "subscribed"  %}
> >     Hello
> > {% endifequal %}
>
> > But it's not working...
>
> > Any tips?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Django Groups In Templates

2010-01-10 Thread G B Smith
user.groups.all returns not one but (possibly) many objects. Thus you
will have to do something like

{% for group in user.groups.all %}
{% if group.name == 'subscribed' %}
   Hello
{% endif %}
{% endfor %}

Regards,
GBS


On Jan 10, 1:12 pm, Dave Merwin  wrote:
> I'm trying to do something I thought was simple.
>
> {% ifequal user.groups "subscribed"  %}
>     Hello
> {% endifequal %}
>
> But it's not working...
>
> Any tips?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Django Groups In Templates

2010-01-10 Thread Dave Merwin
I'm trying to do something I thought was simple.

{% ifequal user.groups "subscribed"  %}
Hello
{% endifequal %}

But it's not working...

Any tips?
-- 
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.