Re: Problems specifying fields for admin inline

2009-02-25 Thread James Bennett

On Thu, Feb 26, 2009 at 2:30 AM, jeff  wrote:
> Wow, that's much simpler. They should list that option on the admin
> documentation page. Many thanks!

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-options

"The InlineModelAdmin class is a subclass of ModelAdmin so it inherits
all the same functionality as well as some of its own:"

(in other words, anything that's legal to do on a plain ModelAdmin is
legal to do on an InlineModelAdmin)


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: NetBeans IDE for Python

2009-02-25 Thread पुनित मदान
u dont need to move django ... but need to configure python path in project
properties 

2009/2/26 Amirouche aka Mouche 

>
> It looks like they plan to give some love to django in the next
> release
>
> http://wiki.netbeans.org/Python70Roadmap
>
> here is the pre-beta nb 7
> http://bits.netbeans.org/download/6.7/m2/
>
> their is a ruby column but no python ! Hell ! I wonder why ! Is ruby
> that mainstream ?
>
> can't try it myself now, hope it helps !
>
>
> On Feb 26, 5:38 am, Amirouche aka Mouche
>  wrote:
> > On Feb 4, 10:54 pm, phillc  wrote:
> >
> > > mine wasnt working exactly as you all described it...
> >
> > > until i moved my django symlink to someplace else on my python path...
> > > and it suddenly worked its really odd.
> >
> > uhh what do you mean ?
> >
> > > On Feb 3, 12:49 am, mrsixcount  wrote:
> >
> > > > Can't seem to get the auto complete to work when I import
> > > > django.db.models as models.  Shows models when I start typing but
> > > > after the . nothing in the django model section comes up.  Shows the
> > > > master list of python options.  IntegerField isn't in there nor could
> > > > I find any of the other ones.  Oh well hopefully it will be out soon
> > > > with more support for Django
> >
> > > > On Jan 17, 3:29 am, Gautam  wrote:
> >
> > > > > There is some problem with the parser recognizing package imports
> in
> > > > > the from ... import ... syntax. What seems to work is if you import
> > > > > packages directly as import ... as 
> >
> > > > > So for the django models import as:
> >
> > > > > import django.db.models as models
> >
> > > > > And voila, completion in Netbeans works!
> >
> > > > > On Nov 20 2008, 5:01 pm, lig  wrote:
> >
> > > > > > On 19 нояб, 21:22, Delta20  wrote:
> >
> > > > > > > NetBeans for Python has been released and based on the NB
> Python
> > > > > > > roadmap, it looks interesting for those of us working with
> Django. I
> > > > > > > haven't had much of a chance to play with it yet since it just
> came
> > > > > > > out today, but here's the info for anyone interested:
> >
> > > > > > > NetBeans IDE for Python:
> http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
> >
> > > > > > from django.db import models
> >
> > > > > > class Page(models.Model):
> > > > > > name= models. # hitting Ctrl+Space here don't show field
> type
> > > > > > suggestions or anything from imported models package
> >
> >
> >
>


-- 
If you spin an oriental man, does he become disoriented?
(-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu

is der net süß » ε(●̮̮̃•̃)з
-PM

--~--~-~--~~~---~--~~
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 specifying fields for admin inline

2009-02-25 Thread jeff

Wow, that's much simpler. They should list that option on the admin
documentation page. Many thanks!

On Feb 25, 10:58 pm, Alex Gaynor  wrote:
> On Thu, Feb 26, 2009 at 1:51 AM, jeff  wrote:
>
> > I'm trying to modify the default Site admin page to include an inline
> > model. Everything seems to be working fine except that no matter what
> > I try I can't get it to limit the fields displayed in the inline. When
> > I go to the site edit page in the admin, it shows the standard site
> > fields as it should, but it shows every field defined for the inline
> > model, not just the one I tell it to. The relevant code is below. Any
> > help would be greatly appreciated.
>
> > -
> > # admin.py
>
> > from django.contrib import admin
> > from django.contrib.sites.models import Site
> > from django.contrib.sites.admin import SiteAdmin
> > from django.forms.models import inlineformset_factory
> > from lindt.sections.models import TopNav
>
> > admin.site.unregister(Site)
>
> > class TopNavInline(admin.StackedInline):
> >    model = TopNav
> >    formset = inlineformset_factory(
> >        Site,
> >        TopNav,
> >        fields = ('order',)
> >    )
> >    extra = 0
> >    max_num = 0
>
> > class SiteAdminMod(SiteAdmin):
> >        inlines = [TopNavInline]
>
> > admin.site.register(Site, SiteAdminMod)
>
> Drop the formset = bit and simply provide fields = ['order'] in the
> InlineModelAdmin definition.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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 specifying fields for admin inline

2009-02-25 Thread Alex Gaynor
On Thu, Feb 26, 2009 at 1:51 AM, jeff  wrote:

>
> I'm trying to modify the default Site admin page to include an inline
> model. Everything seems to be working fine except that no matter what
> I try I can't get it to limit the fields displayed in the inline. When
> I go to the site edit page in the admin, it shows the standard site
> fields as it should, but it shows every field defined for the inline
> model, not just the one I tell it to. The relevant code is below. Any
> help would be greatly appreciated.
>
> -
> # admin.py
>
> from django.contrib import admin
> from django.contrib.sites.models import Site
> from django.contrib.sites.admin import SiteAdmin
> from django.forms.models import inlineformset_factory
> from lindt.sections.models import TopNav
>
> admin.site.unregister(Site)
>
> class TopNavInline(admin.StackedInline):
>model = TopNav
>formset = inlineformset_factory(
>Site,
>TopNav,
>fields = ('order',)
>)
>extra = 0
>max_num = 0
>
> class SiteAdminMod(SiteAdmin):
>inlines = [TopNavInline]
>
> admin.site.register(Site, SiteAdminMod)
>
>
> >
>
Drop the formset = bit and simply provide fields = ['order'] in the
InlineModelAdmin definition.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 specifying fields for admin inline

2009-02-25 Thread jeff

I'm trying to modify the default Site admin page to include an inline
model. Everything seems to be working fine except that no matter what
I try I can't get it to limit the fields displayed in the inline. When
I go to the site edit page in the admin, it shows the standard site
fields as it should, but it shows every field defined for the inline
model, not just the one I tell it to. The relevant code is below. Any
help would be greatly appreciated.

-
# admin.py

from django.contrib import admin
from django.contrib.sites.models import Site
from django.contrib.sites.admin import SiteAdmin
from django.forms.models import inlineformset_factory
from lindt.sections.models import TopNav

admin.site.unregister(Site)

class TopNavInline(admin.StackedInline):
model = TopNav
formset = inlineformset_factory(
Site,
TopNav,
fields = ('order',)
)
extra = 0
max_num = 0

class SiteAdminMod(SiteAdmin):
inlines = [TopNavInline]

admin.site.register(Site, SiteAdminMod)


--~--~-~--~~~---~--~~
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: Fwd: python sql query in django

2009-02-25 Thread Parthan SR

On Thu, Feb 26, 2009 at 2:24 AM, Jesse  wrote:

>
> I have three statements:
> publications = Publication.objects.filter(techpubcombo__technology=t)
> publications2 = Publication.objects.filter(pathpubcombo__pathology=p)
> publications3 = Publication.objects.filter(commpubcombo__commodity=c)
>
> I need to combine the three sets into one set to eliminate duplication
> in the publications and then output the final set to the template.

If am not wrong, the result of first filter is a query object until
you do .all() on it (for ex.) and hence the query object can be
subjected to other filters as well if required. So you should be able
to do one of the following..

[1] publications =
Publication.objects.filter(techpubcombo__technology=t).filter(pathpubcombo__pathology=p).filter(commpubcombo__commodity=c)
[2]  publications = Publication.objects.filter(techpubcombo__technology=t)
 publications = Publication.objects.filter(pathpubcombo__pathology=p)
 publications = Publication.objects.filter(commpubcombo__commodity=c)

both [1] and [2] applies all the three filter conditions on the
Publication.objects and return you the final query object on which you
might be able to do publications.all() and get all the results.


-- 
With Regards,

Parthan "Technofreak" (2FF01026)
http://blog.technofreak.in

--~--~-~--~~~---~--~~
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: Modifying the default admin edit page for Sites

2009-02-25 Thread jeff

Worked like a charm. Thank you!

On Feb 25, 6:07 pm, Alex Gaynor  wrote:
> On Wed, Feb 25, 2009 at 9:03 PM, jeff  wrote:
>
> > Is there a good way to modify what fields are displayed on the edit
> > page for a site (from django.contrib.sites)? I want to have the page
> > include inline editing for a model that has a ForeignKey to Sites.
>
> > Is there a way to change the django.contrib.admin.ModelAdmin class for
> > the Site model? Do I have to dig in and start modifying the admin
> > templates? It seems like there ought to be a simpler way to do this.
>
> > Any guidance would be much appreciated. Thanks!
>
> Sure, just import the old model admin, use admin.site.unregister(Site) to
> remove the old one, create you're own subclass of the current one and
> register it like normal, presto!
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: NetBeans IDE for Python

2009-02-25 Thread Amirouche aka Mouche

It looks like they plan to give some love to django in the next
release

http://wiki.netbeans.org/Python70Roadmap

here is the pre-beta nb 7
http://bits.netbeans.org/download/6.7/m2/

their is a ruby column but no python ! Hell ! I wonder why ! Is ruby
that mainstream ?

can't try it myself now, hope it helps !


On Feb 26, 5:38 am, Amirouche aka Mouche
 wrote:
> On Feb 4, 10:54 pm, phillc  wrote:
>
> > mine wasnt working exactly as you all described it...
>
> > until i moved my django symlink to someplace else on my python path...
> > and it suddenly worked its really odd.
>
> uhh what do you mean ?
>
> > On Feb 3, 12:49 am, mrsixcount  wrote:
>
> > > Can't seem to get the auto complete to work when I import
> > > django.db.models as models.  Shows models when I start typing but
> > > after the . nothing in the django model section comes up.  Shows the
> > > master list of python options.  IntegerField isn't in there nor could
> > > I find any of the other ones.  Oh well hopefully it will be out soon
> > > with more support for Django
>
> > > On Jan 17, 3:29 am, Gautam  wrote:
>
> > > > There is some problem with the parser recognizing package imports in
> > > > the from ... import ... syntax. What seems to work is if you import
> > > > packages directly as import ... as 
>
> > > > So for the django models import as:
>
> > > > import django.db.models as models
>
> > > > And voila, completion in Netbeans works!
>
> > > > On Nov 20 2008, 5:01 pm, lig  wrote:
>
> > > > > On 19 нояб, 21:22, Delta20  wrote:
>
> > > > > > NetBeans for Python has been released and based on the NB Python
> > > > > > roadmap, it looks interesting for those of us working with Django. I
> > > > > > haven't had much of a chance to play with it yet since it just came
> > > > > > out today, but here's the info for anyone interested:
>
> > > > > > NetBeans IDE for 
> > > > > > Python:http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
>
> > > > > from django.db import models
>
> > > > > class Page(models.Model):
> > > > >     name    = models. # hitting Ctrl+Space here don't show field type
> > > > > suggestions or anything from imported models package
>
>
--~--~-~--~~~---~--~~
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: NetBeans IDE for Python

2009-02-25 Thread Amirouche aka Mouche



On Feb 4, 10:54 pm, phillc  wrote:
> mine wasnt working exactly as you all described it...
>
> until i moved my django symlink to someplace else on my python path...
> and it suddenly worked its really odd.

uhh what do you mean ?

> On Feb 3, 12:49 am, mrsixcount  wrote:
>
> > Can't seem to get the auto complete to work when I import
> > django.db.models as models.  Shows models when I start typing but
> > after the . nothing in the django model section comes up.  Shows the
> > master list of python options.  IntegerField isn't in there nor could
> > I find any of the other ones.  Oh well hopefully it will be out soon
> > with more support for Django
>
> > On Jan 17, 3:29 am, Gautam  wrote:
>
> > > There is some problem with the parser recognizing package imports in
> > > the from ... import ... syntax. What seems to work is if you import
> > > packages directly as import ... as 
>
> > > So for the django models import as:
>
> > > import django.db.models as models
>
> > > And voila, completion in Netbeans works!
>
> > > On Nov 20 2008, 5:01 pm, lig  wrote:
>
> > > > On 19 нояб, 21:22, Delta20  wrote:
>
> > > > > NetBeans for Python has been released and based on the NB Python
> > > > > roadmap, it looks interesting for those of us working with Django. I
> > > > > haven't had much of a chance to play with it yet since it just came
> > > > > out today, but here's the info for anyone interested:
>
> > > > > NetBeans IDE for 
> > > > > Python:http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
>
> > > > from django.db import models
>
> > > > class Page(models.Model):
> > > >     name    = models. # hitting Ctrl+Space here don't show field type
> > > > suggestions or anything from imported models package
>
>
--~--~-~--~~~---~--~~
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: A solution for django/postgresql transaction problem

2009-02-25 Thread Karen Tracey
On Wed, Feb 25, 2009 at 10:29 PM, Sushant Sinha wrote:

>
> I am also facing the same problem. Here is the description of my
> problem. The code tries to create a new user and emits an error when
> an error happens:
>
> try:
>user = auth.models.User.objects.create_user(uname, email, password
> = passwd)
> except db.IntegrityError:
>htmldict['msg'] = 'Username "%s" has already been taken. Try a
> different one.' % uname
>return render_to_response('register.html', htmldict)
>
> Now this gives the error:
>
> Traceback (most recent call last):
>
> [snip]
>  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/
> query.py", line 1700, in execute_sql
>cursor.execute(sql, params)
>
> InternalError: current transaction is aborted, commands ignored until
> end of transaction block
>
> I did not know that the template rendering also uses the database
> cursor. So I am catching the exception but I why should I care about
> the cursor. The django model does not expose cursor by default and
> that should be used only when I am writing custom SQL queries.
>

You want to use the transaction commit/rollback routines, not cursor ones:

http://docs.djangoproject.com/en/dev/topics/db/transactions/


>
> I think that the cursor should rollback if there is an error and then
> throw the exception. Thats a more reasonable behavior than what we
> have right now.
>

Except rollback isn't the only option, from what I read.  Though I have
never experimented with it, apparently your code could also choose to commit
the transaction at this point.  Your code is the only code with enough
context to know whether what's been done so far should be committed anyway
despite the error or if the error should cause the whole thing to be rolled
back.

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



updated poll example to take points for each item, gives more than 1 to upack err

2009-02-25 Thread seamusjr

I am trying to modify the polls example from djangoproject.com to take
a integer point value for each of the 1 thru 5 poll items instead of
having a radio button where u select one.  However, I am having
problems with the views.py syntax.  I changed the Choice obejct to be
a Song object and changed the name of the choice and votes properties
to be name and points respectively.  I keep getting this annoying
"need more than 1 value to unpack" error.  Below are some snippets of
code.  Please can someone help me out with the views syntax, or do I
need to create a ModelForm/form to deal with getting the input to the
views.

Thanks in advance,
Seamus

views.py

from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from mysite.polls.models import Poll, PollForm, Song, SongForm

def vote(request, poll_id):
p = get_object_or_404(Poll, poll_id)
try:
#selected_song_set = p.song_set.get(pk=request.POST['song'])
selected_song_set = p.song_set.get(pk=poll_id)
except (KeyError, Song.DoesNotExist):
# Redisplay the poll voting form.
return render_to_response('polls/poll_detail.html', {
'object': p,
'error_message': "You didn't select a choice.",
})
else:
# need to submit
#   selected_song_set.points += 1
selected_song_set.points1 = points1
selected_song_set.points2 = points2
selected_song_set.points3 = points3
selected_song_set.points4 = points4
selected_song_set.points5 = points5
selected_song_set.save()
# Always return an HttpResponseRedirect after successfully 
dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
#return 
HttpResponseRedirect(reverse('mysite.polls.views.results',
args=(p.id,)))
return HttpResponseRedirect(reverse('poll_results', 
args=(p.id,)))

models.py:
from django.db import models
from django.forms import ModelForm
import datetime

# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question

def was_published_today(self):
return self.pub_date.date() == datetime.date.today()

class Song(models.Model):
poll = models.ForeignKey(Poll)
name = models.CharField(max_length=200)
points = models.IntegerField()
#points = models.IntegerField(min_value='1', max_value='5')

def __unicode__(self):
return self.song

poll_detail.html
{{ object.question }}

{% if error_message %}{{ error_message }}{%
endif %}

{% for song in object.song_set.all %}


{{ song.name }}
{% endfor %}



results.html:
{{ object.question }}


{% for song in object.song_set.all %}
{{ song.name }} -- {{ song.points }} points{{ song.points|
pluralize }}

{% endfor %}



--~--~-~--~~~---~--~~
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: A solution for django/postgresql transaction problem

2009-02-25 Thread Sushant Sinha

I am also facing the same problem. Here is the description of my
problem. The code tries to create a new user and emits an error when
an error happens:

try:
user = auth.models.User.objects.create_user(uname, email, password
= passwd)
except db.IntegrityError:
htmldict['msg'] = 'Username "%s" has already been taken. Try a
different one.' % uname
return render_to_response('register.html', htmldict)

Now this gives the error:

Traceback (most recent call last):

  File "/usr/lib64/python2.5/site-packages/django/core/handlers/
base.py", line 86, in get_response
response = callback(request, *callback_args, **callback_kwargs)

  File "/usr/lib64/python2.5/site-packages/djangobb/users/views.py",
line 88, in signup
return render_to_response('register.html', htmldict)

  File "/usr/lib64/python2.5/site-packages/django/shortcuts/
__init__.py", line 18, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs),
**httpresponse_kwargs)

  File "/usr/lib64/python2.5/site-packages/django/template/loader.py",
line 107, in render_to_string
return t.render(context_instance)

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 176, in render
return self.nodelist.render(context)

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 768, in render
bits.append(self.render_node(node, context))

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 781, in render_node
return node.render(context)

  File "/usr/lib64/python2.5/site-packages/django/template/
loader_tags.py", line 111, in render
return self.template.render(context)

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 176, in render
return self.nodelist.render(context)

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 768, in render
bits.append(self.render_node(node, context))

  File "/usr/lib64/python2.5/site-packages/django/template/
__init__.py", line 781, in render_node
return node.render(context)

  File "/usr/lib64/python2.5/site-packages/django/template/
defaulttags.py", line 123, in render
len_values = len(values)

  File "/usr/lib64/python2.5/site-packages/django/db/models/query.py",
line 154, in __len__
self._result_cache = list(self.iterator())

  File "/usr/lib64/python2.5/site-packages/django/db/models/query.py",
line 269, in iterator
for row in self.query.results_iter():

  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
for rows in self.execute_sql(MULTI):

  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/
query.py", line 1700, in execute_sql
cursor.execute(sql, params)

InternalError: current transaction is aborted, commands ignored until
end of transaction block

I did not know that the template rendering also uses the database
cursor. So I am catching the exception but I why should I care about
the cursor. The django model does not expose cursor by default and
that should be used only when I am writing custom SQL queries.

I think that the cursor should rollback if there is an error and then
throw the exception. Thats a more reasonable behavior than what we
have right now.

-Sushant.


Karen Tracey wrote:
> On Tue, Feb 10, 2009 at 9:58 AM, azer  wrote:
>
> >
> > Hi,
> > I modified django's db/backends/postgresq_psycopg2/base.py and fixed
> > the problem.I added this lines before "cursor = self.connection.cursor
> > ()":
> >
> ># if transaction is broken, run rollback method
> >if self.connection.get_transaction_status()==3:
> >self.connection.rollback()
> >#
> >
> > I hope it will be useful for you too.Also, I've written a blog post
> > about this;
> >
> > http://berraksular.blogspot.com/2009/02/transaction-problem-of-django-and.html
> >
>
> Some description of the problem you are trying to solve here would have been
> useful.  Based on what the code does, I guess you are trying to fix the
> problem that once some sort of database error is encountered, PostgreSQL
> refuses to process any subsequent commands in that transaction and instead
> returns another error along the lines of "current transaction is aborted,
> commands ignored until end of transaction block"?
>
> I don't believe what you have proposed here is a good solution.  When the
> original error occurs, an exception is raised.  In order for your code to
> get to the point of issuing another SQL command in that transaction, some
> code had to catch that exception and decide to continue on instead of
> abandoning whatever is being attempted.  It is the code that catches the
> original exception and decides to proceed on anyway that should be
> responsible for restoring the connection to a state where SQL commands can
> be issued.  That is the code that has enough context to know it is safe to
> proceed in the face of whatever error caused the 

reload models module in manage.py shell

2009-02-25 Thread RustedInSeattle

Hi,
   Is there anyway I can reload my models in manage.py shell to pick
up changes made to them? I have tried reload(), it returns without
error however it doesn't pick up the updated source file. so now I
have to restart the shell. and I have to do bunch of imports and other
things to get to where I was.
   any way I can reload without restarting shell? thanks!

-Rusted.

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



reload models module in manage.py shell

2009-02-25 Thread RustedInSeattle

Hi,
   Is there anyway I can reload my models in manage.py shell to pick
up changes made to them? I have tried reload(), it returns without
error however it doesn't pick up the updated source file. so now I
have to restart the shell. and I have to do bunch of imports and other
things to get to where I was.
   any way I can reload without restarting shell? thanks!

-Rusted.

--~--~-~--~~~---~--~~
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: avoiding a save when the form contains no new data

2009-02-25 Thread Margie

Hi Alex,

Thanks for your reply.  Yes, I had found and experimented with both
has_changed() and changed_data(), but I found that they don't deal as
I'd like with my case where my form contains fields that are not in
the model.   IE, using the Book example, if I have

model Book(models.Model):
  name = models.CharField()

model Author(models.Model)
  books =  models.ManyToManyField(Book)

If I create a BookForm that is like this, that allows the user to put
in the authors:

class BookForm(forms.ModelForm)
authors = forms.CharField(widget=forms.Textarea,  help_text="space
separated list of authors")

class Meta:
model=Book

I find that changed_data() always returns 'authors' and has_changed is
always True.  I will take a look at the source a bit more.

Margie





On Feb 25, 4:59 pm, Alex Gaynor  wrote:
> On Wed, Feb 25, 2009 at 7:55 PM, Margie  wrote:
>
> > Say I create a form that reflects the current state of an object.  The
> > user can edit that form, and when they click 'save', I get back the
> > new, possibly edited, values via the POST.  In my POST code I do
> > something like this:
>
> > postDict = request.POST.copy()
> > bookForm = BookForm(postDict, instance=bookObj)
> > if bookForm.is_valid()
> >  bookForm.save()
>
> > What do folks typically do to avoid saving the data if nothing has
> > been modified in the form?  Is there any django functionality for
> > doing this, or do I just write the manual check that compares the
> > fields in the form to the fields in the existing object?
>
> > I'm not only concerned with the database access.  In addition to
> > avoiding the save, I'd like to emit a message to the user that
> > reflects what they've done, or not done.  IE, "book foo updated' or
> > "book foo unchanged".
>
> > Anyway, just curious if others have encountered this.
>
> > Margie
>
> > Form's have a method "has_changed" which says whether or not there is
>
> changed data, this should do just what you expect.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: checking if db is empty

2009-02-25 Thread Jacob Kaplan-Moss

On Wed, Feb 25, 2009 at 5:23 PM, Russell Keith-Magee
 wrote:
> There isn't a simple 'is_my_database_empty' command that returns
> true/false.

Actually, "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public'"
does pretty well. But Russ is right that this isn't the type of
question Django's going to help you answer; I'm just being pedantic
here :)

Jacob

--~--~-~--~~~---~--~~
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: Anybody had any problems increasing the length of a varchar field in PostgreSQL?

2009-02-25 Thread Jacob Kaplan-Moss

On Wed, Feb 25, 2009 at 5:16 PM, bobhaugen  wrote:
> This is probably something that lots of people do all the time, but
> this will be my first such change on a production Django + PostgreSQL
> installation, so I thought I'd ask.

For the record, it works fine.

However, you really shouldn't be making this sort of change on a
production database without testing it on a development/staging
environment first. That's why people make those sorts of
pre-production systems, in fact; if you've not got one you'll be stuck
trusting strangers on mailing lists :)

Jacob

--~--~-~--~~~---~--~~
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: Modifying the default admin edit page for Sites

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 9:03 PM, jeff  wrote:

>
> Is there a good way to modify what fields are displayed on the edit
> page for a site (from django.contrib.sites)? I want to have the page
> include inline editing for a model that has a ForeignKey to Sites.
>
> Is there a way to change the django.contrib.admin.ModelAdmin class for
> the Site model? Do I have to dig in and start modifying the admin
> templates? It seems like there ought to be a simpler way to do this.
>
> Any guidance would be much appreciated. Thanks!
>
> >
>
Sure, just import the old model admin, use admin.site.unregister(Site) to
remove the old one, create you're own subclass of the current one and
register it like normal, presto!

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Modifying the default admin edit page for Sites

2009-02-25 Thread jeff

Is there a good way to modify what fields are displayed on the edit
page for a site (from django.contrib.sites)? I want to have the page
include inline editing for a model that has a ForeignKey to Sites.

Is there a way to change the django.contrib.admin.ModelAdmin class for
the Site model? Do I have to dig in and start modifying the admin
templates? It seems like there ought to be a simpler way to do this.

Any guidance would be much appreciated. Thanks!

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



Can a custom profile reference User's 'first_name' and 'last_name' attrs?

2009-02-25 Thread Stephen Waterbury

I'm using django-registration and django-profiles, and I've
created an app-specific profile and subclassed RegistrationForm
to populate various profile fields during the registration process.

The User class has attributes 'first_name' and 'last_name' that
I'd like to access from my customized profile (DRY! :) -- and
I'd also like to populate them during registration.

In my profile class, I defined 'first_name' and 'last_name'
as properties that point to profile.user.first_name
and profile.user.last_name using getters and setters (of course),
and in my custom RegistrationForm I defined a 'save()' function
that attempts to populate them, but the two things I have tried
have not worked (which is rather baffling to me!):

(1) set them directly on the new_user obtained from
 create_inactive_user()

(2) after the new_user is set as my new_profile's 'user' attr,
 set them on new_profile (which should propagate their values
 to new_user via the property's setters ...)

Any suggestions on a way to do this?

(I could always ignore those attrs of User and just give my
profile its own first_name and last_name -- somewhat ugly, but
I'll do it if there's no other way.)

Thanks!
Steve


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



Model and Validation Confusion - Looking for advice.

2009-02-25 Thread Ty

I'm new to Python and Django, and I'd like some advice on how to
layout the code I'd like to write.

I have the model written that allows a file to be uploaded. In the
models save method I'm checking if the file has a specific extension.
If it has an XML extension I'm opening the file and grabbing some
information from the file to save in the database. I have this model
working. I've tested it in the built-in administration. It works.

Currently when there's an error (it's not an XML file; the file can't
be opened; a specific attribute doesn't exist) I'm throwing an custom
"Exception" error. What I *would* like to do is some how pass these
"Exception" error messages to the view (whether that's a custom view
or the built-in administration view) and have an error message
displayed like if the forms library was being used. Is that possible?

I'm starting to think I'm going to have to write the validation checks
again using the forms library. If that's the case, is it possible to
still use the built-in administration template, but extend the form it
uses to add these custom validations?

Anything to help my confusion would be appreciated.
--~--~-~--~~~---~--~~
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: Versioning/revisioning content (a la Mediawiki)

2009-02-25 Thread Kevin Teague



On Feb 25, 3:33 pm, Horst Gutmann  wrote:
> Or you could leave the versioning to dedicated tools like bzr and git
> and use django-rcsfield :-)
>
> http://code.google.com/p/django-rcsfield/
>

I'm not sure what you gain from using a VCS for storing versions?
They're designed for a pretty different use-case than supporting a web
application. You'll lose transactional integrity. Performance of many
operations will be sluggish (which is why tools like Fisheye copy much
of data into a relational database so that it can take advantage of
indexes and data views cached for performance). And I'm not sure, but
since DVCS is designed such that each user has their own copy of the
repo, how well do they handle concurrent operations?

If you have a hook to intercept the save, won't this conflict with
creating a new revision when attempting to revert to a previous
revision? I would just use a separate Model for storing revisions.
Something along the lines of this project looks pretty good:

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



--~--~-~--~~~---~--~~
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: avoiding a save when the form contains no new data

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 7:55 PM, Margie  wrote:

>
> Say I create a form that reflects the current state of an object.  The
> user can edit that form, and when they click 'save', I get back the
> new, possibly edited, values via the POST.  In my POST code I do
> something like this:
>
> postDict = request.POST.copy()
> bookForm = BookForm(postDict, instance=bookObj)
> if bookForm.is_valid()
>  bookForm.save()
>
> What do folks typically do to avoid saving the data if nothing has
> been modified in the form?  Is there any django functionality for
> doing this, or do I just write the manual check that compares the
> fields in the form to the fields in the existing object?
>
> I'm not only concerned with the database access.  In addition to
> avoiding the save, I'd like to emit a message to the user that
> reflects what they've done, or not done.  IE, "book foo updated' or
> "book foo unchanged".
>
> Anyway, just curious if others have encountered this.
>
> Margie
> >
> Form's have a method "has_changed" which says whether or not there is
changed data, this should do just what you expect.

Alex


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



avoiding a save when the form contains no new data

2009-02-25 Thread Margie

Say I create a form that reflects the current state of an object.  The
user can edit that form, and when they click 'save', I get back the
new, possibly edited, values via the POST.  In my POST code I do
something like this:

postDict = request.POST.copy()
bookForm = BookForm(postDict, instance=bookObj)
if bookForm.is_valid()
  bookForm.save()

What do folks typically do to avoid saving the data if nothing has
been modified in the form?  Is there any django functionality for
doing this, or do I just write the manual check that compares the
fields in the form to the fields in the existing object?

I'm not only concerned with the database access.  In addition to
avoiding the save, I'd like to emit a message to the user that
reflects what they've done, or not done.  IE, "book foo updated' or
"book foo unchanged".

Anyway, just curious if others have encountered this.

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



Eager Fetching

2009-02-25 Thread saxon75

I'm having an issue where my templates are taking a really long time
to load, and it looks like the problem is that a lot of database calls
are made inside the template.  This seems like it would be easy enough
to fix, but I have kind of an odd setup with my model relationships
that seems to be adding extra complexity.

The application is more or less a blog with multiple types of posts--
articles, book reviews, etc.  Each of the post-type models is
subclassed from a base model called Node.  The base class contains the
fields for things like the node title, author, creation date, and
comment FKs, where the subclass contains the fields for things
specific to the post type--body text, external URLs, start and end
dates, etc.  Additionally, I'm using the django-tagging app, with the
tagging fields being located in the Node class.  However, because of
the way that the tagging app works, the M2M relationships seem to be
formed with the subclass instance rather than the base class instance.

Let's make this a bit more concrete:

class Node(models.Model):
  author = models.ForeignKey(User)
  created = models.DateTimeField()
  published = models.BooleanField()
  promoted = models.BooleanField()
  section = models.ForeignKey(Section)
  archetype = models.ForeignKey(Archetype)
  title = models.CharField(max_length=255)
  slug = models.SlugField(max_length=25)
  comments_enabled = models.BooleanField()
  tag_list = models.CharField(max_length=255)

  def _get_tags(self):
return Tag.objects.get_for_object(self)

  def _set_tags(self, tag_list):
Tag.objects.update_tags(self, tag_list)

  tags = property(_get_tags, _set_tags)

  def get_absolute_url(self):
return ('sake.node.views.node_detail', (), {
'sect': self.section.keyword,
'yr': self.created.year,
'mo': self.created.strftime('%m'),
'slg': self.slug})
  get_absolute_url = models.permalink(get_absolute_url)

  def save(self):
self.archetype = Archetype.objects.get(classname=type
(self).__name__)
if len(self.slug) == 0:
  self.slug = re.sub('\W', slugrepl, self.title.lower().strip())[:
25]
super(Node,self).save()
self.tags = self.tag_list

  def _comment_count(self):
return self.comment_set.count()

  comment_count = property(_comment_count)

class Article(Node):
  body = models.TextField()

A typical view returns all of the nodes within a given section:

def node_section_all(request, sect):
  try:
objects = Node.objects.filter(section__keyword=sect,
published=True).order_by('-created')
  except:
return render_to_response('doesntexist.html', {'identifier':
'node'}, context_instance=RequestContext(request))
  if len(objects) == 0:
return render_to_response('doesntexist.html', {'identifier':
'node'}, context_instance=RequestContext(request))
  return list_detail.object_list(
  request,
  queryset = Node.objects.filter(section__keyword=sect,
published=True).order_by('-created'),
  template_name = 'node/section_list.html',
  allow_empty = True,
  paginate_by = 10,
  )

The main template calls a custom template tag in order to figure out
what type of node is being rendered and pulls the appropriate template
for that subclass:

{% extends "base.html" %}
{% load tags %}

{% block content %}
{% for node in object_list %}
{% render_node node user %}
{% endfor %}
{%comment%}{% pager 9 %}{%endcomment%}
{% endblock %}

Where render_node looks like this:

def render_node(node, user):
  from django.contrib.contenttypes.models import ContentType
  c = ContentType.objects.get(model = node.archetype.classname.lower
())
  template_name = c.app_label + '/' + node.archetype.classname.lower()
+ '_detail.html'
  edit = False
  if user.is_authenticated():
if user.is_superuser or user.groups.filter
(name=node.section.keyword).count():
  edit = True
  return render_to_string(template_name, {'node': node, 'user': user,
'edit': edit})

register.simple_tag(render_node)

And in the case of the Article subclass, this is the template used to
render each node:


  {{ node.title }}
  
{{ node.article.body|safe }}
  
  
Posted on {{ node.created|date:"F j, Y" }} by {% if
node.author.get_profile %}
{{ node.author.get_profile.display_name }}{% else %}
{{ node.author.username }}{% endif %} in 
{{ node.section.section }}{% if node.article.tags %} ({% for tag
in node.article.tags %}{% if forloop.last %}{{ tag }}{% else %}{{ tag }}, {% endif %}{% endfor %}){% endif %}. | Permalink | {{ node.comment_count }}
comment{% ifnotequal node.comment_count 1%}s{% endifnotequal %}{%
if edit %} | Edit | Delete{% endif %}
  


As you can see, just about everything displayed needs to reference an
FK in the end template, and then this is iterated many times over the
entire set of nodes.  One easy thing I can do is add select_related()
to the queryset in the view, and that does help some.  But things are
still quite slow, taking 4 to 6 seconds to render the template.

The culprits seem to 

Re: Versioning/revisioning content (a la Mediawiki)

2009-02-25 Thread Horst Gutmann

Or you could leave the versioning to dedicated tools like bzr and git
and use django-rcsfield :-)

http://code.google.com/p/django-rcsfield/

-- Horst

On Thu, Feb 26, 2009 at 12:29 AM, Scott Newman  wrote:
> I'm creating an app similar to the flatpages contribution that will
> store the simple content for a page. When I save the data, I'd like to
> automatically create a previous revision so it can be reverted back if
> necessary. (multiple admins will be editing content) Does anyone have
> a strategy they like for pulling this off? The customer requested this
> feature in response to the way Mediawiki can save previous versions of
> content.
>
> I was thinking of using some kind of hook to intercept the save and
> create a new object with a unique timestamp or possibly flag it as
> "latest". I'm probably going to have to create a custom admin page to
> keep the previous revisions hidden from the change list and also offer
> a way to revert to previous versions from within the admin page.
>
> If anyone has suggestions, I'd love to hear them.
>
> Thanks!
>
> -- Scott
>
> >
>

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



Versioning/revisioning content (a la Mediawiki)

2009-02-25 Thread Scott Newman

I'm creating an app similar to the flatpages contribution that will
store the simple content for a page. When I save the data, I'd like to
automatically create a previous revision so it can be reverted back if
necessary. (multiple admins will be editing content) Does anyone have
a strategy they like for pulling this off? The customer requested this
feature in response to the way Mediawiki can save previous versions of
content.

I was thinking of using some kind of hook to intercept the save and
create a new object with a unique timestamp or possibly flag it as
"latest". I'm probably going to have to create a custom admin page to
keep the previous revisions hidden from the change list and also offer
a way to revert to previous versions from within the admin page.

If anyone has suggestions, I'd love to hear them.

Thanks!

-- Scott

--~--~-~--~~~---~--~~
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: checking if db is empty

2009-02-25 Thread Russell Keith-Magee

On Thu, Feb 26, 2009 at 4:24 AM, knight  wrote:
>
> Hi,
>
> I'm using postgres database in my Django application.
> Is there a way to check if the database is empty from my models.py? (I
> mean before the first syncdb)

There isn't a simple 'is_my_database_empty' command that returns
true/false. However, inspect_db will try to produce Django models for
any existing tables in a database. If inspectdb doesn't produce any
models, then your database is probably empty.

The other way is to use the postgres prompt; running \dp at a postgres
prompt will show you all the tables that are in your database. That
will give you some indication of what models (if any) have already
been synchronized.

Yours,
Russ Magee %-)

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



Anybody had any problems increasing the length of a varchar field in PostgreSQL?

2009-02-25 Thread bobhaugen

This is on a populated production database.  Want to increase a
models.CharField from max_length=128 to 255.

This is probably something that lots of people do all the time, but
this will be my first such change on a production Django + PostgreSQL
installation, so I thought I'd ask.
--~--~-~--~~~---~--~~
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: Fwd: python sql query in django

2009-02-25 Thread Briel

You have two choices. Either you can add .exclude() using the __in to
avoid get the duplicates in the first place. Or you could iterate over
the 3 pubs and append them to a list with an if statement. Something
like this:
list = []
for pub in publications123:
If pub not in list:
list.append(pub)

On 25 Feb., 21:54, Jesse  wrote:
> > I believe this would work:
>
> > publications = Publication.objects.filter(techpubcombo__technology=t)
>
> > Regards,
>
> > --
> > Christian Joergensenhttp://www.technobabble.dk
>
> Hello Christian,
>
> Thank you so much for your answer.  I have been struggling with the
> users group to get that syntax (I must not have been explaining it
> well enough).  Now I need the syntax for the next step, which I'm
> hoping you can help with.
>
> I have three statements:
> publications = Publication.objects.filter(techpubcombo__technology=t)
> publications2 = Publication.objects.filter(pathpubcombo__pathology=p)
> publications3 = Publication.objects.filter(commpubcombo__commodity=c)
>
> I need to combine the three sets into one set to eliminate duplication
> in the publications and then output the final set to the template.
>
> Thanks for any help!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Model-specific admin templatetag template OR admin list multi-sort

2009-02-25 Thread Chris Czub

I am trying to customize the list view of one of my models in the
admin to separate it into a few different tables for organization
purposes.

My model is an "order". The important fields for this problem are the
user who placed the order, the date is was placed, the restaurant it
was for, and the item at that restaurant they ordered.

I have the date filtering set up with date_hierarchy so that's all
okay, but what people would really like to be able to do is sort by
restaurant THEN by items within that restaurant.

Is that possible with the current admin?

If not, what I'd like to do is break this out into a series of
different tables, one for each restaurant. Then you'd be able to sort
by item within those tables.

I looked at:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates
which says you can override admin templates on a per model basis, and
I was able to do so for my change_list.html template, however I can't
do it for the change_list_results.html template which is referenced by
the results_list templatetag and handles the actual table output.

In order to accomplish this, would I need to define a new custom
templatetag and call it from the custom change_list.html template?

Is there an easier way to do what I want?

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



list_display_links wont accept a callable

2009-02-25 Thread Jay

Hey Guys:

Wondering if I can get some advice/help.

I'm trying to alter the admin in a simple way so that instead of the
first column (by default) be linked to the change screen I want to
create a callable property and use that as the change screen link.

Here is my code:

class SubmissionAdmin(admin.ModelAdmin):
list_display = ('full_name', 'message', 'submit_ip', 'edit')
list_display_links = ('edit',)

def full_name(self, obj):
return ('%s %s' % (obj.first_name, obj.last_name))
full_name.short_description = 'Name'

def edit(self, obj):
return('Edit')
edit.short_description = 'Edit'

def save_model(self, request, obj, form, change):
obj.submit_ip = request.META['REMOTE_ADDR']
obj.save()

I have a callable that just returns a string 'Edit' that I want to use
as the link in the admin.  But django apparently wont let me do this
with 'list_display_links' even though it does let you do it with
'list_display'

I know I could probably create this in the model itself, but that
seems unintuitive to me since all I'm trying to do is alter the admin
display.

Thoughts?

--~--~-~--~~~---~--~~
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: Passing argument to Model.save via ModelForm

2009-02-25 Thread bretro...@gmail.com

Thanks, again.

def save_model(self, request, obj, form, change):
obj.save(request.user.username)

did the trick.  i should've found that in the docs myself.


On Feb 25, 3:58 pm, Alex Gaynor  wrote:
> On Wed, Feb 25, 2009 at 3:56 PM, bretro...@gmail.com 
> wrote:
>
>
>
>
>
> > This is working fine in my custom interface, but the admin is broken
> > now since it is not passing the argument to the save() function.
>
> > On Feb 23, 5:56 pm, "bretro...@gmail.com"  wrote:
> > > Perfect. Thanks!
>
> > > On Feb 23, 5:51 pm, Alex Gaynor  wrote:
>
> > > > On Mon, Feb 23, 2009 at 5:40 PM, bretro...@gmail.com <
> > bretro...@gmail.com>wrote:
>
> > > > > Hello,
>
> > > > > I'd like to send an email when a Model is saved via it's ModelForm.
> > > > > I'm aware that I can override thesavefunctionof the model, then
> > > > > call it's super but I was wondering how topassrequest.user.username
> > > > > to the Model'ssavefunction.  Or if someone has a better suggestion
> > > > > I'd be willing to use it.
>
> > > > > -Bret
>
> > > > The easiest way would just to do:
>
> > > > defsave(self, username):
> > > >     obj = call super with commit = false
> > > >     obj.save(username)
> > > >     return obj
>
> > > > Just add this method to the ModelForm and you're golden.
>
> > > > Alex
>
> > > > --
> > > > "I disapprove of what you say, but I will defend to the death your
> > right to
> > > > say it." --Voltaire
> > > > "The people's good is the highest law."--Cicero
>
> Perhaps this hook could be of 
> assistance:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-model-se...
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: Incompatibility with FreeTDS/ODBC and Unicode on a MSSQL server?

2009-02-25 Thread kgingeri

Ok, I figured this out myself...

I had to un-install all pre-installed odbc stuff - unixODBC (possibly
iODBC as well, except it didn't seem to actually uninstall completely)
and FreeTDS.

I then got source and did configure/make/make installs of unixODBC
first, then FreeTDS.
This order is important so that the ./configure command can find all
the right stuff.
An important note is the params for the FreeTDS ./configure command.
I used the following:

$ ./configure --with-unixodbc=/usr/local  --enable-msdblib --disable-
libiconv --with-tdsver=8.0

Anyway, it's working now without complaint!

:v)




--~--~-~--~~~---~--~~
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: Passing argument to Model.save via ModelForm

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 3:56 PM, bretro...@gmail.com wrote:

>
> This is working fine in my custom interface, but the admin is broken
> now since it is not passing the argument to the save() function.
>
> On Feb 23, 5:56 pm, "bretro...@gmail.com"  wrote:
> > Perfect. Thanks!
> >
> > On Feb 23, 5:51 pm, Alex Gaynor  wrote:
> >
> > > On Mon, Feb 23, 2009 at 5:40 PM, bretro...@gmail.com <
> bretro...@gmail.com>wrote:
> >
> > > > Hello,
> >
> > > > I'd like to send an email when a Model is saved via it's ModelForm.
> > > > I'm aware that I can override thesavefunctionof the model, then
> > > > call it's super but I was wondering how topassrequest.user.username
> > > > to the Model'ssavefunction.  Or if someone has a better suggestion
> > > > I'd be willing to use it.
> >
> > > > -Bret
> >
> > > The easiest way would just to do:
> >
> > > defsave(self, username):
> > > obj = call super with commit = false
> > > obj.save(username)
> > > return obj
> >
> > > Just add this method to the ModelForm and you're golden.
> >
> > > Alex
> >
> > > --
> > > "I disapprove of what you say, but I will defend to the death your
> right to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
> >
>
Perhaps this hook could be of assistance:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-model-self-request-obj-form-change

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Passing argument to Model.save via ModelForm

2009-02-25 Thread bretro...@gmail.com

This is working fine in my custom interface, but the admin is broken
now since it is not passing the argument to the save() function.

On Feb 23, 5:56 pm, "bretro...@gmail.com"  wrote:
> Perfect. Thanks!
>
> On Feb 23, 5:51 pm, Alex Gaynor  wrote:
>
> > On Mon, Feb 23, 2009 at 5:40 PM, bretro...@gmail.com 
> > wrote:
>
> > > Hello,
>
> > > I'd like to send an email when a Model is saved via it's ModelForm.
> > > I'm aware that I can override thesavefunctionof the model, then
> > > call it's super but I was wondering how topassrequest.user.username
> > > to the Model'ssavefunction.  Or if someone has a better suggestion
> > > I'd be willing to use it.
>
> > > -Bret
>
> > The easiest way would just to do:
>
> > defsave(self, username):
> >     obj = call super with commit = false
> >     obj.save(username)
> >     return obj
>
> > Just add this method to the ModelForm and you're golden.
>
> > Alex
>
> > --
> > "I disapprove of what you say, but I will defend to the death your right to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: Fwd: python sql query in django

2009-02-25 Thread Jesse

> I believe this would work:
>
> publications = Publication.objects.filter(techpubcombo__technology=t)
>
> Regards,
>
> --
> Christian Joergensenhttp://www.technobabble.dk

Hello Christian,

Thank you so much for your answer.  I have been struggling with the
users group to get that syntax (I must not have been explaining it
well enough).  Now I need the syntax for the next step, which I'm
hoping you can help with.

I have three statements:
publications = Publication.objects.filter(techpubcombo__technology=t)
publications2 = Publication.objects.filter(pathpubcombo__pathology=p)
publications3 = Publication.objects.filter(commpubcombo__commodity=c)

I need to combine the three sets into one set to eliminate duplication
in the publications and then output the final set to the template.

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



template ifequal substitution of value

2009-02-25 Thread Jesse

I have two date fields:  startdt and enddt.  The template code that
works is:

{% ifequal  items.startdt  items.enddt %}

this says startdt and enddt are the same (as seen in the template)

   {% endifequal %}

In  postgres I have a date value in the startdt and enddt fields
stored like this:  1999-01-08, which appears as Jan 08, 1999 in the
template.

I would like the Jan 08, 1999 value to appear as blank or nothing in
the template.  I tried this:

{% ifequal  items.startdt  "1999-01-08" %}

   (this space should show nothing) (as not seen in the template)

   {% endifequal %}

I get no error, but I also get no action for this syntax, either.

Any help would be appreciated.

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



finally found Free Django Hosting

2009-02-25 Thread xankya

I finally got django hosted on free. Thanks to joyent.us, google,
google-groups and joyent community. Being a newbie, I am too happy to
have come so far. I gotta go much farther.
For those who wanna check: http://dac402c1.fb.joyent.us

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



Databrowse pagination

2009-02-25 Thread saeb

My admin webpage gets stuck and often fails on large database when I
use Databrowse. I think it needs pagination,  is there a way to get
around this?  I really like the Databrowse feature as a read-only
tool, it would be great if someone helps me out in this issue.

Thanks,
saeb
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



checking if db is empty

2009-02-25 Thread knight

Hi,

I'm using postgres database in my Django application.
Is there a way to check if the database is empty from my models.py? (I
mean before the first syncdb)

Thanks, Arshavski Alexander.
--~--~-~--~~~---~--~~
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: optional parameter url

2009-02-25 Thread Raffaele Salmaso

Adonis wrote:
> (r'^appname/mainpage/(?P.*)$', 'django.views.static.serve',
> {'document_root': '/mesa'}),
this takes *everything* as 'path'
> (r'^appname/mainpage/(?P\d+)/(?P.*)$',
> 'django.views.static.serve', {'document_root': '/mesa'}),
this takes only digits as 'xexe', but it never get called because it
cames after .*

swap them as
(r'^appname/mainpage/(?P\d+)/(?P.*)$',
 'django.views.static.serve', {'document_root': '/mesa'}),
(r'^appname/mainpage/(?P.*)$', 'django.views.static.serve',
 {'document_root': '/mesa'}),

-- 
()_() | That said, I didn't actually _test_ my patch.  | +
(o.o) | That's what users are for! | +---+
'm m' |   (Linus Torvalds) |  O  |
(___) |  raffaele at salmaso punto org |

--~--~-~--~~~---~--~~
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: linking to files from database

2009-02-25 Thread Tonu Mikk

Alex Gaynor wrote:
>
>
> On Tue, Feb 24, 2009 at 10:41 AM, Daniel Roseman 
> > 
> wrote:
>
>
> On Feb 24, 2:36 pm, Tonu Mikk  > wrote:
>
> > Then I save it with the above method.  The problem I am running
> into, is that when saving the file, it gives is a different name
> which is the original name with an
> > "_" at the end.  The link in the database also points to the
> file with this new name.  How can I simply create a link in the
> database to the original file?
>
>
> Use a FilePathField rather than a FileField. This just takes a path,
> rather than a file object. See:
> http://docs.djangoproject.com/en/dev/ref/models/fields/#filepathfield
> --
> DR.
>
>
> If you want to reference an existing file what you want to do is just
> obj.file_field = "file/location.txt"
>
> That just assigns the location(the field will act like a file when you 
> try to actually access it).
>
I see, this allows me to upload files using the web interface and still 
create links to existing files in the database.

Thank you,
Tonu


--~--~-~--~~~---~--~~
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: Searching a list of Q

2009-02-25 Thread Kevin Audleman

Ah, gotcha.

Maybe django should include a iin function =)

Kevin

On Feb 25, 10:37 am, Alex Gaynor  wrote:
> On Wed, Feb 25, 2009 at 1:34 PM, Kevin Audleman 
> wrote:
>
>
>
>
>
> > What about the following?
>
> > qset = Q(author__in=[u"Foo", u"Bar"])
>
> > Kevin
>
> > On Feb 25, 10:03 am, Peter Bengtsson  wrote:
> > > This works:
>
> > >  >>> from django.db.models import Q
> > >  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
> > >  >>> Books.objects.filter(qset)
>
> > > But what if the list of things I want to search against is a list.
> > > E.g.
>
> > >  >>> possible_authors = [u"Foo", u"Bar"]
>
> > > ???
>
> > > I have a solution but it's very ugly and feels "clunky":
>
> > >  qset = None
> > >  for each in [u"Foo", u"Bar"]:
> > >      if qset is None:
> > >          qset = Q(author__iexact=each)
> > >      else:
> > >          qset = qset | Q(author__iexact=each)
>
> Kevin, the way IN works at the SQL level basically means that it will be
> doing an exact match against each item, which isn't what he wants, he wants
> an iexact match.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: Searching a list of Q

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 1:34 PM, Kevin Audleman wrote:

>
> What about the following?
>
> qset = Q(author__in=[u"Foo", u"Bar"])
>
>
> Kevin
>
> On Feb 25, 10:03 am, Peter Bengtsson  wrote:
> > This works:
> >
> >  >>> from django.db.models import Q
> >  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
> >  >>> Books.objects.filter(qset)
> >
> > But what if the list of things I want to search against is a list.
> > E.g.
> >
> >  >>> possible_authors = [u"Foo", u"Bar"]
> >
> > ???
> >
> > I have a solution but it's very ugly and feels "clunky":
> >
> >  qset = None
> >  for each in [u"Foo", u"Bar"]:
> >  if qset is None:
> >  qset = Q(author__iexact=each)
> >  else:
> >  qset = qset | Q(author__iexact=each)
> >
>
Kevin, the way IN works at the SQL level basically means that it will be
doing an exact match against each item, which isn't what he wants, he wants
an iexact match.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Fwd: Re: Admin/Application Integration and Automatic Actions

2009-02-25 Thread Paul Waldo


> On Feb 25, 2:41 pm, Paul Waldo p...@waldoware.com> wrote:
>   
>> Hi all,
>>
>> I am brand new to Django, so forgive me if my questions are naive :-)
>>
>> I have read the tutorials and I'm starting my first learning
>> application.  This is a small time-tracking application.  As you can
>> imagine, the majority of the application is basic CRUD data entry.  The
>> other significant part is that I want to automatically create reports on
>> a regular basis and email them.  I have two questions:
>>
>> * The Admin application is great for my CRUD functionality; Django does
>> a really fine job of creating this interface automatically.  
>> Unfortunately, using the Admin app. for data entry does not provide a
>> seamless experience; the URLs are different, the look and feel is
>> different, and the Admin is much more polished than my hand-crafted
>> pages :-).  Do people use the Admin for regular users, or do they
>> duplicate all that CRUD in their own pages?  Is there a way to make the
>> Application/Admin more seamless?
>> 
>
> There are various options, depending on what sort of users you are
> catering for:
> * Extend the admin using the built-in hooks, eg using a custom form
> for your model. Django renders this in exactly the same way as any
> other admin form.
> * Write your own views but inherit from the admin templates, to get
> their look and feel. This is good if you have trusted users, but need
> a bit more functionality than the admin can provide.
> * Use the CRUD generic views. Best for regular users.
>
>   
>> * Is there a standard model for running automated tasks?  I was thinking
>> about a cron task that uses lynx or curl to call a URL that performs the
>> task, but that gets kind of ugly.  Is there a better way to do this?
>> 
>
> Ugly is right. Use cron by all means, but don't run the process via
> the webserver. Instead, create a custom manage.py command within your
> app, and get cron to call that. See the (unfortunately very basic)
> documentation here:
> http://docs.djangoproject.com/en/dev/howto/custom-management-commands/
>
> --
> DR.
>   
Excellent ideas, Daniel.  I'm going to try extending the admin forms, 
and I'll try the manage.py command.  Thanks!

Paul

--~--~-~--~~~---~--~~
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: Searching a list of Q

2009-02-25 Thread Kevin Audleman

What about the following?

qset = Q(author__in=[u"Foo", u"Bar"])


Kevin

On Feb 25, 10:03 am, Peter Bengtsson  wrote:
> This works:
>
>  >>> from django.db.models import Q
>  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
>  >>> Books.objects.filter(qset)
>
> But what if the list of things I want to search against is a list.
> E.g.
>
>  >>> possible_authors = [u"Foo", u"Bar"]
>
> ???
>
> I have a solution but it's very ugly and feels "clunky":
>
>  qset = None
>  for each in [u"Foo", u"Bar"]:
>      if qset is None:
>          qset = Q(author__iexact=each)
>      else:
>          qset = qset | Q(author__iexact=each)
--~--~-~--~~~---~--~~
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: optional parameter url

2009-02-25 Thread Kevin Audleman

I think you're missing the trailing slash in your URL's. Should be:

(r'^appname/mainpage/(?P.*)/$', 'django.views.static.serve',
 {'document_root': '/mesa'}),
(r'^appname/mainpage/(?P\d+)/(?P.*)/$',
 'django.views.static.serve', {'document_root': '/mesa'}),

Mind you, I don't know if this will fix anything...

Kevin


On Feb 25, 4:26 am, Adonis  wrote:
> Hello,
> I am having some trouble serving static files when i try to pass an
> optional parameter.
> For url: appname.mainpage/, the static files work fine
> For url: appname.mainpage/10/, the static files are not read.
>
> **
> url.py
>
> (r'^appname/mainpage/(?P.*)$', 'django.views.static.serve',
> {'document_root': '/mesa'}),
> (r'^appname/mainpage/(?P\d+)/(?P.*)$',
> 'django.views.static.serve', {'document_root': '/mesa'}),
>
> views.py
>
> def mainpage(request, xexe=0):
>     print "optional parameter: ", xexe
>     return render_to_response('mesa/blah.html', {...some args...})
> **
>
> Any suggestions my respectful django users?
--~--~-~--~~~---~--~~
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: Searching a list of Q

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 1:03 PM, Peter Bengtsson  wrote:

>
> This works:
>
>  >>> from django.db.models import Q
>  >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
>  >>> Books.objects.filter(qset)
>
> But what if the list of things I want to search against is a list.
> E.g.
>
>  >>> possible_authors = [u"Foo", u"Bar"]
>
> ???
>
>
> I have a solution but it's very ugly and feels "clunky":
>
>  qset = None
>  for each in [u"Foo", u"Bar"]:
> if qset is None:
> qset = Q(author__iexact=each)
> else:
> qset = qset | Q(author__iexact=each)
>
>
> >
>
You can clean it up slightly, but that strategy is basically what you want
to do:
qset = Q()
for term in ['foo', 'bar']:
qset |= Q(author__iexact=term)

alternatively if you're a funcitonal kind of guy:
import operator
qset=reduce(operator.or_, [Q(author__iexact=term) for term in ['foo',
'bar']])

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Searching a list of Q

2009-02-25 Thread Peter Bengtsson

This works:

 >>> from django.db.models import Q
 >>> qset = Q(author__iexact=u"Foo") | Q(author__iexact=u"Bar")
 >>> Books.objects.filter(qset)

But what if the list of things I want to search against is a list.
E.g.

 >>> possible_authors = [u"Foo", u"Bar"]

???


I have a solution but it's very ugly and feels "clunky":

 qset = None
 for each in [u"Foo", u"Bar"]:
 if qset is None:
 qset = Q(author__iexact=each)
 else:
 qset = qset | Q(author__iexact=each)


--~--~-~--~~~---~--~~
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: Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 12:52 PM, NoviceSortOf wrote:

>
> Briel, I see the userfriendlyness or even consideration in what
> you are saying, looking at the specs, actually users
> checkboxing us their interests is an optional part of
> registration process, we still we need to do it somehow.
>
> Gordy, I see the logic in what you are saying, although unclear
> on how to get the class Interest into a form, listing all of
> the rows as Boolean checkboxes, any hints on this appreciated.
>
>
> >
>
If you're using the standard django forms(which I hope you are :) ) it's
just a matter of using a MultipleModelChoiceField with a
CheckboxSelectMultiple widget, which does exactly what you want(assuming you
set it up as a many to many field).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: Admin/Application Integration and Automatic Actions

2009-02-25 Thread rajeesh

>
> > * Is there a standard model for running automated tasks?  I was thinking
> > about a cron task that uses lynx or curl to call a URL that performs the
> > task, but that gets kind of ugly.  Is there a better way to do this?
>
 What about the django-cron? Just check it out here:
http://code.google.com/p/django-cron/
--~--~-~--~~~---~--~~
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: Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread NoviceSortOf

Briel, I see the userfriendlyness or even consideration in what
you are saying, looking at the specs, actually users
checkboxing us their interests is an optional part of
registration process, we still we need to do it somehow.

Gordy, I see the logic in what you are saying, although unclear
on how to get the class Interest into a form, listing all of
the rows as Boolean checkboxes, any hints on this appreciated.


--~--~-~--~~~---~--~~
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: InlineModelAdmin objects question

2009-02-25 Thread Kevin Audleman

First of all, are you using the AUTH_PROFILE_MODULE methodology? See
the documentation here:
http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs#storing-additional-information-about-users

If you've defined a foreign key on your People model, I would guess
you're not. This is preferrable over rolling your own as django will
automatically populate request.user with the fields from your profile
module.

The previous response identifies how to get it to show up in the
admin. Namely, you overwrite the User object to display the related
record.

Cheers,
Kevin

On Feb 24, 5:12 pm, Kevin Coyner  wrote:
> I am using the Auth system in django and have a separate app People
> that I'm using to keep more detailed info (i.e. address, phone, etc)
> on my users. I presume from my docs reading that this is the best way.
>
> Question:   Can I use InlineModelAdmin to handle new user input from
> just onepage, preferably my People admin page?
>
> Here's what I've tried in people/admin.py:
>
> from django.contrib import admin
> from django.contrib.auth.models import User
> from local1042.people.models import People
>
> class PeopleInline(admin.TabularInline):
>     model = User
>
> class PeopleAdmin(admin.ModelAdmin):
>     search_fields = ['username__last_name']
>     inlines = [ PeopleInline ]
>
> admin.site.register(People, PeopleAdmin)
> 
>
> But when I try this I get:
>
>  has no ForeignKey to  'local1042.people.models.People'>
>
> But in people/models.py I have:
>
> from django.contrib.auth.models import User
> class People(models.Model):
>     username = models.OneToOneField(User, parent_link=False)
>     address = ... etc
> --
>
> Any pointers would be appreciated.  Thanks.
>
> --
> Kevin Coyner  GnuPG key: 1024D/8CE11941
--~--~-~--~~~---~--~~
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: Authenticating django users from Apache using cookies

2009-02-25 Thread Karantir

http://www.djangosnippets.org/snippets/62/
--~--~-~--~~~---~--~~
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: InlineModelAdmin objects question

2009-02-25 Thread Jamie Richard Wilson

This might answer your question:

http://groups.google.com/group/django-developers/browse_thread/thread/45bce29f331acb5e


Kevin Coyner wrote:
> I am using the Auth system in django and have a separate app People
> that I'm using to keep more detailed info (i.e. address, phone, etc)
> on my users. I presume from my docs reading that this is the best way.
>
> Question:   Can I use InlineModelAdmin to handle new user input from
> just onepage, preferably my People admin page?
>
>
> Here's what I've tried in people/admin.py:
>
> from django.contrib import admin
> from django.contrib.auth.models import User
> from local1042.people.models import People
>
> class PeopleInline(admin.TabularInline):
> model = User
>
> class PeopleAdmin(admin.ModelAdmin):
> search_fields = ['username__last_name']
> inlines = [ PeopleInline ]
>
> admin.site.register(People, PeopleAdmin)
> 
>
> But when I try this I get:
>
>  has no ForeignKey to  'local1042.people.models.People'>
>
>
> But in people/models.py I have:
>
> from django.contrib.auth.models import User
> class People(models.Model):
> username = models.OneToOneField(User, parent_link=False)
> address = ... etc
> --
>
> Any pointers would be appreciated.  Thanks.
>
>
>   

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



Admin interface for user management

2009-02-25 Thread Jamie Richard Wilson

I'm working on an online newsroom project and have a need to extend the
user profile beyond the included basics. I also need to grant
permissions to allow the online editorial staff to create new user
accounts to associate with new content if the account doesn't already
exist. In most cases there is no need for regular staff to login to the
site, but this could change in the future and I'm thinking it may be a
good idea to have those accounts in place from the beginning instead of
trying to create them later.

Right now, I have a UserProfile model that is linked to the built-in
User model for inline editing in the admin interface so that all of the
extended info can be added/edited along with the default userid, name,
password, etc.

The problem I am running into is that I don't want to give online
editorial staff the ability to grant "staff" or superuser access when
they create new accounts. If I use the built-in admin interface, this
seems inevitable. I can collapse those options so they aren't
immediately visible, but that just obscures the option a bit.

On the other hand, I could keep the built-in User model separate from
UserProfile and allow online staff to create UserProfiles for news staff
and only create accounts for those who absolutely need them. The problem
there is that if I need to create User accounts I will end up
duplicating information such as name, userid, etc. in a different table.

My questions are...

1. Is there a way to use the built-in Admin interface but restrict
granting superuser permissions?

2. Is there a way to create new User accounts by using UserProfile to
select existing userids and prepopulating the name and email address fields?

I imagine custom forms may allow me to do exactly what I need, but I
have no experience using them and want to make sure I can't do what I
need with the built-in Admin interface before moving into custom forms.
Thoughts?

--~--~-~--~~~---~--~~
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: Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread gordyt

You could try something like this (in models.py)

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Interest(models.Model):
label = models.CharField(max_length=64)
users = models.ManyToManyField(User, blank=True)
def __unicode__(self):
return unicode(self.label)

You can enable the admin interface for the Interest model so that the
list if interests can be easily updated without have to edit any
code.  You can generate the form that the users fill out
programmatically.

Given any Interest i, you will have i.users that represents all of the
Users who have indicated that interest applies to them.

Given any User u, u.interest_set will be the collection of all of the
Interests that they have.

--gordy
--~--~-~--~~~---~--~~
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: Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread NoviceSortOf


This is what we have been doing for over 10 years now via the
internet, and over 20 years via mail and telephone... its a management
requirement that will not change. The questions are broken into
sections easy to navigate on the page, the 'questions' in this
instance is simply having them check box their particular interests
which appear grouped to category. I'm curious if Django innately has a
way of dealing with such scenarios.


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



cache backend file: No need for cull

2009-02-25 Thread Thomas Guettler

Hi,

I profiled my application and discovered, that it spends
a lot of time in _cull() and get_num_entries() in the file
cache backend.

It is very easy to have a cron job which cleans the directory
by deleting all files older than N minutes. There is no need to cull during
request time.

I suggest that if you set max_entries to zero, _cull() is not called.

Before I open a ticket, I ask for feedback.

Anyone?

 Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: Search Professional Webdesign Company in Berlin (Germany)

2009-02-25 Thread rknobelspies

Should have put in the pointer to my own profile though:
http://djangopeople.net/reinhard/

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



Re: Admin/Application Integration and Automatic Actions

2009-02-25 Thread Daniel Roseman

On Feb 25, 2:41 pm, Paul Waldo  wrote:
> Hi all,
>
> I am brand new to Django, so forgive me if my questions are naive :-)
>
> I have read the tutorials and I'm starting my first learning
> application.  This is a small time-tracking application.  As you can
> imagine, the majority of the application is basic CRUD data entry.  The
> other significant part is that I want to automatically create reports on
> a regular basis and email them.  I have two questions:
>
> * The Admin application is great for my CRUD functionality; Django does
> a really fine job of creating this interface automatically.  
> Unfortunately, using the Admin app. for data entry does not provide a
> seamless experience; the URLs are different, the look and feel is
> different, and the Admin is much more polished than my hand-crafted
> pages :-).  Do people use the Admin for regular users, or do they
> duplicate all that CRUD in their own pages?  Is there a way to make the
> Application/Admin more seamless?

There are various options, depending on what sort of users you are
catering for:
* Extend the admin using the built-in hooks, eg using a custom form
for your model. Django renders this in exactly the same way as any
other admin form.
* Write your own views but inherit from the admin templates, to get
their look and feel. This is good if you have trusted users, but need
a bit more functionality than the admin can provide.
* Use the CRUD generic views. Best for regular users.

> * Is there a standard model for running automated tasks?  I was thinking
> about a cron task that uses lynx or curl to call a URL that performs the
> task, but that gets kind of ugly.  Is there a better way to do this?

Ugly is right. Use cron by all means, but don't run the process via
the webserver. Instead, create a custom manage.py command within your
app, and get cron to call that. See the (unfortunately very basic)
documentation here:
http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

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



Re: Search Professional Webdesign Company in Berlin (Germany)

2009-02-25 Thread rknobelspies

Yep!

we don´t push our django projects publicly yet because we want to
leave that for the relaunch of our then django-based site, but we are
happily using
the framework of choice for a range of different projects from
brochureware like sites to larger community portals:

http://www.creative-city-berlin.de/
http://www.lindemann.de/
http://www.lindemann-projekt.net/
http://www.jarmuschek.de/

You will also find a bunch of people (and some well known usual
suspects) form Berlin at http://djangopeople.net/de/

Cheers
Reinhard

On 25 Feb., 15:33, Thomas Bechtold 
wrote:
> Hi,
>
> i'm searching a webdesign company from berlin/germany which use
> django. Anybody here from Berlin?
>
> Cheers,
>
> Tom
--~--~-~--~~~---~--~~
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: Dealing with multiple M2Ms

2009-02-25 Thread Jeff Gentry

> and suppose "obj_a" is your given A instance. Then I suspect this is the
> type of queryset you're after:
> C.objects.filter(Q(to_a=obj_a) | Q(to_b__to_a=obj_a))

This did the trick Malcolm, thanks.  I'm not sure what was hanging me up
as I could swear I had tried this one already, but must have been just
slightly wrong syntactically at the time.

Thanks!
-J


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



Admin/Application Integration and Automatic Actions

2009-02-25 Thread Paul Waldo

Hi all,

I am brand new to Django, so forgive me if my questions are naive :-)

I have read the tutorials and I'm starting my first learning 
application.  This is a small time-tracking application.  As you can 
imagine, the majority of the application is basic CRUD data entry.  The 
other significant part is that I want to automatically create reports on 
a regular basis and email them.  I have two questions:

* The Admin application is great for my CRUD functionality; Django does 
a really fine job of creating this interface automatically.  
Unfortunately, using the Admin app. for data entry does not provide a 
seamless experience; the URLs are different, the look and feel is 
different, and the Admin is much more polished than my hand-crafted 
pages :-).  Do people use the Admin for regular users, or do they 
duplicate all that CRUD in their own pages?  Is there a way to make the 
Application/Admin more seamless?

* Is there a standard model for running automated tasks?  I was thinking 
about a cron task that uses lynx or curl to call a URL that performs the 
task, but that gets kind of ugly.  Is there a better way to do this?

Thanks in advance for your insights!

Paul

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



Search Professional Webdesign Company in Berlin (Germany)

2009-02-25 Thread Thomas Bechtold

Hi,

i'm searching a webdesign company from berlin/germany which use
django. Anybody here from Berlin?


Cheers,

Tom
--~--~-~--~~~---~--~~
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: Beginners question

2009-02-25 Thread Daniel Roseman

On Feb 25, 12:33 pm, wegi  wrote:
> Hi all,
> I'm new to django, made my way through the tutorial and parts of the
> remaining documentation. But one thing remains unclear to me. Let's
> assume I have two apps news and links which just manage these type of
> objects. I have a view and a template for displaying a list of the 5
> newest entries in each app.
> As long as I just display static content and the latest 5 news (or
> links) entries everything is fine (something like base.html with news/
> 5_newest_entries.html).
> But now I want to embed these apps in a site and want to display both,
> the newest 5 news AND newest 5 links on the startpage. I can have a
> template with blocks defined, ...
> Can I reuse the views of the apps or do I have to write a special view
> doing all the logic of the apps views again? Of course the given
> example is trivial, but the question is a general one.
> What is the preferred way of embedding multiple app views in one page?
> I guess I missed something in the docs, any hints will be appreciated.
>
> thanks,
> wegi

This is what templatetags are for. In particular, inclusion tags are
well-suited to this: they're basically a way of encapsulating code to
render a template fragment, including any database logic, which you
can then embed in any other template. See:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags

And James Bennett did a great post on these a few years ago:
http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread Briel

It's really not a good practice to ask 190 yes/no questions upon
registration. A lot of the answers will most likely be random as very
few would want to spend time answering 190 questions to complete a
registration. My advice would be to not have that many fields.

On 25 Feb., 13:02, NoviceSortOf  wrote:
> We have over 100 Yes/No questions asked in our registration process
> These questions are mostly static (requiring minor modification every
> 5-10 years),
> we don't especially need a dynamic data driven solution.
>
> These Yes/No questions are basically the user informing us of their
> specific
> interests IE. Archeology [ ], Poetry [ ], Art [ ] and so on.
>
> In our legacy client-side application (we are coming from a mailorder
> business started
> in the 60s) we store these selections in an abbreviated comma
> delimited character field ie
> Interests = "Arc,Art,Lit". Using a comma-delimited char field in this
> situation provides elegance on the data side, but of course we have to
> parse the field coming and going in order to make it usable also
> linking it to table that provides more human readable labels for the
> abbreviations.
>
> I'm considering simply adding the 190 odd boolean fields to accomplish
> this in profiles.models and the subsequent class needed in
> profiles.views to add presentable labels --- but am wondering if more
> of a data driven method may exist somewhere to
> accomplish this, perhaps using a comma delimited char field?
>
> Or how are such large amounts of yes/no boolean questions made
> manageable in Django?
>
> Any suggestion appreciated.
--~--~-~--~~~---~--~~
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: Beginners question

2009-02-25 Thread Alex Gaynor
On Wed, Feb 25, 2009 at 7:33 AM, wegi wrote:

>
> Hi all,
> I'm new to django, made my way through the tutorial and parts of the
> remaining documentation. But one thing remains unclear to me. Let's
> assume I have two apps news and links which just manage these type of
> objects. I have a view and a template for displaying a list of the 5
> newest entries in each app.
> As long as I just display static content and the latest 5 news (or
> links) entries everything is fine (something like base.html with news/
> 5_newest_entries.html).
> But now I want to embed these apps in a site and want to display both,
> the newest 5 news AND newest 5 links on the startpage. I can have a
> template with blocks defined, ...
> Can I reuse the views of the apps or do I have to write a special view
> doing all the logic of the apps views again? Of course the given
> example is trivial, but the question is a general one.
> What is the preferred way of embedding multiple app views in one page?
> I guess I missed something in the docs, any hints will be appreciated.
>
> thanks,
> wegi
>
> >
>
The most common technique for doing this are template tags, either regular
ones or inclusion tags, James Bennet wrote an excellent blog post on the
subject:
http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 can one template extend multiple templates?

2009-02-25 Thread lzhshen

Take a poll application for example.

There is a "poll_result.html" template that will be used in different
templates, such as latest_polls.html and hottest_polls.html.

How can I achieve that?
In "poll_result.html", can I add both " {% extends "latest_polls.html"
%}" and "" {% extends "hosttest_polls.html" %}"" in it?



On 2月24日, 下午11时14分, Mark Jones  wrote:
> It seems like maybe I don't understand the question but it willextend
> an infinite number of templates
>
> Just add {% extends "base.html" %} into everytemplateyou want toextend.
>
> You can even do {% extends "derived.html" %} which extends base.html
>
> On Feb 24, 8:41 am, lzhshen  wrote:
>
> > Suppose I have basetemplatecalled "base.html", can itextendmore
> > then two othertemplate, such as "a01.html" and "a02.html"?
>
> > Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: admin is not allowing users to see the main page

2009-02-25 Thread Shantanoo
On Wed, Feb 25, 2009 at 15:02, Kenneth Gonsalves wrote:

>
> hi,
>
> I have a django site which has been working well, with an app name 'web' -
> recently I some changes in the database and now find that all users
> (including
> superusers) are blocked from viewing web in the main admin page. They can
> view
> and edit other pages under 'web' by typing in the url. Where do I go to
> reset
> the permission for 'web' in the db?
> --
> regards
> kg
> http://lawgon.livejournal.com


Following maybe useful.
Source: http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs

===
Creating 
superusers¶
New
in Django 1.0: The manage.py createsuperuser command is new.

manage.py syncdb prompts you to create a superuser the first time you run it
after adding 'django.contrib.auth' to your
INSTALLED_APPS.
If you need to create a superuser at a later date, you can use a command
line utility:

manage.py createsuperuser --username=joe --email=...@example.com

You will be prompted for a password. After you enter one, the user will be
created immediately. If you leave off the --username or the --email options,
it will prompt you for those values.

If you're using an older release of Django, the old way of creating a
superuser on the command line still works:

python /path/to/django/contrib/auth/create_superuser.py

...where /path/to is the path to the Django codebase on your filesystem. The
manage.py command is preferred because it figures out the correct path and
environment for you.

===


-- 

Fran Lebowitz  - "You're only has good as your last haircut."

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



Beginners question

2009-02-25 Thread wegi

Hi all,
I'm new to django, made my way through the tutorial and parts of the
remaining documentation. But one thing remains unclear to me. Let's
assume I have two apps news and links which just manage these type of
objects. I have a view and a template for displaying a list of the 5
newest entries in each app.
As long as I just display static content and the latest 5 news (or
links) entries everything is fine (something like base.html with news/
5_newest_entries.html).
But now I want to embed these apps in a site and want to display both,
the newest 5 news AND newest 5 links on the startpage. I can have a
template with blocks defined, ...
Can I reuse the views of the apps or do I have to write a special view
doing all the logic of the apps views again? Of course the given
example is trivial, but the question is a general one.
What is the preferred way of embedding multiple app views in one page?
I guess I missed something in the docs, any hints will be appreciated.

thanks,
wegi

--~--~-~--~~~---~--~~
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: Faster Database?

2009-02-25 Thread Paul Nema
One option is to create a new table that is a mirror of the target table
except the new table should NOT have any of the keys enabled.  Using a bulk
load tool add the data to the new table.  Then add the keys to the new
table.  Drop the old table and rename the new table to the original target
table name. This technique usually saves a bunch of time.

On Wed, Feb 25, 2009 at 1:00 PM, Sean  wrote:

>
> Hi,
>
> I am using django+MySql.
> My job involves to write a huge number of products codes into the
> MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
> to 50 million codes within 1 file, which need to be uploaded/
> downloaded into MySql.
>
> The problem for this is it takestoo much time to insert data into the
> database, a typical 10 million code file will take 3 hours at least to
> load/download into MySql, it is even took a night time to process a 50
> million code file, which is a nightmare. So I want to make it faster.
>
> I got a powerful Core2 workstation and Xeron Server, which are almost
> the most powerful machin I can get in the market, so hardware is not a
> issue.
>
> I guess the slow down is caused by I/O to hard-disk.
>
> Anyone have any suggestion how can I make this process faster, or
> there is any other superfast database engine than MySql?
>
> Sean

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



Re: model inheritance without a new database table

2009-02-25 Thread Ryan Kelly

Thanks again for your feedback on this Malcolm, I've created the
following ticket in Trac:

   Proxy models: subclass a model without creating a new table
   http://code.djangoproject.com/ticket/10356



  Cheers,

 Ryan

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



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


Re: Static file serve with prior authentication?

2009-02-25 Thread John Hensley

On Feb 23, 2009, at 5:20 PM, Graham Dumpleton wrote:

> The approach for mod_python documented in that link, and equivalent
> for mod_wsgi, are only good for HTTP Basic authentication, it is no
> good if you want the page to be authenticated using HTML form/cookie
> based authentication as Django uses.

Assuming you can add an Apache module, or use lighttpd or nginx, you  
can write a Django view to handle the authorization, then delegate the  
actual file delivery to your web server. I think Perlbal also has its  
reproxy feature to do this.

It's been covered a few times in this group:

http://groups.google.com/group/django-users/search?group=django-users=sendfile_g=Search+this+group

Links:

   http://tn123.ath.cx/mod_xsendfile/

   http://blog.lighttpd.net/articles/2006/07/02/x-sendfile

   http://wiki.codemongers.com/NginxXSendfile

John


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



optional parameter url

2009-02-25 Thread Adonis

Hello,
I am having some trouble serving static files when i try to pass an
optional parameter.
For url: appname.mainpage/, the static files work fine
For url: appname.mainpage/10/, the static files are not read.

**
url.py

(r'^appname/mainpage/(?P.*)$', 'django.views.static.serve',
{'document_root': '/mesa'}),
(r'^appname/mainpage/(?P\d+)/(?P.*)$',
'django.views.static.serve', {'document_root': '/mesa'}),

views.py

def mainpage(request, xexe=0):
print "optional parameter: ", xexe
return render_to_response('mesa/blah.html', {...some args...})
**

Any suggestions my respectful django users?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Managing over 100 static booleanfield fields Model, Form Class and so on. Profiles process

2009-02-25 Thread NoviceSortOf

We have over 100 Yes/No questions asked in our registration process
These questions are mostly static (requiring minor modification every
5-10 years),
we don't especially need a dynamic data driven solution.

These Yes/No questions are basically the user informing us of their
specific
interests IE. Archeology [ ], Poetry [ ], Art [ ] and so on.

In our legacy client-side application (we are coming from a mailorder
business started
in the 60s) we store these selections in an abbreviated comma
delimited character field ie
Interests = "Arc,Art,Lit". Using a comma-delimited char field in this
situation provides elegance on the data side, but of course we have to
parse the field coming and going in order to make it usable also
linking it to table that provides more human readable labels for the
abbreviations.

I'm considering simply adding the 190 odd boolean fields to accomplish
this in profiles.models and the subsequent class needed in
profiles.views to add presentable labels --- but am wondering if more
of a data driven method may exist somewhere to
accomplish this, perhaps using a comma delimited char field?

Or how are such large amounts of yes/no boolean questions made
manageable in Django?

Any suggestion appreciated.

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



database trigger or what ?

2009-02-25 Thread marco sedda

Hi,

i'm newbie in django and i'm writing a model to record a general
booking in a particular date for a particular item
The booking model looks like this:

class Booking(models.Model):
item = models.ForeignKey(Item)
startDate = models.DateField("From")
endDate = models.DateField("To")

obviously i want to check if the item is available for the selected
dates before create a new booking.

I've to ckeck it via a database trigger or there is a django method to
do this?

p.s. I'll use this model both in django admin and in a custom user
interface.






--~--~-~--~~~---~--~~
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: Faster Database?

2009-02-25 Thread Tim Chase

> I am using django+MySql.
> My job involves to write a huge number of products codes into the
> MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
> to 50 million codes within 1 file, which need to be uploaded/
> downloaded into MySql.
> 
> The problem for this is it takestoo much time to insert data into the
> database, a typical 10 million code file will take 3 hours at least to

Once you start dealing with such large volumes of data, you'll 
want to look into database-specific commands for bulk-loading 
(and later dumping) data.  In the case of MySQL, you'll want to 
use the LOAD DATA[1] command.  I believe it needs to be executed 
locally on the server (or at least the data-file needs to be 
local to the server)  unless overridden by the LOCAL keyword 
(read the docs to learn more) which may or may not be supported 
by the Python MySQL driver.

-tim


[1]
http://dev.mysql.com/doc/refman/5.1/en/load-data.html

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



Re: Faster Database?

2009-02-25 Thread Sebastian Bauer

W dniu 25.02.2009 11:53, bruno desthuilliers pisze:
> On 25 fév, 11:00, Sean  wrote:
>
>> Hi,
>>
>> I am using django+MySql.
>> My job involves to write a huge number of products codes into the
>> MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
>> to 50 million codes within 1 file, which need to be uploaded/
>> downloaded into MySql.
>>
>> The problem for this is it takestoo much time to insert data into the
>> database,
>>  
You can remove ORM from import and insert by plain sql and mysqldb this 
will reduce python CPU usage

--~--~-~--~~~---~--~~
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: Faster Database?

2009-02-25 Thread bruno desthuilliers


On 25 fév, 11:00, Sean  wrote:
> Hi,
>
> I am using django+MySql.
> My job involves to write a huge number of products codes into the
> MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
> to 50 million codes within 1 file, which need to be uploaded/
> downloaded into MySql.
>
> The problem for this is it takestoo much time to insert data into the
> database,

What does the file looks like, where does it come from, and how do you
manage these insertions?


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



Faster Database?

2009-02-25 Thread Sean

Hi,

I am using django+MySql.
My job involves to write a huge number of products codes into the
MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
to 50 million codes within 1 file, which need to be uploaded/
downloaded into MySql.

The problem for this is it takestoo much time to insert data into the
database, a typical 10 million code file will take 3 hours at least to
load/download into MySql, it is even took a night time to process a 50
million code file, which is a nightmare. So I want to make it faster.

I got a powerful Core2 workstation and Xeron Server, which are almost
the most powerful machin I can get in the market, so hardware is not a
issue.

I guess the slow down is caused by I/O to hard-disk.

Anyone have any suggestion how can I make this process faster, or
there is any other superfast database engine than MySql?

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



admin is not allowing users to see the main page

2009-02-25 Thread Kenneth Gonsalves

hi,

I have a django site which has been working well, with an app name 'web' - 
recently I some changes in the database and now find that all users (including 
superusers) are blocked from viewing web in the main admin page. They can view 
and edit other pages under 'web' by typing in the url. Where do I go to reset 
the permission for 'web' in the db?
-- 
regards
kg
http://lawgon.livejournal.com

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