Re: how to use filter
On Sunday 17 May 2009 11:00:15 pm laspal wrote: > list = Status.objects.filter(someid = 20, value < val2, value > val1) try this: list = Status.objects.filter(someid=20, value__lt=val2).filter(value__gt=val1) -- Aaron Maxwell http://redsymbol.net/ --~--~-~--~~~---~--~~ 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 use filter
Hi, class Status(models.Model): someid = models.IntegerField() value = models.IntegerField() status_msg = models.CharField(max_length = 2000) so my database look like: 20 1234567890 'some mdg' 20 4597434534 'some msg2' 20 345394593'sdfgsdf' 10 450348534 'ddfgg' so I have to fetch values contain a giving someid between some values. so let say val1 = '1234567890' and val2 = '4414544544' so my final result should be list containing of 2 entry for id = 20 how to implement this. i tried using list = Status.objects.filter(someid = 20, value < val2, value > val1) which is wrong? how to fix this. 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: escape problem in django templates
Karen, thanks for your effort. It is bizarre that the problem seems to be gone after I have restarted the computer. I don't know if I can reproduce the situation (in fact I hope I can't). On May 16, 6:17 pm, Karen Tracey wrote: > On Sat, May 16, 2009 at 12:23 AM, ozgurisil wrote: > > > Hello all, > > > Let's say that I have this string: > > > s = 'Hello!' > > > When I pass this variable to a template, I want it to be rendered as > > raw html. Looking at the docs I see that I can either use the safe > > filter: > > > {{s|safe}} > > > or disable autoescape: > > > {%autoescape off} > > {{s}} > > {%endautoescape%} > > > or inside the python code declare it safe: > > > from django.utils.safestring import mark_safe > > s = mark_safe(s) > > > None of these options are working for me. Whatever I do, the string is > > displayed as: > > > Hello! > > > I must be missing something, just couldn't figure out what. Is there > > some security setting somewhere that disallows escaping? > > No, there is no setting like that. Given this view: > > from django.shortcuts import render_to_response > from django.template import Context > from django.utils.safestring import mark_safe > def escape_view(request): > v1 = 'Hello!' > v2 = mark_safe(v1) > > c = Context({'v1': v1, 'v2': v2}) > return render_to_response('escape_template.html', c) > > with an 'escape_template.html' that contains: > -- > v1 is: {{ v1 }} > > > > {% autoescape off %} > Inside an autoescape off block, v1 is: {{ v1 }} > {% endautoescape %} > > v1|safe is: {{ v1|safe }} > > v2 is: {{ v2 }} > -- > > I see: > -- > v1 is: Hello! > > Inside an autoescape off block, v1 is: > > Hello! > > v1|safe is: > > Hello! > > v2 is: > > Hello! > > -- > > in a browser. Looking at the source HTML, it is: > > -- > > v1 is:Hello!
> > > > Inside an autoescape off block, v1 is: Hello! > > v1|safe is: Hello! > > v2 is: Hello! > > -- > > So I only see the tag characters escaped when the string is not marked safe, > not sent through the safe filter, and not in an autoescape off block. If > you try that view/template, what do you see? If that works for you, what > are you doing differently in your code? (If that test view/template doesn't > work for you, I will be very confused.) > > 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 -~--~~~~--~~--~--~---
Does a django social sharing widget app exist?
Hi. Is anyone aware of a django app that helps with providing social-network sharing buttons to pages? I'm talking about services like Add to Any (http://addtoany.com/), or the Wordpress plugin known as Sociable (http://yoast.com/wordpress/sociable/). Ideally this would be a django app you could just add to the installed apps in settings.py, set a few config variables, then include something like {% social_share_buttons %} in the template. If this exists, google doesn't seem to know about it. Maybe I need to write it... Thanks, Aaron -- Aaron Maxwell http://redsymbol.net/ --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On Sun, 2009-05-17 at 20:01 -0700, Bobby Roberts wrote: > yeah i'm still lost... You don't need to change your form, just use form.cleaned_data in your view. Same example, a few more lines: >>> # our form ... >>> from django import forms >>> from django.contrib.auth.models import User >>> >>> class MessageForm(forms.Form): ... users = forms.ModelMultipleChoiceField( ... queryset=User.objects, ... widget=forms.CheckboxSelectMultiple) ... >>> # a dump of our template source ... >>> from django.template.loader import find_template_source >>> print find_template_source('message.html')[0] {{ form }} >>> >>> # our view ... >>> from django.shortcuts import render_to_response >>> from django.http import HttpResponseRedirect >>> >>> def message(request): # no auto_id just for testing ... if request.method == 'POST': ... form = MessageForm(request.POST, auto_id=False) ... if form.is_valid(): ... # normally: do something, then redirect ... print 'users:', form.cleaned_data['users'] ... return HttpResponseRedirect('') ... else: ... form = MessageForm(auto_id=False) ... return render_to_response('message.html', { 'form': form }) ... >>> # our urls ... >>> from django.conf.urls import defaults >>> urlpatterns = defaults.patterns('', (r'^message', message)) >>> >>> # example output ... >>> User(username='sdc').save() >>> User(username='bobby').save() >>> >>> from django.test.client import Client >>> client = Client() >>> >>> # get the form ... print client.get('/message/') Content-Type: text/html; charset=utf-8 Users: sdc bobby >>> >>> # post with some good data ... print client.post('/message/', {'users': [1, 2]}) users: [, ] Content-Type: text/html; charset=utf-8 Location: http://testserver/message/ >>> And yeah, request.POST.get() returns one value, and getlist() returns a list. See: http://docs.djangoproject.com/en/1.0/ref/request-response/#querydict-objects sdc --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
> You should be looking in cleaned_data, see: > > http://docs.djangoproject.com/en/1.0/topics/forms/#processing-the-dat... > > For a ModelMultipleChoiceField, cleaned_data will be a list of model > instances. You shouldn't even have to think about the pk s. > > sdc yeah i'm still lost... this is what i have now: forms.py class FrmIdMessage (forms.Form): posted_to = forms.ModelMultipleChoiceField (queryset=User.objects, required=True,widget=forms.CheckboxSelectMultiple()) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) def clean_posted_to(self): data=self.cleaned_data['posted_to'] return data still results in the last checkbox checked... I'm not sure what to do in the clean function views.py #process or just push form if request.method=='POST': form=FrmIdMessage(request.POST) if form.is_valid(): #process valid form here assert False, request.POST.get('posted_to','') [snip] --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On Sun, 2009-05-17 at 18:43 -0700, Bobby Roberts wrote: > in my view i have this: > > > if request.method=='POST': > form=FrmIdMessage(request.POST) > if form.is_valid(): #process valid form here > assert False, request.POST.get('posted_to','') > [snip] You should be looking in cleaned_data, see: http://docs.djangoproject.com/en/1.0/topics/forms/#processing-the-data-from-a-form For a ModelMultipleChoiceField, cleaned_data will be a list of model instances. You shouldn't even have to think about the pk s. sdc --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On May 17, 4:23 pm, Bobby Roberts wrote: > > ... users = forms.ModelMultipleChoiceField( > > ... queryset=User.objects, > > ... widget=forms.CheckboxSelectMultiple, > > ... required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > ok so here's what i have so far: class FrmIdMessage (forms.Form): posted_to = forms.ModelMultipleChoiceField (queryset=User.objects, required=True,widget=forms.CheckboxSelectMultiple()) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) in my view i have this: if request.method=='POST': form=FrmIdMessage(request.POST) if form.is_valid(): #process valid form here assert False, request.POST.get('posted_to','') [snip] The only that prints out is: 2 which represents the last textbox checked. The HTML generated by the form.py includes: admin test test2 all of these checkboxes have the same name. Why isn't this passed back to forms.py as a list? How can i get all of the values for the checkboxes if i check all three? --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On May 17, 4:23 pm, Bobby Roberts wrote: > > ... users = forms.ModelMultipleChoiceField( > > ... queryset=User.objects, > > ... widget=forms.CheckboxSelectMultiple, > > ... required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > ok so here's what i have so far: class FrmIdMessage (forms.Form): posted_to = forms.ModelMultipleChoiceField (queryset=User.objects, required=True,widget=forms.CheckboxSelectMultiple()) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) in my view i have this: if request.method=='POST': form=FrmIdMessage(request.POST) if form.is_valid(): #process valid form here assert False, request.POST.get('posted_to','') [snip] The only that prints out is: 2 which represents the last textbox checked. The HTML generated by the form.py includes: admin test test2 all of these checkboxes have the same name. Why isn't this passed back to forms.py as a list? How can i get all of the values for the checkboxes if i check all three? --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On May 17, 4:23 pm, Bobby Roberts wrote: > > ... users = forms.ModelMultipleChoiceField( > > ... queryset=User.objects, > > ... widget=forms.CheckboxSelectMultiple, > > ... required=True) > > ...>>> User(username='sdc').save() > > >>> User(username='bobby').save() > ok so here's what i have so far: class FrmIdMessage (forms.Form): posted_to = forms.ModelMultipleChoiceField (queryset=User.objects, required=True,widget=forms.CheckboxSelectMultiple()) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) in my view i have this: if request.method=='POST': form=FrmIdMessage(request.POST) if form.is_valid(): #process valid form here assert False, request.POST.get('posted_to','') [snip] The only that prints out is: 2 which represents the last textbox checked. The HTML generated by the form.py includes: admin test test2 all of these checkboxes have the same name. Why isn't this passed back to forms.py as a list? How can i get all of the values for the checkboxes if i check all three? --~--~-~--~~~---~--~~ 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: dictsort / regroup - custom order?
Well, it was worth a shot. ;-) Thanks! On May 17, 6:27 pm, Alex Gaynor wrote: > On Sun, May 17, 2009 at 5:23 PM, ringemup wrote: > > > If I have a dict that needs to be sorted and regrouped, but I want to > > order the groups in a custom manner rather than alphabetically by the > > regrouping key... is that feasible? > > The dictsort template filter just uses the default ordering of the key you > provide, if you want some other ordering the best way to do it would > probably be to write a custom template tag/filter. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: additional data on ManyToManyField and symmetrical
On Sat, May 16, 2009 at 6:14 PM, Alex Rades wrote: > > Hi, > I have a model which looks like: > > class Person(models.Model): > friends = models.ManyToManyField("self", through="Friendship") > > class Friendship(models.Model): > person_a = models.ForeignKey(Person) > person_b = models.ForeignKey(Person, related_name="_unused_") > > Now, as mentioned in: > > http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany > > For this to work, you also /have/ to use symmetrical=False in the > ManyToManyField, but frankly I don't understand why. > Do you have an explanation? When you have a symmetrical m2m relation to self, Django needs to store 2 rows in the m2m table to fully represent the relation - that is, when you store a 'friendship' between Alice and Bob, Django stores the relationship (alice, bob) and the relationship (bob, alice). This poses a problem when you are using an intermediate m2m table: what happens to the other data in the m2m table? Do you duplicate the intermediate data? How do you guarantee consistency? If I modify the m2m relation in one direction, what updates the row in the other direction? If anyone comes up with a creative way to address this issue, I'm certainly willing to entertain those ideas. However, in the interim, Django takes the conservative path, preventing behaviour that is predictably problematic. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: RE searches using sqlite3 on server failing
Thank you for your reply, Karen. Your interpretations are correct. The searching works fine using sqlite3 on my windows development machine. The searching works fine on the Linux machine (Apache 2) using MySQL as the DB engine, but blows up when I try to use the sqlite3 engine there. I can use the Django shell on the Linux machine with sqlite3 to do the same searching as I perform in the view and then there are no problems. I will try your suggestion to set up some very simple regexp filters and see if I can get something to work through Apache, then go from there step-by-step. The problem does seem to reside with the user- defined regex function, because when I substituted "icontains" for "iregex" the altered filter worked fine. There is some mysterious interaction here. I'll report any break-throughs on my part. On May 17, 6:01 pm, Karen Tracey wrote: > On Sun, May 17, 2009 at 5:20 PM, Ned wrote: > > > I would greatly appreciate any explanations or suggested > > courses of action to get to the bottom of the problem described below. > > If more information would be helpful I'd be glad to supply it. I'm > > using Django 1.0. > > > I have a search application, in prototype stage, that makes use of > > regular expressions entered by the user to search text values in a > > table. The application is being developed using sqlite3 on a windows > > machine. I transfer the files and load MySQL records > > to a linux machine set up as a server. The application runs as > > expected using MySQL and successfully searches the text values with > > regular expressions, including those with special characters. > > > I wanted to compare performance on the linux machine if instead it > > used sqlite3. For reasons I don't understand, the attempt to search, > > with any regular expression, produces an exception: > > > --- begin exception traceback --- > > [snip gory details] > > 19. return self.cursor.execute(sql, params) > > File "/var/lib/python-support/python2.5/django/db/backends/sqlite3/ > > base.py" in execute > > 167. return Database.Cursor.execute(self, query, params) > > > Exception Type: OperationalError at /mrdocs-search/results/ > > Exception Value: user-defined function raised exception > > > --- end exception traceback --- > > > An excerpt of the code in my view that leads to this problem is the > > ff: > > [snip code details] > > I can duplicate the essence of the code above and run it manually > > in the django shell: it works without problems using sqlite3. > > I'm a little fuzzy on what works and doesn't work here. Sounds like you > have a Windows development machine where you use sqlite3 and all works OK? > Also all is OK on your production Linux machine (running the server under > Apache...something else?) so long as the Linux machine is set up to use > MySQL? But if you change settings on the production machine to use sqlite3 > you get the error? > > You say you can duplicate the essence of the code and run it in the shell OK > -- you mean on the same machine where you are seeing the error? > > How about some absolutely trivial regex filter in the environment where you > see the failure? Never mind duplicating the complexity of your real code -- > can you get a trivial regex filter to work there? If yes, then you can > modify it step by step and figure out where the error crops up, which might > give a clue. > > > > > I thought that the query or the params in the final traceback > > statement: > > > return Database.Cursor.execute(self, query, params) > > > might be mangled somehow. I enclosed that statment in base.py > > with a try - except clause and raised my own Exception, to view > > the SQL and the param: they were as expected (from looking at > > connection.queries[-1]['sql'] while running the code manually in the > > django shell). > > > I'm mystified at this point. Thanks for looking into this. > > Unfortunately the sqlite error message is not very informative. You can see > the user-defined function involved in regex handling here: > > http://code.djangoproject.com/browser/django/tags/releases/1.0/django... > > It's got a try/except around everything (all 1line) except 'import re', so > I'm puzzled how that could be raising an exception. But you could add some > logging to it, and perhaps the other user-defined functions registered for > the connection, you can see them all here: > > http://code.djangoproject.com/browser/django/tags/releases/1.0/django... > > and see if that sheds any light. > > 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: has_add_permission() isn't working properly
here it is: http://code.djangoproject.com/ticket/11136 hope this will be considered, since it improves the user experience. Thanks for your feedback, Sergio On May 18, 12:19 am, Alex Gaynor wrote: > On Sun, May 17, 2009 at 5:15 PM, Karen Tracey wrote: > > On Sun, May 17, 2009 at 5:34 PM, Sergio A. > > wrote: > > >> the issue seems not to be totally solved by the patch. > > >> If I have two classes A and B > >> class A has a field being a foreign key to a B class field > >> in the admin, when I add an A element, I see the '+' button on the > >> foreign key field to B even though I do not have the rights to create > >> a B element. > >> Therefore I see a pop-up with permission denied. > > >> How to fix this? > > > That's a slightly different problem, and will need its own ticket. Despite > > superficial similarity, hose "add another" links on the add/change pages for > > an object are coming from completely different code than the other problem > > mentioned in this thread. Specifically, they are added by the > > RelatedFieldWidgetWrapper. From a quick look I'm not sure this one is going > > to be easy to fixI don't know that the widget wrapper has the necessary > > information to decide whether to include that link. But you could open a > > ticket for someone to take a closer look. > > > Karen > > The widget doesn't really have the necessary info there. Specfically it > needs the logged in user (or at least the computed info about them), however > it's not going to have that since there's no way for the render() method to > get that since it's not a part of the forms library. The best you could do > is to pass it the widget constructor, which will be ok because of how we use > the widgets in the admin, which will require a little bit of > re-architecting. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: RE searches using sqlite3 on server failing
On Sun, May 17, 2009 at 5:20 PM, Ned wrote: > > I would greatly appreciate any explanations or suggested > courses of action to get to the bottom of the problem described below. > If more information would be helpful I'd be glad to supply it. I'm > using Django 1.0. > > I have a search application, in prototype stage, that makes use of > regular expressions entered by the user to search text values in a > table. The application is being developed using sqlite3 on a windows > machine. I transfer the files and load MySQL records > to a linux machine set up as a server. The application runs as > expected using MySQL and successfully searches the text values with > regular expressions, including those with special characters. > > I wanted to compare performance on the linux machine if instead it > used sqlite3. For reasons I don't understand, the attempt to search, > with any regular expression, produces an exception: > > --- begin exception traceback --- > [snip gory details] > 19. return self.cursor.execute(sql, params) > File "/var/lib/python-support/python2.5/django/db/backends/sqlite3/ > base.py" in execute > 167. return Database.Cursor.execute(self, query, params) > > Exception Type: OperationalError at /mrdocs-search/results/ > Exception Value: user-defined function raised exception > > --- end exception traceback --- > > An excerpt of the code in my view that leads to this problem is the > ff: > [snip code details] > I can duplicate the essence of the code above and run it manually > in the django shell: it works without problems using sqlite3. > I'm a little fuzzy on what works and doesn't work here. Sounds like you have a Windows development machine where you use sqlite3 and all works OK? Also all is OK on your production Linux machine (running the server under Apache...something else?) so long as the Linux machine is set up to use MySQL? But if you change settings on the production machine to use sqlite3 you get the error? You say you can duplicate the essence of the code and run it in the shell OK -- you mean on the same machine where you are seeing the error? How about some absolutely trivial regex filter in the environment where you see the failure? Never mind duplicating the complexity of your real code -- can you get a trivial regex filter to work there? If yes, then you can modify it step by step and figure out where the error crops up, which might give a clue. > > I thought that the query or the params in the final traceback > statement: > >return Database.Cursor.execute(self, query, params) > > might be mangled somehow. I enclosed that statment in base.py > with a try - except clause and raised my own Exception, to view > the SQL and the param: they were as expected (from looking at > connection.queries[-1]['sql'] while running the code manually in the > django shell). > > I'm mystified at this point. Thanks for looking into this. > > Unfortunately the sqlite error message is not very informative. You can see the user-defined function involved in regex handling here: http://code.djangoproject.com/browser/django/tags/releases/1.0/django/db/backends/sqlite3/base.py#L199 It's got a try/except around everything (all 1line) except 'import re', so I'm puzzled how that could be raising an exception. But you could add some logging to it, and perhaps the other user-defined functions registered for the connection, you can see them all here: http://code.djangoproject.com/browser/django/tags/releases/1.0/django/db/backends/sqlite3/base.py#L146 and see if that sheds any light. 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: LANGUAGE_CODE
friend ,you can do a judge operation ,mapping the English terms to the Chinese terms . that is all your need to do .because django is wirtten by english-spoken guys .(i am chinese but this is a english list ,so I write english) On 5/18/09, Kai Kuehne wrote: > > Hi, > > 2009/5/17 sammysun : >> >> Hi: >>When I set LANGUAGE_CODE = 'zh-cn' in the sitting file. I want to >> get a 3 letters of month useing filter "date" in the template, e.g. >> Useing {{ entry.pub_date|date:"M"}}, I will get "五月" in chinese, but >> the one I expect is "May". How can I fix this? > > Why do you expect an english term when you said django > you want chinese 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: parsing data from fileupload
On Sun, May 17, 2009 at 5:39 PM, Patrick wrote: > > Filenames is also a table, but I'm interested in the data withing the > file. > > On May 17, 2:38 pm, Antoni Aloy wrote: > > 2009/5/17 Patrick : > > > > > How do I add data from a fileupload to a database? > > > For example, if I have a Book model that is for names of books and a > > > FileNames model that is used on a form, how do I populate Book.title. > > > > > class FileNames(models.Model): > > >title = models.FileField(upload_to='tmp', blank=False) > > > > > class Book(models.Model): > > >title = models.CharField(max_length=30) > > > > > I'm able to upload and parse the file. I'm just not sure how to add > > > the parsed data to Book. > > > > So FileNames is not a real table? I'm confused ... > > > > Please checkhttp:// > docs.djangoproject.com/en/dev/topics/http/file-uploads/ > > it would help you a lot to deal with file uploads. > > > > -- > > Antoni Aloy López > > Blog:http://trespams.com > > Site:http://apsl.net > > > Getting an instance of a FileName and accessing .title on it will give you a file like object you can work with normally and extract whatever information you want from it. I'm not 100% sure I understand your question. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: parsing data from fileupload
Filenames is also a table, but I'm interested in the data withing the file. On May 17, 2:38 pm, Antoni Aloy wrote: > 2009/5/17 Patrick : > > > How do I add data from a fileupload to a database? > > For example, if I have a Book model that is for names of books and a > > FileNames model that is used on a form, how do I populate Book.title. > > > class FileNames(models.Model): > > title = models.FileField(upload_to='tmp', blank=False) > > > class Book(models.Model): > > title = models.CharField(max_length=30) > > > I'm able to upload and parse the file. I'm just not sure how to add > > the parsed data to Book. > > So FileNames is not a real table? I'm confused ... > > Please checkhttp://docs.djangoproject.com/en/dev/topics/http/file-uploads/ > it would help you a lot to deal with file uploads. > > -- > Antoni Aloy López > Blog:http://trespams.com > Site:http://apsl.net --~--~-~--~~~---~--~~ 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: please help me
thank you for your reply ,I will try . On 5/17/09, Eric Abrahamsen wrote: > > > On May 17, 2009, at 1:26 AM, Apple wrote: > >> >> I write some code like following: >> >> #coding=utf8 >> from django.shortcuts import render_to_response >> from django.http import * >> from django.contrib.auth.models import User >> from django.contrib.auth.decorators import login_required >> import datetime >> import md5 >> >> def to_reg(request): >>section = '欢迎注册为本系统的合法用户' >>return render_to_response('user_manage/to_reg.html', >> {'section':section}) >> def reg(request): >>username = request.POST['user_name'] >>first_name = request.POST['first_name'] >>last_name = request.POST['last_name'] >>email = request.POST['email'] >>password = request.POST['password'] >>re_password = request.POST['re_password'] >>#获取当前时间 >>nowtime = datetime.datetime.now() >> >>try: >>user = User.objects.get(username=username) >>msg = '此用户名已经被注册,请选用其他的用户名' >>return HttpResponse('alert(\'' + msg + >> '\');history.go(-1)') >>except: >>pass >> >>if password != re_password: >>msg = '您两次输入的密码不一致,请重新输入!' >>return HttpResponse('alert(\'' + msg + >> '\');history.go(-1)') >>else: >>try: >>user = User() >>user.username = username >>user.first_name = first_name >>user.last_name = last_name >>user.email = email >>user.password = md5.md5(password).hexdigest()#出于安全 >> 性的考虑 >>user.is_staff = 0 #没有管理权限 >>user.is_active = 1 #默认注册即激活 >>user.is_superuser = 0 #不是超级用户 >>user.last_login = nowtime #当前时间即最后登陆时间 >>user.date_joined = nowtime #注册时间 >>user.save() >>msg = '注册成功,请登陆后使用系统提供的各项功能!' >>return HttpResponse('alert(\'' + msg + >> '\');window.location.href="/"') >>except: >>msg = '注册失败,请重新尝试!' >>return HttpResponse('alert(\'' + msg + >> '\');history.go(-1)') >> >> def login(request): >>username = request.POST['user_name'] >>password = request.POST['password'] >>password = md5.md5(password).hexdigest() >>try: >>user = User.objects.get(username=username) >>real_password = user.password >>if password == real_password and user.is_active == 1: >>msg = '登陆成功,您将进入会员中心!' >>return HttpResponse('alert(\'' + msg + >> '\');window.location.href="/user/user_center/"') > > All you're doing here is checking that the password matches, you're > not actually logging the user in (which requires sessions and cookies > and all that). Take a look at this section of the docs to see how to > do that: > > http://docs.djangoproject.com/en/dev/topics/auth/#how-to-log-a-user-in > > If you don't need your login view to do anything special, you can just > use the built-in view that comes with the auth contrib app, found at > django.contrib.auth.views.login. You can tie that directly into your > url config. > > Hope that helps, > Eric > > >>else: >>return HttpResponse("密码不正确") >>except: >>msg = '此用户不存在,或者因其他原因被禁止!' >>return HttpResponse('alert(\'' + msg + '\');history.go >> (-1)') >> >> @login_required >> def user_center(request): >>section = '用户中心' >>user = request.user >>user_id = user.id >>return render_to_response('user_manage/user_center.html', >> {'section':section},context_instance=RequestContext(request)) >> *** >> >> I login the system successfully ,but when I redirect to the url that >> processed by the function user_center ,it said that i didn't login and >> redirect the page to the login page . why ? I really logged in ! Where >> is the point ? >> > > > > > > --~--~-~--~~~---~--~~ 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: What's the recommended way to use ForeignKey?
On Sun, May 17, 2009 at 5:31 PM, Thierry wrote: > > In the Django doc at > http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey > , > it mentions explicitly specifying the application label in 1.0: > > class Car(models.Model): >manufacturer = models.ForeignKey('production.Manufacturer') > > The above is using a string for the ForeignKey, is that the preferred > way over explicitly specifying Manufacturer, like the following: > > # assuming class Manufacturer is in the same file as class Car > class Car(models.Model): >manufacturer = models.ForeignKey(Manufacturer) > > > > The generally reccomended way to use it is to always import the module, except in the case where a circular reference would prevent you from doing so. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
What's the recommended way to use ForeignKey?
In the Django doc at http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey, it mentions explicitly specifying the application label in 1.0: class Car(models.Model): manufacturer = models.ForeignKey('production.Manufacturer') The above is using a string for the ForeignKey, is that the preferred way over explicitly specifying Manufacturer, like the following: # assuming class Manufacturer is in the same file as class Car class Car(models.Model): manufacturer = models.ForeignKey(Manufacturer) --~--~-~--~~~---~--~~ 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: dictsort / regroup - custom order?
On Sun, May 17, 2009 at 5:23 PM, ringemup wrote: > > If I have a dict that needs to be sorted and regrouped, but I want to > order the groups in a custom manner rather than alphabetically by the > regrouping key... is that feasible? > > > The dictsort template filter just uses the default ordering of the key you provide, if you want some other ordering the best way to do it would probably be to write a custom template tag/filter. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
dictsort / regroup - custom order?
If I have a dict that needs to be sorted and regrouped, but I want to order the groups in a custom manner rather than alphabetically by the regrouping key... is that feasible? --~--~-~--~~~---~--~~ 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: has_add_permission() isn't working properly
On Sun, May 17, 2009 at 5:15 PM, Karen Tracey wrote: > On Sun, May 17, 2009 at 5:34 PM, Sergio A. wrote: > >> >> >> the issue seems not to be totally solved by the patch. >> >> If I have two classes A and B >> class A has a field being a foreign key to a B class field >> in the admin, when I add an A element, I see the '+' button on the >> foreign key field to B even though I do not have the rights to create >> a B element. >> Therefore I see a pop-up with permission denied. >> >> How to fix this? >> >> > That's a slightly different problem, and will need its own ticket. Despite > superficial similarity, hose "add another" links on the add/change pages for > an object are coming from completely different code than the other problem > mentioned in this thread. Specifically, they are added by the > RelatedFieldWidgetWrapper. From a quick look I'm not sure this one is going > to be easy to fixI don't know that the widget wrapper has the necessary > information to decide whether to include that link. But you could open a > ticket for someone to take a closer look. > > Karen > > > > The widget doesn't really have the necessary info there. Specfically it needs the logged in user (or at least the computed info about them), however it's not going to have that since there's no way for the render() method to get that since it's not a part of the forms library. The best you could do is to pass it the widget constructor, which will be ok because of how we use the widgets in the admin, which will require a little bit of re-architecting. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: has_add_permission() isn't working properly
On Sun, May 17, 2009 at 5:34 PM, Sergio A. wrote: > > > the issue seems not to be totally solved by the patch. > > If I have two classes A and B > class A has a field being a foreign key to a B class field > in the admin, when I add an A element, I see the '+' button on the > foreign key field to B even though I do not have the rights to create > a B element. > Therefore I see a pop-up with permission denied. > > How to fix this? > > That's a slightly different problem, and will need its own ticket. Despite superficial similarity, hose "add another" links on the add/change pages for an object are coming from completely different code than the other problem mentioned in this thread. Specifically, they are added by the RelatedFieldWidgetWrapper. From a quick look I'm not sure this one is going to be easy to fixI don't know that the widget wrapper has the necessary information to decide whether to include that link. But you could open a ticket for someone to take a closer look. 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: LANGUAGE_CODE
Hi, 2009/5/17 sammysun : > > Hi: >When I set LANGUAGE_CODE = 'zh-cn' in the sitting file. I want to > get a 3 letters of month useing filter "date" in the template, e.g. > Useing {{ entry.pub_date|date:"M"}}, I will get "五月" in chinese, but > the one I expect is "May". How can I fix this? Why do you expect an english term when you said django you want chinese 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: How do I override __unicode__ for User?
Sorry, pressed that button too early: You could also write a default method inside your BlogPost model. Maybe something like: class BlogPost(models.Model): ... def author_name(self): return '%s %s' % (self.author.first_name, self.author.last_name) --~--~-~--~~~---~--~~ 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: parsing data from fileupload
2009/5/17 Patrick : > > How do I add data from a fileupload to a database? > For example, if I have a Book model that is for names of books and a > FileNames model that is used on a form, how do I populate Book.title. > > class FileNames(models.Model): > title = models.FileField(upload_to='tmp', blank=False) > > > class Book(models.Model): > title = models.CharField(max_length=30) > > I'm able to upload and parse the file. I'm just not sure how to add > the parsed data to Book. > So FileNames is not a real table? I'm confused ... Please check http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ it would help you a lot to deal with file uploads. -- Antoni Aloy López Blog: http://trespams.com Site: http://apsl.net --~--~-~--~~~---~--~~ 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 do I override __unicode__ for User?
Hi, On Sun, May 17, 2009 at 10:59 PM, Thierry wrote: > > I currently have a blog model: > > [BlogPost Model] > > Right now, author is returning the default User.username. I have > other models who has a ForeignKey to User, I want them to keep > defaulting to username while for Blogpost, I want it to return > "first_name last_name". How can I customize the above so that author > returns me "first_name last_name" if they are present? You can create a proxy model to add new methods to the User model. Description here: http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models --~--~-~--~~~---~--~~ 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: has_add_permission() isn't working properly
the issue seems not to be totally solved by the patch. If I have two classes A and B class A has a field being a foreign key to a B class field in the admin, when I add an A element, I see the '+' button on the foreign key field to B even though I do not have the rights to create a B element. Therefore I see a pop-up with permission denied. How to fix this? Cheers, Sergio On Mar 25, 7:14 pm, Alex Gaynor wrote: > 2009/3/25 João Olavo Baião de Vasconcelos > > > > > On Wed, Mar 25, 2009 at 10:25 AM, Karen Tracey wrote: > > >> Probably a missed bit from when this was fixed for the other pages, see > >> ticket #5447: > > > Thanks a lot, Karen. I opened a new ticket: > >http://code.djangoproject.com/ticket/10624#preview(they said in #5447 to > > create a new one if an issue remains). > > >>http://code.djangoproject.com/ticket/5447 > > >> In a quick look I don't see a ticket for this one, so if you get a chance > >> it would be useful if you could write it up so it's not forgotten. > > >> Karen > > > -- > > João Olavo Baião de Vasconcelos > > Bacharel em Ciência da Computação > > Analista de Sistemas - Infraestrutura > > joaoolavo.wordpress.com > > I've closed this as a dupe of #9036, as you can see the issue is that the > has_add_permission method isn't ever called. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
RE searches using sqlite3 on server failing
I would greatly appreciate any explanations or suggested courses of action to get to the bottom of the problem described below. If more information would be helpful I'd be glad to supply it. I'm using Django 1.0. I have a search application, in prototype stage, that makes use of regular expressions entered by the user to search text values in a table. The application is being developed using sqlite3 on a windows machine. I transfer the files and load MySQL records to a linux machine set up as a server. The application runs as expected using MySQL and successfully searches the text values with regular expressions, including those with special characters. I wanted to compare performance on the linux machine if instead it used sqlite3. For reasons I don't understand, the attempt to search, with any regular expression, produces an exception: --- begin exception traceback --- Environment: Request Method: GET Request URL: http://dyndoc.dyndns.org:8000/mrdocs-search/results/ Django Version: 1.0-final-SVN-unknown Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.sessions', 'proto.mr'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/var/lib/python-support/python2.5/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/home/django/project/proto/mr/views.py" in mrsearch 111. for p in mpageQS: File "/var/lib/python-support/python2.5/django/db/models/query.py" in _result_iter 179. self._fill_cache() File "/var/lib/python-support/python2.5/django/db/models/query.py" in _fill_cache 612. self._result_cache.append(self._iter.next ()) File "/var/lib/python-support/python2.5/django/db/models/query.py" in iterator 269. for row in self.query.results_iter(): File "/var/lib/python-support/python2.5/django/db/models/sql/query.py" in results_iter 206. for rows in self.execute_sql(MULTI): File "/var/lib/python-support/python2.5/django/db/models/sql/query.py" in execute_sql 1700. cursor.execute(sql, params) File "/var/lib/python-support/python2.5/django/db/backends/util.py" in execute 19. return self.cursor.execute(sql, params) File "/var/lib/python-support/python2.5/django/db/backends/sqlite3/ base.py" in execute 167. return Database.Cursor.execute(self, query, params) Exception Type: OperationalError at /mrdocs-search/results/ Exception Value: user-defined function raised exception --- end exception traceback --- An excerpt of the code in my view that leads to this problem is the ff: ... re_s = request.session.get('re_s', '') cs = request.session.get('cs', 0) pageQS = Page.objects.all() page_count = pageQS.count() if cs: qre_s = Q(line2__text__regex = re_s) else: qre_s = Q(line2__text__iregex = re_s) mpageQS = pageQS.filter(qre_s).distinct() fullpagelist = [] mpgno = 0 for p in mpageQS: fields = [] mpgno += 1 ... (What I'm doing essentially is searching records in a table whose content is lines from pages in documents: I want to know, for a given regular expression pattern (re_s) and for a specified case-sensitivity (cs) which pages contain lines in which there is an re match. In the code above the re pattern is retrieved from the session.) I can duplicate the essence of the code above and run it manually in the django shell: it works without problems using sqlite3. I thought that the query or the params in the final traceback statement: return Database.Cursor.execute(self, query, params) might be mangled somehow. I enclosed that statment in base.py with a try - except clause and raised my own Exception, to view the SQL and the param: they were as expected (from looking at connection.queries[-1]['sql'] while running the code manually in the django shell). I'm mystified at this point. Thanks for looking into 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 -~--~~~~--~~--~--~---
How do I override __unicode__ for User?
I currently have a blog model: class BlogPost(models.Model): title = models.CharField(max_length=150) body = models.TextField() author = models.ForeignKey(User) timestamp = models.DateTimeField() Right now, author is returning the default User.username. I have other models who has a ForeignKey to User, I want them to keep defaulting to username while for Blogpost, I want it to return "first_name last_name". How can I customize the above so that author returns me "first_name last_name" if they are present? --~--~-~--~~~---~--~~ 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: Oracle connection "cx_Oracle.DatabaseError: ORA-00911: invalid character"
On Sun, May 17, 2009 at 3:14 PM, Doug wrote: > > When I attempt to use Oracle as the backend for Django, I get this > error on issuing the 'syndb' command: > "cx_Oracle.DatabaseError: ORA-00911: invalid character". > > ** Configuration: Python 2.5; cx_Oracle 5.0.1- 10g and Django version...? > > ** Setting: Backend=oracle; User=django; PW=django; Host=BLANK; > Port=BLANK > > ** Complete Error Stack: > > Traceback (most recent call last): > File "manage.py", line 11, in >execute_manager(settings) > File "C:\Python25\lib\site-packages\django\core\management.py", line > 1672, in > execute_manager >execute_from_command_line(action_mapping, argv) > File "C:\Python25\lib\site-packages\django\core\management.py", line > 1571, in > execute_from_command_line >action_mapping[action](int(options.verbosity), > options.interactive) > File "C:\Python25\lib\site-packages\django\core\management.py", line > 534, in s > yncdb >cursor.execute(statement) File "C:\Python25\lib\site-packages\django\db\backends\oracle > \base.py", line 7 > 2, in execute >return Database.Cursor.execute(self, query, params) > cx_Oracle.DatabaseError: ORA-00911: invalid character > > > ** I can connect outside of Django: > >>> USER = 'django'; DATABASE_PW = 'django'; DATABASE_NAME = 'XE'; > >>> conn_str = "%s/%...@%s" % (USER, DATABASE_PW, DATABASE_NAME) > >>> conn_str > 'django/dja...@xe' > >>> myDB = cx_Oracle.connect(conn_str) > >>> myDB > > > Can someone help me with some guidance? What am I doing wrong? > The file django\core\management.py, referenced several times in that traceback, doesn't exist in Django 1.0. It existed in Django 0.96 but was refactored into a directory django\core\management before the 1.0 release. So you seem to be running some version of Django lower than 1.0. Yet 1.0 was the first version to have working Oracle support -- the branch that got Oracle working wasn't merged back to trunk until after 0.96 was released. So, if you are running a 0.96.x version of Django I wouldn't expect the Oracle backend to work there. If you are running an SVN checkout from after the Oracle branch merge (r5519), I have no idea what's going wrong. 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: How do I override the __unicode__ of User?
On Sun, May 17, 2009 at 3:51 PM, Thierry wrote: > > I currently have a blog model: > > class BlogPost(models.Model): >title = models.CharField(max_length=150) >body = models.TextField() >author = models.ForeignKey(User) >timestamp = models.DateTimeField() > > Right now, author is returning the default User.username. How can I > customize the above so that author returns me "first_name last_name" > if they are present? > > > The way to do that would be to use a proxy model: http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models if you're on the latest development version. Otherwise I'd just add a method to your model to print the user formatted as you'd like. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How do I override the __unicode__ of User?
I currently have a blog model: class BlogPost(models.Model): title = models.CharField(max_length=150) body = models.TextField() author = models.ForeignKey(User) timestamp = models.DateTimeField() Right now, author is returning the default User.username. How can I customize the above so that author returns me "first_name last_name" if they are present? --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On Sun, 2009-05-17 at 10:41 -0700, Bobby Roberts wrote: > from django import forms > from django.contrib.auth.models import User > > # pull a recordset of the users > userdata = User.objects.all() > > def myuserlist(self): > for i in userdata: > self[i.id]='%s %s' %(i.first_name,i.last_name) > return self.items() > > #used to post messages to oher users > class FrmIdMessage (forms.Form): > posted_to = forms.ChoiceField > (required=True,widget=forms.CheckboxSelectMultiple(attrs= > {'class':'optchecklist'},choices=myuserlist(userdata))) > message = forms.CharField (max_length=300, required=True, > widget=forms.Textarea(attrs={'class':'smallblob'})) I think you are looking for ModelMultipleChoiceField. Example: >>> from django import forms >>> from django.contrib.auth.models import User >>> >>> class MessageForm(forms.Form): ... users = forms.ModelMultipleChoiceField( ... queryset=User.objects, ... widget=forms.CheckboxSelectMultiple, ... required=True) ... >>> User(username='sdc').save() >>> User(username='bobby').save() >>> >>> print MessageForm(auto_id=False) Users: sdc bobby >>> For formatting the select list, see today's thread 'Formatting a Foreign key combo box'. sdc --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
> ... users = forms.ModelMultipleChoiceField( > ... queryset=User.objects, > ... widget=forms.CheckboxSelectMultiple, > ... required=True) > ...>>> User(username='sdc').save() > >>> User(username='bobby').save() dude you rock... i totally missed this. Does exactly what i need! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Oracle connection "cx_Oracle.DatabaseError: ORA-00911: invalid character"
When I attempt to use Oracle as the backend for Django, I get this error on issuing the 'syndb' command: "cx_Oracle.DatabaseError: ORA-00911: invalid character". ** Configuration: Python 2.5; cx_Oracle 5.0.1- 10g ** Setting: Backend=oracle; User=django; PW=django; Host=BLANK; Port=BLANK ** Complete Error Stack: Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "C:\Python25\lib\site-packages\django\core\management.py", line 1672, in execute_manager execute_from_command_line(action_mapping, argv) File "C:\Python25\lib\site-packages\django\core\management.py", line 1571, in execute_from_command_line action_mapping[action](int(options.verbosity), options.interactive) File "C:\Python25\lib\site-packages\django\core\management.py", line 534, in s yncdb cursor.execute(statement) File "C:\Python25\lib\site-packages\django\db\backends\oracle \base.py", line 7 2, in execute return Database.Cursor.execute(self, query, params) cx_Oracle.DatabaseError: ORA-00911: invalid character ** I can connect outside of Django: >>> USER = 'django'; DATABASE_PW = 'django'; DATABASE_NAME = 'XE'; >>> conn_str = "%s/%...@%s" % (USER, DATABASE_PW, DATABASE_NAME) >>> conn_str 'django/dja...@xe' >>> myDB = cx_Oracle.connect(conn_str) >>> myDB Can someone help me with some guidance? What am I doing wrong? Regards, Doug www.rmsfinance.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: Formatting a Foreign key combo box in admin change form
oops forgot to include: from django.contrib.auth.models import User On May 17, 6:18 pm, nih wrote: > Thanks for the info, took me a while to figure out what to do next, > I haven't delved into django internals much before. I ended up > with > > from django.db.models import ForeignKey > from django.forms import ModelChoiceField > > class UserModelChoiceField(ModelChoiceField): > def label_from_instance(self, obj): > if obj.first_name and obj.last_name: > return "%s.%s" % (obj.first_name[0], obj.last_name) > else: > # return username if first_name or last_name is empty > return obj.username > > class UserForeignKey(ForeignKey): > def formfield(self, **kwargs): > defaults = {'form_class': UserModelChoiceField} > defaults.update(kwargs) > return super(UserForeignKey, self).formfield(**defaults) > > class TestModel(models.Model): > name = UserForeignKey(User) > > # and that's it!, hardly any extra code in the end. > # django :) > > thx for the help Sam, i'd of never found that in the docs otherwise. > or it would of taken a really long time :) > > On May 17, 3:15 am, Sam Chuparkoff wrote: > > > On Fri, 2009-05-15 at 15:12 -0700, nih wrote: > > > in the admin change form the select box only shows name.username (eg > > > nih) > > > is it possible to show the full name in the select box > > > You are looking to override label_from_instance(). See here > > >http://docs.djangoproject.com/en/1.0/ref/forms/fields/#modelchoicefield > > > sdc --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
parsing data from fileupload
How do I add data from a fileupload to a database? For example, if I have a Book model that is for names of books and a FileNames model that is used on a form, how do I populate Book.title. class FileNames(models.Model): title = models.FileField(upload_to='tmp', blank=False) class Book(models.Model): title = models.CharField(max_length=30) I'm able to upload and parse the file. I'm just not sure how to add the parsed data to Book. 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
> oops, please modify the line from "self[i.id]='%s %s', > (i.first_name,i.last_name)" to "self[i.id]='%s %s' % > (i.first_name,i.last_name) " this results in the same issue: from django import forms from django.contrib.auth.models import User # pull a recordset of the users userdata = User.objects.all() def myuserlist(self): for i in userdata: self[i.id]='%s %s' %(i.first_name,i.last_name) return self.items() #used to post messages to oher users class FrmIdMessage (forms.Form): posted_to = forms.ChoiceField (required=True,widget=forms.CheckboxSelectMultiple(attrs= {'class':'optchecklist'},choices=myuserlist(userdata))) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) ~ --~--~-~--~~~---~--~~ 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 not respecting "exclude" - what am I doing wrong?
On Sun, May 17, 2009 at 12:38 PM, ringemup wrote: > > > Aha. I'm on 1.0. Can I still use custom validation on the ModelForm > if I use the ModelAdmin to exclude the fields? > > Thank you! > > > On May 17, 1:36 pm, Alex Gaynor wrote: > > On Sun, May 17, 2009 at 12:34 PM, ringemup wrote: > > > > > I'm trying to exclude some fields from an admin form, but the exclude > > > option on the ModelForm is being ignored, as far as I can tell. The > > > following is my code. When I view the admin page in question, "Entry > > > Form Initialized" is printed to the command line, but all the fields, > > > including blog and slug, appear on the page. Clearly I'm doing > > > something wrong, but I can't figure out what. > > > > > Would someone be so good as to point me in the right direction? > > > Thanks! > > > > > class EntryForm(forms.ModelForm): > > >def __init__(self, *args, **kwargs): > > >super(EntryForm, self).__init__(*args, **kwargs) > > >print 'EntryForm Initialized' > > >class Meta: > > >model = Entry > > >exclude = ('blog', 'slug') > > > > > class EntryAdmin(admin.ModelAdmin): > > >form = EntryForm > > > > > admin.register(Entry, EntryAdmin) > > > > What version of Django are you using? Django only respects the exclude > and > > field options from the form in the latest development version, you can > > instead use the exclude and field options on the ModelAdmin class > directly > > if you're using an older version. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > Yes. :) Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelForm not respecting "exclude" - what am I doing wrong?
Aha. I'm on 1.0. Can I still use custom validation on the ModelForm if I use the ModelAdmin to exclude the fields? Thank you! On May 17, 1:36 pm, Alex Gaynor wrote: > On Sun, May 17, 2009 at 12:34 PM, ringemup wrote: > > > I'm trying to exclude some fields from an admin form, but the exclude > > option on the ModelForm is being ignored, as far as I can tell. The > > following is my code. When I view the admin page in question, "Entry > > Form Initialized" is printed to the command line, but all the fields, > > including blog and slug, appear on the page. Clearly I'm doing > > something wrong, but I can't figure out what. > > > Would someone be so good as to point me in the right direction? > > Thanks! > > > class EntryForm(forms.ModelForm): > >def __init__(self, *args, **kwargs): > >super(EntryForm, self).__init__(*args, **kwargs) > >print 'EntryForm Initialized' > >class Meta: > >model = Entry > >exclude = ('blog', 'slug') > > > class EntryAdmin(admin.ModelAdmin): > >form = EntryForm > > > admin.register(Entry, EntryAdmin) > > What version of Django are you using? Django only respects the exclude and > field options from the form in the latest development version, you can > instead use the exclude and field options on the ModelAdmin class directly > if you're using an older version. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ModelForm not respecting "exclude" - what am I doing wrong?
On Sun, May 17, 2009 at 12:34 PM, ringemup wrote: > > I'm trying to exclude some fields from an admin form, but the exclude > option on the ModelForm is being ignored, as far as I can tell. The > following is my code. When I view the admin page in question, "Entry > Form Initialized" is printed to the command line, but all the fields, > including blog and slug, appear on the page. Clearly I'm doing > something wrong, but I can't figure out what. > > Would someone be so good as to point me in the right direction? > Thanks! > > class EntryForm(forms.ModelForm): >def __init__(self, *args, **kwargs): >super(EntryForm, self).__init__(*args, **kwargs) >print 'EntryForm Initialized' >class Meta: >model = Entry >exclude = ('blog', 'slug') > > class EntryAdmin(admin.ModelAdmin): >form = EntryForm > > admin.register(Entry, EntryAdmin) > > > What version of Django are you using? Django only respects the exclude and field options from the form in the latest development version, you can instead use the exclude and field options on the ModelAdmin class directly if you're using an older version. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Seeking Example of MultipleChoiceField Example with dynamic Choices
oops, please modify the line from "self[i.id]='%s %s', (i.first_name,i.last_name)" to "self[i.id]='%s %s' % (i.first_name,i.last_name) " On May 17, 10:28 pm, Bobby Roberts wrote: > > Try this below code. I guess this will solve your purpose > > # pull a recordset of the users > > userdata = auth_user.objects.all() > > > def user_filler(self): > > for i in userdata: > > self[i.id] = '%s, %s', (i.firstname, i.lastname) > > return self.items() > > from django import forms > from django.contrib.auth.models import User > > # pull a recordset of the users > userdata = User.objects.all() > > def myuserlist(self): > for i in userdata: > self[i.id]='%s %s', (i.first_name,i.last_name) << return self.items() > > #used to post messages to oher users > class FrmIdMessage (forms.Form): > posted_to = forms.ChoiceField > (required=True,widget=forms.CheckboxSelectMultiple(attrs= > {'class':'optchecklist'},choices=myuserlist(userdata))) > message = forms.CharField (max_length=300, required=True, > widget=forms.Textarea(attrs={'class':'smallblob'})) > > I get a traceback at line 9 (flagged with <<< ERROR HERE above) > > Traceback is : QuerySet' object does not support item assignment --~--~-~--~~~---~--~~ 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 not respecting "exclude" - what am I doing wrong?
I'm trying to exclude some fields from an admin form, but the exclude option on the ModelForm is being ignored, as far as I can tell. The following is my code. When I view the admin page in question, "Entry Form Initialized" is printed to the command line, but all the fields, including blog and slug, appear on the page. Clearly I'm doing something wrong, but I can't figure out what. Would someone be so good as to point me in the right direction? Thanks! class EntryForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(EntryForm, self).__init__(*args, **kwargs) print 'EntryForm Initialized' class Meta: model = Entry exclude = ('blog', 'slug') class EntryAdmin(admin.ModelAdmin): form = EntryForm admin.register(Entry, EntryAdmin) --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
> Try this below code. I guess this will solve your purpose > > # pull a recordset of the users > userdata = auth_user.objects.all() > > def user_filler(self): > for i in userdata: > self[i.id] = '%s, %s', (i.firstname, i.lastname) > return self.items() > from django import forms from django.contrib.auth.models import User # pull a recordset of the users userdata = User.objects.all() def myuserlist(self): for i in userdata: self[i.id]='%s %s', (i.first_name,i.last_name) <
Re: Formatting a Foreign key combo box in admin change form
Thanks for the info, took me a while to figure out what to do next, I haven't delved into django internals much before. I ended up with from django.db.models import ForeignKey from django.forms import ModelChoiceField class UserModelChoiceField(ModelChoiceField): def label_from_instance(self, obj): if obj.first_name and obj.last_name: return "%s.%s" % (obj.first_name[0], obj.last_name) else: # return username if first_name or last_name is empty return obj.username class UserForeignKey(ForeignKey): def formfield(self, **kwargs): defaults = {'form_class': UserModelChoiceField} defaults.update(kwargs) return super(UserForeignKey, self).formfield(**defaults) class TestModel(models.Model): name = UserForeignKey(User) # and that's it!, hardly any extra code in the end. # django :) thx for the help Sam, i'd of never found that in the docs otherwise. or it would of taken a really long time :) On May 17, 3:15 am, Sam Chuparkoff wrote: > On Fri, 2009-05-15 at 15:12 -0700, nih wrote: > > in the admin change form the select box only shows name.username (eg > > nih) > > is it possible to show the full name in the select box > > You are looking to override label_from_instance(). See here > > http://docs.djangoproject.com/en/1.0/ref/forms/fields/#modelchoicefield > > sdc --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
Hi, Try this below code. I guess this will solve your purpose # pull a recordset of the users userdata = auth_user.objects.all() def user_filler(self): for i in userdata: self[i.id] = '%s, %s', (i.firstname, i.lastname) return self.items() Regards, Lokesh On May 17, 9:41 pm, Bobby Roberts wrote: > > p=Country.objects.all() -> capturing all the records from > > Country table > > def country_filler(self): -> function to generate a country > > list which we are going to fetch from the records > > incr = 0 > > for i in p: > > self[incr] = i.country > > incr = incr+1 > > return self.items() > > > country = forms.CharField(label="cnty", > > widget=forms.CheckboxSelectMultiple(choices=country_filler > > (country_list))) > > ok here's what i have based on that example: > > from django import forms > > # pull a recordset of the users > userdata = auth_user.objects.all() > > def user_filler(self): > counter=0 > for i in userdata: > self[counter] = i.username > counter=counter+1 > return self.items() > > #used to post messages to other users > class FrmMessage (forms.Form): > posted_to = forms.ChoiceField > (required=True,widget=forms.CheckboxSelectMultiple(attrs= > {'class':'optchecklist'},choices=user_filler(userdata))) > message = forms.CharField (max_length=300, required=True, > widget=forms.Textarea(attrs={'class':'smallblob'})) > > two questions. > > 1. first, is this right? > 2. secondly, how can i pass the auth_user.id and the right > auth_user.username back to the form? This example seems to just send > one back. I need the value of the checkboxes to be the id and the > visible text to be the firstname + lastname > > The idea is to let them choose to whom they want to send a quick > message --~--~-~--~~~---~--~~ 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: Help required to generate a query
On Sun, May 17, 2009 at 11:58 AM, Lokesh wrote: > > Hi, > > class BasicDetails(models.Model): >age = models.PositiveSmallIntegerField(null=False, blank=False) >dom = models.PositiveSmallIntegerField(null=False, blank=False) >dod = models.PositiveSmallIntegerField(null=False, blank=False) >doy = models.PositiveIntegerField(null=False, blank=False) >gender = models.CharField(max_length=1) > > Below I have provided the queries with results which I executed from > mysql prompt. > I am not able to figure out the django queries for these sql queries. > Could some one please guide me on resolving the below mysql queries in > django. > > mysql> select * from polls_basicdetails; > Django---> polls_basicdetails.objects.all() > > ++-+-+-+--++ > | id | age | dom | dod | doy | gender | > ++-+-+-+--++ > | 1 | 18 | 1 | 1 | 1991 | M | > | 2 | 19 | 1 | 1 | 1991 | M | > | 3 | 20 | 1 | 1 | 1991 | M | > | 4 | 18 | 1 | 1 | 1991 | M | > ++-+-+-+--++ > > mysql> select distinct age from polls_basicdetail > Django > ? > +-+ > | age | > +-+ > | 18 | > | 19 | > | 20 | > +-+ > > mysql> select age, dom from polls_basicdetails; > Django > ? > +-+-+ > | age | dom | > +-+-+ > | 18 | 1 | > | 19 | 1 | > | 20 | 1 | > | 18 | 1 | > +-+-+ > > Thanks for your time. > > Regards, > Lokesh > > > > > For the first one you want: Model.objects.values_list('age', flat=True).distinct() for the second: Model.objects.values('age', 'dom') Hopefully those are self-explanitory, if not: http://docs.djangoproject.com/en/dev/topics/db/queries/ :) Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Help required to generate a query
Hi, class BasicDetails(models.Model): age = models.PositiveSmallIntegerField(null=False, blank=False) dom = models.PositiveSmallIntegerField(null=False, blank=False) dod = models.PositiveSmallIntegerField(null=False, blank=False) doy = models.PositiveIntegerField(null=False, blank=False) gender = models.CharField(max_length=1) Below I have provided the queries with results which I executed from mysql prompt. I am not able to figure out the django queries for these sql queries. Could some one please guide me on resolving the below mysql queries in django. mysql> select * from polls_basicdetails; Django---> polls_basicdetails.objects.all() ++-+-+-+--++ | id | age | dom | dod | doy | gender | ++-+-+-+--++ | 1 | 18 | 1 | 1 | 1991 | M | | 2 | 19 | 1 | 1 | 1991 | M | | 3 | 20 | 1 | 1 | 1991 | M | | 4 | 18 | 1 | 1 | 1991 | M | ++-+-+-+--++ mysql> select distinct age from polls_basicdetail Django > ? +-+ | age | +-+ | 18 | | 19 | | 20 | +-+ mysql> select age, dom from polls_basicdetails; Django > ? +-+-+ | age | dom | +-+-+ | 18 | 1 | | 19 | 1 | | 20 | 1 | | 18 | 1 | +-+-+ Thanks for your time. Regards, Lokesh --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
> p=Country.objects.all() -> capturing all the records from > Country table > def country_filler(self): -> function to generate a country > list which we are going to fetch from the records > incr = 0 > for i in p: > self[incr] = i.country > incr = incr+1 > return self.items() > > country = forms.CharField(label="cnty", > widget=forms.CheckboxSelectMultiple(choices=country_filler > (country_list))) > ok here's what i have based on that example: from django import forms # pull a recordset of the users userdata = auth_user.objects.all() def user_filler(self): counter=0 for i in userdata: self[counter] = i.username counter=counter+1 return self.items() #used to post messages to other users class FrmMessage (forms.Form): posted_to = forms.ChoiceField (required=True,widget=forms.CheckboxSelectMultiple(attrs= {'class':'optchecklist'},choices=user_filler(userdata))) message = forms.CharField (max_length=300, required=True, widget=forms.Textarea(attrs={'class':'smallblob'})) two questions. 1. first, is this right? 2. secondly, how can i pass the auth_user.id and the right auth_user.username back to the form? This example seems to just send one back. I need the value of the checkboxes to be the id and the visible text to be the firstname + lastname The idea is to let them choose to whom they want to send a quick message --~--~-~--~~~---~--~~ 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: Seeking Example of MultipleChoiceField Example with dynamic Choices
On Sun, May 17, 2009 at 11:24 AM, Lokesh wrote: > > Hi Alex, > > Then I can go ahead with required=false attribute to avoid form > validation and validation should be taken care by program. > Correct me if I am wrong. > > Regards, > Lokesh > > > >incr = 0 > > >for i in p: > > > self[incr] = i.country > > > incr = incr+1 > > >return self.items() > > > > > country = forms.CharField(label="cnty", > > > widget=forms.CheckboxSelectMultiple(choices=country_filler > > > (country_list))) > > > > > Hope the above lines will help you. > > > > > Regards, > > > Lokesh > > > > > On May 17, 7:10 pm, Bobby Roberts wrote: > > > > Hi. I'm needing to learn how to dynamically pull data out of the > > > > database and pass it as a CHOICES argument in my form. I want to > pull > > > > a recordset of options, dump it into the choices and pass it to the > > > > form etc. Can someone out there lend me a hand? I'd like the > options > > > > on the form to be checkboxes. > > > > If you're using choices you really should use a ChoiceField as it will > > validate that the selections is one of the desired choices, which won't > be > > validated with a CharField. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > Yes, if you don't want Django to automatically validate it is a valid choice you can just do it is a CharField and do it yourself. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Seeking Example of MultipleChoiceField Example with dynamic Choices
Hi Alex, Then I can go ahead with required=false attribute to avoid form validation and validation should be taken care by program. Correct me if I am wrong. Regards, Lokesh > > incr = 0 > > for i in p: > > self[incr] = i.country > > incr = incr+1 > > return self.items() > > > country = forms.CharField(label="cnty", > > widget=forms.CheckboxSelectMultiple(choices=country_filler > > (country_list))) > > > Hope the above lines will help you. > > > Regards, > > Lokesh > > > On May 17, 7:10 pm, Bobby Roberts wrote: > > > Hi. I'm needing to learn how to dynamically pull data out of the > > > database and pass it as a CHOICES argument in my form. I want to pull > > > a recordset of options, dump it into the choices and pass it to the > > > form etc. Can someone out there lend me a hand? I'd like the options > > > on the form to be checkboxes. > > If you're using choices you really should use a ChoiceField as it will > validate that the selections is one of the desired choices, which won't be > validated with a CharField. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Seeking Example of MultipleChoiceField Example with dynamic Choices
On Sun, May 17, 2009 at 11:16 AM, wrote: > > Hi, > > p=Country.objects.all() -> capturing all the records from > Country table > def country_filler(self):-> function to generate a country > list which we are going to fetch from the records >incr = 0 >for i in p: > self[incr] = i.country > incr = incr+1 >return self.items() > > country = forms.CharField(label="cnty", > widget=forms.CheckboxSelectMultiple(choices=country_filler > (country_list))) > > Hope the above lines will help you. > > Regards, > Lokesh > > On May 17, 7:10 pm, Bobby Roberts wrote: > > Hi. I'm needing to learn how to dynamically pull data out of the > > database and pass it as a CHOICES argument in my form. I want to pull > > a recordset of options, dump it into the choices and pass it to the > > form etc. Can someone out there lend me a hand? I'd like the options > > on the form to be checkboxes. > > > If you're using choices you really should use a ChoiceField as it will validate that the selections is one of the desired choices, which won't be validated with a CharField. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Seeking Example of MultipleChoiceField Example with dynamic Choices
Hi, p=Country.objects.all() -> capturing all the records from Country table def country_filler(self):-> function to generate a country list which we are going to fetch from the records incr = 0 for i in p: self[incr] = i.country incr = incr+1 return self.items() country = forms.CharField(label="cnty", widget=forms.CheckboxSelectMultiple(choices=country_filler (country_list))) Hope the above lines will help you. Regards, Lokesh On May 17, 7:10 pm, Bobby Roberts wrote: > Hi. I'm needing to learn how to dynamically pull data out of the > database and pass it as a CHOICES argument in my form. I want to pull > a recordset of options, dump it into the choices and pass it to the > form etc. Can someone out there lend me a hand? I'd like the options > on the form to be checkboxes. --~--~-~--~~~---~--~~ 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: Form trouble
On Sun, May 17, 2009 at 4:29 AM, zayatzz wrote: > > > > btw... what is tuple? i am not native english speaker so i fail to > > > understand some words like that. > > > > It's a python data structure. It's an "" Array "" . > > > > > > > > > > Thanks. :) > > Alan > > > Specifically tuple's are immutable arrays. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: check_constraints module error
> > > >>> from check_constraints import Check > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named check_constraints This is the right code. What this is saying is that you don't have the check_constraints module properly installed. Have you installed the check_contraints module? It doesn't come with django itself. If you have installed it, check and see if it is on your python path (from sys import path; print path) I haven't used this module in the past but that looks like it is the problem. Hope that helps, Michael --~--~-~--~~~---~--~~ 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: Counting pageviews
On Sun, May 17, 2009 at 10:29 AM, Oleg Oltar wrote: > Well, what I want is t implement voting application, so my users can see > article, vote for it and see the vote displayed > So I want to show in template: this page was viewed 100 times, and has 10 > votes for example > > how can I get those numbers > > views.py: def vote_detail(request, id): obj = get_object_or_404(Voter, pk = id) obj.page_count += 1 obj.save() return render_to_response('your/template.html', { 'object' : obj }) This won't be able to be optimized however. Every pageview has to hit the database (2 times in the example I have given) and you can not cache this if you want an accurate count. This might not be a problem for you, but what Antoni has said about Google Analytics or another analytics program is valid. Analytics is notoriously intensive on databases just by its nature. Google Analytics is set up to deal with this with thousands of servers. Google Analytics has an API now that I think could be used to accomplish this same style of thing (not really sure, haven't gotten a chance to mess with it). I hope that helps, Michael --~--~-~--~~~---~--~~ 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: displaying image in a template
On Sun, May 17, 2009 at 2:54 AM, newbie wrote: > > > Hi, > >I followed those steps in the link and its working fine for > static files (like css scripts etc). But when i'm trying to display an > image, its not working. I'm trying to display an image which is in > static/barcodeimages directory (static is the directory to which i set > all static files should be served). So when i try {{ imagepath }}> {{ imagepath }} > > where imagepath = "/barcodeimages/image.png" its not working > The issue here is right in front of you: "/barcodeimages/image.png" != "/static/barcodeimages/image.png" If you want to serve images from the barcodeimages root directory you must set up the static server to server that directory the same way. Debugging this is easy. Just go to the URL that you are requesting and if you get a 404, it's not there. If you get an image it is. If you go to: "/static/barcodeimages/image.png" my bet is that the image is there. I hope that helps, Michael --~--~-~--~~~---~--~~ 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: Counting pageviews
Well, what I want is t implement voting application, so my users can see article, vote for it and see the vote displayed So I want to show in template: this page was viewed 100 times, and has 10 votes for example how can I get those numbers On Sat, May 16, 2009 at 12:12 PM, Antoni Aloy wrote: > > 2009/5/15 Oleg Oltar : > > Hi! > > > > I am writing simple article manager application. Is there a way I can > store > > pageviews number for my articles in database (want to display them in > > future, and use for rating on site) > > > > Thanks in advance, > > Oleg > > > You can use google analytics for that. > You can store it also in your views before displaying the page or you > can use your own javascript method. > > Perhapts I don't understand the question, but if you own the site you > can do whatever you want. If you use the view method you can't use > cache and this could have a great impact in performance. It depends on > your needs and application. > > -- > Antoni Aloy López > Blog: http://trespams.com > Site: http://apsl.net > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Seeking Example of MultipleChoiceField Example with dynamic Choices
Hi. I'm needing to learn how to dynamically pull data out of the database and pass it as a CHOICES argument in my form. I want to pull a recordset of options, dump it into the choices and pass it to the form etc. Can someone out there lend me a hand? I'd like the options on the form to be checkboxes. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
LANGUAGE_CODE
Hi: When I set LANGUAGE_CODE = 'zh-cn' in the sitting file. I want to get a 3 letters of month useing filter "date" in the template, e.g. Useing {{ entry.pub_date|date:"M"}}, I will get "五月" in chinese, but the one I expect is "May". How can I fix this? Thanks! sammysun --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
subscription based web app - want to develop - bounty
Hi I have looked enough and failed to identify anything that solves or like "SaaS railskit" if I am wrong please let me know. I am not technically savvy enough to develop such app myself. Maybe someone is using django-paypal to make subscription based (e.g. a.la basecamp) web app. What I want to do is this http://uswaretech.com/django-subdomains/ However author I am not so sure about licensing above also I believe it should be a community effort i.e. adding other payment provider as needed. I would like to use django-paypal instead of what is available above. This is my current need I am guessing in the future it will be adding django-authorizenet or some other payment provider. You can find django paypal here http://github.com/johnboxall/django-paypal/tree/master can anyone help me to develop this if so could you please mail me directly about cost/time. The end code will be under MIT/GPL and I hope you have enough interest to maintain it further. the specification is very well described @ http://railskits.com/saas/ but paypal only that's solve my problem at the moment. I am after a re-usable app so all of django community can benefit from it. Regards Antonio --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
looping through form.errors in templates
Hi I've noticed that there have been changes in form error processing for templates when I've been updating some old code to work with django 1.0.2 from 0.96. My code for displaying errors at the top of the pages looked like this in 0.96: {% if form.has_errors %} Please correct the following error{{ form.error_dict| pluralize }}: {% for elem in form.error_dict.items %} {{ elem.0 }}: {{ elem.1.0 }} {% endfor %} {% endif %} I've had to replace form.has_errors with form.errors, as shown below: {% if form.errors %} Please correct the following error{{ form.errors|pluralize }}: {% for elem in form.errors %} {{ elem }}: {% endfor %} {% endif %} However the new code shown above only displays the field name and not the actual error text. What's the syntax for showing the actual error message on form.errors. Thanks for any help Simon --~--~-~--~~~---~--~~ 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: Implementing A/B Testing in Django
> > Does anyone have any other ideas or suggestions about how to > dynamically show templates to users in a pluggable way while at the > same time measuring what template the user sees? > It's not about doing it in Django, but you know that Google Website Optimizer does this, and provides you out of the box with goal-conversions, and all other pretty analytical stuf? --~--~-~--~~~---~--~~ 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: referencing the object id from clean validation methods
thanks for that alex On May 16, 9:53 pm, Ramiro Morales wrote: > On Sat, May 16, 2009 at 5:18 PM, Alex Gaynor wrote: > > > On Sat, May 16, 2009 at 3:03 PM, simon101 wrote: > > >> Hi > > >> I am using ModelForms to create forms from the models [...] > >> but it doesn't contain the id > >> for the object id for the object which the ModelForm pulled it off. > > >> Anyone got any ideas how to fix this? My code looks like this. > > > self.instance will be the current object, and therefore self.instances.pk > > will be that object's id. This is all assuming GAE's forms work the same as > > djangos. > > For Django, there is a ticket ([1]8861) open that asks for a documentation > enhancement: adding a mention about self.instance in the relevant model form > validation sections. > > -- > Ramiro Moraleshttp://rmorales.net > > 1.http://code.djangoproject.com/ticket/8861 --~--~-~--~~~---~--~~ 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 refer a foreign key to a non primary column from other model
This is not true for Oracle either. A foreign key can certainly reference a unique (not primary) key in Oracle. See Oracle documentation, e.g. http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/data_int.htm#sthref2329, or simply verify by trying it ! -- PeterN On May 16, 6:04 pm, Joshua Russo wrote: > Ok, apologize. I just tried it myself and MySQL did accept the alter > table. It is certainly not an operation that I have been able to > perform in MS SQL Server or Oracle, though I wonder if it's something > that is changing industry wide. MySQL seems to allow a foreign key to > any unique index. > > > This is simply not true, you can have foreign keys to non primary key > > fields. As a linked the "to_field" option allows you to do just that. > > > Alex > > > -- > > "I disapprove of what you say, but I will defend to the death your right to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Form trouble
> > btw... what is tuple? i am not native english speaker so i fail to > > understand some words like that. > > It's a python data structure. It's an "" Array "" . > > > > Thanks. :) Alan --~--~-~--~~~---~--~~ 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: Form trouble
> > > Call > if form.*is_valid()*: Sorry > > # use cleaned_data > > Jorge > > >> >> -- neo2001[at]gmail.com jorge[at]thecodefarm.com neo[at]art-xtreme.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: Form trouble
2009/5/17 zayatzz > > Thanks > > I actually tried that form.cleaned_data at one point but then i got > error that was something like: form object has no cleaned_data > attribute. Call if form.isvalid(): # use cleaned_data Jorge > > > Anyway, its working now - thanks alot. > > btw... what is tuple? i am not native english speaker so i fail to > understand some words like that. It's a python data structure. It's an "" Array "" . > > > Alan > > On May 17, 2:02 am, Daniel Roseman > wrote: > > On May 16, 10:51 pm, Alex Gaynor wrote: > > > > > > > > > On Sat, May 16, 2009 at 4:49 PM, zayatzz > wrote: > > > > > > Hello > > > > > > Been trying to figure out where the problem is, but its almost 1am > and > > > > im out of ideas. > > > > > > i have this model: > > > > class tuser (models.Model): > > > >username = models.CharField(max_length=20, help_text="Enter > Username > > > > of your account") > > > >email = models.EmailField(max_length=100, help_text="Enter > your e- > > > > mail address", unique=True) > > > >pwd = models.CharField(max_length=100, help_text="Enter your > > > > password") > > > >active = models.SmallIntegerField(help_text="Different states > of > > > > activity - inactive, active...") > > > >joined = models.DateField(help_text="Date when registered") > > > >llogin = models.DateField(help_text="Date of last activity", > > > > null=True) > > > > > > then i have this form: > > > > class RegisterForm(ModelForm): > > > >class Meta: > > > >model = tuser > > > >fields = ('email') > > > > > > this is the view that handles the post: > > > > def regattempt(request): > > > >if request.method == 'POST': > > > >form = RegisterForm(request.POST) > > > >if form.is_valid(): > > > >p = tuser(username=form.email, > email=form.email, > > > > pwd=randompass > > > > (12), active = 1, joined = datetime.datetime.now()) > > > >p.save() > > > >else: > > > >form = RegisterForm() > > > >return render_to_response('authprof/register.html', { > > > >'form': form, > > > >}) > > > > > > i've been trying to follow different examples like : > > > > > > > http://docs.djangoproject.com/en/1.0/topics/forms/#processing-the-dat... > > > > > > The error i get is : > > > > 'RegisterForm' object has no attribute 'email' > > > > > > Request Method: POST > > > > Request URL:http://127.0.0.1/account/register/regattempt/ > > > > Exception Type: AttributeError > > > > Exception Value: > > > > > > 'RegisterForm' object has no attribute 'email' > > > > > > Exception Location: /home/projects/tst/authprof/views.py in > > > > regattempt, line 47 > > > > > > line 47 is the p = tuser(so-on and so-forth > > > > > > If anyone can explain me where this error comes from i would be very > > > > happy. > > > > > > Alan > > > > > The issue is ('email') is a string, and you need a tuple there, so it > > > should have a comma: ('email',) > > > > > Alex > > > > Well, that's one issue. The other is that you can't refer to form > > fields as attributes on the form instance. In fact, on the very link > > that the OP gave, it shows the right way to do it: > > p = tuser(username=form.cleaned_data['email'] > > etc ... ) > > -- > > DR. > > > -- neo2001[at]gmail.com jorge[at]thecodefarm.com neo[at]art-xtreme.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: Form trouble
Thanks I actually tried that form.cleaned_data at one point but then i got error that was something like: form object has no cleaned_data attribute. Anyway, its working now - thanks alot. btw... what is tuple? i am not native english speaker so i fail to understand some words like that. Alan On May 17, 2:02 am, Daniel Roseman wrote: > On May 16, 10:51 pm, Alex Gaynor wrote: > > > > > On Sat, May 16, 2009 at 4:49 PM, zayatzz wrote: > > > > Hello > > > > Been trying to figure out where the problem is, but its almost 1am and > > > im out of ideas. > > > > i have this model: > > > class tuser (models.Model): > > > username = models.CharField(max_length=20, help_text="Enter > > > Username > > > of your account") > > > email = models.EmailField(max_length=100, help_text="Enter your e- > > > mail address", unique=True) > > > pwd = models.CharField(max_length=100, help_text="Enter your > > > password") > > > active = models.SmallIntegerField(help_text="Different states of > > > activity - inactive, active...") > > > joined = models.DateField(help_text="Date when registered") > > > llogin = models.DateField(help_text="Date of last activity", > > > null=True) > > > > then i have this form: > > > class RegisterForm(ModelForm): > > > class Meta: > > > model = tuser > > > fields = ('email') > > > > this is the view that handles the post: > > > def regattempt(request): > > > if request.method == 'POST': > > > form = RegisterForm(request.POST) > > > if form.is_valid(): > > > p = tuser(username=form.email, email=form.email, > > > pwd=randompass > > > (12), active = 1, joined = datetime.datetime.now()) > > > p.save() > > > else: > > > form = RegisterForm() > > > return render_to_response('authprof/register.html', { > > > 'form': form, > > > }) > > > > i've been trying to follow different examples like : > > > >http://docs.djangoproject.com/en/1.0/topics/forms/#processing-the-dat... > > > > The error i get is : > > > 'RegisterForm' object has no attribute 'email' > > > > Request Method: POST > > > Request URL: http://127.0.0.1/account/register/regattempt/ > > > Exception Type: AttributeError > > > Exception Value: > > > > 'RegisterForm' object has no attribute 'email' > > > > Exception Location: /home/projects/tst/authprof/views.py in > > > regattempt, line 47 > > > > line 47 is the p = tuser(so-on and so-forth > > > > If anyone can explain me where this error comes from i would be very > > > happy. > > > > Alan > > > The issue is ('email') is a string, and you need a tuple there, so it > > should have a comma: ('email',) > > > Alex > > Well, that's one issue. The other is that you can't refer to form > fields as attributes on the form instance. In fact, on the very link > that the OP gave, it shows the right way to do it: > p = tuser(username=form.cleaned_data['email'] > etc ... ) > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: quickest way to print template names
On Sat, 2009-05-16 at 23:37 -0500, Alex Gaynor wrote: > There isn't a better solution, a Template doesn't store the file it > was rendered from (especially since that doesn't make sense for all > template loaders, such as if you render a template from a string), nor > does the context inherently have it available. A template name passed into render_to_response is stored, of course. What Alex is suggesting is that instead of just: from django.shortcuts import render_to_response you use something like: from django.shortcuts import render_to_response as r_t_r def render_to_response(name, context, *args, **kwargs): context['template_name'] = name return r_t_r(name, context, *args, **kwargs) sdc --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---