why create and get_or_create can't use id to set foerign key ?
why create and get_or_create can't use id to set foerign key ? for example I can't write like below: Star.objects.get_or_create(user=request.user,title_id=title_id) I have to write like this: try: Star.objects.get(user=request.user,title=title_id) except Star.DoesNotExist: Star(user=request.user,title_id=title_id).save() -- 博客:http://zsp.javaeye.com/ 专业:生物医学工程+计算机科学与技术 技能:C++(STL,BOOST) Python(Django) HTML+CSS AJAX -- 张沈鹏 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
Re: [Jython-dev] django on jython (new version)?
On 9/23/07, Tristan King <[EMAIL PROTECTED]> wrote: > > you were close :) > "return unicode(self)" instead Almost. That alone would also end on and infinite loop on CPython. This is directly from django.db.models.Model: def __str__(self): if hasattr(self, '__unicode__'): return force_unicode(self).encode('utf-8') return '%s object' % self.__class__.__name__ The key is the hasattr() check. It's always true on Jython because __unicode__ is defined on object. Anyway, I just noticed that the uploaded test case uses the hasattr, so it's OK. -- Leo Soto M. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
Re: [Jython-dev] django on jython (new version)?
you were close :) "return unicode(self)" instead i've attached a test file to the bug i submitted at: https://sourceforge.net/tracker/index.php?func=detail=1800378_id=12867=112867 On Sun, 2007-09-23 at 12:55 -0700, Charlie Groves wrote: > Hi Tristan, > > Would you mind coming up with a small test case that shows this going > off the rails? From reading your description, the basic object setup > sounds like the following: > > class Model(object): > def __str__(self): > return self.__unicode__() > > class Poll(Model): > pass > > However, that code complains about the lack of __unicode__ under > CPython or Jython with your changes in place, so I must be missing > something. > > Charlie > > On 9/21/07, Tristan King <[EMAIL PROTECTED]> wrote: > > Ok I've been working on the problem quoted at the end of this email and have > > come up with a solution. but i'm not sure what to make of it. > > > > Poll extends from Model and does not implement __str__ or __unicode__, but > > inherits __str__ from Model, which calls __unicode__, and __unicode__ from > > object. however, object.__unicode__ calls __str__, which in this case is > > model.__str__ and so the loop begins. > > > > of course this code works fine in CPython. so what's different? > > simple: > > > > [EMAIL PROTECTED]:~$ python > > Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) > > [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> hasattr(object, '__unicode__') > > False > > >>> > > [EMAIL PROTECTED]:~$ jython > > Jython 2.3a0 on java1.5.0_11 > > Type "copyright", "credits" or "license" for more information. > > >>> hasattr(object, '__unicode__') > > True > > >>> > > > > so, applying the following patch to jython fixes the aforementioned problem. > > and running 'ant bugtests' shows no change > > Index: jython/src/org/python/core/PyObject.java > > === > > --- jython/src/org/python/core/PyObject.java(revision > > 3484) > > +++ jython/src/org/python/core/PyObject.java(working > > copy) > > @@ -224,7 +224,7 @@ > > } > > } > > -dict.__setitem__("__unicode__",new > > PyMethodDescr("__unicode__",PyObject.class,0,0,new > > exposed___unicode__(null,null))); > > +//dict.__setitem__("__unicode__",new > > PyMethodDescr("__unicode__", PyObject.class,0,0,new > > exposed___unicode__(null,null))); > > class exposed___init__ extends PyBuiltinMethod { > > exposed___init__(PyObject self,PyBuiltinFunction.Info info) { > > > > My question is. Why, if in CPython object.__unicode__ doesn't exist, why > > does it in jython? > > > > > > On 20/09/2007, at 7:30 PM, Tristan King wrote: > > > > I've been working on getting the django tutorial to work, and got up to: > > --- > > # objects.all() displays all the polls in the database. > > Poll.objects.all() > > [] > > -- > > before writing this (i'm about to pack it in for the day), which threw me a > > nasty error: > > .. > > File > > "/usr/local/share/jython/Lib/django/db/models/base.py", > > line 101, in __str__ > > File > > "/usr/local/share/jython/Lib/django/utils/encoding.py", > > line 37, in force_unicode > > File > > "/usr/local/share/jython/Lib/django/db/models/base.py", > > line 101, in __str__ > > File > > "/usr/local/share/jython/Lib/django/utils/encoding.py", > > line 37, in force_unicode > > java.lang.StackOverflowError: java.lang.StackOverflowError > > > > > > - > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ > > ___ > > Jython-dev mailing list > > [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/jython-dev > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
Re: MEDIA_URL and trailing slash (documentation)
Deryck Hodge said the following: > Another use case to consider: > > {{ MEDIA_URL }}{{ photo.get_absolute_url }} > > No way to avoid an extra slash if your get_absolute_url begins with a > slash, which is common. I'm not passionate about what we recommend, > but just wanted to remind that MEDIA_URL is not just used for > get_FOO_url construction or for manually building urls. That's not really a valid use case though - get_absolute_url should be returning an absolute URL, not one relative to MEDIA_URL. If your photo object involves a FileField or ImageField, it will already be using MEDIA_URL in the get_fieldname_url function, so there'd be no reason to attach it to MEDIA_URL after the fact. -- Collin Grady When you're ready to give up the struggle, who can you surrender to? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
Re: Visual recognition of Django website
That is really good. Thanks :) On Sep 19, 1:44 pm, Ned Batchelder <[EMAIL PROTECTED]> wrote: > I agree that a favicon is one of those fit-and-finish touches that helps > complete a website. Attached are my attempts. I agree with Todd that > "dj" is a better reminder of Django, and the color should be greener > (look at the badges to see that Wilson didn't slavishly follow the deep > green of the logos when making smaller versions of it). I've also > rejiggered the letters a bit to avoid smeary-looking blurs. > > Now we just need to get someone to put it on the site... > > --Ned. > > > > Todd O'Bryan wrote: > > On Wed, 2007-09-19 at 00:29 +, Johann C. Rocholl wrote: > > >> On Sep 17, 10:17 am, "Justin Lilly" <[EMAIL PROTECTED]> wrote: > > >>> I personally would also like a favicon for the django sites. I took the > >>> liberty of creating one using django's colors and fonts (stole the d from > >>> the logo). > > >>> http://www.flickr.com/photos/[EMAIL PROTECTED]/1397125183/ > > >> Here's another attempt, with improved vertical alignment > >> (mathematically perfect), and in Windows ICO format: > >>http://johann.rocholl.net/django-icon/favicon.ico > > > While I'm +0 on the favicon thing, I personally think "d" is > > insufficient and "dj" would be much more identifiable as uniquely > > Django. > > > Todd > > -- > Ned Batchelder,http://nedbatchelder.com > > django-favicon.png > 1KViewDownload > > django-favicon.ico > 1KDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
Re: Tutorial wiki broken: Failed to load TOC proccessor
On 9/21/07, msaelices <[EMAIL PROTECTED]> wrote: > > The problem is the [[TOC]] proccessor situated on top: > > http://code.djangoproject.com/wiki/Tutorials Works for me (now). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---