Re: How to get the url for media_root?

2009-01-08 Thread itsnotvalid

Thanks a lot!!
I completely missed the part regarding context processors... poor
me...
That means I am still not googlish enough...

On Jan 9, 3:09 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-08 at 22:58 -0800, itsnotvalid wrote:
> > Second question at the same time
>
> > Anyways, I encountered a problem that when I want to get an item from
> > my media directory, which is set correctly in settings.py, however I
> > couldn't find a template tag to get the url of the media. Looked into
> > the code for djangoproject.com and found that they just quote the full
> > url in base.html.
> > That would be pretty weird to do hard coding since there is attributes
> > in the settings file. Any hints?
>
> There's a context processor available that can be used to supply the
> media URL to your template's context. Have a look at
>
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
>
> and, in particular, django.core.context_processors.media. Every time you
> use RequestContext as the context you pass to render_to_response (or
> Template.render()), the context processors are all run and the media
> one, if you include it, will put a particular variable (MEDIA_URL) in
> your context that you can use to display that particular string.
>
> A lot of people, as you notice, just include the string in the base
> templates, since it doesn't really change that often (in fact, only if
> you change the location of your static files, typically). So it's often
> not an impractical solution (you don't *have* to use the setting URL,
> after all). I do that on my blog, for example. Whether I'm serving from
> my hosted system or using the development server, the static files are
> always under /static/, so it's not particularly onerous to just write
> that in the (single) base template.
>
> Others might have some other little function that reads that setting and
> passes it into the context. For example, I often have a common function
> that almost all my views call instead of render_to_response(). This
> function does some common tidying up operations and inserts some common
> stuff into the context and then returns the result of
> render_to_response().
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to get the url for media_root?

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 22:58 -0800, itsnotvalid wrote:
> Second question at the same time
> 
> Anyways, I encountered a problem that when I want to get an item from
> my media directory, which is set correctly in settings.py, however I
> couldn't find a template tag to get the url of the media. Looked into
> the code for djangoproject.com and found that they just quote the full
> url in base.html.
> That would be pretty weird to do hard coding since there is attributes
> in the settings file. Any hints?

There's a context processor available that can be used to supply the
media URL to your template's context. Have a look at 

http://docs.djangoproject.com/en/dev/ref/templates/api/#id1

and, in particular, django.core.context_processors.media. Every time you
use RequestContext as the context you pass to render_to_response (or
Template.render()), the context processors are all run and the media
one, if you include it, will put a particular variable (MEDIA_URL) in
your context that you can use to display that particular string.

A lot of people, as you notice, just include the string in the base
templates, since it doesn't really change that often (in fact, only if
you change the location of your static files, typically). So it's often
not an impractical solution (you don't *have* to use the setting URL,
after all). I do that on my blog, for example. Whether I'm serving from
my hosted system or using the development server, the static files are
always under /static/, so it's not particularly onerous to just write
that in the (single) base template.

Others might have some other little function that reads that setting and
passes it into the context. For example, I often have a common function
that almost all my views call instead of render_to_response(). This
function does some common tidying up operations and inserts some common
stuff into the context and then returns the result of
render_to_response().

Regards,
Malcolm



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



Re: Your IDE of choice

2009-01-08 Thread Nikolay Panov

You may also try Rope. Theyr auto-completion is better than pysmell too.

Have a nice day,
   Nikolay.



On Fri, Jan 9, 2009 at 01:23, Marco Buttu  wrote:
>
> On Wed, 2009-01-07 at 13:06 +, Adam Stein wrote:
>
>> I have omnicomplete working (haven't used it too much yet).  I have
>> this
>> in my $HOME/.vimrc file:
> ...
>> Also, I have vim starting automatically importing the Django db.  I
>> have
>> a little script (below) that will automatically find my settings.py
>> file
>> and start vim.  I do this by starting at the location of the file on
>> the
>> vim command line and working upwards in the directory structure until
>> I
>> find it:
> ...
>> I only use Django on Unix/Linux so I'm guessing it would need some
>> tweaking for Windows.
>
> I am using PySmell to autocomplete Django code, but I think omnicomplete
> is better. Tomorrow I'll try it :-)
> Thanks
> --
> Marco Buttu
>
>
> >
>

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



How to get the url for media_root?

2009-01-08 Thread itsnotvalid

Second question at the same time

Anyways, I encountered a problem that when I want to get an item from
my media directory, which is set correctly in settings.py, however I
couldn't find a template tag to get the url of the media. Looked into
the code for djangoproject.com and found that they just quote the full
url in base.html.
That would be pretty weird to do hard coding since there is attributes
in the settings file. Any hints?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to customize admin interface to edit foreignkey objects on the same page?

2009-01-08 Thread itsnotvalid

I have two model, say CustomProfile and User. When I want to edit
CustomProfile I also want to edit the required User object at the same
time, which means that for the admin it would look like they are
joined together on the add/edit page of CustomProfile.

However since I have different profiles for different group of people
(and any user could have as many kinds of profile assoicated, but only
one profile of each), so I am not sure if I can get it hooked up
simply by defining the user profile settings attribute.

And from django ticket #2373 seems that there is "no way" (not even
proposed ways which may break the compatibility of django 1.x is
provided in that ticket) to get it done within the system.

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



Re: Django/Apache on Ubuntu - admin page looks weird

2009-01-08 Thread elithrar

Just in case you miss it - and this is the method I'd suggest, as it
makes updating easy:

> Create a symbolic link to the admin media files from within your document 
> root. This way, all of your Django-related files -- code and templates -- 
> stay in
> one place, and you'll still be able to svn update your code to get the latest 
> admin templates, if they change.

Also, if you have the admin files symlinked under your_document_root/
media/admin/ and have your other static content under media/css/ &
media/js/ (for example), you'll want to do the following to avoid
requesting static media through the Django stack for each request (ie.
bad):


SetHandler None

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



Re: Problem when using RAW SQL Query with Django (not all arguments converted during string formatting)

2009-01-08 Thread Kedare

Thank you, that work fine !

On 9 jan, 05:59, "Karen Tracey"  wrote:
> On Thu, Jan 8, 2009 at 11:41 PM, Kedare  wrote:
>
> > Hi, i have made a Cache management Page for Django, but i have a
> > problem, i need to expire single cache entries, so i made this :
>
> > (the url is like that by example: "/admin/cache_management/?
>
> > action=clear=views.decorators.cache.cache_page../.d41d8cd98f00b204e9800998ecf8427e")
>
> >        if request.GET.get("action","") == "clear":
> >                entry = request.GET.get("key","")
> >                cursor.execute("""DELETE FROM django_cache" WHERE cache_key
> > = %s""",
> > (entry))
>
> Just a guess, but I think you may be missing a comma after entry here.
> Single-element tuples need trailing commas after the single element in order
> to make them tuples.
>
>
>
> >                cursor.execute("COMMIT")
> >                message = _("Cache entry %s deleted" % (entry))
>
> > But i get this error, i don't know why :
> > TypeError at /admin/cache_management/
> > not all arguments converted during string formatting
>
> > I don't think my query have a problem, i use anothers query on the
> > same view (with %s too), and i don't have any problems
>
> > I am using Postgresql with psycopg2
>
> > Any ideas on my problem ?
> > Thank and happy new year
> > Sorry for my bad english :)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem when using RAW SQL Query with Django (not all arguments converted during string formatting)

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 11:41 PM, Kedare  wrote:

>
> Hi, i have made a Cache management Page for Django, but i have a
> problem, i need to expire single cache entries, so i made this :
>
> (the url is like that by example: "/admin/cache_management/?
>
> action=clear=views.decorators.cache.cache_page../.d41d8cd98f00b204e9800998ecf8427e")
>
>if request.GET.get("action","") == "clear":
>entry = request.GET.get("key","")
>cursor.execute("""DELETE FROM django_cache" WHERE cache_key
> = %s""",
> (entry))


Just a guess, but I think you may be missing a comma after entry here.
Single-element tuples need trailing commas after the single element in order
to make them tuples.


>
>cursor.execute("COMMIT")
>message = _("Cache entry %s deleted" % (entry))
>
> But i get this error, i don't know why :
> TypeError at /admin/cache_management/
> not all arguments converted during string formatting
>
> I don't think my query have a problem, i use anothers query on the
> same view (with %s too), and i don't have any problems
>
> I am using Postgresql with psycopg2
>
> Any ideas on my problem ?
> Thank and happy new year
> Sorry for my bad english :)
>
> >
>

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



Re: Django/Apache on Ubuntu - admin page looks weird

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 11:45 PM, djangofett  wrote:

>
> Hi, I am trying to get Django running on an Ubuntu server with Apache.
> Everything seems to be installed fine (mod_python, plus MySQL with
> MySQLdb python bindings), and I am running the main tutorial on the
> Django site. I am doing the second part of the tutorial, with the
> admin site, and noticed that when I load the admin page, the page is
> pretty much bare bones HTML (not the nice, colorful one shown on the
> demo).
>
> I'm wondering if this is because I'm using Apache instead of litehttpd
> as in the tutorial, or if I'm missing some install or config. Should I
> be concerned about this?
>

Yes, it's basically because you are using Apache instead of the development
server and yes, you are missing some (Apache) config, not covered by the
tutorial since it assumes you'll follow along with the development server.
See:

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id3

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



Django/Apache on Ubuntu - admin page looks weird

2009-01-08 Thread djangofett

Hi, I am trying to get Django running on an Ubuntu server with Apache.
Everything seems to be installed fine (mod_python, plus MySQL with
MySQLdb python bindings), and I am running the main tutorial on the
Django site. I am doing the second part of the tutorial, with the
admin site, and noticed that when I load the admin page, the page is
pretty much bare bones HTML (not the nice, colorful one shown on the
demo).

I'm wondering if this is because I'm using Apache instead of litehttpd
as in the tutorial, or if I'm missing some install or config. Should I
be concerned about this?

(BTW the Ubuntu server is a Linode VPS, but I don't think this should
matter).

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



Problem when using RAW SQL Query with Django (not all arguments converted during string formatting)

2009-01-08 Thread Kedare

Hi, i have made a Cache management Page for Django, but i have a
problem, i need to expire single cache entries, so i made this :

(the url is like that by example: "/admin/cache_management/?
action=clear=views.decorators.cache.cache_page../.d41d8cd98f00b204e9800998ecf8427e")

if request.GET.get("action","") == "clear":
entry = request.GET.get("key","")
cursor.execute("""DELETE FROM django_cache" WHERE cache_key = 
%s""",
(entry))
cursor.execute("COMMIT")
message = _("Cache entry %s deleted" % (entry))

But i get this error, i don't know why :
TypeError at /admin/cache_management/
not all arguments converted during string formatting

I don't think my query have a problem, i use anothers query on the
same view (with %s too), and i don't have any problems

I am using Postgresql with psycopg2

Any ideas on my problem ?
Thank and happy new year
Sorry for my bad english :)

--~--~-~--~~~---~--~~
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: get_profile not working (get_model returns None)

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 11:19 PM, Hans Fangohr  wrote:

>
> You are right: using 'People.profile' works. To be clear (for others): the
> application name should (in  contrast to the documentation) NOT be converted
> to lowercase. (But the actual model -- here 'Profile' -- should.)
> Then everything works.
>
> Should I report this? If so, could you point me in the right direction,
> please?
>

Yes, please report it.  The doc doesn' t match the code, so one should be
fixed.  I'm guessing it's the doc that is wrong. This page:

http://code.djangoproject.com/simpleticket

is where you can create a ticket.

Thanks,
Karen

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



Re: Change the url

2009-01-08 Thread Praveen

Thank you so much Briel. Really you gave me a nice explanation and the
same think i was thinking but was not able to make understand to my
senior. let me put your idea to my senior and lets see what they say..
but really i appreciate you and for your politeness.

On Jan 8, 6:43 pm, Briel  wrote:
> Hi Praveen
> I personally would prefer naming the urls rather than using the
> get_absolute_url.
> Both can accomplish your goal, but naming the urls is a more robust
> and in other ways a better solution.
>
> If you in a week decide that the url should not be /category/... but
> instead /whatever/... you would have to recode your get_absolute_url
> method. However, if you use the names in urls, everything would still
> work after changing the urls. The reason is that when using the name
> of an url, Django will find what the absolute url will be given the
> args you use, in your example the id.
> In a way, you could say that when using named urls, django is both
> writing and running get_absolute_url for you.
>
> Another plus when using named urls, is that you can give your urls
> name that give meaning. That will make it a lot easier to understand
> what's going on in the template when you read your own code 6 months
> from now. Especially if you have several views of one model.
>
> Say you had a model for blog posts.
> Then you might want to have an url for your own blogs, another one for
> your friend's blogs ect. You could still use get_absolute_url, but
> this time, it would be harder to make and use, as you now would need
> to know what url to get. Also when reading the template it would be
> hard to see which url is being displayed. Instead using tags like
> {% url friends_blog args=x %}
> {% url your_blog args=x %}
> {% url all_blog args=x %}
> would be easy to understand after not working with the code for a long
> time.
>
> -Briel
>
>
>
> Praveen wrote:
> > Hi Briel i am totally confused now.
> > My senior told me to write get_absolute_url
>
> > so i wrote get_absolute_url like this
> > class Listing_channels(models.Model):
> >     list_channel = models.CharField(max_length = 20)
> >     visibility = models.BooleanField()
>
> >     def __unicode__(self):
> >         return self.list_channel
>
> >     def get_absolute_url(self):
> >            return u'/category/listing_view/%i/' % self.id
>
> > and in html template i am calling
>
> > {%if listing_result %}
> >     {% for n in listing_result %}
> >          {{n.list_channel}} > li>
> >     {% endfor %}
> > {% else %}
> >     not available
> > {% endif %}
> > 
>
> > so its working fine.
>
> > so now i have two mechanism one is your as you told me to write and
> > second one is
> > get_absolute_url() function.
>
> > Now my confusion is if we have another same class event_channel and
> > event and many more classes like this then i will have to write
> > get_absolute_url() for each class
> > and if go with you then there i need to change only in urls.py that i
> > think fine.
>
> > so i should go with get_absolute_url? give me the best and solid
> > reason so i could make understand to senior, and you know the senior
> > behave..
>
> > Briel wrote:
>
> > > Using urls with names will solve your problem.
>
> > > Basically if you change your urls.py like this:
>
> > >     url(
> > >         r'^category/listing_view/(?P\w+)/$',
> > >        'mysite.library.views.listing_view',
> > >        name = 'name_for_this_view'
> > >     ),
>
> > > What I have done is to add a name to the url for convenience I also
> > > used the url() function. This name can now be used instead of the link
> > > to your view. So if you were to change the site structure, when
> > > changes would be made to your urlconf, django would then be able to
> > > figure things out for you. In this version your new link would look
> > > like this:
>
> > > {{n.list_channel}}
>
> > > In the docs you can read about it at
> > > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > > Good luck.
> > > -Briel
>
> > > On 8 Jan., 12:41, Praveen  wrote:
> > > > Hi Malcolm i am very new bie of Django. i read through
> > > > get_absolute_url but do not know how to use.
> > > > What you have given the answer i tried with that and its working fine
> > > > but my senior asked me what will happen if i change the site name then
> > > > every where you will have to change url
> > > > mysite.library.views.listing_view.
>
> > > > so they told me to use get_absolute_url
>
> > > > i wrote get_absolute_ul in models.py
> > > > def get_absolute_url(self):
> > > > return "/listing/%i/" % self.id
> > > > and i am trying to use in my html page template but i don't know how
> > > > to use
>
> > > >  {{n.list_channel}} > > > li>
>
> > > > then again same problem. first time when some one click on link it
> > > > works fine but second time it appends the link 
> > > > 

Re: get_profile not working (get_model returns None)

2009-01-08 Thread Hans Fangohr
Dear Karen,

On 9 Jan 2009, at 00:35, Karen Tracey wrote:

> On Thu, Jan 8, 2009 at 6:24 PM, Hans Fangohr   
> wrote:
>
>
> Dear all,
>
> I have difficulties with the get_profile to link my Profile class with
> the inbuilt User object.
>
> The error message (which can be obtained through the 'chatroom' view
> shown below, or via the shell) is:
>
> ---
> AttributeErrorTraceback (most recent call
> last)
>
> /Users/fangohr/local/hg/scico_web/debug/mysite/ in
> ()
>
> /Library/Frameworks/Python.framework/Versions/4.0.30002/lib/python2.5/
> site-packages/django/contrib/auth/models.pyc in get_profile(self)
>291 app_label, model_name =
> settings.AUTH_PROFILE_MODULE.split('.')
>292 model = models.get_model(app_label, model_name)
> --> 293 self._profile_cache =
> model._default_manager.get(user__id__exact=self.id)
>294 except (ImportError, ImproperlyConfigured):
>295 raise SiteProfileNotAvailable
>
> AttributeError: 'NoneType' object has no attribute '_default_manager'
>
>
> This indicates that models.get_model() does return None, but I don't
> know why.
>
> I have in settings.py:
> AUTH_PROFILE_MODULE = 'people.profile'
> which I believe is the right entry.
>
>
> (Thanks for the very detailed question.) I think you have found a  
> documentation bug.  I do not believe the 'people' part of that  
> should be normalized to lower case.  It is not normalized to lower  
> case in INSTALLED_APPS, and I don't think it should be normalized to  
> lower case here.  Since you have a capital P in People for your  
> directory name, try 'People.profile'.
You are right: using 'People.profile' works. To be clear (for others):  
the application name should (in  contrast to the documentation) NOT be  
converted to lowercase. (But the actual model -- here 'Profile' --  
should.)

Then everything works.

Should I report this? If so, could you point me in the right  
direction, please?

Many thanks,

Hans


>
>
> Karen
>
> >




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



Re: Extending Group for a GroupProfile

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 19:46 -0800, Cortland Klein wrote:
> Hi. I'm planning on extending Group for a GroupProfile. I noticed that  
> the recommended way to extend User is to create a UserProfile with a  
> ForeignKey(User, unique=True) instead of a OneToOneField[a].
> 
> 1. Why is it recommended to use a ForeignKey(unique=True) from a  
> UserProfile to User instead of a OneToOneField or subclassing User for  
> multi-table inheritance?

Partly historical. Prior to the queryset-refactor branch being merged
into trunk, we weren't recommending that people used OneToOneField, as
it had a few internal problems. That was subsequently tidied up and
OneToOneField is a grade A field again these days.

Similarly for model inheritance (although see the next paragraph for the
real problem here). It was only added to Django last year, but the user
profile concept has been around for ages. There's also an element of
explicitness involved: using the related field and including it
explicitly makes it clear what's going on. Model inheritance is, in many
ways, a bit of a cheat to make something look Pythonic that really isn't
(the relational database structure of the storage leaks through in a few
ways).

More importantly, though, just as in Python you cannot "downcast" with
Django's model inheritance. That is, if you've already created the User
instance, you cannot, without poking about under the covers, make that
instance correspond to a subclass instance that you haven't created yet.
Since user profiles are always created after the User instance (possibly
via the post_save signal, but that's the earliest you can do it), this
is a bit of a problem. On the other hand, it's easy and documented how
to add a user profile class at a later stage after the user is created
(you can simulate "downcasting", but you end up having to admit that the
multi-table inheritance is done with a OneToOneField and poking at a
hidden field and possibly having to sacrifice a chicken, so you might as
well just right it out explicitly in the first place).

> 2. As I'm planning on extending Group with GroupProfile, should I use  
> a ForeignKey(Group, unique=True), a OneToOneField(Group), or have  
> GroupProfile subclass Group to use Multi-table interitence? Does it  
> even matter since Group currently has no get_profile() function anyways?

These days, if you're implementing something that really is one-to-one,
I would recommend the OneToOneField. In fact, I suspect there's probably
no reason it can't be used for the User profile class, either. The only
significant difference between OneToOneField and ForeignKey(unique=True)
is when you're traversing the reverse relation. If you have

class ModelA(models.Model):
   ...

class ModelB(models.Model):
   related = Models.OneToOneField(ModelA)
   ...

and obj_a is a ModelA instance, then obj_a.modelb will return a ModelB
instance.

On the other hand, if ModelB is using a ForeignKey(ModelA, unique=True)
setup, obj_a.modelb_set.all() is the required spelling and will return
an iterator containing a single ModelB instance. So, for single instance
things, OneToOneField provides a more natural API -- you immediately get
hold of the object you care about.

Note, however (in case you care) that User.get_profile() doesn't use the
reverse relation, which is why you can switch OneToOneField and
ForeignKey there. It does an explicit get() call to retrieve the
instance with the correct primary key.

Regards,
Malcolm



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



Extending Group for a GroupProfile

2009-01-08 Thread Cortland Klein

Hi. I'm planning on extending Group for a GroupProfile. I noticed that  
the recommended way to extend User is to create a UserProfile with a  
ForeignKey(User, unique=True) instead of a OneToOneField[a].

1. Why is it recommended to use a ForeignKey(unique=True) from a  
UserProfile to User instead of a OneToOneField or subclassing User for  
multi-table inheritance?
2. As I'm planning on extending Group with GroupProfile, should I use  
a ForeignKey(Group, unique=True), a OneToOneField(Group), or have  
GroupProfile subclass Group to use Multi-table interitence? Does it  
even matter since Group currently has no get_profile() function anyways?



a: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/

-- 
Cortland Klein 
Work: +1 408 862 3775
Mobile: +1 408 506 9791
Web Developer, Media and Technology
Retail Training & Development
MS 49-SM
https://retailu.apple.com/


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



Re: Process file after upload

2009-01-08 Thread varikin



On Jan 7, 7:32 am, dmishe  wrote:
> Hey.
>
> I have FielField in my model for user to upload ZIP-archives. I want
> to unpack that zip, place some files in some dirs and delete it just
> after user uploaded it in admin.
>
> How can i do this? Model's save won't work because it gets called
> everytime model is saved regardless of were the file uploaded again or
> not. Custom storage/upload handler seems too complicated for this.

I may not be reading your description right, but it sounds like you
are not really saving this zip file, just processing what is in it,
correct? If that is the case, you don't need it in the model. You
could just create a form and view that take a zip file, unzip it and
do any processing. I do this to upload multiple pictures to a gallery
site.  I then overrode the admin list page for a model to have a
button by "Add Object" called "Add Multiple Objects" which has just
this form instead of the normal add object form.

If you a more complete explanation, let me know. But, if I am reading
your question wrong, this might not work.

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



Re: defining form fieldsets in view (not in admin)

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 18:43 -0800, adrian wrote:
> 
> What would be the best way to do it so when django updates
> I don't have to rewrite my extension?   So that it might be reusable
> by others?   Should I
> checkout a version or can I use the 1.0.2 I have?

You should be able to write your class without modifying Django's code
at all. It would be completely independent.

I'm thinking you would end up with something like this in your code:

class SomeForm(MyModelForm):
fieldsets = [...]

class Meta:
# ...

where MyModelForm is a subclass of forms.ModelForm containing, perhaps,
some code like django.contrib.admin.helpers.InlineAdminForm, or
something similar.

> 
> Don't know if I have the depth of understanding of django to do this
> well, but I'm willing to try.
> I would try to use the same fieldset syntax as is used in admin.py,
> but it would be put in the
> the Meta of the ModelForm.

Initially, I would just make it an attribute, say, on a subclass of
ModelForm. Simply to avoid having to mess around with the metaclassing
infrastructure (although that might be unavoidable).

Really, though, the idea is to solve your problem. If you want to roll
up your sleeves and work out the subclassing solution based on
InlineAdminForm, do that. Or you could override
django.forms.forms.BaseForm._html_output() in your subclass to work with
fieldsets for your forms. Or you could do the organisation in your
template.

Depends on how much time you have available to invest in this and your
skill and comfort level. All that being said, a healthy dose of
persistence and stubborness usually manages to get any problem solved
pretty well. You just have to be prepared not to let the code win. ;-)

Best wishes,
Malcolm


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



Re: defining form fieldsets in view (not in admin)

2009-01-08 Thread adrian


What would be the best way to do it so when django updates
I don't have to rewrite my extension?   So that it might be reusable
by others?   Should I
checkout a version or can I use the 1.0.2 I have?

Don't know if I have the depth of understanding of django to do this
well, but I'm willing to try.
I would try to use the same fieldset syntax as is used in admin.py,
but it would be put in the
the Meta of the ModelForm.

On Jan 8, 7:53 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-08 at 17:32 -0800, adrian wrote:
>
> > Is there a way to display a form with fields grouped using fieldsets,
> > without entering all the html manually in the view?   The Form I have
> > in mind is generated directly from a Model.   I see that the admin has
> > this feature but it isn't mentioned anywhere else in the doc.
>
> The way admin does it is somewhat specific to the admin. But if
> something in Django already does what you want, that's a clue: look at
> how Django does it. Change into the django/contrib/admin/ directory and
> search for the word "fieldset". You'll see references to InlineAdminForm
> and might be able to write an equivalent of something like that for
> yourself.
>
> > This would have two advantages - one it's an easy way to control
> > display of fields in the view without loads of manual html.   Since I
> > have choices for some of my fields, the manual html is large and
> > clutters up my view.
>
> > Second it would let me reorder the fields in the view with affecting
> > the model.   Once a database is live it's not so easy to change it but
> > I'd still like the freedom to change the view it's based on (without
> > voluminous html).
>
> Django's form classes are designed to be subclassed and extended and we
> intentionally don't try to do more than provide the basic foundation, as
> there are far too many possibilities to try and cover the field (it
> would also be seen as too generally restrictive). So do that. Write some
> Python code that does what you want. Use InlineAdminForm as inspiration.
>
> If your code turns out to be wonderfully useful, stick it up on Google
> code or somewhere as a useful library that others might want to use. Or
> not.
>
> I'm really not trying to be dismissive here. This is an expectation
> thing. In many cases, you are expected to build on top of what Django
> provides. Certainly have a look and ask, as you're doing, to see if the
> code already exists in Django. However, don't be afraid or shocked when
> it requires building on top of the existing libraries (again, not
> assuming you will have that reaction, but it seems to be a common enough
> response).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: upload_to not found

2009-01-08 Thread Kottiyath

Oops -- My bad.
Thank you Karen.

Regards
K

On Jan 9, 5:01 am, "Karen Tracey"  wrote:
> On Thu, Jan 8, 2009 at 3:16 PM, Kottiyath Nair wrote:
>
>
>
> > Hi,
> >   I was trying out a form - with filefield. I used the option upload_to,
> > and django server erred out saying - upload_to not found.
> >   I checked django code :
> > >>> import django
> > >>> django.VERSION
> > (1, 0, 2, 'final', 0)
>
> > class FileField(Field):
> >     widget = FileInput
> >     default_error_messages = {
> >         'invalid': _(u"No file was submitted. Check the encoding type on
> > the form."),
> >         'missing': _(u"No file was submitted."),
> >         'empty': _(u"The submitted file is empty."),
> >     }
>
> >     def __init__(self, *args, **kwargs):
> >         super(FileField, self).__init__(*args, **kwargs)
>
> > --> As we can see there is no upload_to parameter in it. I am sure I am
> > missing something because upload_to seems to be the basic option as per
> > documents.
> > Can somebody help me out?
>
> upload_to is a parameter for model FileFields:
>
> http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
>
> not form FileFields:
>
> http://docs.djangoproject.com/en/dev/ref/forms/fields/#filefield
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Passing a form a user before validation

2009-01-08 Thread DragonSlayre

Thank you thank you thank you

Cheers Malcolm, you're the best!

On Jan 9, 2:31 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-08 at 17:09 -0800, DragonSlayre wrote:
> > I'm trying to generate a form with a user's details, so that they can
> > change the details they've submitted.
>
> > One of my forms is a ModelForm, which is the profile of the User
> > object.  I also want to show the first name, last name and email from
> > the User object, so I've created a form for that which validates the
> > email (to make sure no-one else has the same email).
>
> > Here's my view code so far:
>
> > @login_required
> > def change_my_account(request):
> >     fireman = Fireman.objects.get(pk=request.user.get_profile().id)
>
> >     if request.method == 'POST':
> >         #also need to check my RegistrationFormSimple
> >         form = FiremanForm(request.POST, instance=fireman)
> >         if form.is_valid():
> >             form.save()
> >     else:
> >         form =FiremanForm(instance=fireman)
> >         data = {'first_name' : request.user.first_name,
> >                 'last_name'  : request.user.last_name,
> >                 'email'      : request.user.email}
> >         userForm = RegistrationFormSimple(data)
> >     return render_to_response('Change_account.html', {'form' : form,
> >                                                       'user_form' :
> > userForm})
>
> > This works well, except that I have a validator in my
> > RegistrationFormSimple, which needs to know who the user is, to check
> > the emails.
>
> > I'm stumped about how I give this information to my
> > RegistrationFormSimple.
>
> The validation method needs to be able to look up the user or have it
> passed in. I would pass it in. You can write an __init__ method for your
> RegistrationFormSimple class that accepts an extra parameter (preferably
> a keyword argument) that it uses in the validator. For example
>
>         class RegistrationFormSimple(forms.Form):
>            def __init__(self, *args, **kwargs):
>               self.user = kwargs.pop("user")
>               super(RegistrationFormSimple, self).__init__(*args,
>         **kwargs)
>
>            def clean_email(self):
>               # Can refer to self.user in here
>
> Then you can create this form in your view like this:
>
>         userForm = RegistrationFormSimple(data, user=request.user)
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: defining form fieldsets in view (not in admin)

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 17:32 -0800, adrian wrote:
> 
> Is there a way to display a form with fields grouped using fieldsets,
> without entering all the html manually in the view?   The Form I have
> in mind is generated directly from a Model.   I see that the admin has
> this feature but it isn't mentioned anywhere else in the doc.

The way admin does it is somewhat specific to the admin. But if
something in Django already does what you want, that's a clue: look at
how Django does it. Change into the django/contrib/admin/ directory and
search for the word "fieldset". You'll see references to InlineAdminForm
and might be able to write an equivalent of something like that for
yourself.

> This would have two advantages - one it's an easy way to control
> display of fields in the view without loads of manual html.   Since I
> have choices for some of my fields, the manual html is large and
> clutters up my view.
> 
> Second it would let me reorder the fields in the view with affecting
> the model.   Once a database is live it's not so easy to change it but
> I'd still like the freedom to change the view it's based on (without
> voluminous html).

Django's form classes are designed to be subclassed and extended and we
intentionally don't try to do more than provide the basic foundation, as
there are far too many possibilities to try and cover the field (it
would also be seen as too generally restrictive). So do that. Write some
Python code that does what you want. Use InlineAdminForm as inspiration.

If your code turns out to be wonderfully useful, stick it up on Google
code or somewhere as a useful library that others might want to use. Or
not.

I'm really not trying to be dismissive here. This is an expectation
thing. In many cases, you are expected to build on top of what Django
provides. Certainly have a look and ask, as you're doing, to see if the
code already exists in Django. However, don't be afraid or shocked when
it requires building on top of the existing libraries (again, not
assuming you will have that reaction, but it seems to be a common enough
response).

Regards,
Malcolm



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



defining form fieldsets in view (not in admin)

2009-01-08 Thread adrian


Is there a way to display a form with fields grouped using fieldsets,
without entering all the html manually in the view?   The Form I have
in mind is generated directly from a Model.   I see that the admin has
this feature but it isn't mentioned anywhere else in the doc.

This would have two advantages - one it's an easy way to control
display of fields in the view without loads of manual html.   Since I
have choices for some of my fields, the manual html is large and
clutters up my view.

Second it would let me reorder the fields in the view with affecting
the model.   Once a database is live it's not so easy to change it but
I'd still like the freedom to change the view it's based on (without
voluminous html).

Thanks

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



Re: Passing a form a user before validation

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 17:09 -0800, DragonSlayre wrote:
> I'm trying to generate a form with a user's details, so that they can
> change the details they've submitted.
> 
> One of my forms is a ModelForm, which is the profile of the User
> object.  I also want to show the first name, last name and email from
> the User object, so I've created a form for that which validates the
> email (to make sure no-one else has the same email).
> 
> Here's my view code so far:
> 
> @login_required
> def change_my_account(request):
> fireman = Fireman.objects.get(pk=request.user.get_profile().id)
> 
> if request.method == 'POST':
> #also need to check my RegistrationFormSimple
> form = FiremanForm(request.POST, instance=fireman)
> if form.is_valid():
> form.save()
> else:
> form =FiremanForm(instance=fireman)
> data = {'first_name' : request.user.first_name,
> 'last_name'  : request.user.last_name,
> 'email'  : request.user.email}
> userForm = RegistrationFormSimple(data)
> return render_to_response('Change_account.html', {'form' : form,
>   'user_form' :
> userForm})
> 
> This works well, except that I have a validator in my
> RegistrationFormSimple, which needs to know who the user is, to check
> the emails.
> 
> I'm stumped about how I give this information to my
> RegistrationFormSimple.

The validation method needs to be able to look up the user or have it
passed in. I would pass it in. You can write an __init__ method for your
RegistrationFormSimple class that accepts an extra parameter (preferably
a keyword argument) that it uses in the validator. For example

class RegistrationFormSimple(forms.Form):
   def __init__(self, *args, **kwargs):
  self.user = kwargs.pop("user")
  super(RegistrationFormSimple, self).__init__(*args,
**kwargs)

   def clean_email(self):
  # Can refer to self.user in here

Then you can create this form in your view like this:

userForm = RegistrationFormSimple(data, user=request.user)

Regards,
Malcolm



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



Re: Session variables

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 05:12 -0800, bradders wrote:
> I will try to put something together.   I have a fairly detailed trace
> that I have put in the session code that shows my session variables
> are set when it calls one of my views, but the trace shows that the
> next session save only a new session variable set in that view exists
> all the other session variables have disappeared. I am not knowingly
> clearing the other variables.


By the way, are your using Windows by any chance and the
filesystem-based session backend? I remembered later last night that
there is one bug due to problems in the Windows filesystem (#9084).

Regards,
Malcolm



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



Re: orm: delete performance and queries optimization

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 04:54 -0800, drakkan wrote:
> In my database I have some tables full of records, when I delete an
> object django use the cascade behaviour and this is good, however
> seems it make a query for every related object and after this django
> seems to issue a delete where id in () for every 100 objects

We need to pull out the ids since deletes can occur across multiple
tables in various situations. We only do deletes in chunks since there
are maximum lengths of SQL queries. 100 isn't a bad number. If you're
needing to do tens of thousands of deletes regularly, use raw SQL.

[...]
> I think some optimization is needed,

We take patches. :-)

Just make sure the changes have a chance of working on all our database
backends.

Seriously, I'm a little surprised your database is only able to do less
than 2.5 queries per second. Be that as it may, if you're needing to do
mass deletes, do them directly. Django is never intended to be a
complete replacement for SQL and typical "delete" usage for a web
framework is a record or two, not thousands and thousands. Although it
should still be able to handle the latter case comfortably (I just
tested a 10,000 object delete and it only took a few minutes) unless
your models are quite complicated or there are lots and lots of indexes
to update or something. In other words, there are going to be
circumstance-specific exceptions, so testing and profiling is a good
idea. If this is a big problem for you, by all means look at what
changes might be possible. The code in question is in
django/db/models/base.py and django/db/models/query.py. It's a little
complex, but not horribly scary.

Regards,
Malcolm


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



Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 7:48 PM, rabbi  wrote:

>
> I get the same exception(s)
>
> The 1st time I try to import swenglish.admin I get:
> ImproperlyConfigured: 'EntryAdmin.fieldsets[3][1]['fields']' refers to
> field 'created_date' that is missing from the form.
>
> The 2nd time I try to import swenglish.admin I get:
> AlreadyRegistered: The model User is already registered
>
> These are the same exceptions that I get when trying to load the admin
> page.
> The 1st time I try to load admin page I get ImproperlyConfigured
> After I press refresh (and every subsequent refresh) I get
> AlreadyRegistered
>

You did not mention the ImproperlyConfigured  exception in your original
report :)  I though it was likely a case of this:

http://code.djangoproject.com/ticket/8245

so was trying to get at what the real problem was, which I see by your
follow-up mail you have solved.  There's been a fix made for that behavior
of the real exception getting hidden by AlreadyRegistered on subsequent
requests, but it seems (based solely on the last comment on that ticket, I
haven't had time to look at it in any detail) there may be more work to be
done for this situation.

Karen

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



Re: ModelForm: exclude fields missing in request

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 07:08 -0800, Flo Ledermann wrote:
> Hi all,
> 
> I am trying to use a ModelForm in a "sparse" way to edit instances,
> i.e. I only render one of its fields (plus a submit button) in the
> template for editing the corresponding field in the model. I would
> have expected that fields not present in the POST data of the request
> would be omitted when updating the model, but to my surprise these
> fields are set to the empty string "" - even fields that have been
> None/NULL before calling form.save().

Django will never save None or NULL in character fields. They will
always be set to empty strings. That's a property of Django's
character-based fields and not particular to this situation.

> 
> Is there a way to get the desired behavior (simply omitting data not
> present in the request)? Shouldn't this even be the default behavior?

No. Don't ask the form class to read your mind. Create a form that knows
which fields it expects so that errors can be raised correctly and
validation will occur normally. You are trying to use a form with extra
fields that you don't really want and hoping the form's
validation/normalisation will be lax enough to let you get away with it.
That might work for your particular case, but it's the sort of behaviour
that leads to problems (validation errors or omissions, in particular)
in the general case.

Regards,
Malcolm


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



Passing a form a user before validation

2009-01-08 Thread DragonSlayre

I'm trying to generate a form with a user's details, so that they can
change the details they've submitted.

One of my forms is a ModelForm, which is the profile of the User
object.  I also want to show the first name, last name and email from
the User object, so I've created a form for that which validates the
email (to make sure no-one else has the same email).

Here's my view code so far:

@login_required
def change_my_account(request):
fireman = Fireman.objects.get(pk=request.user.get_profile().id)

if request.method == 'POST':
#also need to check my RegistrationFormSimple
form = FiremanForm(request.POST, instance=fireman)
if form.is_valid():
form.save()
else:
form =FiremanForm(instance=fireman)
data = {'first_name' : request.user.first_name,
'last_name'  : request.user.last_name,
'email'  : request.user.email}
userForm = RegistrationFormSimple(data)
return render_to_response('Change_account.html', {'form' : form,
  'user_form' :
userForm})

This works well, except that I have a validator in my
RegistrationFormSimple, which needs to know who the user is, to check
the emails.

I'm stumped about how I give this information to my
RegistrationFormSimple.

Any help would be greatly 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: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread rabbi

I've solved it.
In case anyone has the same problem, I think it's because
'created_date' is set to auto_now, which means it's not editable and
should be in fieldsets

This link was helpful:
http://www.nabble.com/-Django-Code---7993:-Admin-complains-about-a-missing-field-even-if-it-is-not-missing-td18680119.html

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



Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread rabbi

I get the same exception(s)

The 1st time I try to import swenglish.admin I get:
ImproperlyConfigured: 'EntryAdmin.fieldsets[3][1]['fields']' refers to
field 'created_date' that is missing from the form.

The 2nd time I try to import swenglish.admin I get:
AlreadyRegistered: The model User is already registered

These are the same exceptions that I get when trying to load the admin
page.
The 1st time I try to load admin page I get ImproperlyConfigured
After I press refresh (and every subsequent refresh) I get
AlreadyRegistered


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



Re: Django Models + ManyToMany

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 7:08 PM, rabbi  wrote:

>
> Thanks Karen,
> I actually deleted the thread soon after posting it as I came across
> what you have written above.
> Somehow you still managed to reply to a deleted thread though...?
> Impressive
>

I don't use the Google groups  interface to read the group, I read it as
mail.  Deleting the message from the group doesn't remove it from the
mailboxes of anyone who gets email copies of messages.

Karen

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



Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 6:33 PM, rabbi  wrote:

>
> OK, thanks
> I also tried deleting the db file and then calling syncdb again... it
> didn't help
> Do you have any suggestions?
>

Try importing your admin.py from a manage.py shell prompt, and see if that
shows a more useful exception.

Karen

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



Re: get_profile not working (get_model returns None)

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 6:24 PM, Hans Fangohr  wrote:

>
>
> Dear all,
>
> I have difficulties with the get_profile to link my Profile class with
> the inbuilt User object.
>
> The error message (which can be obtained through the 'chatroom' view
> shown below, or via the shell) is:
>
> ---
> AttributeErrorTraceback (most recent call
> last)
>
> /Users/fangohr/local/hg/scico_web/debug/mysite/ in
> ()
>
> /Library/Frameworks/Python.framework/Versions/4.0.30002/lib/python2.5/
> site-packages/django/contrib/auth/models.pyc in get_profile(self)
>291 app_label, model_name =
> settings.AUTH_PROFILE_MODULE.split('.')
>292 model = models.get_model(app_label, model_name)
> --> 293 self._profile_cache =
> model._default_manager.get(user__id__exact=self.id)
>294 except (ImportError, ImproperlyConfigured):
>295 raise SiteProfileNotAvailable
>
> AttributeError: 'NoneType' object has no attribute '_default_manager'
>
>
> This indicates that models.get_model() does return None, but I don't
> know why.
>
> I have in settings.py:
> AUTH_PROFILE_MODULE = 'people.profile'
> which I believe is the right entry.
>
>
(Thanks for the very detailed question.) I think you have found a
documentation bug.  I do not believe the 'people' part of that should be
normalized to lower case.  It is not normalized to lower case in
INSTALLED_APPS, and I don't think it should be normalized to lower case
here.  Since you have a capital P in People for your directory name, try
'People.profile'.

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



How to change a TabularInline widget size

2009-01-08 Thread Luis Miguel Morillas

When I use a TabularInline class, type text inputs haven't a correct
size, so I'm getting too large lines for input:

 

How can I add a size attribute to this input?.  I want size to have
the maxlength value.

This is my code:

class BidonInline(admin.TabularInline):
model = Bidon

class BidonAdmin(admin.ModelAdmin):
inlines = [
BidonInline,
]

-- lm
--~--~-~--~~~---~--~~
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: bug in models.Model __str__ return and non-ascii characters !?

2009-01-08 Thread adrian

thank you very much. i am using version 1.0.2 right now.
i think i started with django at version 0.95. that time they used
__str__ (i just checked that in my local-copy-archive of the docs for
0.95/0.96) in the tutorial - and i kept that until now.

so with __unicode__ instead of __str__ it works the way i expected it.
thank you very much for your help!



On Jan 9, 1:12 am, "Karen Tracey"  wrote:
> On Thu, Jan 8, 2009 at 6:14 PM, adrian  wrote:
>
> > hi,
> > i am posting here to follow the "i found a bug" guide ...
>
> > let's assume i have a model like this:
>
> > ---
> > class Test(models.Model):
> >    testname = models.CharField(max_length=60, null=False,
> > blank=False, unique=True)
> >    [... some more fields ...]
> >    def __str__(self):
> >        return self.testname
> > --
>
> > this models works perfectly as long as users only use ascii-characters
> > in the testname field. as soon as a user (in django.admin) enters a
> > german umlaut -for example- an error is thrown like this:
>
> > Caught an exception while rendering: ('ascii', u'German Umlaut\xfc',
> > 20, 21, 'ordinal not in range(128)')
>
> > this error is reproducable with different database backends (i tested
> > sqlite3 and psycopg2) and the model above is reduced to the minimum to
> > reproduce. (probably you could remove null, blank and unique
>
> > i don't know where the error is produced, wether it is when the
> > template uses something like {{Test}} because {{Test.testname}}
> > works ... if 'testname' is used as foreignkey in other models and the
> > admin interface wants to render this as a dropdown with probably
> > something like 

Re: bug in models.Model __str__ return and non-ascii characters !?

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 6:14 PM, adrian  wrote:

>
> hi,
> i am posting here to follow the "i found a bug" guide ...
>
> let's assume i have a model like this:
>
> ---
> class Test(models.Model):
>testname = models.CharField(max_length=60, null=False,
> blank=False, unique=True)
>[... some more fields ...]
>def __str__(self):
>return self.testname
> --
>
> this models works perfectly as long as users only use ascii-characters
> in the testname field. as soon as a user (in django.admin) enters a
> german umlaut -for example- an error is thrown like this:
>
> Caught an exception while rendering: ('ascii', u'German Umlaut\xfc',
> 20, 21, 'ordinal not in range(128)')
>
> this error is reproducable with different database backends (i tested
> sqlite3 and psycopg2) and the model above is reduced to the minimum to
> reproduce. (probably you could remove null, blank and unique
>
> i don't know where the error is produced, wether it is when the
> template uses something like {{Test}} because {{Test.testname}}
> works ... if 'testname' is used as foreignkey in other models and the
> admin interface wants to render this as a dropdown with probably
> something like 

Re: Django Models + ManyToMany

2009-01-08 Thread rabbi

Thanks Karen,
I actually deleted the thread soon after posting it as I came across
what you have written above.
Somehow you still managed to reply to a deleted thread though...?
Impressive

On Jan 9, 1:04 am, "Karen Tracey"  wrote:
> On Thu, Jan 8, 2009 at 12:06 PM, rabbi  wrote:
>
> > Hi,
> > I have a question that is probably very simple to answer.
>
> > class Example(models.Model):
> >    value = models.CharField(max_length=200)
> >    related_examples = models.ManyToMany
> > ('self',related_name='related_example_set')
>
> > If I define a ManyToMany relationship like the one above and I want to
> > access all Example's that are related to a specific Example instance,
> > which of the following methods should I use?
>
> >   1) related_examples.all()
> >   2) related_examples.all().append(related_example_set.all())
>
> > The reason I ask is that it is possible that one instance is assigned
> > a relationship to another instance, but the relationship is not
> > defined in the other direction.
>
> > E.g. x.add(y) BUT NOT y.add(x)
>
> ManyToMany fields to 'self' are symmetrical by default:
>
> http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod...
>
> Since you have not specified symmetrical=False I do not think your 2nd
> option will even work, since per the docs the example_set attribute will not
> be created for a symmetrical ManyToMany relationship to 'self'.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models + ManyToMany

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 12:06 PM, rabbi  wrote:

>
> Hi,
> I have a question that is probably very simple to answer.
>
> class Example(models.Model):
>value = models.CharField(max_length=200)
>related_examples = models.ManyToMany
> ('self',related_name='related_example_set')
>
> If I define a ManyToMany relationship like the one above and I want to
> access all Example's that are related to a specific Example instance,
> which of the following methods should I use?
>
>   1) related_examples.all()
>   2) related_examples.all().append(related_example_set.all())
>
> The reason I ask is that it is possible that one instance is assigned
> a relationship to another instance, but the relationship is not
> defined in the other direction.
>
> E.g. x.add(y) BUT NOT y.add(x)
>
>
ManyToMany fields to 'self' are symmetrical by default:

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyFields.symmetrical

Since you have not specified symmetrical=False I do not think your 2nd
option will even work, since per the docs the example_set attribute will not
be created for a symmetrical ManyToMany relationship to 'self'.

Karen

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



Re: upload_to not found

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 3:16 PM, Kottiyath Nair wrote:

> Hi,
>   I was trying out a form - with filefield. I used the option upload_to,
> and django server erred out saying - upload_to not found.
>   I checked django code :
> >>> import django
> >>> django.VERSION
> (1, 0, 2, 'final', 0)
>
> class FileField(Field):
> widget = FileInput
> default_error_messages = {
> 'invalid': _(u"No file was submitted. Check the encoding type on
> the form."),
> 'missing': _(u"No file was submitted."),
> 'empty': _(u"The submitted file is empty."),
> }
>
> def __init__(self, *args, **kwargs):
> super(FileField, self).__init__(*args, **kwargs)
>
> --> As we can see there is no upload_to parameter in it. I am sure I am
> missing something because upload_to seems to be the basic option as per
> documents.
> Can somebody help me out?
>
>
upload_to is a parameter for model FileFields:

http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

not form FileFields:

http://docs.djangoproject.com/en/dev/ref/forms/fields/#filefield

Karen

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



Re: ModelForm: exclude fields missing in request

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 11:34 AM, Flo Ledermann
wrote:

>
> Hi all,
>
> after some more thinking, the workaround I came up with is now:
>
> if form.is_valid():
>for key in form.cleaned_data.keys():
>if not key in request.POST: del form.cleaned_data[key]
>form.save()
>
> This removes all values that are not found in the original request
> from the form data before saving. Is this the way the pro's in this
> group would do it?
>
> I could still see some demand to put this into the core form logic
> (controllable by a flag), what do you think?
>
> Best regards and shout outs to everyone using Django,
>

Is there some reason you are not simply using exclude in Meta for the form
to avoid having these fields present in the form at all:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

?

Karen

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



Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread rabbi

OK, thanks
I also tried deleting the db file and then calling syncdb again... it
didn't help
Do you have any suggestions?

On Jan 9, 12:17 am, adrian  wrote:
> syncdb does not modify already existing tables.
> so if you modified a model - syncdb will not modify the tables 
>
> On Jan 9, 12:01 am, rabbi  wrote:
>
> > Hi,
> > I've search around a bit and found a few references to this error, but
> > it seems that everyone else was getting this when they migrated to
> > Django 1.0 and newforms... for me it's a different situation, as I
> > started on 1.0 from the beginning
>
> > Background:
> > Went through tutorial, got a basic site working fine on runserver
> > Migrated site to Apache, site worked fine
>
> > I wanted to extend the site a bit, so I modified the models and
> > performed the following steps:
> >    modified models.py (changed existing and added new)
> >    modifed admin.py accordingly
> >    ran python manage.py syncdb
> >    restarted Apache
> >    ALREADY REGISTERED error
> >    deleted existing db file
> >    ran python manage.py syncdb
> >    ALREADY REGISTERED error
>
> > Does anyone have any suggestions?
>
> > Thanks,
> > Alex
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



get_profile not working (get_model returns None)

2009-01-08 Thread Hans Fangohr


Dear all,

I have difficulties with the get_profile to link my Profile class with
the inbuilt User object.

The error message (which can be obtained through the 'chatroom' view
shown below, or via the shell) is:

---
AttributeErrorTraceback (most recent call  
last)

/Users/fangohr/local/hg/scico_web/debug/mysite/ in  
()

/Library/Frameworks/Python.framework/Versions/4.0.30002/lib/python2.5/ 
site-packages/django/contrib/auth/models.pyc in get_profile(self)
291 app_label, model_name =  
settings.AUTH_PROFILE_MODULE.split('.')
292 model = models.get_model(app_label, model_name)
--> 293 self._profile_cache =  
model._default_manager.get(user__id__exact=self.id)
294 except (ImportError, ImproperlyConfigured):
295 raise SiteProfileNotAvailable

AttributeError: 'NoneType' object has no attribute '_default_manager'


This indicates that models.get_model() does return None, but I don't  
know why.

I have in settings.py:
AUTH_PROFILE_MODULE = 'people.profile'
which I believe is the right entry.


For clarity, I have created a small django-site that can be downloaded  
in a tar file as:

http://www.soton.ac.uk/~fangohr/geheim/django/get_profile/debug.tar.gz

or can be viewed online in the untarred version at

http://www.soton.ac.uk/~fangohr/geheim/django/get_profile/debug

I summarise the most important elements below (so that this email can  
stand on its own for the archives):


mysite/People/models.py contains:

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

class Profile(models.Model):
user = models.ForeignKey(User,unique=True)
homepageURL=models.URLField('homepage',blank=True)

class Admin:
pass
#---

The corresponding view (which fails) is in mysite/People/views.py:
#---
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required


def chatrooms(request):
u = User.objects.get(pk=1) # Get the first user
user_address = u.get_profile().homepageURL
#at this point we get an error, equivalent to shell example
#---

The mysite/settings.py reads

#---
# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'   # 'postgresql_psycopg2',  
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'test.dat' # Or path to database file if  
using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.  
Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not  
used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as  
your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as  
not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com;, "http://example.com/media/;
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure  
to use a
# trailing slash.
# Examples: "http://foo.com/media/;, "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

AUTH_PROFILE_MODULE = 'people.profile'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'afxb6gs$x!8o3z5...@4#g0^z_mpuscs1=#c700@cdpvn^&51@'

# List of callables that know how to import templates from various  
sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'mysite.urls'
#ROOT_URLCONF = 'urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/ 
django/templates".
# Always use forward slashes, even on Windows.
# 

Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread adrian

syncdb does not modify already existing tables.
so if you modified a model - syncdb will not modify the tables 

On Jan 9, 12:01 am, rabbi  wrote:
> Hi,
> I've search around a bit and found a few references to this error, but
> it seems that everyone else was getting this when they migrated to
> Django 1.0 and newforms... for me it's a different situation, as I
> started on 1.0 from the beginning
>
> Background:
> Went through tutorial, got a basic site working fine on runserver
> Migrated site to Apache, site worked fine
>
> I wanted to extend the site a bit, so I modified the models and
> performed the following steps:
>    modified models.py (changed existing and added new)
>    modifed admin.py accordingly
>    ran python manage.py syncdb
>    restarted Apache
>    ALREADY REGISTERED error
>    deleted existing db file
>    ran python manage.py syncdb
>    ALREADY REGISTERED error
>
> Does anyone have any suggestions?
>
> Thanks,
> Alex

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



bug in models.Model __str__ return and non-ascii characters !?

2009-01-08 Thread adrian

hi,
i am posting here to follow the "i found a bug" guide ...

let's assume i have a model like this:

---
class Test(models.Model):
testname = models.CharField(max_length=60, null=False,
blank=False, unique=True)
[... some more fields ...]
def __str__(self):
return self.testname
--

this models works perfectly as long as users only use ascii-characters
in the testname field. as soon as a user (in django.admin) enters a
german umlaut -for example- an error is thrown like this:

Caught an exception while rendering: ('ascii', u'German Umlaut\xfc',
20, 21, 'ordinal not in range(128)')

this error is reproducable with different database backends (i tested
sqlite3 and psycopg2) and the model above is reduced to the minimum to
reproduce. (probably you could remove null, blank and unique

i don't know where the error is produced, wether it is when the
template uses something like {{Test}} because {{Test.testname}}
works ... if 'testname' is used as foreignkey in other models and the
admin interface wants to render this as a dropdown with probably
something like 

Re: AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread rabbi

here's my admin.py

from mysite.swenglish.models import User
from mysite.swenglish.models import Entry
from mysite.swenglish.models import Category
from mysite.swenglish.models import Language
from django.contrib import admin

class UserAdmin(admin.ModelAdmin):
list_display = ('name', 'password')

class EntryAdmin(admin.ModelAdmin):
fieldsets = [
(None,{'fields': ['value']}),
('Created Details',{'fields': ['created_date','created_user'],
'classes': ['collapse']}),
('Language & Category',{'fields': ['language','category'],
'classes': ['collapse']}),
('Translations',{'fields': ['translations'], 'classes':
['collapse']}),
]
list_filter = ['value']
search_fields = ['created_user','category']
date_hierarchy = 'created_date'

class CategoryAdmin(admin.ModelAdmin):
fieldsets = [
(None,{'fields': ['value']}),
('Created Details',{'fields': ['created_date','created_user'],
'classes': ['collapse']}),
('Language',{'fields': ['language'], 'classes':
['collapse']}),
('Translations',{'fields': ['translations'], 'classes':
['collapse']}),
]
list_filter = ['value']
search_fields = ['created_user']
date_hierarchy = 'created_date'

class LanguageAdmin(admin.ModelAdmin):
fieldsets = [
(None,{'fields': ['value','value_english']}),
('Created Details',{'fields': ['created_date','created_user'],
'classes': ['collapse']}),
('Translations',{'fields': ['translations'], 'classes':
['collapse']}),
]
list_filter = ['value']
search_fields = ['created_user','value_english']
date_hierarchy = 'created_date'

admin.site.register(User,UserAdmin)
admin.site.register(Entry,EntryAdmin)
admin.site.register(Category,CategoryAdmin)
admin.site.register(Language,LanguageAdmin)

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



AlreadyRegistered at /admin/, The model #### is already registered

2009-01-08 Thread rabbi

Hi,
I've search around a bit and found a few references to this error, but
it seems that everyone else was getting this when they migrated to
Django 1.0 and newforms... for me it's a different situation, as I
started on 1.0 from the beginning

Background:
Went through tutorial, got a basic site working fine on runserver
Migrated site to Apache, site worked fine

I wanted to extend the site a bit, so I modified the models and
performed the following steps:
   modified models.py (changed existing and added new)
   modifed admin.py accordingly
   ran python manage.py syncdb
   restarted Apache
   ALREADY REGISTERED error
   deleted existing db file
   ran python manage.py syncdb
   ALREADY REGISTERED error

Does anyone have any suggestions?

Thanks,
Alex
--~--~-~--~~~---~--~~
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: Iterate over model database fields

2009-01-08 Thread Matias Surdi

Great!!

I think that the _meta attribute will be enough. I think that if I 
define a method on the base model of all my models something like 
get_fields() it could then return a list of the fields by accessing 
self._meta.fields, and this get_fields should be accessible from 
templates,shouldn't it?.

Thanks for your help :-)


bruno desthuilliers wrote:
> On 8 jan, 16:22, Matias Surdi  wrote:
>> Is there any way to iterate over all the fields in a model instance on a
>> template?
> 
> Not directly. The fields names are accessible thru the
> model_instance._meta attribute, and you cannot access '_protected'
> attributes in a template.
> 
>> I'd like to have a "default" template which iterates over whatever model
>> yo give it and prints all its field on a table.
> 
> You'll have to write a (simple) view that returns the model instance's
> fields names and values as context. But that's mostly trivial once you
> know how to get field names and values from an instance (which has
> already been explained here - but feel free to ask if you fail to find
> the relevant posts).
> 
> 
> > 
> 


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



Re: django design methods

2009-01-08 Thread bruno desthuilliers

On 8 jan, 19:33, chiggsy  wrote:
> A meta question about django:  how do people design dango apps?

Like any other. Domain analysis to get the models (database schema,
mostly), functional analysis to get the use cases (urls and views),
and common sense to fill the gaps.

> I understand that the urlconf really is a map of the application, and
> that works for me.  As for applications, I think that they are pieces
> of functionality and i have few problems with that.

Well, just everything in a program is a "piece of functionality", so
this doesn't mean much.

> However:
>
> when i try to mix and match apps i find ( which is the point of having
> apps no? )

Partly. You're not forced into reusing the _whole_ app - you can
override and/or extend whole parts of it (templates, urls, views etc -
mostly, anything but the models). Most of the times, I have one
"project-app" where I override/extend existings "pluggable" apps so
they fit my needs.

> I tend to create projects that have a mishmash of css/
> javascript libraries.  ie I like YUI-grids, whilst someone else likes
> blueprint css, I like mookit, while others like jquery especially in
> templates...   How are other people fighting this problem ?

I personnaly avoid any such external dependencies in my own apps -
except of course for the "project" app(s) - and don't even try to
reuse third-part apps that are too tightly coupled to a specific js or
css library - unless they in fact just provide helpers for using one
of these libraries that I happen to use in a given project, but then
it's a different story.

But anyway : the less reusable parts of a pluggable app are the
templates - heck, that the very first thing you're going to override
for any project.

--~--~-~--~~~---~--~~
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: Iterate over model database fields

2009-01-08 Thread bruno desthuilliers

On 8 jan, 16:22, Matias Surdi  wrote:
> Is there any way to iterate over all the fields in a model instance on a
> template?

Not directly. The fields names are accessible thru the
model_instance._meta attribute, and you cannot access '_protected'
attributes in a template.

> I'd like to have a "default" template which iterates over whatever model
> yo give it and prints all its field on a table.

You'll have to write a (simple) view that returns the model instance's
fields names and values as context. But that's mostly trivial once you
know how to get field names and values from an instance (which has
already been explained here - but feel free to ask if you fail to find
the relevant posts).


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

2009-01-08 Thread Marco Buttu

On Wed, 2009-01-07 at 13:06 +, Adam Stein wrote:

> I have omnicomplete working (haven't used it too much yet).  I have
> this
> in my $HOME/.vimrc file:
...
> Also, I have vim starting automatically importing the Django db.  I
> have
> a little script (below) that will automatically find my settings.py
> file
> and start vim.  I do this by starting at the location of the file on
> the
> vim command line and working upwards in the directory structure until
> I
> find it:
...
> I only use Django on Unix/Linux so I'm guessing it would need some
> tweaking for Windows.

I am using PySmell to autocomplete Django code, but I think omnicomplete
is better. Tomorrow I'll try it :-)
Thanks
-- 
Marco Buttu


--~--~-~--~~~---~--~~
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: Is Django best for modular extensible projects?

2009-01-08 Thread bruno desthuilliers

On 8 jan, 19:05, walterbyrd  wrote:
(nb: reinjecting the question in the post's body)

>  Is Django best for modular extensible projects?

"best" compared to what ?-)

> For example, let's suppose you wanted to create a application that
> would be fairly easy to extend by creating new modules.
>
> I don't really know django, but I get the idea that django would be a
> decent solution for a project  like that.

Mmm That's not quite the basic philosophy of Django apps IMHO.
It's mote about writing small, focused and reusable components
("apps") that you can reuse in different "projects", than about a true
plugin system. Not that you cannot write an "extensible" (thru a
plugin architecture) system in Django - heck, it's basically Python
code, and Python is pretty good here -, but the notion of "pluggable"
apps in Django is quite different from, let's say, Trac plugins
system.


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



upload_to not found

2009-01-08 Thread Kottiyath Nair
Hi,
  I was trying out a form - with filefield. I used the option upload_to, and
django server erred out saying - upload_to not found.
  I checked django code :
>>> import django
>>> django.VERSION
(1, 0, 2, 'final', 0)

class FileField(Field):
widget = FileInput
default_error_messages = {
'invalid': _(u"No file was submitted. Check the encoding type on the
form."),
'missing': _(u"No file was submitted."),
'empty': _(u"The submitted file is empty."),
}

def __init__(self, *args, **kwargs):
super(FileField, self).__init__(*args, **kwargs)

--> As we can see there is no upload_to parameter in it. I am sure I am
missing something because upload_to seems to be the basic option as per
documents.
Can somebody help me out?

Regards
K

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



django design methods

2009-01-08 Thread chiggsy

A meta question about django:  how do people design dango apps?

I understand that the urlconf really is a map of the application, and
that works for me.  As for applications, I think that they are pieces
of functionality and i have few problems with that.

However:

when i try to mix and match apps i find ( which is the point of having
apps no? ) I tend to create projects that have a mishmash of css/
javascript libraries.  ie I like YUI-grids, whilst someone else likes
blueprint css, I like mookit, while others like jquery especially in
templates...   How are other people fighting this problem ?


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



project for hire

2009-01-08 Thread Chad

Available for 6-30 hour django project?
To find out more please contact c...@brattiss.com

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



Re: best way to do tabs?

2009-01-08 Thread Margie

Yes, I agree, my main problem is figuring out how to avoid rewriting
the css files.  I will look at that link and the active class, that
sounds like it's a good way to go.  Thanks!!

On Jan 8, 9:40 am, "Ariel Mauricio Nunez Gomez"
 wrote:
> Since I think you are not (yet) using AJAX, all the logic you need should be
> available to the template already.
> Your main issue sems to be not having to rewrite any css files but only
> change the html item 'class' attribute. The last link and code snippet on my
> previous mail address that issue(Using an 'active' class on the selected
> item, you can dynamically set it on your template).
>
> Take some time to play with it and let us know how it goes.
>
> Frameworks like jquery can also create and change css styles on the fly,
> like I said I see it as an overkill for such a simple task, but it is your
> bikeshed and you get to paint it any color you may want :)
>
> Ariel.
>
>
>
> On Thu, Jan 8, 2009 at 12:30 PM, Margie  wrote:
>
> > I think the issue I have is that I seem to need to maintain "state".
> > Let me use a contrived example.
>
> > Suppose I have three tabs:  books-tab, music-tab, and video-tab.  When
> > I click on books-tab, I get a subnav bar with three subnav tabs:
> > "books about animals", "books about video", "books about places".  And
> > similarly, when I click on music-tab I get 3 different subnav tabs:
> > music-1, music-2, music-3.  When I click on books-tab, I want books-
> > tab to darken.  When I then clock on "books about video", I want books-
> > tab to stay dark and books about video"  to also darken.  It seems
> > that when I use css, when I go to the "books about video" html page, I
> > must "remember" to set a special id that makes books-tab darken.   It
> > seems that the html for "books about video" has to know it is being
> > called on behalf of the books tab, which seems inflexible. For
> > example, say I wanted to create a "books about video" under video-tab,
> > the html for "books about video" needs to now set a different id in
> > order to darken the video tab instead of the books tab.  Basically,
> > the html for "books about video" needs to know which tab it is being
> > invoked by - this seems bad.
>
> > I haven't had a chance to look at your links below in any detail, but
> > do you think they address this?  Does javascript or jquery or yui
> > address this issue in a way that is significantly different from css?
> > I know I have to start looking into those tools so I at least
> > understand what they provide.
>
> > And secondly, what about creating dynamic tabs?  Ie, if the usr is
> > going to click on something that ends up creating a new tab, how can
> > css address this at all?  I mean, in the css one needs to up front
> > have knowledge of the ids that cause the tabs to darken.  If each tab
> > has its own id and you are creating them dynamically, it seems like
> > the static nature of css just can't deal with this.
>
> > On Jan 8, 8:29 am, "Ariel Mauricio Nunez Gomez"
> >  wrote:
> > > Margie, I agree the current metod for adding new tabs in Pinax is kind of
> > > cumbersome.
>
> > > I also think ther is no need for javascript for that kind of simle stuff
> > > (i.e. This would be an overkillhttp://
> > blog.evaria.com/wp-content/themes/blogvaria/jquery/index-multi...)
> > > Perhaps you may want to search for more 'css menu' examples, I think you
> > can
> > > getaway with just using two classes 'selected' and 'normal'
>
> > > Like this guys do:
> >http://www.3point7designs.com/blog/2007/12/22/advanced-css-menu-trick...
>
> > > >   
> > > >     > > > title="Home Page">Home Page
> > > >    About Us
> > > >     > title="Web
> > > > Design and Development">Web Design
> > > >    Graphic Designs
> > > >    Search Engine
> > > > Optimization SEO
> > > >     > > > title="Contact Us">Contact Us
> > > >    
>
> > > Ariel.- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Is Django best for modular extensible projects?

2009-01-08 Thread walterbyrd

For example, let's suppose you wanted to create a application that
would be fairly easy to extend by creating new modules.

I don't really know django, but I get the idea that django would be a
decent solution for a project  like that.
--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread Ariel Mauricio Nunez Gomez
Since I think you are not (yet) using AJAX, all the logic you need should be
available to the template already.
Your main issue sems to be not having to rewrite any css files but only
change the html item 'class' attribute. The last link and code snippet on my
previous mail address that issue(Using an 'active' class on the selected
item, you can dynamically set it on your template).

Take some time to play with it and let us know how it goes.

Frameworks like jquery can also create and change css styles on the fly,
like I said I see it as an overkill for such a simple task, but it is your
bikeshed and you get to paint it any color you may want :)

Ariel.
On Thu, Jan 8, 2009 at 12:30 PM, Margie  wrote:

>
> I think the issue I have is that I seem to need to maintain "state".
> Let me use a contrived example.
>
> Suppose I have three tabs:  books-tab, music-tab, and video-tab.  When
> I click on books-tab, I get a subnav bar with three subnav tabs:
> "books about animals", "books about video", "books about places".  And
> similarly, when I click on music-tab I get 3 different subnav tabs:
> music-1, music-2, music-3.  When I click on books-tab, I want books-
> tab to darken.  When I then clock on "books about video", I want books-
> tab to stay dark and books about video"  to also darken.  It seems
> that when I use css, when I go to the "books about video" html page, I
> must "remember" to set a special id that makes books-tab darken.   It
> seems that the html for "books about video" has to know it is being
> called on behalf of the books tab, which seems inflexible. For
> example, say I wanted to create a "books about video" under video-tab,
> the html for "books about video" needs to now set a different id in
> order to darken the video tab instead of the books tab.  Basically,
> the html for "books about video" needs to know which tab it is being
> invoked by - this seems bad.
>
> I haven't had a chance to look at your links below in any detail, but
> do you think they address this?  Does javascript or jquery or yui
> address this issue in a way that is significantly different from css?
> I know I have to start looking into those tools so I at least
> understand what they provide.
>
> And secondly, what about creating dynamic tabs?  Ie, if the usr is
> going to click on something that ends up creating a new tab, how can
> css address this at all?  I mean, in the css one needs to up front
> have knowledge of the ids that cause the tabs to darken.  If each tab
> has its own id and you are creating them dynamically, it seems like
> the static nature of css just can't deal with this.
>
>
> On Jan 8, 8:29 am, "Ariel Mauricio Nunez Gomez"
>  wrote:
> > Margie, I agree the current metod for adding new tabs in Pinax is kind of
> > cumbersome.
> >
> > I also think ther is no need for javascript for that kind of simle stuff
> > (i.e. This would be an overkillhttp://
> blog.evaria.com/wp-content/themes/blogvaria/jquery/index-multi...)
> > Perhaps you may want to search for more 'css menu' examples, I think you
> can
> > getaway with just using two classes 'selected' and 'normal'
> >
> > Like this guys do:
> http://www.3point7designs.com/blog/2007/12/22/advanced-css-menu-trick/http://www.3point7designs.com/keyword-optimization/michigan-seo.html
> >
> >
> >
> >
> >
> > >   
> > > > > title="Home Page">Home Page
> > >About Us
> > > title="Web
> > > Design and Development">Web Design
> > >Graphic Designs
> > >Search Engine
> > > Optimization SEO
> > > > > title="Contact Us">Contact Us
> > >
> >
> > Ariel.- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: best way to do tabs?

2009-01-08 Thread Margie

I think the issue I have is that I seem to need to maintain "state".
Let me use a contrived example.

Suppose I have three tabs:  books-tab, music-tab, and video-tab.  When
I click on books-tab, I get a subnav bar with three subnav tabs:
"books about animals", "books about video", "books about places".  And
similarly, when I click on music-tab I get 3 different subnav tabs:
music-1, music-2, music-3.  When I click on books-tab, I want books-
tab to darken.  When I then clock on "books about video", I want books-
tab to stay dark and books about video"  to also darken.  It seems
that when I use css, when I go to the "books about video" html page, I
must "remember" to set a special id that makes books-tab darken.   It
seems that the html for "books about video" has to know it is being
called on behalf of the books tab, which seems inflexible. For
example, say I wanted to create a "books about video" under video-tab,
the html for "books about video" needs to now set a different id in
order to darken the video tab instead of the books tab.  Basically,
the html for "books about video" needs to know which tab it is being
invoked by - this seems bad.

I haven't had a chance to look at your links below in any detail, but
do you think they address this?  Does javascript or jquery or yui
address this issue in a way that is significantly different from css?
I know I have to start looking into those tools so I at least
understand what they provide.

And secondly, what about creating dynamic tabs?  Ie, if the usr is
going to click on something that ends up creating a new tab, how can
css address this at all?  I mean, in the css one needs to up front
have knowledge of the ids that cause the tabs to darken.  If each tab
has its own id and you are creating them dynamically, it seems like
the static nature of css just can't deal with this.


On Jan 8, 8:29 am, "Ariel Mauricio Nunez Gomez"
 wrote:
> Margie, I agree the current metod for adding new tabs in Pinax is kind of
> cumbersome.
>
> I also think ther is no need for javascript for that kind of simle stuff
> (i.e. This would be an 
> overkillhttp://blog.evaria.com/wp-content/themes/blogvaria/jquery/index-multi...)
> Perhaps you may want to search for more 'css menu' examples, I think you can
> getaway with just using two classes 'selected' and 'normal'
>
> Like this guys 
> do:http://www.3point7designs.com/blog/2007/12/22/advanced-css-menu-trick/http://www.3point7designs.com/keyword-optimization/michigan-seo.html
>
>
>
>
>
> >   
> >     > title="Home Page">Home Page
> >    About Us
> >    Web Design
> >    Graphic Designs
> >    Search Engine
> > Optimization SEO
> >     > title="Contact Us">Contact Us
> >    
>
> Ariel.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Models + ManyToMany

2009-01-08 Thread rabbi

Hi,
I have a question that is probably very simple to answer.

class Example(models.Model):
value = models.CharField(max_length=200)
related_examples = models.ManyToMany
('self',related_name='related_example_set')

If I define a ManyToMany relationship like the one above and I want to
access all Example's that are related to a specific Example instance,
which of the following methods should I use?

   1) related_examples.all()
   2) related_examples.all().append(related_example_set.all())

The reason I ask is that it is possible that one instance is assigned
a relationship to another instance, but the relationship is not
defined in the other direction.

E.g. x.add(y) BUT NOT y.add(x)

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



Re: Problems with locale of dates queryset

2009-01-08 Thread motard

I've been playing around with my settings file and have included a
DATE_FORMAT and a DATETIME_FORMAT setting.

DATETIME_FORMAT = 'j F Y H:i'

DATE_FORMAT = 'j F Y'

When using the date template filter on a date or datetime variable, I
get my dates formatted in the format set in DATE_FORMAT.

{{ myvariable|date }}

This outputs to something like '24 december 2008' independently if
this is a date or datetime variable.

Shouldn't this filter use the DATETIME_FORMAT if the provided variable
is a datetime one?

Is this the correct way to handle localized date and datetime formats
in django?

Regards, Stefan



On Jan 7, 3:52 pm, Stefan Tunsch  wrote:
> Hi!
>
> I'm trying to display a list of possible months in a queryset. I do so
> like this:
>
> premonths = MyModel.objects.dates('date_published', 'month')
> months = [m.strftime('%B') for m in premonths]
>
> The problem is that months get displayed in english instead of spanish,
> which is what I want.
>
> I have the following setting in my settings file, but it does not seem
> to do what I want:
>
> LANGUAGE_CODE = 'es-ES'
>
> I can indeed work out a solution doing something like this:
>
> premonths = MyModel.objects.dates('date_published', 'month')
> import locale
> locale.setlocale(locale.LC_TIME, "sp")
> months = [m.strftime('%B') for m in premonths]
>
> But I guess I'm missing something here...
>
> BTW, the problem of the wrong locale of dates is everywhere I use dates
> on my site, not only in this snippet.
>
> Regards, Stefan
--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread phoebebright

I guess google has reached the status of hoover and tarmac!

On Jan 8, 10:25 am, Matias Surdi  wrote:
>  > implement.  Just google YUI.
> Shoudn't it have been "yahoo for YUI" ?
>
> :-D
>
> phoebebright escribió:
>
> > I'm a great fan of YUI and they have some nice tabs that are easy to
> > implement.  Just google YUI.
>
> > On Jan 8, 10:03 am, Matias Surdi  wrote:
> >> JQuery UI?
>
> >> Margie escribió:
>
> >>> Hi,
> >>> This is not a directly a django question, but since django is the only
> >>> web framework I know (and it's really cool, by the way!) I hope it's
> >>> ok to post this here.
> >>> Could someone advise me on the "best" way to do tabs?  IE, I'd like to
> >>> have a set of tabs at the top of my page with a sub navigation bar
> >>> below.  I am currently using a mechanism that I got from the pinax
> >>> project - I use css similar to that in tabs.css, for those of you that
> >>> know pinax.  That css controls how the html classes are set up when
> >>> html is rendered for a particular tab, causing the tabs to look
> >>> "pressed" at the appropriate times.
> >>> I'm a newbie at web page design, so I don't have a good feeling for if
> >>> this is the right direction to be pursing.  I find the css code and
> >>> the way it interacts with site_base.html and base.html fairly
> >>> confusing and hard to maintain, so I'm wondering if there is a better
> >>> way.  Also (and more importantly) would like my tabs to be more
> >>> dynamic.  For example, based on the user clicking on something, I
> >>> would like to be able to add additional tabs.  It seems like using the
> >>> css mechanism in pinax makes that very difficult, because the css for
> >>> each tab has to be defined up front in order to get the shading right
> >>> when you click on a tab.
> >>> Can anyone advise me on what the best direction to go in is for having
> >>> nice tabs that are easy to undrestand?
> >>> I have not yet learned jquery or ajax, but they are on my list,
> >>> perhaps those provide better frameworks than css?  Anyway, any
> >>> pointers from those of you more experienced than me are appreciated!
> >>> 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
-~--~~~~--~~--~--~---



Re: very basic beginners question

2009-01-08 Thread Adam Yee


On Jan 8, 7:49 am, Evan  wrote:
> This is probably the most basic question in the history of the group.
> Still, I googled the error message both in this group and in google at
> large and went through the first 5 pages, and didn't see anything.
>
> i installed django a few weeks ago.  i'm pretty sure it's installed
> correctly.   i start on the first step of 
> thehttp://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01
> Django tutorial.   after typing django import into the command prompt,
> it tells me to type django-admin.py startproject mysite.   when i do
> that, i get this error message.
>
> File "", line 1
>
> i'm running this in Vista, btw.

It might not seem very clear in their wording, but they are telling
you to type in "django-admin.py startproject mysite" from the command
line prompt and not the Python IDE interpreter.  If it doesn't work,
the cmd line prompt will complain about the file not existing or batch
file thingy.  Something to that effect.  Read through carefully and
follow directions.  Make sure that you have django-admin.py in the
directory where you plan to make your project.  Or depending on if you
installed django with "python setup.py" you should have django-
admin.py on the system path.  Hph.
--~--~-~--~~~---~--~~
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: ModelForm: exclude fields missing in request

2009-01-08 Thread Flo Ledermann

Hi all,

after some more thinking, the workaround I came up with is now:

if form.is_valid():
for key in form.cleaned_data.keys():
if not key in request.POST: del form.cleaned_data[key]
form.save()

This removes all values that are not found in the original request
from the form data before saving. Is this the way the pro's in this
group would do it?

I could still see some demand to put this into the core form logic
(controllable by a flag), what do you think?

Best regards and shout outs to everyone using Django,

Flo

--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread Ariel Mauricio Nunez Gomez
Margie, I agree the current metod for adding new tabs in Pinax is kind of
cumbersome.

I also think ther is no need for javascript for that kind of simle stuff
(i.e. This would be an overkill
http://blog.evaria.com/wp-content/themes/blogvaria/jquery/index-multi.php)
Perhaps you may want to search for more 'css menu' examples, I think you can
getaway with just using two classes 'selected' and 'normal'

Like this guys do:
http://www.3point7designs.com/blog/2007/12/22/advanced-css-menu-trick/
http://www.3point7designs.com/keyword-optimization/michigan-seo.html

>   
> title="Home Page">Home Page
>About Us
>Web Design
>Graphic Designs
>Search Engine
> Optimization SEO
> title="Contact Us">Contact Us
>
>

Ariel.

--~--~-~--~~~---~--~~
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: subquery has too many columns

2009-01-08 Thread timc3


>
> We'll need a bit more information here, since the devil's always in the
> details. At a minimum, what is the output of
>
>         groupmembers.query.as_sql()
>
> There may be a problem with exclude and nested querysets. I just
> realised I haven't explicitly tested those.
>
> Also, which database are you using? There are lots of SQL variations
> between databases (for example, nested queries don't work with Oracle at
> the moment for an unusual reason that I'll fix later today).

I am using PostgreSQL 8.3.4 on OS X and on Linux. The output of that
command is:

('SELECT "auth_user"."id", "auth_user"."username",
"auth_user"."first_name", "auth_user"."last_name",
"auth_user"."email", "auth_user"."password", "auth_user"."is_staff",
"auth_user"."is_active", "auth_user"."is_superuser",
"auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user"
INNER JOIN "group_groupsofuser_group_members" ON ("auth_user"."id" =
"group_groupsofuser_group_members"."user_id") WHERE
("group_groupsofuser_group_members"."groupsofuser_id" = %s  AND NOT
("auth_user"."id" IN (SELECT U0."id", U0."id" FROM "auth_user" U0
INNER JOIN "group_groupsofuser_group_admins" U1 ON (U0."id" =
U1."user_id") WHERE U1."groupsofuser_id" = %s )))',
 (1, 1))

And my model looks like this:

class GroupsOfUser(models.Model):
"""
Groups containing users for allowing them to build communities
"""
name = models.CharField(_("Name"), max_length=50)
description = models.TextField(_("Description"), blank=True,
help_text=_("Optional"))
slug = models.SlugField()
group_members = models.ManyToManyField(User, verbose_name="group
members", related_name="groupofumembers")
group_admins = models.ManyToManyField(User, verbose_name="group
admins", related_name="groupofuadmins")
group_owner = models.ForeignKey(User, verbose_name="group owner",
related_name="groupofuowner")
date_created = models.DateTimeField(_("Creation date"),
auto_now_add=True)
closed_group = models.BooleanField(_("Closed group"),
default=False)
request_to_join = models.BooleanField(_("Users have to request to
join"), default=False)
adult_content = models.BooleanField(_("18 and above only"),
default=False)
group_picture = models.ImageField(_("Group image"),
upload_to="groupsimage/", blank=True, null=True)

def __str__(self):
return self.name

def save(self):
self.slug = slugify(self.name, instance=self)
super(GroupsOfUser, self).save()

class Meta:
ordering = ['-date_created']

def get_absolute_url(self):
return ('groupdetail', [str(self.slug)])
get_absolute_url = models.permalink(get_absolute_url)


In my views:

try:
requestedgroup = GroupsOfUser.objects.select_related().get
(slug=slug)
except GroupsOfUser.DoesNotExist:
objTemplate = loader.get_template('groups/
group_notfound.html')
objContext = RequestContext(request, {
'slug': slug,
})
return HttpResponse(objTemplate.render(objContext))

# Bring back the requests for this group we might be an
administrator for.
groupadminfor = request.user.groupofuadmins.all()
groupreq = GroupsOfUserRequest.objects.filter(to_group__in = [grp
for grp in groupadminfor]).filter(to_group =
requestedgroup).select_related()
isgroupadmin = request.user.groupofuadmins.filter(id =
requestedgroup.id)
ismember = request.user.groupofumembers.filter(id =
requestedgroup.id)

#Check to make sure that this isn't a closed group
if requestedgroup.closed_group == True and ismember.count() < 1:
logging.info('User trying to get to closed group')
raise Http404

groupadmins = requestedgroup.group_admins.values_list('id',
flat=True)
groupmembers = requestedgroup.group_members.exclude
(id__in=groupadmins)


Any help will 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
-~--~~~~--~~--~--~---



very basic beginners question

2009-01-08 Thread Evan

This is probably the most basic question in the history of the group.
Still, I googled the error message both in this group and in google at
large and went through the first 5 pages, and didn't see anything.

i installed django a few weeks ago.  i'm pretty sure it's installed
correctly.   i start on the first step of the
http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01
Django tutorial.   after typing django import into the command prompt,
it tells me to type django-admin.py startproject mysite.   when i do
that, i get this error message.

File "", line 1

i'm running this in Vista, btw.

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



Iterate over model database fields

2009-01-08 Thread Matias Surdi

Is there any way to iterate over all the fields in a model instance on a 
template?

I'd like to have a "default" template which iterates over whatever model 
yo give it and prints all its field on a table.


Any help will 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
-~--~~~~--~~--~--~---



ModelForm: exclude fields missing in request

2009-01-08 Thread Flo Ledermann

Hi all,

I am trying to use a ModelForm in a "sparse" way to edit instances,
i.e. I only render one of its fields (plus a submit button) in the
template for editing the corresponding field in the model. I would
have expected that fields not present in the POST data of the request
would be omitted when updating the model, but to my surprise these
fields are set to the empty string "" - even fields that have been
None/NULL before calling form.save().

Is there a way to get the desired behavior (simply omitting data not
present in the request)? Shouldn't this even be the default behavior?

I believe the issue is actually not constrained to ModelForms but
probably applies to all forms in general, but it would be especially
handy to use ModelForms in such a sparse way in some scenarios.

Regards,

Flo Ledermann
--~--~-~--~~~---~--~~
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: HttpResponse HTML links missing URL prefix when emailing

2009-01-08 Thread Eric Abrahamsen


On Jan 8, 2009, at 8:37 PM, Eki wrote:

>
> Hi guys,
>
> I'm implementing a view which sends a (nightly) status report email.
> The code works mostly fine. I can both receive the email and see the
> result rendered as I query the view. The HTML shown and emailed is
> gotten from the same response object. However, the links included in
> the report only work in the browser view, but not in the email. For
> the email, the links are rendered with a default prefix of "http://;,
> and they are missing the domain name and https protocol specifier.
> I've been digging, but so far unable to find any reason why the prefix
> should be lost between two lines of code.

My guess is that in the HTML all the links come out as absolute links,  
minus the hostname. Ie href="/home/leaf/page/", rather than 
href="http://www.domain.com/home/leaf/page 
". That's usually how it is on a webpage, because the server assumes  
that all links are relative to the same domain. It's not that your  
code is changing between html and email, but that the domain is left  
out altogether in both cases – which works fine on a webserver, not so  
well when clicking a link in an email message.

You might want to use a separate template for the emails, or else put  
the current HTTP_HOST in a variable and resolve that for the links in  
both html and email.

Hope that helps,
Eric


>
>
> Here are the relevant parts of my functions:
>
> def send_daily(request):
>...
>
>response = render_to_response('email/status.html',
>{ ... a bunch of context stuff ... })
>send_email('Daily project status', 'sen...@nowhere.not',
> 'recei...@nowhere.not',
>'This report can only be viewed in HTML, which appears not to
> be supported by your email client.',
>response._get_content())
>return response
>
> def send_email(subject, from_email, to, text, html):
>msg = EmailMultiAlternatives(subject, text, from_email, [to])
>msg.attach_alternative(html, "text/html")
>msg.send()
>
> Thanks for any hints.
>
> -- Eki
>
> >


--~--~-~--~~~---~--~~
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: Shouldn't blank=True imply null=True?

2009-01-08 Thread tofergus

On 08.01-13:00, Malcolm Tredinnick wrote:
[ ... ]
> > a 'blank' value is essentially undefined in database terms and may be
> > interpreted in various ways.
> 
> Not, that's a NULL value. Blank has absolutely no technical meaning at
> the database level and certainly not any kind of ambiguous one. That's
> just confusing the issue.

you appear to re-affirming what i stated but saying it's wrong and
contradicting yourself at the same time.  i'm not sure if this is a
language problem but i'm now totally lost.

let's just agree to agree instead.  'blank' means nothing to a database
and is used as an input validation option in django.  we can also
agree that it should stay.

ps: i still think we should change the usage conventions but that
needs to be a seperate thread at this stage

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



HttpResponse HTML links missing URL prefix when emailing

2009-01-08 Thread Eki

Hi guys,

I'm implementing a view which sends a (nightly) status report email.
The code works mostly fine. I can both receive the email and see the
result rendered as I query the view. The HTML shown and emailed is
gotten from the same response object. However, the links included in
the report only work in the browser view, but not in the email. For
the email, the links are rendered with a default prefix of "http://;,
and they are missing the domain name and https protocol specifier.
I've been digging, but so far unable to find any reason why the prefix
should be lost between two lines of code.

Here are the relevant parts of my functions:

def send_daily(request):
...

response = render_to_response('email/status.html',
{ ... a bunch of context stuff ... })
send_email('Daily project status', 'sen...@nowhere.not',
'recei...@nowhere.not',
'This report can only be viewed in HTML, which appears not to
be supported by your email client.',
response._get_content())
return response

def send_email(subject, from_email, to, text, html):
msg = EmailMultiAlternatives(subject, text, from_email, [to])
msg.attach_alternative(html, "text/html")
msg.send()

Thanks for any hints.

-- Eki

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



Re: Django on Jython 2.5 alpha3 unicode characters in templates problem

2009-01-08 Thread naos


I found it works on Jython 2.5 beta0

On 8 Sty, 12:38, naos  wrote:
> Hi all,
>
> I'm recently playing with Django 1.0.2 on Jython 2.5 alpha3 build.
> Besides missing os.getcwdu function (which I got over by assigning
> os.getcwdu= os.getcwd at app init) I have problem with template
> rendering.
>
> When Jython string includes non-ASCII unicode characters (central
> europe specific letters) then it is not rendered by the template, it
> is missing in the resulting HTML document. If for eg. I have  a =
> "żźćłśąłł" and {{ a }} in the template then it won't appear.
>
> I found that doing a = a.encode('utf-8') helps, so a hot fix for that
> would be writing own custom filter that would utf-8 encode string and
> doing something like this: {{ a|utf8 }} . But it is not satisfactory
> enough for me, does anyone have better idea?
--~--~-~--~~~---~--~~
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: Change the url

2009-01-08 Thread Briel

Hi Praveen
I personally would prefer naming the urls rather than using the
get_absolute_url.
Both can accomplish your goal, but naming the urls is a more robust
and in other ways a better solution.

If you in a week decide that the url should not be /category/... but
instead /whatever/... you would have to recode your get_absolute_url
method. However, if you use the names in urls, everything would still
work after changing the urls. The reason is that when using the name
of an url, Django will find what the absolute url will be given the
args you use, in your example the id.
In a way, you could say that when using named urls, django is both
writing and running get_absolute_url for you.

Another plus when using named urls, is that you can give your urls
name that give meaning. That will make it a lot easier to understand
what's going on in the template when you read your own code 6 months
from now. Especially if you have several views of one model.

Say you had a model for blog posts.
Then you might want to have an url for your own blogs, another one for
your friend's blogs ect. You could still use get_absolute_url, but
this time, it would be harder to make and use, as you now would need
to know what url to get. Also when reading the template it would be
hard to see which url is being displayed. Instead using tags like
{% url friends_blog args=x %}
{% url your_blog args=x %}
{% url all_blog args=x %}
would be easy to understand after not working with the code for a long
time.

-Briel

Praveen wrote:
> Hi Briel i am totally confused now.
> My senior told me to write get_absolute_url
>
> so i wrote get_absolute_url like this
> class Listing_channels(models.Model):
> list_channel = models.CharField(max_length = 20)
> visibility = models.BooleanField()
>
> def __unicode__(self):
> return self.list_channel
>
> def get_absolute_url(self):
>   return u'/category/listing_view/%i/' % self.id
>
> and in html template i am calling
>
> {%if listing_result %}
> {% for n in listing_result %}
>  {{n.list_channel}} li>
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
>
> so its working fine.
>
> so now i have two mechanism one is your as you told me to write and
> second one is
> get_absolute_url() function.
>
> Now my confusion is if we have another same class event_channel and
> event and many more classes like this then i will have to write
> get_absolute_url() for each class
> and if go with you then there i need to change only in urls.py that i
> think fine.
>
> so i should go with get_absolute_url? give me the best and solid
> reason so i could make understand to senior, and you know the senior
> behave..
>
>
> Briel wrote:
>
> > Using urls with names will solve your problem.
> >
> > Basically if you change your urls.py like this:
> >
> > url(
> > r'^category/listing_view/(?P\w+)/$',
> >'mysite.library.views.listing_view',
> >name = 'name_for_this_view'
> > ),
> >
> > What I have done is to add a name to the url for convenience I also
> > used the url() function. This name can now be used instead of the link
> > to your view. So if you were to change the site structure, when
> > changes would be made to your urlconf, django would then be able to
> > figure things out for you. In this version your new link would look
> > like this:
> >
> > {{n.list_channel}}
> >
> >
> > In the docs you can read about it at
> > url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
> >
> > Good luck.
> > -Briel
> >
> > On 8 Jan., 12:41, Praveen  wrote:
> > > Hi Malcolm i am very new bie of Django. i read through
> > > get_absolute_url but do not know how to use.
> > > What you have given the answer i tried with that and its working fine
> > > but my senior asked me what will happen if i change the site name then
> > > every where you will have to change url
> > > mysite.library.views.listing_view.
> > >
> > > so they told me to use get_absolute_url
> > >
> > > i wrote get_absolute_ul in models.py
> > > � � def get_absolute_url(self):
> > > � � � � return "/listing/%i/" % self.id
> > > and i am trying to use in my html page template but i don't know how
> > > to use
> > >
> > >  {{n.list_channel}} > > li>
> > >
> > > then again same problem. first time when some one click on link it
> > > works fine but second time it appends the link 
> > > likehttp://127.0.0.1:8000/category/listing_view/3/3
> > >
> > > Please give me some idea
> > >
> > > On Jan 8, 3:37�pm, Praveen  wrote:
> > >
> > > > Thank you so much Malcolm.
> > > > every one gives only the link and tell to read but your style of
> > > > solving the problem is amazing. how you explained me in a nice way
> > > > that i can never ever find in djangoproject.com.
> > > > Thanks you so much malcom
> > >
> > > > On Jan 8, 3:23�pm, Malcolm Tredinnick 

Re: Change the url

2009-01-08 Thread Kip Parker

You can use reverse()  in your get_absolute_url method, it works the
same as the url template tag in using your url patterns to generate
the url.

http://docs.djangoproject.com/en/dev/topics/http/urls/?from=olddocs#reverse

On Jan 8, 12:58 pm, Praveen  wrote:
> Hi Briel i am totally confused now.
> My senior told me to write get_absolute_url
>
> so i wrote get_absolute_url like this
> class Listing_channels(models.Model):
>     list_channel = models.CharField(max_length = 20)
>     visibility = models.BooleanField()
>
>     def __unicode__(self):
>         return self.list_channel
>
>     def get_absolute_url(self):
>         return u'/category/listing_view/%i/' % self.id
>
> and in html template i am calling
>
> {%if listing_result %}
>     {% for n in listing_result %}
>          {{n.list_channel}} li>
>     {% endfor %}
> {% else %}
>     not available
> {% endif %}
> 
>
> so its working fine.
>
> so now i have two mechanism one is your as you told me to write and
> second one is
> get_absolute_url() function.
>
> Now my confusion is if we have another same class event_channel and
> event and many more classes like this then i will have to write
> get_absolute_url() for each class
> and if go with you then there i need to change only in urls.py that i
> think fine.
>
> so i should go with get_absolute_url? give me the best and solid
> reason so i could make understand to senior, and you know the senior
> behave..
>
> Briel wrote:
> > Using urls with names will solve your problem.
>
> > Basically if you change your urls.py like this:
>
> >     url(
> >         r'^category/listing_view/(?P\w+)/$',
> >        'mysite.library.views.listing_view',
> >        name = 'name_for_this_view'
> >     ),
>
> > What I have done is to add a name to the url for convenience I also
> > used the url() function. This name can now be used instead of the link
> > to your view. So if you were to change the site structure, when
> > changes would be made to your urlconf, django would then be able to
> > figure things out for you. In this version your new link would look
> > like this:
>
> > {{n.list_channel}}
>
> > In the docs you can read about it at
> > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > Good luck.
> > -Briel
>
> > On 8 Jan., 12:41, Praveen  wrote:
> > > Hi Malcolm i am very new bie of Django. i read through
> > > get_absolute_url but do not know how to use.
> > > What you have given the answer i tried with that and its working fine
> > > but my senior asked me what will happen if i change the site name then
> > > every where you will have to change url
> > > mysite.library.views.listing_view.
>
> > > so they told me to use get_absolute_url
>
> > > i wrote get_absolute_ul in models.py
> > > def get_absolute_url(self):
> > > return "/listing/%i/" % self.id
> > > and i am trying to use in my html page template but i don't know how
> > > to use
>
> > >  {{n.list_channel}} > > li>
>
> > > then again same problem. first time when some one click on link it
> > > works fine but second time it appends the link 
> > > likehttp://127.0.0.1:8000/category/listing_view/3/3
>
> > > Please give me some idea
>
> > > On Jan 8, 3:37 pm, Praveen  wrote:
>
> > > > Thank you so much Malcolm.
> > > > every one gives only the link and tell to read but your style of
> > > > solving the problem is amazing. how you explained me in a nice way
> > > > that i can never ever find in djangoproject.com.
> > > > Thanks you so much malcom
>
> > > > On Jan 8, 3:23 pm, Malcolm Tredinnick 
> > > > wrote:
>
> > > > > I'm going to trim your code to what looks like the relevant portion of
> > > > > the HTML template, since that's where the easiest solution lies.
>
> > > > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > > > > [...]
>
> > > > > > list_listing.html
>
> > > > > > 
> > > > > > Sight Seeings
> > > > > > 
> > > > > > {%if listing_result %}
> > > > > > {% for n in listing_result %}
> > > > > > {{n.list_channel}}
> > > > > > {% endfor %}
> > > > > > {% else %}
> > > > > > not available
> > > > > > {% endif %}
> > > > > > 
> > > > > > 
>
> > > > > [...]
>
> > > > > > I am displaying Listing_channels and Listing on same page. if some 
> > > > > > one
> > > > > > click on any Listing_channels the corresponding Listing must display
> > > > > > on same page. that is why i am also sending the Listing_channels
> > > > > > object to list_listing.html page. if some one click first time on
> > > > > > Listing_channels it shows the 
> > > > > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > > > > but second time it appends 1 at the end and the url becomes
> > > > > >http://127.0.0.1:8000/category/listing_view/1/1
>
> > > > > The above code fragment is putting an element in the template that 
> > > > > looks
> > > > > like
>

Re: Session variables

2009-01-08 Thread bradders

I will try to put something together.   I have a fairly detailed trace
that I have put in the session code that shows my session variables
are set when it calls one of my views, but the trace shows that the
next session save only a new session variable set in that view exists
all the other session variables have disappeared. I am not knowingly
clearing the other variables.
Thanks for your interest.
John

On Jan 8, 10:34 am, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-08 at 02:30 -0800, bradders wrote:
> > Can anyone recommend a session system that works more reliably than
> > the built-in Django session handling?  I am finding that after calling
> > 2 or 3 different views the session variables that were stored at login
> > time get cleared. I am using django 1.0, but I think the problem
> > existed in earlier versions.
>
> Perhaps if you could provide a replicable test case we could look at
> whatever problem may exist in the Django system. To the best of my
> knowledge it doesn't just arbitrarily throw away variables, but there's
> not way to tell what you're doing from the description you've provided.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Praveen

Hi Briel i am totally confused now.
My senior told me to write get_absolute_url

so i wrote get_absolute_url like this
class Listing_channels(models.Model):
list_channel = models.CharField(max_length = 20)
visibility = models.BooleanField()

def __unicode__(self):
return self.list_channel

def get_absolute_url(self):
return u'/category/listing_view/%i/' % self.id

and in html template i am calling

{%if listing_result %}
{% for n in listing_result %}
 {{n.list_channel}}
{% endfor %}
{% else %}
not available
{% endif %}


so its working fine.

so now i have two mechanism one is your as you told me to write and
second one is
get_absolute_url() function.

Now my confusion is if we have another same class event_channel and
event and many more classes like this then i will have to write
get_absolute_url() for each class
and if go with you then there i need to change only in urls.py that i
think fine.

so i should go with get_absolute_url? give me the best and solid
reason so i could make understand to senior, and you know the senior
behave..


Briel wrote:

> Using urls with names will solve your problem.
>
> Basically if you change your urls.py like this:
>
> url(
> r'^category/listing_view/(?P\w+)/$',
>'mysite.library.views.listing_view',
>name = 'name_for_this_view'
> ),
>
> What I have done is to add a name to the url for convenience I also
> used the url() function. This name can now be used instead of the link
> to your view. So if you were to change the site structure, when
> changes would be made to your urlconf, django would then be able to
> figure things out for you. In this version your new link would look
> like this:
>
> {{n.list_channel}}
>
>
> In the docs you can read about it at
> url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> Good luck.
> -Briel
>
> On 8 Jan., 12:41, Praveen  wrote:
> > Hi Malcolm i am very new bie of Django. i read through
> > get_absolute_url but do not know how to use.
> > What you have given the answer i tried with that and its working fine
> > but my senior asked me what will happen if i change the site name then
> > every where you will have to change url
> > mysite.library.views.listing_view.
> >
> > so they told me to use get_absolute_url
> >
> > i wrote get_absolute_ul in models.py
> > � � def get_absolute_url(self):
> > � � � � return "/listing/%i/" % self.id
> > and i am trying to use in my html page template but i don't know how
> > to use
> >
> >  {{n.list_channel}} > li>
> >
> > then again same problem. first time when some one click on link it
> > works fine but second time it appends the link 
> > likehttp://127.0.0.1:8000/category/listing_view/3/3
> >
> > Please give me some idea
> >
> > On Jan 8, 3:37�pm, Praveen  wrote:
> >
> > > Thank you so much Malcolm.
> > > every one gives only the link and tell to read but your style of
> > > solving the problem is amazing. how you explained me in a nice way
> > > that i can never ever find in djangoproject.com.
> > > Thanks you so much malcom
> >
> > > On Jan 8, 3:23�pm, Malcolm Tredinnick 
> > > wrote:
> >
> > > > I'm going to trim your code to what looks like the relevant portion of
> > > > the HTML template, since that's where the easiest solution lies.
> >
> > > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
> >
> > > > [...]
> >
> > > > > � � list_listing.html
> >
> > > > > 
> > > > > Sight Seeings
> > > > > 
> > > > > {%if listing_result %}
> > > > > � � {% for n in listing_result %}
> > > > > � � � � {{n.list_channel}}
> > > > > � � {% endfor %}
> > > > > {% else %}
> > > > > � � not available
> > > > > {% endif %}
> > > > > 
> > > > > 
> >
> > > > [...]
> >
> > > > > I am displaying Listing_channels and Listing on same page. if some one
> > > > > click on any Listing_channels the corresponding Listing must display
> > > > > on same page. that is why i am also sending the Listing_channels
> > > > > object to list_listing.html page. if some one click first time on
> > > > > Listing_channels it shows the 
> > > > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > > > but second time it appends 1 at the end and the url becomes
> > > > >http://127.0.0.1:8000/category/listing_view/1/1
> >
> > > > The above code fragment is putting an element in the template that looks
> > > > like
> >
> > > > � � � � ...
> >
> > > > That is a relative URL reference and will be relative to the URL of the
> > > > current page (which is .../category/listing_view/1/). In other words, it
> > > > will be appended to that URL. One solution is to change the relative
> > > > reference to look like
> >
> > > > � � � � ...
> >
> > > > or, in template language:
> >
> > > > � � � � {{n.list_channel}}
> >
> > > > That assumes you will only be displaying this template
> > 

orm: delete performance and queries optimization

2009-01-08 Thread drakkan

In my database I have some tables full of records, when I delete an
object django use the cascade behaviour and this is good, however
seems it make a query for every related object and after this django
seems to issue a delete where id in () for every 100 objects

look at this, Oggetti returns 8244 records:

t=Test.objects.get(pk=10)
Oggetti.objects.filter(test=t).delete()

I interrupted the operation after about 30 minutes and:

len(connection.queries)
4188

now in the database I have 6044 records so only 2200 were deleted and
this make 4188 queries

I think some optimization is needed,

reagards
drakkan





--~--~-~--~~~---~--~~
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: Setting Bound Fields Programmatically

2009-01-08 Thread Keyton Weissinger

WAIT!

Crap. If all else fails, RTFM. I'm sorry everyone. I just re-read the
docs at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
on commit=False. I get it now. Thank you all!

K

On Jan 8, 7:47 am, Keyton Weissinger  wrote:
> Thank you both very much for taking the time to respond...
>
> I got it to work using the following:
>     if request.method == 'POST':
>
>         my_data = {'type':user_type,
>                    'school':current_school.id,
>                    'title': request.POST['title'],
>                    'first_name': request.POST['first_name'],
>                    'last_name': request.POST['last_name'],
>                    'phone_1': request.POST['phone_1'],
>                    'phone_2': request.POST['phone_2'],
>                    }
>         #request.POST.update(my_data)
>         form = form_class(data=my_data, files=request.FILES)
>         # blah blah blah
>
> I haven't the foggiest why this worked and the former didn't. They're
> just dictionaries for goodness sake.
>
> Anyway...
>
> To Karen's (and your) points, I think I may be missing the boat here.
>
> I have a Teacher class that needs to have a school. I'm setting it
> above manually ('school':current_school.id) as I don't want a teacher
> setting his/her OWN school (I want to do it based on the admin's
> actions etc).
>
> It seems Karen's suggestion of having school be excluded from the form
> (via the class's Meta class) makes sense, but wouldn't that mean I
> have to have required=False on the school field in my Teacher object
> for it before the form.save will work in such a way as to save the
> underlying model?
>
> Keyton
>
> On Jan 8, 12:38 am, Malcolm Tredinnick 
> wrote:
>
> > On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote:
> > > I have a form with the following fields (all required):
> > > - first_name
> > > - last_name
> > > - site_id
>
> > > I'd like to use a template to display only the FIRST two items to the
> > > user for him to fill out:
>
> > > 
> > > {{ form.first_name }} 
> > > {{ form.last_name }} 
> > > 
> > > 
>
> > > Then when it gets posted back to me I'd like to set the site_id based
> > > on a session variable or whatever like this (from my view):
>
> > >     if request.method == 'POST':
> > >         my_data = {'site_id':1234}
> > >         my_data.update(request.POST)
> > >         form = form_class(data=my_data, files=request.FILES)
> > >         if form.is_valid():
> > >              process form here...
>
> > > My problem is that I cannot get the form to validate. It keeps telling
> > > me that site_id is not set.
>
> > On the surface, that look like it should work. Which makes me suspect
> > some important detail has been lost in the simplification.
>
> > What does the my_data dictionary look like just before you execute the
> > "form = ..." line (print it out)?
>
> > Also, how is form_class specified? Finally, what is the exact error
> > Django gives you? Print out form._errors, for example.
>
> > Maybe somewhere in there the answer will jump out. Admittedly, all the
> > clues may already be there and I'm just missing the obvious, but I can't
> > see it right now.
>
> > On a related note, is there any particular reason you need to have
> > site_id in the form class at all? Even if it's a model form, you could
> > exclude it, and add it into the model object later, couldn't you? You
> > might be going about this slightly backwards by trying to force in
> > site_id when it's not something that actually needs to be validated or
> > form-processed.
>
> > Regards,
> > Malcolm
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Setting Bound Fields Programmatically

2009-01-08 Thread Keyton Weissinger

Thank you both very much for taking the time to respond...

I got it to work using the following:
if request.method == 'POST':

my_data = {'type':user_type,
   'school':current_school.id,
   'title': request.POST['title'],
   'first_name': request.POST['first_name'],
   'last_name': request.POST['last_name'],
   'phone_1': request.POST['phone_1'],
   'phone_2': request.POST['phone_2'],
   }
#request.POST.update(my_data)
form = form_class(data=my_data, files=request.FILES)
# blah blah blah

I haven't the foggiest why this worked and the former didn't. They're
just dictionaries for goodness sake.

Anyway...

To Karen's (and your) points, I think I may be missing the boat here.

I have a Teacher class that needs to have a school. I'm setting it
above manually ('school':current_school.id) as I don't want a teacher
setting his/her OWN school (I want to do it based on the admin's
actions etc).

It seems Karen's suggestion of having school be excluded from the form
(via the class's Meta class) makes sense, but wouldn't that mean I
have to have required=False on the school field in my Teacher object
for it before the form.save will work in such a way as to save the
underlying model?

Keyton

On Jan 8, 12:38 am, Malcolm Tredinnick 
wrote:
> On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote:
> > I have a form with the following fields (all required):
> > - first_name
> > - last_name
> > - site_id
>
> > I'd like to use a template to display only the FIRST two items to the
> > user for him to fill out:
>
> > 
> > {{ form.first_name }} 
> > {{ form.last_name }} 
> > 
> > 
>
> > Then when it gets posted back to me I'd like to set the site_id based
> > on a session variable or whatever like this (from my view):
>
> >     if request.method == 'POST':
> >         my_data = {'site_id':1234}
> >         my_data.update(request.POST)
> >         form = form_class(data=my_data, files=request.FILES)
> >         if form.is_valid():
> >              process form here...
>
> > My problem is that I cannot get the form to validate. It keeps telling
> > me that site_id is not set.
>
> On the surface, that look like it should work. Which makes me suspect
> some important detail has been lost in the simplification.
>
> What does the my_data dictionary look like just before you execute the
> "form = ..." line (print it out)?
>
> Also, how is form_class specified? Finally, what is the exact error
> Django gives you? Print out form._errors, for example.
>
> Maybe somewhere in there the answer will jump out. Admittedly, all the
> clues may already be there and I'm just missing the obvious, but I can't
> see it right now.
>
> On a related note, is there any particular reason you need to have
> site_id in the form class at all? Even if it's a model form, you could
> exclude it, and add it into the model object later, couldn't you? You
> might be going about this slightly backwards by trying to force in
> site_id when it's not something that actually needs to be validated or
> form-processed.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Briel

Using urls with names will solve your problem.

Basically if you change your urls.py like this:

url(
r'^category/listing_view/(?P\w+)/$',
   'mysite.library.views.listing_view',
   name = 'name_for_this_view'
),

What I have done is to add a name to the url for convenience I also
used the url() function. This name can now be used instead of the link
to your view. So if you were to change the site structure, when
changes would be made to your urlconf, django would then be able to
figure things out for you. In this version your new link would look
like this:

{{n.list_channel}}


In the docs you can read about it at
url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

Good luck.
-Briel

On 8 Jan., 12:41, Praveen  wrote:
> Hi Malcolm i am very new bie of Django. i read through
> get_absolute_url but do not know how to use.
> What you have given the answer i tried with that and its working fine
> but my senior asked me what will happen if i change the site name then
> every where you will have to change url
> mysite.library.views.listing_view.
>
> so they told me to use get_absolute_url
>
> i wrote get_absolute_ul in models.py
>     def get_absolute_url(self):
>         return "/listing/%i/" % self.id
> and i am trying to use in my html page template but i don't know how
> to use
>
>  {{n.list_channel}} li>
>
> then again same problem. first time when some one click on link it
> works fine but second time it appends the link 
> likehttp://127.0.0.1:8000/category/listing_view/3/3
>
> Please give me some idea
>
> On Jan 8, 3:37 pm, Praveen  wrote:
>
> > Thank you so much Malcolm.
> > every one gives only the link and tell to read but your style of
> > solving the problem is amazing. how you explained me in a nice way
> > that i can never ever find in djangoproject.com.
> > Thanks you so much malcom
>
> > On Jan 8, 3:23 pm, Malcolm Tredinnick 
> > wrote:
>
> > > I'm going to trim your code to what looks like the relevant portion of
> > > the HTML template, since that's where the easiest solution lies.
>
> > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > > [...]
>
> > > >     list_listing.html
>
> > > > 
> > > > Sight Seeings
> > > > 
> > > > {%if listing_result %}
> > > >     {% for n in listing_result %}
> > > >         {{n.list_channel}}
> > > >     {% endfor %}
> > > > {% else %}
> > > >     not available
> > > > {% endif %}
> > > > 
> > > > 
>
> > > [...]
>
> > > > I am displaying Listing_channels and Listing on same page. if some one
> > > > click on any Listing_channels the corresponding Listing must display
> > > > on same page. that is why i am also sending the Listing_channels
> > > > object to list_listing.html page. if some one click first time on
> > > > Listing_channels it shows the 
> > > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > > but second time it appends 1 at the end and the url becomes
> > > >http://127.0.0.1:8000/category/listing_view/1/1
>
> > > The above code fragment is putting an element in the template that looks
> > > like
>
> > >         ...
>
> > > That is a relative URL reference and will be relative to the URL of the
> > > current page (which is .../category/listing_view/1/). In other words, it
> > > will be appended to that URL. One solution is to change the relative
> > > reference to look like
>
> > >         ...
>
> > > or, in template language:
>
> > >         {{n.list_channel}}
>
> > > That assumes you will only be displaying this template
> > > as /listing_view/1/ (or with a different number as the final
> > > component), since it will *always* remove the final component and
> > > replace it with the id value.
>
> > > The alternative, which is a little less fragile, is to use the "url"
> > > template tag to include a URL that goes all the way back to the hostname
> > > portion. You could write
>
> > >         {{n.list_channel}}
>
> > > (I've put in some line breaks just to avoid unpleasant line-wrapping).
> > > The {% url ... %} portion will return "/category/listing_view/1/" -- or
> > > whatever the right n.id value is -- which will always be correct.
>
> > > Have a read 
> > > ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> > > you're not familiar with the URL tag.
>
> > > Regards,
> > > Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Newbie - Foreign Key Error

2009-01-08 Thread Tony

Dear List,

I'm developing with 1.0.2 and am getting the following error:

(1451, 'Cannot delete or update a parent row: a foreign key constraint
fails (`project/comment_comment`, CONSTRAINT
`in_reply_to_id_refs_id_35b80077` FOREIGN KEY (`in_reply_to_id`)
REFERENCES `comment_comment` (`id`))')

... where the Comment model i've defined is:

class Comment(models.Model):
  objects = CommentManager()

  user = models.ForeignKey(User)
  title = models.CharField(max_length=60)
  comment = models.TextField()
  content_type = models.ForeignKey(ContentType)
  object_id = models.PositiveIntegerField()
  owner = generic.GenericForeignKey('content_type', 'object_id')
  in_reply_to = models.ForeignKey('self', null=True, blank=True,
related_name='reply_to')
  rating = models.FloatField(default=5.00)
  created = models.DateTimeField('date created', auto_now_add=True)

... when trying to delete the owner object (genericforeignkey) and
when there are two comments pointing to the owner object - one with
in_reply_to == None, and the other with in_reply_to == the first
comment. The cascade works fine if I try to delete the first comment,
but when i'm trying to delete the owner object the error comes up???
Could anyone please help me understand why this exception is being
thrown, and how to possibly fix it?


--~--~-~--~~~---~--~~
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: Change the url

2009-01-08 Thread Praveen

Hi Malcolm i am very new bie of Django. i read through
get_absolute_url but do not know how to use.
What you have given the answer i tried with that and its working fine
but my senior asked me what will happen if i change the site name then
every where you will have to change url
mysite.library.views.listing_view.

so they told me to use get_absolute_url

i wrote get_absolute_ul in models.py
def get_absolute_url(self):
return "/listing/%i/" % self.id
and i am trying to use in my html page template but i don't know how
to use

 {{n.list_channel}}

then again same problem. first time when some one click on link it
works fine but second time it appends the link like
http://127.0.0.1:8000/category/listing_view/3/3

Please give me some idea

On Jan 8, 3:37 pm, Praveen  wrote:
> Thank you so much Malcolm.
> every one gives only the link and tell to read but your style of
> solving the problem is amazing. how you explained me in a nice way
> that i can never ever find in djangoproject.com.
> Thanks you so much malcom
>
> On Jan 8, 3:23 pm, Malcolm Tredinnick 
> wrote:
>
>
>
> > I'm going to trim your code to what looks like the relevant portion of
> > the HTML template, since that's where the easiest solution lies.
>
> > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > [...]
>
> > >     list_listing.html
>
> > > 
> > > Sight Seeings
> > > 
> > > {%if listing_result %}
> > >     {% for n in listing_result %}
> > >         {{n.list_channel}}
> > >     {% endfor %}
> > > {% else %}
> > >     not available
> > > {% endif %}
> > > 
> > > 
>
> > [...]
>
> > > I am displaying Listing_channels and Listing on same page. if some one
> > > click on any Listing_channels the corresponding Listing must display
> > > on same page. that is why i am also sending the Listing_channels
> > > object to list_listing.html page. if some one click first time on
> > > Listing_channels it shows the 
> > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > but second time it appends 1 at the end and the url becomes
> > >http://127.0.0.1:8000/category/listing_view/1/1
>
> > The above code fragment is putting an element in the template that looks
> > like
>
> >         ...
>
> > That is a relative URL reference and will be relative to the URL of the
> > current page (which is .../category/listing_view/1/). In other words, it
> > will be appended to that URL. One solution is to change the relative
> > reference to look like
>
> >         ...
>
> > or, in template language:
>
> >         {{n.list_channel}}
>
> > That assumes you will only be displaying this template
> > as /listing_view/1/ (or with a different number as the final
> > component), since it will *always* remove the final component and
> > replace it with the id value.
>
> > The alternative, which is a little less fragile, is to use the "url"
> > template tag to include a URL that goes all the way back to the hostname
> > portion. You could write
>
> >         {{n.list_channel}}
>
> > (I've put in some line breaks just to avoid unpleasant line-wrapping).
> > The {% url ... %} portion will return "/category/listing_view/1/" -- or
> > whatever the right n.id value is -- which will always be correct.
>
> > Have a read 
> > ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> > you're not familiar with the URL tag.
>
> > Regards,
> > Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django on Jython 2.5 alpha3 unicode characters in templates problem

2009-01-08 Thread naos

Hi all,

I'm recently playing with Django 1.0.2 on Jython 2.5 alpha3 build.
Besides missing os.getcwdu function (which I got over by assigning
os.getcwdu= os.getcwd at app init) I have problem with template
rendering.

When Jython string includes non-ASCII unicode characters (central
europe specific letters) then it is not rendered by the template, it
is missing in the resulting HTML document. If for eg. I have  a =
"żźćłśąłł" and {{ a }} in the template then it won't appear.

I found that doing a = a.encode('utf-8') helps, so a hot fix for that
would be writing own custom filter that would utf-8 encode string and
doing something like this: {{ a|utf8 }} . But it is not satisfactory
enough for me, does anyone have better idea?
--~--~-~--~~~---~--~~
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: Using a model method in ModelAdmin fieldsets

2009-01-08 Thread Andy

One more comment:

You would also want to make sure that the init method of SampleForm
populates the non-model fields (ie. lastname) with the correct values.

class SampleForm(forms.ModelForm):

   lastname = form.CharField...

   def  __init__(self, *args, **kwargs):
  super(SampleForm, self).__init__(self, *args, **kwargs)
  ...
  self.fields['lastname'].initial = ...

On Jan 8, 3:14 am, Andy  wrote:
> The better approach would be to specify a custom form in your
> ModelAdmin.  This way your fieldset definition could include anything
> that's specified in your custom form.
>
> For Example:
>
> class SampleModel(models.Model):
>
>    email = models.EmailField...
>    firstname = models.CharField...
>
> class SampleForm(forms.ModelForm):
>
>    lastname = form.CharField...
>
> class SampleModelAdmin(admin.ModelAdmin)
>
>    fieldsets = (('General Info', {'fields' : ('email', 'firstname',
> 'lastname')}),)
>    form = SampleForm
>
> You would just have to override save_model to ensure that it does the
> appropriate things with the additional fields.
>
> On Jan 7, 9:44 am, EagerToUnderstand  wrote:
>
> > Thanks Karen & Daniel,
>
> > I think your overiding approach will work.  Thank you.
>
> > Implemented a work around.  I added extra fields (that persist my
> > method information) to my model that I update and save when I do a
> > listing.  Price I pay is an extra database update each time the model
> > is getting listed.
> > Will see how it influence performance.
>
> > Thank you for your replies.
--~--~-~--~~~---~--~~
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: Using a model method in ModelAdmin fieldsets

2009-01-08 Thread Andy

The better approach would be to specify a custom form in your
ModelAdmin.  This way your fieldset definition could include anything
that's specified in your custom form.

For Example:

class SampleModel(models.Model):

   email = models.EmailField...
   firstname = models.CharField...

class SampleForm(forms.ModelForm):

   lastname = form.CharField...

class SampleModelAdmin(admin.ModelAdmin)

   fieldsets = (('General Info', {'fields' : ('email', 'firstname',
'lastname')}),)
   form = SampleForm


You would just have to override save_model to ensure that it does the
appropriate things with the additional fields.



On Jan 7, 9:44 am, EagerToUnderstand  wrote:
> Thanks Karen & Daniel,
>
> I think your overiding approach will work.  Thank you.
>
> Implemented a work around.  I added extra fields (that persist my
> method information) to my model that I update and save when I do a
> listing.  Price I pay is an extra database update each time the model
> is getting listed.
> Will see how it influence performance.
>
> Thank you for your replies.
--~--~-~--~~~---~--~~
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: Subprocess module in Python CGI

2009-01-08 Thread Anurag


Hello Kenneth,

Thank you for your suggestion. This was helpful to remove a sort of
redundancy in my program but removal of '\' still does not solve my
problem as the Error displayed remains exactly the same.
Any other suggestions?

Once again thank you so much for your valuable time.
Regards.



On Dec 23 2008, 1:59 pm, Kenneth Gonsalves 
wrote:
> On Monday 22 Dec 2008 4:21:31 pm Anurag wrote:
>
> > comd = [\
> >         "tar -xf x.tar.gz", \
>
> nothing to do with python:
> [law...@localhost programs]$ tar -xf x.tar.gz
> tar: x.tar.gz: Cannot open: No such file or directory
> tar: Error is not recoverable: exiting now
>
> btw, there is no need to put '\' when putting a list in more than one line. In
> general, in python, you can put anything within (), [] or {} on more than one
> line without any escaping.
>
> --
> regards
> KGhttp://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
-~--~~~~--~~--~--~---



Re: Django too slow

2009-01-08 Thread bruno desthuilliers

On 8 jan, 07:04, Vicky  wrote:
> I using the django to generate xml and to fetch datas from database.
> When i run it the response is too slow. it takes nearly 4sec to load
> the page. So what can i do to make my program more efficient. Plse
> tell me some things to avoid so that it becomes faster

First make sure you set DEBUG=False in your settings. Then profile -
it's the only way to know where the bottlenecks are.
--~--~-~--~~~---~--~~
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: Change the url

2009-01-08 Thread Praveen

Thank you so much Malcolm.
every one gives only the link and tell to read but your style of
solving the problem is amazing. how you explained me in a nice way
that i can never ever find in djangoproject.com.
Thanks you so much malcom

On Jan 8, 3:23 pm, Malcolm Tredinnick 
wrote:
> I'm going to trim your code to what looks like the relevant portion of
> the HTML template, since that's where the easiest solution lies.
>
> On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> [...]
>
>
>
> >     list_listing.html
>
> > 
> > Sight Seeings
> > 
> > {%if listing_result %}
> >     {% for n in listing_result %}
> >         {{n.list_channel}}
> >     {% endfor %}
> > {% else %}
> >     not available
> > {% endif %}
> > 
> > 
>
> [...]
>
> > I am displaying Listing_channels and Listing on same page. if some one
> > click on any Listing_channels the corresponding Listing must display
> > on same page. that is why i am also sending the Listing_channels
> > object to list_listing.html page. if some one click first time on
> > Listing_channels it shows the 
> > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > but second time it appends 1 at the end and the url becomes
> >http://127.0.0.1:8000/category/listing_view/1/1
>
> The above code fragment is putting an element in the template that looks
> like
>
>         ...
>
> That is a relative URL reference and will be relative to the URL of the
> current page (which is .../category/listing_view/1/). In other words, it
> will be appended to that URL. One solution is to change the relative
> reference to look like
>
>         ...
>
> or, in template language:
>
>         {{n.list_channel}}
>
> That assumes you will only be displaying this template
> as /listing_view/1/ (or with a different number as the final
> component), since it will *always* remove the final component and
> replace it with the id value.
>
> The alternative, which is a little less fragile, is to use the "url"
> template tag to include a URL that goes all the way back to the hostname
> portion. You could write
>
>         {{n.list_channel}}
>
> (I've put in some line breaks just to avoid unpleasant line-wrapping).
> The {% url ... %} portion will return "/category/listing_view/1/" -- or
> whatever the right n.id value is -- which will always be correct.
>
> Have a read 
> ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> you're not familiar with the URL tag.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Session variables

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 02:30 -0800, bradders wrote:
> Can anyone recommend a session system that works more reliably than
> the built-in Django session handling?  I am finding that after calling
> 2 or 3 different views the session variables that were stored at login
> time get cleared. I am using django 1.0, but I think the problem
> existed in earlier versions.

Perhaps if you could provide a replicable test case we could look at
whatever problem may exist in the Django system. To the best of my
knowledge it doesn't just arbitrarily throw away variables, but there's
not way to tell what you're doing from the description you've provided.

Regards,
Malcolm



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



Session variables

2009-01-08 Thread bradders

Can anyone recommend a session system that works more reliably than
the built-in Django session handling?  I am finding that after calling
2 or 3 different views the session variables that were stored at login
time get cleared. I am using django 1.0, but I think the problem
existed in earlier versions.
--~--~-~--~~~---~--~~
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: Change the url

2009-01-08 Thread Briel

Hi.
Instead of manually writing the url, you can instead use the {% url %}
tag, then Django would figure out what the correct url is. If you are
using url tags you should considder using named urls. The link with
url tag would end up something like this: {{n.list_channel}}

read about the url tag in the Django Doc
http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#url

-Briel

Praveen skrev:
> MODELS.py
>
> class Listing_channels(models.Model):
> list_channel = models.CharField(max_length = 20)
> visibility = models.BooleanField()
>
> def __unicode__(self):
> return self.list_channel
>
> class Listing(models.Model):
>   name = models.CharField(max_length=20)
>   description = models.TextField(max_length = 100)
>   website = models.URLField()
>   timing = models.CharField(max_length=20)
>   channels = models.ForeignKey(Listing_channels)
>   visibility = models.BooleanField()
>
>   def __unicode__(self):
>   return self.name
>
>URLS.py
>
>  (r'^category/listing_view/(?P\w+)/
> $','mysite.library.views.listing_view'),
>
>VIEWS.py
>
> def listing_view(request, id):
> report_list = get_object_or_404(Listing_channels, pk = id)
> listing_result = Listing_channels.objects.all()
> r = report_list. listing_set.all()
> print r
> return render_to_response("list_listing.html", {'report_list' :
> report_list,'r':r,'listing_result':listing_result})
>
>
> list_listing.html
>
> 
> Sight Seeings
> 
> {%if listing_result %}
> {% for n in listing_result %}
> {{n.list_channel}}
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
> 
>  
>  {% if report_list  %}
>
>  
>   
>height="100px">Sight
> Seeings Details
>   
>   
>   
>   
> {% for t in r %}
> 
>   {{ t.name }}
> 
> 
>   {{ t.timing }}
> 
> 
>   {{ t.description }}
> 
> 
>   {{ t.website }}
> 
> 
> {% endfor %}
>   
>  {% else %}
>No names found
>
>   {% endif %}
>   
>
> I am displaying Listing_channels and Listing on same page. if some one
> click on any Listing_channels the corresponding Listing must display
> on same page. that is why i am also sending the Listing_channels
> object to list_listing.html page. if some one click first time on
> Listing_channels it shows the url 
> http://127.0.0.1:8000/category/listing_view/1/
> but second time it appends 1 at the end and the url becomes
> http://127.0.0.1:8000/category/listing_view/1/1
>
> I am trying to display like frameset left side all channels and right
> side description of that channel.
--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread Matias Surdi

 > implement.  Just google YUI.
Shoudn't it have been "yahoo for YUI" ?

:-D


phoebebright escribió:
> I'm a great fan of YUI and they have some nice tabs that are easy to
> implement.  Just google YUI.
> 
> 
> On Jan 8, 10:03 am, Matias Surdi  wrote:
>> JQuery UI?
>>
>> Margie escribió:
>>
>>> Hi,
>>> This is not a directly a django question, but since django is the only
>>> web framework I know (and it's really cool, by the way!) I hope it's
>>> ok to post this here.
>>> Could someone advise me on the "best" way to do tabs?  IE, I'd like to
>>> have a set of tabs at the top of my page with a sub navigation bar
>>> below.  I am currently using a mechanism that I got from the pinax
>>> project - I use css similar to that in tabs.css, for those of you that
>>> know pinax.  That css controls how the html classes are set up when
>>> html is rendered for a particular tab, causing the tabs to look
>>> "pressed" at the appropriate times.
>>> I'm a newbie at web page design, so I don't have a good feeling for if
>>> this is the right direction to be pursing.  I find the css code and
>>> the way it interacts with site_base.html and base.html fairly
>>> confusing and hard to maintain, so I'm wondering if there is a better
>>> way.  Also (and more importantly) would like my tabs to be more
>>> dynamic.  For example, based on the user clicking on something, I
>>> would like to be able to add additional tabs.  It seems like using the
>>> css mechanism in pinax makes that very difficult, because the css for
>>> each tab has to be defined up front in order to get the shading right
>>> when you click on a tab.
>>> Can anyone advise me on what the best direction to go in is for having
>>> nice tabs that are easy to undrestand?
>>> I have not yet learned jquery or ajax, but they are on my list,
>>> perhaps those provide better frameworks than css?  Anyway, any
>>> pointers from those of you more experienced than me are appreciated!
>>> 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
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Malcolm Tredinnick

I'm going to trim your code to what looks like the relevant portion of
the HTML template, since that's where the easiest solution lies.

On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
[...]
> 
> list_listing.html
> 
> 
> Sight Seeings
> 
> {%if listing_result %}
> {% for n in listing_result %}
> {{n.list_channel}}
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
> 

[...]
> I am displaying Listing_channels and Listing on same page. if some one
> click on any Listing_channels the corresponding Listing must display
> on same page. that is why i am also sending the Listing_channels
> object to list_listing.html page. if some one click first time on
> Listing_channels it shows the url 
> http://127.0.0.1:8000/category/listing_view/1/
> but second time it appends 1 at the end and the url becomes
> http://127.0.0.1:8000/category/listing_view/1/1

The above code fragment is putting an element in the template that looks
like

...

That is a relative URL reference and will be relative to the URL of the
current page (which is .../category/listing_view/1/). In other words, it
will be appended to that URL. One solution is to change the relative
reference to look like

...

or, in template language:

{{n.list_channel}}

That assumes you will only be displaying this template
as /listing_view/1/ (or with a different number as the final
component), since it will *always* remove the final component and
replace it with the id value.

The alternative, which is a little less fragile, is to use the "url"
template tag to include a URL that goes all the way back to the hostname
portion. You could write

{{n.list_channel}}

(I've put in some line breaks just to avoid unpleasant line-wrapping).
The {% url ... %} portion will return "/category/listing_view/1/" -- or
whatever the right n.id value is -- which will always be correct.

Have a read of
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url if
you're not familiar with the URL tag.

Regards,
Malcolm



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



Re: best way to do tabs?

2009-01-08 Thread phoebebright

I'm a great fan of YUI and they have some nice tabs that are easy to
implement.  Just google YUI.


On Jan 8, 10:03 am, Matias Surdi  wrote:
> JQuery UI?
>
> Margie escribió:
>
> > Hi,
>
> > This is not a directly a django question, but since django is the only
> > web framework I know (and it's really cool, by the way!) I hope it's
> > ok to post this here.
>
> > Could someone advise me on the "best" way to do tabs?  IE, I'd like to
> > have a set of tabs at the top of my page with a sub navigation bar
> > below.  I am currently using a mechanism that I got from the pinax
> > project - I use css similar to that in tabs.css, for those of you that
> > know pinax.  That css controls how the html classes are set up when
> > html is rendered for a particular tab, causing the tabs to look
> > "pressed" at the appropriate times.
>
> > I'm a newbie at web page design, so I don't have a good feeling for if
> > this is the right direction to be pursing.  I find the css code and
> > the way it interacts with site_base.html and base.html fairly
> > confusing and hard to maintain, so I'm wondering if there is a better
> > way.  Also (and more importantly) would like my tabs to be more
> > dynamic.  For example, based on the user clicking on something, I
> > would like to be able to add additional tabs.  It seems like using the
> > css mechanism in pinax makes that very difficult, because the css for
> > each tab has to be defined up front in order to get the shading right
> > when you click on a tab.
>
> > Can anyone advise me on what the best direction to go in is for having
> > nice tabs that are easy to undrestand?
>
> > I have not yet learned jquery or ajax, but they are on my list,
> > perhaps those provide better frameworks than css?  Anyway, any
> > pointers from those of you more experienced than me are appreciated!
>
> > 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
-~--~~~~--~~--~--~---



Re: Does using the IPython shell add "LIMIT" to Django ORM discussion (using SQLite)

2009-01-08 Thread Ramiro Morales

On Thu, Jan 8, 2009 at 7:58 AM, Christopher Mutel  wrote:
>
> Hello all-
>
> I recently filed a bug about incorrect SQL generation, and Malcom
> Tredinnick said that the example SQL I provided couldn't be correct,
> because there was an extra LIMIT clause that shouldn't be there. After
> poking around for a bit, I realized that everytime I was executing my
> query in the IPython shell, it was appending a LIMIT 21 to the SQL,
> but this limit clause wasn't being appended if the query was part of a
> regular python process. Both queries are run against SQLite 3.
>
> I uploaded a small test case here that demonstrates this behaviour:
>
> http://www.bitbucket.org/cmutel/extra_limit_21/
>
> It is possible that I have poor python-fu, or is this known behaviour?
> Is it possible that Django is truncating the result list because
> IPython won't show all results anyway?
>
> I have tried searching the Django codebase, and the mailing list, but
> to no avail.

Django [1]generates a LIMIT 21 in the __repr__ method of a queryset,
because it limits such representation to 20 items when it's in the
context of (for example) showing it in a traceback, this was added in
[2]r9202. Maybe you are getting the SQL clause generated by you ROM
query with .query().as_sql() in the interactive Python interpreter and
triggering this?

See if r9717 solves you duplicate column name problem, the problem
in the query isn't caused by that LIMIT part as it isn't sent to the
DB in other 'normal' conditions.

Regards,

-- 
 Ramiro Morales

1. 
http://code.djangoproject.com/browser/django/trunk/django/db/models/query.py#L146
2. http://code.djangoproject.com/changeset/9202

--~--~-~--~~~---~--~~
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: Does using the IPython shell add "LIMIT" to Django ORM discussion (using SQLite)

2009-01-08 Thread Malcolm Tredinnick

On Thu, 2009-01-08 at 10:58 +0100, Christopher Mutel wrote:
> Hello all-
> 
> I recently filed a bug about incorrect SQL generation, and Malcom
> Tredinnick said that the example SQL I provided couldn't be correct,
> because there was an extra LIMIT clause that shouldn't be there. After
> poking around for a bit, I realized that everytime I was executing my
> query in the IPython shell, it was appending a LIMIT 21 to the SQL,
> but this limit clause wasn't being appended if the query was part of a
> regular python process. Both queries are run against SQLite 3.

Aah .. I understand what's going on now! :-)

You were printing (or, at least, trying to print) the repr() of the
queryset. To avoid people accidentally trying to retrieve and print a
million results, we (well, I) changed that to only retrieve and print
the first 20 results and print "remainder truncated" if there were more.
This is achieved by limiting the query to 21 results (if there are 21
results there are more than 20, so we print the "truncated" message).
That only happens in the  __repr__() -- i.e. it's only for diagnostic
printing. No normal user code has this limit included automatically, so
you happily create a queryset that iterates over a million results.

It hadn't occurred to me when reading that ticket that you were pulling
the query out of django.db.connection.queries, but that makes sense now
that I see your code. I, almost invariably, use
"queryset.query.as_sql()" to view the query that the queryset is
creating and that wouldn't show the limit.

So, you aren't losing your mind (and, luckily, neither am I). The SQL
limit you're seeing isn't the direct representation of the queryset.
It's a result of trying to print the repr() of the queryset. Not related
to IPython or anything like that. Just a safeguard against accidental
repr() printing (after hearing people like Google, NASA and even a
semi-well-known media organisation in Kansas complain about making that
blunder, I broke down and added it a couple of months ago).

Thanks for following this up a bit more. Hopefully next time I see a
strange "LIMIT 21" on something, I'll remember how it might occur.

In any case, your example was clear enough that I could repeat the
problem and, as you have no doubt seen, it was actually exposing a
different and more significant problem which has now been fixed.

Regards,
Malcolm




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



Re: best way to do tabs?

2009-01-08 Thread Matias Surdi

JQuery UI?



Margie escribió:
> Hi,
> 
> This is not a directly a django question, but since django is the only
> web framework I know (and it's really cool, by the way!) I hope it's
> ok to post this here.
> 
> Could someone advise me on the "best" way to do tabs?  IE, I'd like to
> have a set of tabs at the top of my page with a sub navigation bar
> below.  I am currently using a mechanism that I got from the pinax
> project - I use css similar to that in tabs.css, for those of you that
> know pinax.  That css controls how the html classes are set up when
> html is rendered for a particular tab, causing the tabs to look
> "pressed" at the appropriate times.
> 
> I'm a newbie at web page design, so I don't have a good feeling for if
> this is the right direction to be pursing.  I find the css code and
> the way it interacts with site_base.html and base.html fairly
> confusing and hard to maintain, so I'm wondering if there is a better
> way.  Also (and more importantly) would like my tabs to be more
> dynamic.  For example, based on the user clicking on something, I
> would like to be able to add additional tabs.  It seems like using the
> css mechanism in pinax makes that very difficult, because the css for
> each tab has to be defined up front in order to get the shading right
> when you click on a tab.
> 
> Can anyone advise me on what the best direction to go in is for having
> nice tabs that are easy to undrestand?
> 
> I have not yet learned jquery or ajax, but they are on my list,
> perhaps those provide better frameworks than css?  Anyway, any
> pointers from those of you more experienced than me are appreciated!
> 
> 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
-~--~~~~--~~--~--~---



Change the url

2009-01-08 Thread Praveen

 MODELS.py

class Listing_channels(models.Model):
list_channel = models.CharField(max_length = 20)
visibility = models.BooleanField()

def __unicode__(self):
return self.list_channel

class Listing(models.Model):
name = models.CharField(max_length=20)
description = models.TextField(max_length = 100)
website = models.URLField()
timing = models.CharField(max_length=20)
channels = models.ForeignKey(Listing_channels)
visibility = models.BooleanField()

def __unicode__(self):
return self.name

   URLS.py

 (r'^category/listing_view/(?P\w+)/
$','mysite.library.views.listing_view'),

   VIEWS.py

def listing_view(request, id):
report_list = get_object_or_404(Listing_channels, pk = id)
listing_result = Listing_channels.objects.all()
r = report_list. listing_set.all()
print r
return render_to_response("list_listing.html", {'report_list' :
report_list,'r':r,'listing_result':listing_result})


list_listing.html


Sight Seeings

{%if listing_result %}
{% for n in listing_result %}
{{n.list_channel}}
{% endfor %}
{% else %}
not available
{% endif %}


 
 {% if report_list  %}

 

Sight
Seeings Details




{% for t in r %}

{{ t.name }}


{{ t.timing }}


{{ t.description }}


{{ t.website }}


{% endfor %}
  
 {% else %}
   No names found

  {% endif %}
  

I am displaying Listing_channels and Listing on same page. if some one
click on any Listing_channels the corresponding Listing must display
on same page. that is why i am also sending the Listing_channels
object to list_listing.html page. if some one click first time on
Listing_channels it shows the url http://127.0.0.1:8000/category/listing_view/1/
but second time it appends 1 at the end and the url becomes
http://127.0.0.1:8000/category/listing_view/1/1

I am trying to display like frameset left side all channels and right
side description of that channel.

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



Does using the IPython shell add "LIMIT" to Django ORM discussion (using SQLite)

2009-01-08 Thread Christopher Mutel

Hello all-

I recently filed a bug about incorrect SQL generation, and Malcom
Tredinnick said that the example SQL I provided couldn't be correct,
because there was an extra LIMIT clause that shouldn't be there. After
poking around for a bit, I realized that everytime I was executing my
query in the IPython shell, it was appending a LIMIT 21 to the SQL,
but this limit clause wasn't being appended if the query was part of a
regular python process. Both queries are run against SQLite 3.

I uploaded a small test case here that demonstrates this behaviour:

http://www.bitbucket.org/cmutel/extra_limit_21/

It is possible that I have poor python-fu, or is this known behaviour?
Is it possible that Django is truncating the result list because
IPython won't show all results anyway?

I have tried searching the Django codebase, and the mailing list, but
to no avail.

-Chris

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



  1   2   >