Using annotate() in a custom model manager
Hi - I have these models; with one custom manager. class OrderByHighestScoreManager(models.Manager): def get_query_set(self, *args, **kwargs): qs = super(OrderByHighestValidationsManager, self).get_query_set(*args, **kwargs) return qs.annotate(score=Count('votes__id'),).order_by('score') class AbstractEntry(models.Model): user = models.ForeignKey(User, null=True, blank=True) last_modified = models.DateTimeField(auto_now=True) objects = models.Manager() order_by_votes = OrderByHighestValidationsManager() class Entry(AbstractEntry): creation_date = models.DateTimeField(auto_now_add=True) votes = generic.GenericRelation(Vote) I can't get the custom manager to work This is OK: Entry.objects.annotate(score=Count('votes__id'),).order_by('score') This does not work: Entry.order_by_votes.all() The error I get is: Error Traceback (most recent call last): File "c:\Python27\Lib\unittest\case.py", line 318, in run testMethod() File "C:\Data\Development\django_projects\oko\\apps\entries \tests\model.py", line 111, in test_order_by_votes self.assertEqual(list(Entry.order_by_votes.values_list('id', flat=True)), [self.e1.id, self.e2.id]) File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\query.py", line 84, in __len__ self._result_cache.extend(self._iter) File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\query.py", line 956, in iterator for row in self.query.get_compiler(self.db).results_iter(): File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\compiler.py", line 680, in results_iter for rows in self.execute_sql(MULTI): File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\compiler.py", line 725, in execute_sql sql, params = self.as_sql() File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\compiler.py", line 60, in as_sql ordering, ordering_group_by = self.get_ordering() File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\compiler.py", line 349, in get_ordering self.query.model._meta, default_order=asc): File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\compiler.py", line 378, in find_ordering_name opts, alias, False) File "C:\Data\Development\django_projects\oko\lib\site-packages \django\db\models\sql\query.py", line 1238, in setup_joins "Choices are: %s" % (name, ", ".join(names))) FieldError: Cannot resolve keyword 'score' into field. Choices are: creation_date, id, last_modified, user, votes = What's going wrong here? I would very much like to perform this sorting via a manager, or at least a method accessible from within an Entry instance as several templates will be using this special sorting (and I don't want to copy this complex queryset over different views). Thanks in advance! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django queryset custom manager - refresh caching
On Dec 20, 2:23 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Monday, December 20, 2010 11:03:10 AM UTC, LaundroMat wrote: > > > Hi - > > > Django seems to be caching data that I query through a custom method on a > > model. I've tried to describe the issue over at SO ( > >http://stackoverflow.com/questions/4010317/django-queryset-custom-man...), > > but received close to no replies... Does anyone here have an idea as to how > > I could solve my problem? > > > Many thanks in advance, > > > Mathieu > > Apologies, I didn't see that you had posted the additional info I requested > on that question. I've answered it there. > -- > DR. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django queryset custom manager - refresh caching
On Dec 20, 2:23 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Monday, December 20, 2010 11:03:10 AM UTC, LaundroMat wrote: > > > Hi - > > > Django seems to be caching data that I query through a custom method on a > > model. I've tried to describe the issue over at SO ( > >http://stackoverflow.com/questions/4010317/django-queryset-custom-man...), > > but received close to no replies... Does anyone here have an idea as to how > > I could solve my problem? > > > Many thanks in advance, > > > Mathieu > > Apologies, I didn't see that you had posted the additional info I requested > on that question. I've answered it there. > -- > DR. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Localized timesince template tag?
On Aug 31, 1:55 pm, LaundroMat <laun...@gmail.com> wrote: > I seem to remember being able to have template tags and filters > localized in Django, but I can't find any information on this back. > Did I misremember, or have my search skill deteriorated? > > I'm particularly looking for a Dutch localization of the timesince > template tag.. > > Many thanks in advance, > > Mathieu Found it - just had to set the LANGUAGE setting in settings.py --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Localized timesince template tag?
I seem to remember being able to have template tags and filters localized in Django, but I can't find any information on this back. Did I misremember, or have my search skill deteriorated? I'm particularly looking for a Dutch localization of the timesince template tag.. Many thanks in advance, Mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Modifying the way a ChoiceField is rendered
On Jun 4, 11:15 am, Tom Evans <tevans...@googlemail.com> wrote: > On Wed, 2009-06-03 at 14:28 -0700, LaundroMat wrote: > > Hi - > > > I'm trying to change the way a ChoiceField (with widget = > > forms.RadioSelect) is being rendered in a template. Currently, > > rendering the form as_p() for instance, will return HTML such as: > > > > > value="1" name="type" />choice 1 > > ... > > > > > Is there a way to control how this ChoiceField is rendered? I'd like > > to use something else than an unordered list... > > > Many thanks in advance, > > > Mathieu > > The RadioSelect widget takes an optional keyword argument 'renderer' > which allows you to pass in a custom class type to use as your renderer. > > Your class should have a render() method, and accept the same > constructor arguments as the default RadioFieldRenderer - name, value, > attrs, choices. Check out django/forms/widgets.py for the gory details. > > Tom Thanks for the informative reply! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Modifying the way a ChoiceField is rendered
Hi - I'm trying to change the way a ChoiceField (with widget = forms.RadioSelect) is being rendered in a template. Currently, rendering the form as_p() for instance, will return HTML such as: choice 1 ... Is there a way to control how this ChoiceField is rendered? I'd like to use something else than an unordered list... Many thanks in advance, Mathieu --~--~-~--~~~---~--~~ 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 App build - the right process?
On Feb 24, 3:25 pm, Alfonsowrote: > I've been putting together a Product Database and Customer Order > application that requires a lot of interim calculations, things like > tax, customer discounts etc. Due to my limited knowledge of django/ > python I have been basically performing these calculations in a custom > save function of the appropriate models. > > Example: > > http://dpaste.com/hold/760/ > > A mess huh!! > > The product model is associated with a PriceOverride table that is > updated by the user and functions as a means of applying a unique > price for a particular customer (let's say it's a great customer and > they should be getting 10% on certain products) > > By doing it this way I've got myself in a horrible mess with the save > functions, things that I haven't considered like updating a > PriceOverride or changing the PriceOverride to cover a different set > of products have meant that I need to write custom code for not only > the save but also the delete and any 'change' operations. > > I'm really not sure what I should be asking to fix it other than maybe > I've been going about this entirely wrong procedure and looking for > some guidance that might make life easier for me. > > Think I could explain all that much better but I think I'll wait for a > few queries first (if any!) > > Thanks I think signals could help you along the way. Have a look at http://docs.djangoproject.com/en/dev/topics/signals/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Securely storing passwords
Hi - I'm working on a small django app that allows users to interact with other websites where they have an account. Ofcourse, using this app means providing your username and password for the other website. What are the most secure ways of handling this information? I suppose encrypting the passwords is one option, but are there any ways to prevent people who have access to the app's source code and database of retrieving user's names and passwords? Thanks in advance, Mathieu --~--~-~--~~~---~--~~ 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: Entering unicode bytestrings in Django
On Feb 12, 8:33 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Thu, Feb 12, 2009 at 12:18 PM, LaundroMat <laun...@gmail.com> wrote: > > > Hi - > > > I'm scraping some information from a website, but I'm having some > > trouble with special characters such as é. I'm using BeautifulSoup for > > the scraping, and would like to be able to have Django print out muy > > strings correctly (on the template, in the shell, in the admin). > > > The way I go about it is: > > > >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup > > >>> html = "André goes to town" > > >>> soup = BeautifulSoup(html) > > >>> soup > > Andr goes to town > > OK, so you've got a problem here, but I'm not sure from what you've said > that you realize it or recognize what it is exactly. (It always helps when > people say what the expected where it differs from what they got.) > is single low-9 quotation mark, not Latin small letter e with acute. > > This implies BeautifulSoup has guessed wrong what the encoding for your html > string is. It appears to me you are using a Windows command prompt that is > using cp437, where é has the code point value x82, but BeautifulSoup is > guessing the string is encoded using cp1252, where code point value x82 is > assigned to the single low-9 quotation mark. So at this point your Latin > small letter e with acute has been turned into an entirely different > character by BeautifulSoup. That character happens to be U+201A, which is > what you see in the rest of what you show. > > > >>> soup = BeautifulSoup(html, > > convertEntities=BeautifulStoneSoup.HTML_ENTITIES) > > So here all you are doing is asking BeautifulSoup to use the unicode value > of the entity instead of the ...but since it's still guessing wrong > on the encoding, you still wind up with the wrong thing, only now it is a > unicode character value which also leads to difficulties in printing it out > in your Windows command prompt. > > > >>> soup > > Traceback (most recent call last): > > File "", line 1, in > > UnicodeEncodeError: 'ascii' codec can't encode character u'\u201a' in > > position 4: ordinal not in range(128) > > This thing returned by BeautifulSoup apparently doesn't return a bytestring > repr, and Python's attempt to auto-convert it to str fails since it contains > a character that has no mapping in ASCII. > > > >>> soup.contents > > [u'Andr\u201a goes to town'] > > >>> soup.contents[0] > > u'Andr\u201a goes to town' > > > >>> from myapp.events.models import Event > > >>> e = Event(title = soup.contents[0]) > > >>> e.save() > > >>> e.name > > u'Andr\u201a goes to town' > > These others are all ways of displaying the value of the unicode object in > an ASCII-only format, to avoid that EncodeError above. I'm not sure if you > are objecting to the fact that the reprs are printed using \u201a notation > or if you are objecting to the fact that your small e with actue accent has > been turned into single low-9 quotation mark? > > > > > But, as you see, the unicode does not get translated. > > Translated to what? You've got something that is not representable ASCII and > are trying to display it in a Windows (I think) command prompt, which is > notoriously bad at handling unicode. But most of what you've run into here > is an artifact of the fact you appear to be using a Windows command prompt, > so I doubt it is actually relevant to your actual Django code. If I try > similar in a Linux command prompt with a utf-8 encoding, I get: > > Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) > [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> > from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup > >>> html = "André goes to town" > >>> soup = BeautifulSoup(html) > >>> soup > > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position > 4: ordinal not in range(128)>>> print soup > André goes to town > >>> soup = BeautifulSoup(html, > > convertEntities=BeautifulStoneSoup.HTML_ENTITIES)>>> print soup > André goes to town > >>> soup.contents > > [u'Andr\xe9 goes to town'] > > In this case BeautifulSoup doesn't mis-guess what the encoding is, so the > accented character never gets converte
Entering unicode bytestrings in Django
Hi - I'm scraping some information from a website, but I'm having some trouble with special characters such as é. I'm using BeautifulSoup for the scraping, and would like to be able to have Django print out muy strings correctly (on the template, in the shell, in the admin). The way I go about it is: >>> from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup >>> html = "André goes to town" >>> soup = BeautifulSoup(html) >>> soup Andr goes to town >>> soup = BeautifulSoup(html, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) >>> soup Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u201a' in position 4: ordinal not in range(128) >>> soup.contents [u'Andr\u201a goes to town'] >>> soup.contents[0] u'Andr\u201a goes to town' >>> from myapp.events.models import Event >>> e = Event(title = soup.contents[0]) >>> e.save() >>> e.name u'Andr\u201a goes to town' But, as you see, the unicode does not get translated. What steps should I take in order to make sure my strings are saved (and later displayed) correctly? Many thanks in advance, Mathieu --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using AJAX and 'normal' forms
Hi - I've just started fiddling about with the prototype library in order to build in some AJAX functionality into my django site (which hasn't gone live yet). On one part of the page I'm using the Ajax.PeriodicalUpdater function which asynchronously polls a URL and then integrates the html response on the current page. Meanwhile, there are two 'standard' forms on the page, and it feels as if using these forms is troublesome. Sometimes the server response time is very slow (I'm using the built-in server) and sometimes I see the following error message: error: [Errno 10053] An established connection was aborted by the software in your host machine. Any ideas if there is any interference between the "classic" forms and the Ajax calls? If so, how can I avoid this? I'm using the latest CVS release of Django with Python 2.6 on Windows XP Pro. Thanks in advance, Laundro --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: request.POST.get is not working
On Sep 10, 1:50 pm, bharathi <[EMAIL PROTECTED]> wrote: > Hi LaundroMat, > > I tried request.POST['task'] .. But that also not working.. > It shows > " MultiValueDictKeyError at /addtask/ > Key task not found in QueryDict: {}" > > Wat i do now? > Help me Well, this means request.POST contains no key 'task', which means it wasn't POSTed by your script in the first place. I don't know enough of Javascript to help you there. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: request.POST.get is not working
On Sep 10, 12:25 pm, bharathi <[EMAIL PROTECTED]> wrote: > Hi, > I am using Django1.0 > In this request.POST.get() is not Working..It Gives empty value > (snip) What about request.POST['task']? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: New to django and python. error following tutorial w/ the shell
On 6 mei, 06:32, Norman <[EMAIL PROTECTED]> wrote: > and what editor do you use? > some advice? Geany (PC & Linux, Mac probably too) is the one I use. As for books, Core Python Programming is invaluable (to me at least) - see http://www.amazon.com/Core-Python-Programming-2nd/dp/0132269937/ref=pd_bbs_sr_7?ie=UTF8=books=1210054267=8-7 , and certainly have a look at these this online books as well: http://www.diveintopython.org/ Mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Subclassing a form, changing one field into required = False
On 5 mei, 14:39, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Mon, May 5, 2008 at 7:08 AM, LaundroMat <[EMAIL PROTECTED]> wrote: > > On 1 mei, 13:43, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > > > On Thu, May 1, 2008 at 7:22 AM, LaundroMat <[EMAIL PROTECTED]> wrote: > > > > > Hi - > > > > > Would it be possible to subclass a form class, and in that subclass > > > > define that one of the fields that were required in the parent class > > > > are no longer required in the subclass? > > > > You mean like this? > > > > >>> from django import newforms as forms > > > >>> class Form1(forms.Form): > > > > ... f1 = forms.CharField() > > > ... f2 = forms.CharField() > > > ... f3 = forms.CharField() > > > ...>>> class Form2(forms.Form): > > > > ... f1 = forms.CharField(required=False) > > > ... > > > > >>> f1inst = Form1({'f2': 'x', 'f3': 'y'}) > > > >>> f2inst = Form2({'f2': 'x', 'f3': 'y'}) > > > >>> f1inst.is_valid() > > > False > > > >>> f2inst.is_valid() > > > True > > > > Karen > > > Yes, but I'd like Form2 be a subclass of Form1, so that it also has > > the f2 and f3 attributes. > > Oops, I forgot to base Form2 on Form1. So you mean like this: > > >>> from django import newforms as forms > >>> class Form1(forms.Form): > > ... f1 = forms.CharField() > ... f2 = forms.CharField() > ... f3 = forms.CharField() > ...>>> class Form2(Form1): > > ... f1 = forms.CharField(required=False) > ...>>> f1inst = Form1({'f2': 'x', 'f3': 'y'}) > >>> f2inst = Form2({'f2': 'x', 'f3': 'y'}) > >>> f1inst.is_valid() > False > >>> f2inst.is_valid() > True > >>> f2inst.fields > > {'f1': , 'f2': > , 'f3': > } > > > > which seems to do what you want? Or am I missing something again? > > Karen Dang. There I was, trying to access f2inst's fields by treating them as if they were attributes (ie f2inst.f1, f2inst.f2 etc), which of course did not work. Thanks for the help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using frames in django
On 5 mei, 05:26, Gboro54 <[EMAIL PROTECTED]> wrote: > Hi everyone...I want to use frames in a web app i am building..I have > a display.html that has the frames sets and takes 2 other html > files...the one problem is the other 2 pages have variables binded to > them...I am not sure how to get this to work...any advice would be > apprciated...Thanks(code provided below for the html) > > sidbar.html > > > > > > > > width="100" align="left"> > > > > main.html > > > > > > > > > > > > height="100" align="left"/> > align="top"/> > > Welcome to Bass Log Online > > > > > display.html > > > > > > > > > > > > Just use urls in your display.html file, and let urlconf.py translate those to views. Within those views, you can render your template & pass along your variables. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Subclassing a form, changing one field into required = False
On 1 mei, 13:43, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Thu, May 1, 2008 at 7:22 AM, LaundroMat <[EMAIL PROTECTED]> wrote: > > > Hi - > > > Would it be possible to subclass a form class, and in that subclass > > define that one of the fields that were required in the parent class > > are no longer required in the subclass? > > You mean like this? > > >>> from django import newforms as forms > >>> class Form1(forms.Form): > > ... f1 = forms.CharField() > ... f2 = forms.CharField() > ... f3 = forms.CharField() > ...>>> class Form2(forms.Form): > > ... f1 = forms.CharField(required=False) > ... > > >>> f1inst = Form1({'f2': 'x', 'f3': 'y'}) > >>> f2inst = Form2({'f2': 'x', 'f3': 'y'}) > >>> f1inst.is_valid() > False > >>> f2inst.is_valid() > True > > Karen Yes, but I'd like Form2 be a subclass of Form1, so that it also has the f2 and f3 attributes. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Subclassing a form, changing one field into required = False
Hi - Would it be possible to subclass a form class, and in that subclass define that one of the fields that were required in the parent class are no longer required in the subclass? Thanks, Mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Confusion over new users and admin pages
Hi, When creating a new user, is_active is automatically set to True. The django docs say this means "Designates whether this account can be used to log in. Set this flag to False instead of deleting accounts." On the admin pages of a django website however, next to the "Active" flag, the description says: "Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts", and next to the "Staff status" (corresponding to the is_staff attribute) it says: "Designates whether the user can log into this admin site.". I suppose the text on the admin pages is wrong, and that newly created users cannot just log into the Django admin? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django Web Hosting Service
I have had good experiences (albeit limited; the hosted site is more a testing thing than something else at the moment) with a small orange as well: asmallorange.com On Nov 21, 2:40 pm, "Ronaldo Z. Afonso" <[EMAIL PROTECTED]> wrote: > Hi all, > > Can anybody recommend me a Django Web Hosting Service? > Thanks. > > Ronaldo. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: pagination for search result ...
request["filter"] is a session variable, that's why it works :) On Aug 10, 5:25 am, "Kai Kuehne" <[EMAIL PROTECTED]> wrote: > On 8/10/07, james_027 <[EMAIL PROTECTED]> wrote: > > > > > > > hi, > > > > def list_filter(request): > > > """Update session filter""" > > > # request['filter'] is a hidden field. frankly, I don't know if > > > this is really needed. > > > # I added it in case I add another form to the template > > > if request.method == 'POST' and request['filter'] == '1': > > > request.session['filter_title'] = request.POST['title'] > > > request.session['filter_genre'] = request.POST['genre'] > > > request.session['filter_rating'] = request.POST['rating'] > > > return HttpResponseRedirect('/') > > > thanks kai :). is this request['filter'] a django builtin or u just > > created it? > > No, I added it. It's a hidden field just to check that's the filter > that is fired up and not another form on the page. > > To tell the truth, this should be request.POST['filter'] and I > don't really know why request['filter'] worked. Thanks for > pointing that out. :-) > > Kai --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: auth system - check if user already exists
Are you sure you want to avoid that? I remember somebody here linking to an article where this wasn't advised, because it's (apparently) quite common for members of the same household to register with the same e-mail address (but with another username ofcourse). On Aug 6, 12:02 pm, Aljosa Mohorovic <[EMAIL PROTECTED]> wrote: > i'm checking username and email because i want to avoid situations > where some user registers with same email using different username. > > Aljosa --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: auth system - check if user already exists
Of the top of my head, but would the following be helpful? user, new = User.objects.get_or_create(username = user, email = email) The function returns either: - a new user object and True if the user didn't exist yet (and had to be created); - an object with existing user data and False. Mind that you still have to call user.save() in case of a new user. On Aug 5, 11:42 pm, Aljosa Mohorovic <[EMAIL PROTECTED]> wrote: > i'm currently looking at django.contrib.auth and wondering what is the > correct way to check if user already exists? > before i call User.objects.create_user() i want to know that user with > submitted username and email doesn't exist. > my current situation is that i call > User.objects.get(username__exact=user) and > User.objects.get(email__exact=email) and if i get exception > "DoesNotExist: User matching query does not exist." and i assume that > it's ok to create new user. > > i'm sure there is a better way to check if user with submitted > username or email already exists, please share your ways... > > Aljosa --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: OR a Q object - Problem with ManyToMany relationships?
Driving to work this morning I was thinking of how I should have had a look at the generated SQL statement (which I can't do now). I think you are right, it's the only way the exclusion could have happened. Would you have an idea of how to prevent this, preferrably without having to write the SQL statement myself? Thanks, Mathieu On Aug 3, 12:54 am, Nowell <[EMAIL PROTECTED]> wrote: > I believe that this is due to the fact that the last Q is performing > an INNER JOIN on the Authors table, and therefore is excluding all > records that do not have an entry in your (what I assume is a) > ManyToManyField/ForeignKey. > > On Aug 2, 5:37 pm, LaundroMat <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Suppose I have defined the models from the django documentation > > (http://www.djangoproject.com/documentation/db-api/). > > > I'm performing a search the entries model, and I want to look through > > all of its fields: > > > from django.db.models import Q > > query = > > 'querystring' # > > User supplied querystring, eg "Lawrence" > > lookup = Q(headline__icontains = querystring) | \ > > Q(body_text__icontains = querystring) | \ > > Q(authors__name__icontains = querystring) > > > p = Prediction.objects.filter(lookup).distinct() > > > The models I have built are more complex than the above, but the gist > > is the same. For one reason or another, I get more results when I > > leave out the last Q object (the one looking through the authors' > > names) than when I leave it in. This shouldn't be happening, as all Q > > objects are being OR'ed. > > > I hope I've given enough information for you to try and simulate my > > problem, and perchance find a solution for it. Many thanks in advance > > already. > > > Mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: shortcut for assigning values to model?
On 20 jul, 10:53, james_027 <[EMAIL PROTECTED]> wrote: > hi, > > is there a short cut for assigning input data to model's data > attribute? > > if Book is a model then > > b = Book(request.POST) > b.save() > > the assignment will be done on all the match key of the request.POST > QueryDict and data attribute of the Book Model. > > or > > if BookForm is a newform then > > bf = BookForm() > if bf.is_valid(): > b = Book(bf.cleaned_data) > > thanks > james You could run through the request.POST's keys and assign them to the Model's attributes: b = Book() for key in request.POST.keys(): ---b.__setattribute__(key, request.POST[key]) b.save() --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Logging in a newly created user
Hi, When running this, I get a "NoneType has no attribute is_authenticated()" error, and I cannot understand why: 1 new_user = User.objects.create_user(username, "your.email", password) 2 new_user.is_active = False 3 new_user.save() 4 user = authenticate(username = new_user.username, password = new_user.password) # See http://code.djangoproject.org/ticket/2656 5 if user.is_authenticated(): # The error is produced here. login(request, user) Why does authenticate() in line 4 return a None object instead of a user? Thanks for your help, Mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: one model per file
On 12 Jul, 10:21, james_027 <[EMAIL PROTECTED]> wrote: > Hi, > > I am following the official tutorial of django, and found out that > several model are define in a single file. I just wonder if we could > have one model per file? or can be as flexible as X no of models in > file A and Y no of models in file B and so on. > > If this is allowed, how to we name the files? > > Thanks > james Within django, models tend to be defined in the models.py file of the application's directory (/polls/models.py in the tutorial's example). Although I cannot try this from where I am now, I'm pretty sure you don't _have_ to do this this way. As you see later on in the tutorial, you register your application ("polls") in settings.py's INSTALLED_APPS. In order to use the model classes, you import them, as eg in: from mysite.polls.models import Polls, Choices What happens is that django (or rather: python) looks in the directory where polls resides, gets the models.py file and from there it imports the classes you want (in this case Polls and Choices). But nothing prevents you from creating a file called "poll_model.py" in the "polls" directory and import the Poll class from poll_model.py with "from mysite.polls.poll_model import Poll". I don't exactly see what you'd want to do this though. It's a lot easier to stick to the standard. I do use this for other classes (such as special form classes), where I create a forms.py file in my application's directory and import the necessary forms via eg "from mysite.polls.forms import SpecialForm". If you're worried about having too many models in one single model.py file, maybe you should consider splitting up your project in different applications. It makes the whole development a lot more manageable. Hope this helps, mathieu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---