Using request.GET and having issues
I have the following view set up: def concord(request): searchterm = request.GET['q'] ... more stuff ... return render_to_response('concord.html', locals()) With URL "http://mysite.com/concord/?q=برشه";, and template code Your search for {{ searchterm }} returned {{ results }} results in {{ texts.count }} texts. I get this result on the page: Your search for برشه returned 0 results in 8 texts. The search term (برشه) is being passed successfully, but there should be 13 results, not zero. When I hard-code "searchterm = 'برشه' " into the concord view, instead of "searchterm = request.GET['q']", the page displays perfectly. The full code for the view is below... What am I missing here? ~Karen def concord(request): searchterm = request.GET['q'] #== Retrieving relevant corpus texts from database === texts = Text.objects.filter(content__contains=searchterm) content = "" for t in texts: content += t.content + "\n" #== Encoding === content_uni = content.encode('utf-8') tokens = content_uni.split() #== Concordancing with NLTK === text = nltk.Text(tokens) ci = nltk.text.ConcordanceIndex(text.tokens) offsets = ci.offsets(searchterm) results = len(offsets) tokens = ci.tokens() #== Set variables to return to webpage === context = [] for offset in offsets: before = ' '.join(tokens[offset-10:offset]) word = tokens[offset] after = ' '.join(tokens[offset+1:offset+10]) context.append([before, word, after]) return render_to_response('concord.html', locals()) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Passing variables to the template... I've having logic problems
Yes, that worked. Thank you! Of course, now that I fixed that, I have to deal with the other problem that I was avoiding... But I'll post that in a different question. :-) Thanks again, Pedro. On Apr 15, 9:35 pm, Pedro Kroger wrote: > You can try something like: > > def my_view(request): > ... > > context = [] > for offset in offsets: > before = ' '.join(tokens[offset-5:offset]) > word = tokens[offset] > after = ' '.join(tokens[offset+1:offset+5]) > context.append(before, word, after) > > ... ... > > return render_to_response("template.html", {'context': context}) > > Now your data will be available inside the 'context' variable and you > can access the 'context' variable in your template like you want. I > hope that helps. > > Pedro > > --http://pedrokroger.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: pagination peculiarities...
On Fri, Apr 15, 2011 at 2:44 PM, Markus T. wrote: > > I have a strange effect using pagination. > > I have a model with events that have a date, time, title, description > field and so on. I display the events using pagination. In the model's > Meta class I tell Django to order by date. > > I create a queryset like this: > > events = Event.objects.filter(date__gte=date.today()) > > All events are there in the result. But after I apply pagination, one > event is missing, and another event of the same date comes twice. If I > raise the items_per_page parameter so I get only one page, all events > are there as well. > > If I tell Django to order [by date, time, title], all events are > there, using pagination or not. > > Can anyone explain this? If you don't supply a total ordering, which you don't if you only specify order by date and there are multiple events on the same date, then the database is free to choose whatever ordering it likes for the elements not covered by the specified ordering. It is also free to choose different orderings for these not- fully-ordered items each time you ask it for a portion of the overall set. Postgres in particular is prone to actually doing this; multiple "identical" queries with the same limit/offset values will often return different results. Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google 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.
Put an "inline" at the top of admin form instead of bottom?
I'm using the admin functionality for most of my needs (a nice CRUD DB frontend, not a user-facing website). Is there a best way to get one of my inline models presented at the top of the form instead of the bottom? I would greatly prefer not to have to specify all of the fields (via ModelAdmin.fields), as we really like the automatic introspection functionality. -- You received this message because you are subscribed to the Google 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 unit test if user has access to page
On Fri, Apr 15, 2011 at 8:54 PM, Pedro Kroger wrote: > result = self.client.post('/dashboard/') > > But I don't know how to test if the result is the dashboard or the > login page. Could you guys point me in the right direction? from the docs (http://docs.djangoproject.com/en/1.3/topics/testing/#django.test.TestCase.assertRedirects): result = self.client.post('/dashboard/') self.assertRedirects(result, '/login/') -- Javier -- You received this message because you are subscribed to the Google 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 unit test if user has access to page
Hi, I writing some unit tests and I'd like to test if an unlogged user has access to the main dashboard page. In my application, if the user is logged it will go to the dashboard, if it isn't, it will go to the login page. I know how to get to the webpage: result = self.client.post('/dashboard/') But I don't know how to test if the result is the dashboard or the login page. Could you guys point me in the right direction? Thanks, Pedro -- http://pedrokroger.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: Passing variables to the template... I've having logic problems
You can try something like: def my_view(request): ... context = [] for offset in offsets: before = ' '.join(tokens[offset-5:offset]) word = tokens[offset] after = ' '.join(tokens[offset+1:offset+5]) context.append(before, word, after) ... ... return render_to_response("template.html", {'context': context}) Now your data will be available inside the 'context' variable and you can access the 'context' variable in your template like you want. I hope that helps. Pedro -- http://pedrokroger.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.
'Context' object has no attribute 'render_context'
I'm fairly new to django and now I'm stuck on this error... 'Context' object has no attribute 'render_context' searching around has told me that render_context did not exist pre django 1.2 but I have django 1.2.4 installed. Here is some of my stack trace... AttributeError at /hsws/ 'Context' object has no attribute 'render_context' Request Method: GET Request URL:http://175.41.175.33/hsws/ Django Version: 1.2.4 Exception Type: AttributeError Exception Value: 'Context' object has no attribute 'render_context' Exception Location: /usr/local/lib/python2.6/dist-packages/django/ template/__init__.py in render, line 171 Python Executable: /usr/bin/python Python Version: 2.6.5 Python Path:['/home/ubuntu/workspace/', '/home/ubuntu/workspace/ hotspot/', '/var', '/usr/lib/python2.6', '/usr/lib/python2.6/plat- linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/ usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/ usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist- packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/ python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/ gtk-2.0', '/usr/local/lib/python2.6/dist-packages'] Server time:Fri, 15 Apr 2011 22:53:34 + Traceback Switch to copy-and-paste view /usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py in get_response response = callback(request, *callback_args, **callback_kwargs) ... ▶ Local vars /home/ubuntu/workspace/hotspot/hsws/views.py in index return HttpResponse(t.render(c)) ... ▶ Local vars /usr/local/lib/python2.6/dist-packages/django/template/__init__.py in render context.render_context.push() ... ▶ Local vars I'm calling context with really basic code ... locs = Location.objects.all() t = loader.get_template('hsws/index.html') c = Context({ 'all_locations': locs, }) return HttpResponse(t.render(c)) the view does exist and I am importing Context and loader at the top of this code.. Any help would be appreciated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Passing variables to the template... I've having logic problems
I'm trying to make a concordance (ie, a list of a certain searchterm, including its surrounding context) and I can get it to work in the interpreter, but I'm having problems figuring out how to make it a list that I can pass it to the template. This is what works in the interpreter (tokens is a list of words which can be accessed by an index number, and offset is the index number corresponding to the searchterm): >>> for offset in offsets: ... before = ' '.join(tokens[offset-5:offset]) #Takes the five preceding words and joins them in a string ... word = tokens[offset] #The searchterm occurance ... after = ' '.join(tokens[offset+1:offset+5])#The five words after the searchterm ... print "%s %s %s" % (before, word, after) ... حنانلافاقتزاهيةتبرلي برشه وسيلة في العادة بكوشة فيهاشويةمشاكلوطلبةوشوية برشه حاجات يعني وكما تعرف يلقىحلعلىالخاطرتوا برشه ناس كما نحنا هكه بالكلّوالبلادقاعدةتخسرفي برشه م الشباب متاعها على كانطحانغيرهاوينوفمّه برشه ممّن تسّوللهم انفسهم الرخيصه I know you can't read the Arabic output that's written there, but it's exactly as it should be. Any way I've tried to get the before, word, after returned as variables (or lists of variables) so I can pass them to the template, it doesn't work. What I want to be able to do is something like this: {% for before, word, after in context %} {{ before }} {{ word }} {{ after }} {% endfor %} I just can't figure out how to do it... Can anyone point me in the right direction? Thanks, Karne -- You received this message because you are subscribed to the Google 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: base.html (extended by others) has to be in project (not app) root?
On Friday, April 15, 2011 4:21:56 PM UTC-4, Brian Neal wrote: > > You didn't post how you loaded the template in your view function. In > particular, what path string you used. > Ah. The missing piece to bring order to all of this confusion on my part. I was using "myapp/index.html", per Tutorial 3's example. Obviously (now), this is what was allowing my index.html to be found when using TEMPLATE_DIRS = ('/myproject',) ... and also what was causing the app to expect to find "base.html" in /myproject and not /myproject/myapp And my failure to be able to use {% extend "myapp/base.html %} with my TEMPLATE_DIR set as above was because... I had not MOVED IT to myapp. Geez. This all makes perfect sense to me now and I have it working as I wanted it to. Thank you all again for the help. In any event, this isn't magic. I suggest you read this section of the > docs: > > http://docs.djangoproject.com/en/1.3/ref/templates/api/#loading-templates > > In particular, pay attention to the TEMPLATE_DIRS and TEMPLATE_LOADERS > settings in your project. Those settings control the template search > order. > > Best, > BN -- You received this message because you are subscribed to the Google 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: base.html (extended by others) has to be in project (not app) root?
On Apr 15, 2:23 pm, Jeff Blaine wrote: > Thank you all. I will digest the replies when I have the time to properly > focus back on the issue (it's obviously small, since I have a workaround in > place by shoving base.html into the project root). > > It still, regardless of solutions, even in light of the words shared in this > thread (which I've only skimmed for now), makes no sense to me how it's "the > right thing" that my index.html is found but base.html cannot be found just > because it is referenced by "extend". I will have to decide for the > time-being that there's some underlying good reason/concept that I just am > not savvy to. > > You found index.html fine! It says in it to extend "base.html"! Find it in > the same place you found index.html! You didn't post how you loaded the template in your view function. In particular, what path string you used. In any event, this isn't magic. I suggest you read this section of the docs: http://docs.djangoproject.com/en/1.3/ref/templates/api/#loading-templates In particular, pay attention to the TEMPLATE_DIRS and TEMPLATE_LOADERS settings in your project. Those settings control the template search order. Best, BN -- You received this message because you are subscribed to the Google 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: base.html (extended by others) has to be in project (not app) root?
Thank you all. I will digest the replies when I have the time to properly focus back on the issue (it's obviously small, since I have a workaround in place by shoving base.html into the project root). It still, regardless of solutions, even in light of the words shared in this thread (which I've only skimmed for now), makes no sense to me how it's "the right thing" that my index.html is found but base.html cannot be found just because it is referenced by "extend". I will have to decide for the time-being that there's some underlying good reason/concept that I just am not savvy to. You found index.html fine! It says in it to extend "base.html"! Find it in the same place you found index.html! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form with two select boxes + javascript - selection gets destroyed???
Thank you to everyone answering - I will look into the Firebug approach the next time. But now I am 99.9% certain that > In an item is not in the original choices then it's invalid. This is the problem. In the cases where things failed the choice eventually sent from the client was not in the initial set. Thanks a lot! Joakim -- You received this message because you are subscribed to the Google 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 with two select boxes + javascript - selection gets destroyed???
Can you show us the field declaration in your form -- specifically the value of 'choices'? In an item is not in the original choices then it's invalid. -- You received this message because you are subscribed to the Google 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 with two select boxes + javascript - selection gets destroyed???
I suggest you to use firefox + firebug extension to see what exactly your form is sending to server in POST (or GET) request via firebug's "Console" tab. If data in request is correct every time (change both selectors, change oly one of them, without changes) -- then problem somewhere in your django app, otherwise -- check javascript code. On 15 апр, 21:58, Joakim Hove wrote: > Hello; > > I have a problem with a Django using JavaScript which I really don't > understand. It must be said that this is my first time using > JavaScript to beef up my forms - that might be source of the problem. > > The form presents the user with two drop down selectors and a submit > button like: > > Country: [--] > Product: [--] > > [ Submit ] > > Now the available products are not the same in the different > countries, so when the user has selected a country the browser will > javscript to ask the server for a list of products available in that > country. This seems to work, at least the product selection box is > automatically updated with seemingly correct values. When I am happy > with both the country and product selection I hit the submit button > and everything goes to the server running django. > > For this particular form I have a clean() method which verifies that > the chosen product is indeed available in the chosen country (the > client side javascript should ensure that already, but anyway): > > def clean( self ): > product_id = self.cleaned_data.get("product_id") > country_id = self.cleaned_data.get("country_id") > > product = Product.objects.get( pk = product_id) < > This fails with Object not found. > > As indicated the clean() method fails, and inspection of the DEBUG > traceback reveals that product_id has the value 'None' - however > looking at the POST data also present on the DEBUG traceback shows > that product_id has a reasonable value??? So to me it seems that > somewhere along the way, the product_id variable is lost? > > Some other observations: > 1. If just dropping the javascrip altogether - i.e. potentially > allowing for a product/country mismatch the django application works > as intended. > 2. If I only change one of the selectors at a time things also work > nicely. It is possible to select a product "No product" which is > "available" in all countries and using that it is possible to go > through the following hoops: > > 1) Select product "No product" [ Submit ] > 2) Select the country you are interested in [Submit] > 3) Select the product you are interested in [Submit] > > To end up with the desired country and product combination. So - all > in all I conclude that things can not be totally messed up? > > Any tips or thoughts on this would be great! > > Joakim -- You received this message because you are subscribed to the Google 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 with two select boxes + javascript - selection gets destroyed???
I suggest you to use firefox + firebug extension to see what exactly your form is sending to server in POST (or GET) request via firebug's "Console" tab. If data in request is correct every time (change both selectors, change oly one of them, without changes) -- then problem somewhere in your django app, otherwise -- check javascript code. On Fri, Apr 15, 2011 at 9:58 PM, Joakim Hove wrote: > Hello; > > I have a problem with a Django using JavaScript which I really don't > understand. It must be said that this is my first time using > JavaScript to beef up my forms - that might be source of the problem. > > The form presents the user with two drop down selectors and a submit > button like: > > Country: [--] > Product: [--] > > [ Submit ] > > > Now the available products are not the same in the different > countries, so when the user has selected a country the browser will > javscript to ask the server for a list of products available in that > country. This seems to work, at least the product selection box is > automatically updated with seemingly correct values. When I am happy > with both the country and product selection I hit the submit button > and everything goes to the server running django. > > For this particular form I have a clean() method which verifies that > the chosen product is indeed available in the chosen country (the > client side javascript should ensure that already, but anyway): > > def clean( self ): > product_id = self.cleaned_data.get("product_id") > country_id = self.cleaned_data.get("country_id") > > product = Product.objects.get( pk = product_id)< > This fails with Object not found. > > As indicated the clean() method fails, and inspection of the DEBUG > traceback reveals that product_id has the value 'None' - however > looking at the POST data also present on the DEBUG traceback shows > that product_id has a reasonable value??? So to me it seems that > somewhere along the way, the product_id variable is lost? > > Some other observations: > 1. If just dropping the javascrip altogether - i.e. potentially > allowing for a product/country mismatch the django application works > as intended. > 2. If I only change one of the selectors at a time things also work > nicely. It is possible to select a product "No product" which is > "available" in all countries and using that it is possible to go > through the following hoops: > > 1) Select product "No product" [ Submit ] > 2) Select the country you are interested in [Submit] > 3) Select the product you are interested in [Submit] > > To end up with the desired country and product combination. So - all > in all I conclude that things can not be totally messed up? > > Any tips or thoughts on this would be great! > > Joakim > > > > > > -- > You received this message because you are subscribed to the Google 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. > > -- You received this message because you are subscribed to the Google 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.
New python, django user... having issues
Hi there. I'm trying to install Django on my computer, but I'm having problems. Any help would be really, really appreciated. My first attempt was with the BitNami Django Stack. It seemed to have installed, but I couldn't verify it through 'import django' on Idle. I played with it a few times, and eventually decided to install latest official version instead. I put the django folder into the site- package directory, and tried to use command prompt to initiate setup.py but nothing came up either. It seems as though my computer doesn't recognize the path or file type. I have a Windows 64 bit with both Python 2.7, Php, and Apache 2.2 installed. I thought that some of these programs were interfering with the django install, so I turned off apache and uninstalled python 2.7. When I installed php previously, I had to change some environmental variables, and I think that maybe that was also an issue. Anyway, I reinstalled BitNami Django Stack, but when it finished installing and gave me the link to my project, I got 404 - Not found. Because python 2.6 comes with the stack, I installed that (it's not installed within the Django directory). I tried to call 'import django' in my shell, but it only gives me an error message. While instlaling BitNami, I did get a warning. "Problem running post- install step. Install may not complete correctly. Error running mysql/ bin/mysql -u root -e Create DATABASE IF NOT EXISTS djangostack; GRANT ALL PRIVILEGES on django stack. to bitnami @ localhost; flush priviledges.. ERROR 1045: Access denied for user 'root'@localhost'" -- I have no idea what this means and if it caused any problems with the install... I had tried to install mysql with php previously, and I couldn't get it done correctly either. -- You received this message because you are subscribed to the Google 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 with two select boxes + javascript - selection gets destroyed???
Thank you for answering: On Apr 15, 8:47 pm, Shawn Milochik wrote: > Two things: > > 1. Does your form use a prefix? I don't really what you mean with prefix? > > 2. Please post a relevant excerpt of your request.POST data. (I mangled things a bit up in the original message; in particular the offending field is not named product_id but rather agent_id): This is my POST data: Variable Value name u'Bjarne Grethe' org_id u'-1' country_id u'45' telephoneu'78' agent_id u'43' <--- This is the relevant quantity . And this is the results of pressing "Local vars" in the traceback in from clean(): ▼ Local vars VariableValue country self country_id 45 org_id -1 agent_id None < Now it has become None??? Joakim -- You received this message because you are subscribed to the Google 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 with two select boxes + javascript - selection gets destroyed???
Two things: 1. Does your form use a prefix? 2. Please post a relevant excerpt of your request.POST data. -- You received this message because you are subscribed to the Google 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.
pagination peculiarities...
Hi everybody, I have a strange effect using pagination. I have a model with events that have a date, time, title, description field and so on. I display the events using pagination. In the model's Meta class I tell Django to order by date. I create a queryset like this: events = Event.objects.filter(date__gte=date.today()) All events are there in the result. But after I apply pagination, one event is missing, and another event of the same date comes twice. If I raise the items_per_page parameter so I get only one page, all events are there as well. If I tell Django to order [by date, time, title], all events are there, using pagination or not. Can anyone explain this? Thanks a lot! Markus -- You received this message because you are subscribed to the Google 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 a django Beginner!
Thank you for the response. Is there any documentation / books out there that you would recommend reading to get acquainted with django in that perspective? On Apr 15, 10:58 am, Jirka Vejrazka wrote: > I use Djano ORM for a lot of my backend processing where no web is > involved. Just make sure that DJANGO_SETTINGS_MODULE is defined in > your environment and you can use pretty much any part of Django in > your own code/scrits/whatever. > > HTH > > Jirka > > On 15/04/2011, Aviv Giladi wrote: > > > > > Hey guys, > > > I am an experienced Python developer starting to work on web service > > backend system. The system feeds data (constantly) from the web to a > > MySQL database. This data is later displayed by a frontend side (there > > is no connection between the frontend and the backend). The backend > > system constantly downloads flight information from the web (some of > > the data is fetched via APIs, and some by downloading and parsing > > text / xls files). I already have a script that downloads the data, > > parses it, and inserts it to the MySQL db - all in a big loop. The > > frontend side is just a bunch of php pages that properly display the > > data by querying the MySQL server. > > > It is crucial that this web service be robust, strong and reliable. > > Therefore, I have been looking into the proper ways to design it, and > > got the following recommendation: > > django as the framework (over Apache). > > wrapping my sources with Piston for API usage. > > All if this sounds great. I used django before to write websites (aka > > request handlers that return data). However I don't see how django can > > fulfill a role of a constant running (non request-serving) system - > > being that it uses views/forms, which are not a part of my backend > > system. Is want I want at all possible / advisable with django? Is > > django what you would recommend for this? > > If so, could you please refer me to some documentation / help files > > more specific to my needs? > > > Thank you so much, > > Aviv > > > -- > > You received this message because you are subscribed to the Google 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. -- You received this message because you are subscribed to the Google 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.
Form with two select boxes + javascript - selection gets destroyed???
Hello; I have a problem with a Django using JavaScript which I really don't understand. It must be said that this is my first time using JavaScript to beef up my forms - that might be source of the problem. The form presents the user with two drop down selectors and a submit button like: Country: [--] Product: [--] [ Submit ] Now the available products are not the same in the different countries, so when the user has selected a country the browser will javscript to ask the server for a list of products available in that country. This seems to work, at least the product selection box is automatically updated with seemingly correct values. When I am happy with both the country and product selection I hit the submit button and everything goes to the server running django. For this particular form I have a clean() method which verifies that the chosen product is indeed available in the chosen country (the client side javascript should ensure that already, but anyway): def clean( self ): product_id = self.cleaned_data.get("product_id") country_id = self.cleaned_data.get("country_id") product = Product.objects.get( pk = product_id)< This fails with Object not found. As indicated the clean() method fails, and inspection of the DEBUG traceback reveals that product_id has the value 'None' - however looking at the POST data also present on the DEBUG traceback shows that product_id has a reasonable value??? So to me it seems that somewhere along the way, the product_id variable is lost? Some other observations: 1. If just dropping the javascrip altogether - i.e. potentially allowing for a product/country mismatch the django application works as intended. 2. If I only change one of the selectors at a time things also work nicely. It is possible to select a product "No product" which is "available" in all countries and using that it is possible to go through the following hoops: 1) Select product "No product" [ Submit ] 2) Select the country you are interested in [Submit] 3) Select the product you are interested in [Submit] To end up with the desired country and product combination. So - all in all I conclude that things can not be totally messed up? Any tips or thoughts on this would be great! Joakim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: change extension of uploaded image
My solution is: def save( self ): if self.image1: original = Image.open( self.image1 ) if original.mode not in ('L', 'RGB'): original = original.convert('RGB') cp_image = original.copy() cp_image_handle = StringIO() cp_image.save( cp_image_handle, 'JPEG', quality=100 ) cp_image_handle.seek(0) cp_image_upload = SimpleUploadedFile(os.path.split(self.image1.name)[-1],cp_image_handle.read(), content_type='image/jpeg') self.image1.save( "changed_extension.jpg", cp_image_upload, save=False) super( MyModel , self ).save() 2011/4/15 ozgur yilmaz : > Hi, > > I want to change the filetype of any uploaded image to JPG. What is > the most efficient way for this? I think i surely do this before > save(). Any ideas? > > 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.
change extension of uploaded image
Hi, I want to change the filetype of any uploaded image to JPG. What is the most efficient way for this? I think i surely do this before save(). Any ideas? 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: base.html (extended by others) has to be in project (not app) root?
On Thu, Apr 14, 2011 at 4:50 PM, Yuka Poppe wrote: > Hi Jeff, > > I think Gladys is correct, the reason for your code finding the index > template, is because its probably looking for 'myapp/index.html' > instead of just 'index.html' > > Im not really sure if you're also distinguishing between the project > template root and the app directory template dirs. > > Generally this would be how the template directories would be layed out: > > /whatever/templates > /whatever/myproject/myapp/templates > /whatever/myproject/mysecondapp/templates > > First django looks in the templates set in your settings.py > (/whatever/templates) then, depending on the order in installed apps, > it looks at /templates > > > So when you try to extend just 'base.html' it tries > /whatever/templates/base.html, > /whatever/myproject/myapp/templates/base.html, /whatever/my.. etc. > regardless of wheter or not the template where you are including from > is in the same directory. So again, why your index.html is working and > extending base.html doesnt work is in my best guess, due to the fact > that your code was looking for 'myapp/index.html' and the template > tried to include just 'base.html', which you said was located in > 'myapp' > > Take note that if you do try to extend 'myapp/base.html' for the app > based template directories, it would actually look in > /whatever/myproject/myapp/templates/myapp/base.html, this might seem > confusing at first. > > Hope this helps, Yuka > > On Thu, Apr 14, 2011 at 10:38 PM, Jeff Blaine wrote: > > Gladys, > > On Thursday, April 14, 2011 4:12:29 PM UTC-4, gladys wrote: > > The root directory for your templates is in '/whatever/myproject', so > >> > >> of course it will look for your base.html here. > >> Now if your base is in another location, say "/whatever/myproject/ > >> myapp/base.html", your extends should look like this: > >> {% extends "myapp/base.html" %}. > > > > First, thanks for the reply. > > It's finding my /myproject/myapp/index.html template (the one that calls > > "base.html"), so something clearly knows about where to find my > templates, > > yet "extend" looks elsewhere. > > That is, if I make /myproject/myapp/index.html to be completely > > self-contained, it is found and loaded fine. > > If I change it to {% extend "base.html" %}, it can't find that referenced > > template. > > > > That seems broken to me. > > I tried your suggestion above (the other day, and again now) in > > /myproject/myapp/index.html > > {% extend "myapp/base.html" %} > > > > It does not work: > > Caught TemplateDoesNotExist while rendering: myapp/base.html > > ALSO... I changed the following from: > > TEMPLATE_DIRS = ( > > '/myproject', > > ) > > > > to: > > TEMPLATE_DIRS = ( > > '/myproject/myapp', > > ) > > > > Which then results in failure to find even /myproject/myapp/index.html > > TemplateDoesNotExist at / > > > > > >> > >> Best of Luck. > >> > >> -- > >> Gladys > >> http://blog.bixly.com > >> > >> > >> On Apr 15, 3:56 am, Jeff Blaine wrote: > >> > Django 1.3 > >> > > >> > Hi all, > >> > > >> > I can't seem to get around this. It appears that, the following > >> > "index.html" template in */whatever/myproject/myapp* > >> > > >> > {% extends "base.html %} > >> > > >> > > >> > Looks for base.html as /whatever/myproject/base.html instead > >> > of /whatever/myproject/myapp/base.html > >> > > >> > My TEMPLATE_DIRS is set as follows, and with this setting, the > >> > */whatever/myproject/myapp/index.html > >> > template is loaded fine* if I make it self-contained (not extending) > >> > > >> > TEMPLATE_DIRS = ( > >> > '/whatever/myproject', > >> > ) > >> > > >> > Any ideas? > > > > -- > > You received this message because you are subscribed to the Google 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. > > > > -- > You received this message because you are subscribed to the Google 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. > > In settings.py you have this: >> > TEMPLATE_DIRS = ( >> > '/whatever/myproject', >> > ) > Note it says "DIRS", and its a tuple. Add the other paths to where you want to look for templates. The way I've done my template layout is to have a template directory under the project, then subdirectories for each app. When you specify a template that is project level, you just use its name. For app specific templates you specify like: "app1/mytemplate.html" -- Joel Goldstick -- You received this message because you are subscribed to the Google Groups "Django users"
Can a OneToOne field be used to generate the value of a SlugField in the same model?
Hi, I have a model which defines a blogger property, which is a OneToOne field on the django.contrib.auth.models.User model as follows: class BlogUser(models.Model): blogger = models.OneToOneField('auth.User', related_name='blogger') url = models.SlugField(max_length=125, unique=True, help_text="URL automatically generated from the bloggers name.") When I create an instance of the BlogUser class and access its blogger property, I get the name of the associated User. However, in my admin site, the blogger property of the BlogUser object is displayed as the ID of the associated User object. I suspect that this is due to lazy-loading of objects by django's querysets leading to related objects not automatically being loaded? Is it possible to use a ForeignKey or OneOnOne relationship property as the field from which to generate a slug? If so, how can it be done? I would appreciate any advice. Thanks. Regards, Sithembewena Lloyd Dube -- You received this message because you are subscribed to the Google 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 a django Beginner!
I use Djano ORM for a lot of my backend processing where no web is involved. Just make sure that DJANGO_SETTINGS_MODULE is defined in your environment and you can use pretty much any part of Django in your own code/scrits/whatever. HTH Jirka On 15/04/2011, Aviv Giladi wrote: > Hey guys, > > I am an experienced Python developer starting to work on web service > backend system. The system feeds data (constantly) from the web to a > MySQL database. This data is later displayed by a frontend side (there > is no connection between the frontend and the backend). The backend > system constantly downloads flight information from the web (some of > the data is fetched via APIs, and some by downloading and parsing > text / xls files). I already have a script that downloads the data, > parses it, and inserts it to the MySQL db - all in a big loop. The > frontend side is just a bunch of php pages that properly display the > data by querying the MySQL server. > > It is crucial that this web service be robust, strong and reliable. > Therefore, I have been looking into the proper ways to design it, and > got the following recommendation: > django as the framework (over Apache). > wrapping my sources with Piston for API usage. > All if this sounds great. I used django before to write websites (aka > request handlers that return data). However I don't see how django can > fulfill a role of a constant running (non request-serving) system - > being that it uses views/forms, which are not a part of my backend > system. Is want I want at all possible / advisable with django? Is > django what you would recommend for this? > If so, could you please refer me to some documentation / help files > more specific to my needs? > > Thank you so much, > Aviv > > -- > You received this message because you are subscribed to the Google 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. > > -- You received this message because you are subscribed to the Google 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.
Please Help a django Beginner!
Hey guys, I am an experienced Python developer starting to work on web service backend system. The system feeds data (constantly) from the web to a MySQL database. This data is later displayed by a frontend side (there is no connection between the frontend and the backend). The backend system constantly downloads flight information from the web (some of the data is fetched via APIs, and some by downloading and parsing text / xls files). I already have a script that downloads the data, parses it, and inserts it to the MySQL db - all in a big loop. The frontend side is just a bunch of php pages that properly display the data by querying the MySQL server. It is crucial that this web service be robust, strong and reliable. Therefore, I have been looking into the proper ways to design it, and got the following recommendation: django as the framework (over Apache). wrapping my sources with Piston for API usage. All if this sounds great. I used django before to write websites (aka request handlers that return data). However I don't see how django can fulfill a role of a constant running (non request-serving) system - being that it uses views/forms, which are not a part of my backend system. Is want I want at all possible / advisable with django? Is django what you would recommend for this? If so, could you please refer me to some documentation / help files more specific to my needs? Thank you so much, Aviv -- You received this message because you are subscribed to the Google 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: remove items from queryset for nested regrouping
Ok its solved now, I updated my nested regroup with the following {% regroup dict by col_mapper as column_gr %} {% for column in column_gr %} {{ column.grouper }} {% with column.list as groupr %} {% regroup groupr by main_title as item_gr %} {% for ggc in item_gr %} {{ ggc.grouper }} {% for i in ggc.list %} {{ i.list_title }} {% endfor %} {% endfor %} {% endwith %} {% endfor %} On Fri, Apr 15, 2011 at 4:39 PM, Mo Mughrabi wrote: > Hi, > > I've been working on a project that takes into consideration performance as > the top priority therefore am trying to use single to queries at each page > to collect all the needed information. > > Any who, I got to a point where I have one query set that need to be > regrouped based on column (left, right, center) and then again regrouped > based on title. The logic is working fine, but when the second regroup > starts it will take the entire queryset meanwhile I only need to regroup > items that are on the left or center..etc. so, I searched for functions to > remove items from the queryset without hitting the database and only thing I > could find was to build a custom template which is where I got stuck :) > > > This is my query result > > > > ++---++---++---+---+-++-+-+ > | col_mapper | list_title| main_title | list_slug | id | slug >| is_active | site_id | id | domain | name| > > > ++---++---++---+---+-++-+-+ > | L | gadget| for sale | gadget| 2 | > for-sale | 1 | 1 | 1 | example.com | example.com | > | L | furniture | for sale | frnture | 2 | > for-sale | 1 | 1 | 1 | example.com | example.com | > | L | engines | for sale | engines | 2 | > for-sale | 1 | 1 | 1 | example.com | example.com | > | L | women seeking men | personals | wsm | 1 | > personals | 1 | 1 | 1 | example.com | example.com | > | L | missed connection | personals | misd-conn | 1 | > personals | 1 | 1 | 1 | example.com | example.com | > | L | men seeking women | personals | msw | 1 | > personals | 1 | 1 | 1 | example.com | example.com | > | R | massage | services | massage | 3 | srvces >| 1 | 1 | 1 | example.com | example.com | > | R | computers | services | compters | 3 | srvces >| 1 | 1 | 1 | example.com | example.com | > > > ++---++---++---+---+-++-+-+ > > > In my template, I did something like this > > {% regroup dict by col_mapper as column_gr %} > > {% for column in column_gr %} > {{ column.grouper }} > > {% regroup column.list by main_title as item_gr %} > {% for i in item_gr %} > {{ i }} > {% endfor %} > {% endfor %} > > The first regroup is working fine, but once it gets to the second regroup > it regroups again the whole queryset while I want to only regroup where > col_mapper is equal to col_mapper.grouper. I tried to build a custom tag, > but most the approaches I know they will cause the queryset to hit the > database again for filtering. > > Any suggestions? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
ie9 and localhost hangs
This week I installed the latest windows 7 microsoft updates. Also since a few days, IE9 hangs when I try to connect to http://127.0.0.1:8000 I do not see any movement on the Django development server DOS-screen. Firefox4 is OK, and connecting to Opera11 at the same time: no problem. But IE9 hangs. When I startup USBWebserver8, and try to connect to 127.0.0.1:8080, no problem. Anyone any idea on what's going on? -- You received this message because you are subscribed to the Google 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: SQL Server
On Fri, Apr 15, 2011 at 9:25 AM, Jirka Vejrazka wrote: > I use exactly the same setup. Look up the "django-odbc" package. > This will be quite easy to use and setup, but there are some > unresolved bugs in that package related to multi-db support. Most of > them have patches attached to their tickets. i tried django-odbc recently but got frustrated because of problems in the utf8-latin1 mismatches. i think it has something to do with the exact versions of the unix-odbc layer and the MSSQL server, and also because the existing database was 'designed' without any thoughts for character encoding (people here are used 'forgive' computers for mangling accents and ñ) in the end i used django's ORM for my own databases and straight SQL (via pyodbc) for MSSQL access. -- Javier -- You received this message because you are subscribed to the Google 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: SQL Server
Mike, I use exactly the same setup. Look up the "django-odbc" package. This will be quite easy to use and setup, but there are some unresolved bugs in that package related to multi-db support. Most of them have patches attached to their tickets. Cheers Jirka On 15/04/2011, Mike Kenny wrote: > Hi, > > I am trying to use a django application developed on Linux with MySQL > on a Windows box with SQL Server. I have downloaded pyodbc and set my > ENGINE to sql_server.pyodbc (and tried just pyodbc as I was able to > import this into python but not sql_server). Both result in an error > message listing the supported engines, of which pyodbc is not listed. > > Obviously I have missed a step somewhere, does anybody know hat it > might be? Or can somebody provide me with an idiot's guide to using > django with SQL Server. (Unfortunately I am not at home in a windows > environment) > > The software I am using is python 2.7 ,django 1.3 and pyodbc 2.18 > > Thanks, > > mike > > -- > You received this message because you are subscribed to the Google 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. > > -- You received this message because you are subscribed to the Google 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.
SQL Server
Hi, I am trying to use a django application developed on Linux with MySQL on a Windows box with SQL Server. I have downloaded pyodbc and set my ENGINE to sql_server.pyodbc (and tried just pyodbc as I was able to import this into python but not sql_server). Both result in an error message listing the supported engines, of which pyodbc is not listed. Obviously I have missed a step somewhere, does anybody know hat it might be? Or can somebody provide me with an idiot's guide to using django with SQL Server. (Unfortunately I am not at home in a windows environment) The software I am using is python 2.7 ,django 1.3 and pyodbc 2.18 Thanks, mike -- You received this message because you are subscribed to the Google 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: satchmo currency
First off, you'll probably get better responses on the Satchmo list. Secondly, changing languages doesn't change currency symbols, which should make sense. 1 Euro is not equal to 1 Dollar. If we were to change symbols, we'd also need to do a currency conversion. It's not impossible by any means just not something that is done out of the box. -Chris On Thu, Apr 14, 2011 at 11:31 PM, ug Charlie wrote: > Hello, I just make a satchmo shop. 3 languages. > > But the currency make me stuck. > > I just want the site change the currency when changing the language. > > In satchmo settings.py, it is like > > L10N_SETTINGS = { >'currency_formats' : { >'EURO' : { >'symbol': u'€ ', >'positive' : u"€ %(val)0.2f", >'negative': u"€ (%(val)0.2f)", >'decimal' : ',' >}, >'USD' : { >'symbol': u'$ ', >'positive' : u"$%(val)0.2f", >'negative': u"$(%(val)0.2f)", >'decimal' : ',' >}, >}, >'default_currency' : 'EURO', >'show_admin_translations': True, >'allow_translation_choice': True, > } > > I do not really know how to do that..:( > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google 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: Stackoverflow kind of Answer/commenting app in Django
Thanks a lot for that suggestion. On Apr 15, 2011 8:52 AM, "Daniel Hilton" wrote: > On 15 April 2011 13:01, roberto wrote: >> You can also have a look at askbot. >> It seems to have more functionalities. >> Good luck ! >> >> www.askbot.org >> >> On Apr 14, 6:43 pm, AJ wrote: >>> Why has this become a case for me? I just wanted to know about a particular >>> solution, that whether it exists or not. I did try Google and other forums. >>> >>> I never complained about 'a couple of days', someone else did. >>> >>> I apologize for asking a 'dumb' question by your standards. Please accept my >>> sincere thanks to all who replied and helped. >> >> -- >> You received this message because you are subscribed to the Google 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. >> >> > Having built one for a project, it took about 10 days with tests and > integration. > > You could use a rating app via generic foreign keys to cut some time down. > HTH > Dan > > > > -- > Dan Hilton > > www.twitter.com/danhilton > www.DanHilton.co.uk > > > -- > You received this message because you are subscribed to the Google 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. > -- You received this message because you are subscribed to the Google 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: Customizing error message in ModelForm
Yes indeed! Thank you very much for your help. Rob -- You received this message because you are subscribed to the Google 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: Customizing error message in ModelForm
This should do the trick: class PrijsvraagForm(ModelForm): mail = forms.EmailField(error_messages={'required':'Vul aub een geldig Email adres in', 'invalid': 'Het email adres is niet geldig'}) class Meta: model = Prijsvraag def clean_code(self): super(PrijsvraagForm, self).clean() x = self.cleaned_data['code'] try: y = Code.objects.all()[0] except: raise forms.ValidationError("Er is iets fout gegaan") if x != y.code: raise forms.ValidationError("De code is niet juist") pass return x -- You received this message because you are subscribed to the Google 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.
remove items from queryset for nested regrouping
Hi, I've been working on a project that takes into consideration performance as the top priority therefore am trying to use single to queries at each page to collect all the needed information. Any who, I got to a point where I have one query set that need to be regrouped based on column (left, right, center) and then again regrouped based on title. The logic is working fine, but when the second regroup starts it will take the entire queryset meanwhile I only need to regroup items that are on the left or center..etc. so, I searched for functions to remove items from the queryset without hitting the database and only thing I could find was to build a custom template which is where I got stuck :) This is my query result ++---++---++---+---+-++-+-+ | col_mapper | list_title| main_title | list_slug | id | slug | is_active | site_id | id | domain | name| ++---++---++---+---+-++-+-+ | L | gadget| for sale | gadget| 2 | for-sale | 1 | 1 | 1 | example.com | example.com | | L | furniture | for sale | frnture | 2 | for-sale | 1 | 1 | 1 | example.com | example.com | | L | engines | for sale | engines | 2 | for-sale | 1 | 1 | 1 | example.com | example.com | | L | women seeking men | personals | wsm | 1 | personals | 1 | 1 | 1 | example.com | example.com | | L | missed connection | personals | misd-conn | 1 | personals | 1 | 1 | 1 | example.com | example.com | | L | men seeking women | personals | msw | 1 | personals | 1 | 1 | 1 | example.com | example.com | | R | massage | services | massage | 3 | srvces | 1 | 1 | 1 | example.com | example.com | | R | computers | services | compters | 3 | srvces | 1 | 1 | 1 | example.com | example.com | ++---++---++---+---+-++-+-+ In my template, I did something like this {% regroup dict by col_mapper as column_gr %} {% for column in column_gr %} {{ column.grouper }} {% regroup column.list by main_title as item_gr %} {% for i in item_gr %} {{ i }} {% endfor %} {% endfor %} The first regroup is working fine, but once it gets to the second regroup it regroups again the whole queryset while I want to only regroup where col_mapper is equal to col_mapper.grouper. I tried to build a custom tag, but most the approaches I know they will cause the queryset to hit the database again for filtering. Any suggestions? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Customizing error message in ModelForm
@Martin Thank you for your reply. I tried to do this, but I still get the default error message (the custom error from the code field works as it should): from django.db import models from django.forms import ModelForm from django import forms class Prijsvraag(models.Model): naam = models.CharField(max_length=60) code = models.CharField(max_length=18) ingeschreven = models.DateField(auto_now_add=True) mail = models.EmailField(unique=True) nieuwsbrief = models.BooleanField(default=1) class PrijsvraagForm(ModelForm): class Meta: mail = forms.EmailField(error_messages={'required': 'Vul aub een geldig Email adres in', 'invalid': 'Het email adres is niet geldig'}) model = Prijsvraag def clean_code(self): super(PrijsvraagForm, self).clean() x = self.cleaned_data['code'] try: y = Code.objects.all()[0] except: raise forms.ValidationError("Er is iets fout gegaan") if x != y.code: raise forms.ValidationError("De code is niet juist") pass return x Rob -- You received this message because you are subscribed to the Google 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: Customizing error message in ModelForm
Error messages in ModelForms work perfectly fine. class PersonForm(forms.ModelForm): first_name = forms.CharField(error_messages={'required': 'Please enter your first name!'}) class Meta: model = Person http://docs.djangoproject.com/en/dev/ref/forms/fields/#error-messages -- You received this message because you are subscribed to the Google 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: Stackoverflow kind of Answer/commenting app in Django
On 15 April 2011 13:01, roberto wrote: > You can also have a look at askbot. > It seems to have more functionalities. > Good luck ! > > www.askbot.org > > On Apr 14, 6:43 pm, AJ wrote: >> Why has this become a case for me? I just wanted to know about a particular >> solution, that whether it exists or not. I did try Google and other forums. >> >> I never complained about 'a couple of days', someone else did. >> >> I apologize for asking a 'dumb' question by your standards. Please accept my >> sincere thanks to all who replied and helped. > > -- > You received this message because you are subscribed to the Google 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. > > Having built one for a project, it took about 10 days with tests and integration. You could use a rating app via generic foreign keys to cut some time down. HTH Dan -- Dan Hilton www.twitter.com/danhilton www.DanHilton.co.uk -- You received this message because you are subscribed to the Google 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: Stackoverflow kind of Answer/commenting app in Django
You can also have a look at askbot. It seems to have more functionalities. Good luck ! www.askbot.org On Apr 14, 6:43 pm, AJ wrote: > Why has this become a case for me? I just wanted to know about a particular > solution, that whether it exists or not. I did try Google and other forums. > > I never complained about 'a couple of days', someone else did. > > I apologize for asking a 'dumb' question by your standards. Please accept my > sincere thanks to all who replied and helped. -- You received this message because you are subscribed to the Google 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.
Customizing error message in ModelForm
I want to show a custom error message in a Modelform. With a normal form I can add an error message like this: error_messages={'required': 'Vul aub een geldig Email adres in', 'invalid': 'Het email adres is niet geldig'} With a ModelForm this won't work. Is there a way to add a custom error message to the ModelForm, or should i write a custom clean method? I am using Django 1.2.3 Rob -- You received this message because you are subscribed to the Google 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.
OneToOne relationship - id displayed in admin instead of object name?
Hi everyone, I have a class definition as follows in my models: class BlogUser(models.Model): *blogger = models.OneToOneField(User)* *# User being the django.contrib.auth.models user* featured =models.BooleanField() url =models.SlugField(max_length=125, unique=True, help_text="URL automatically generated from the bloggers name.") active = models.BooleanField() date_created = models.DateTimeField(auto_now_add=True) date_edited = models.DateTimeField(auto_now=True) def __unicode__(self): return self.blogger.username In admin.py, I have the following: class BlogUserAdmin(admin.ModelAdmin): list_display = ('blogger', 'featured', 'url', 'active', 'date_created', 'date_edited') ordering = ('-featured', 'blogger') prepopulated_fields = {"url": ("*blogger*",)} admin.site.register(BlogUser, BlogUserAdmin) I fire up the python shell, import the BlogUser model and create an instance of it. >>>from myproject.myapp.models import BlogUser >>>blog_user = BlogUser.objects.get(pk=1) >>>blog_user.blogger Mike I get the blogger object's name However, in the admin section the blogger id is displayed. How can I display the unicode representation of the blogger object? Thanks. -- Regards, Sithembewena Lloyd Dube -- You received this message because you are subscribed to the Google 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: Error: No module named mysql.base when trying to sync.db
Solved! in settings.py file, option 'ENGINE' must be like this: django.db.backends.mysql 2011/4/14, pagan : > same problem. apache2, mod_wsgi, python-mysqldb installed. When i add > databases engine, name, user, password in settings.py, i got a > message: > > ImportError at /wsgi > No module named mysql.baseRequest Method: GET > Request URL: http://x/wsgi > Django Version: 1.3 > Exception Type: ImportError > Exception Value: No module named mysql.base > Exception Location: /usr/lib/python2.5/site-packages/django/utils/ > importlib.py in import_module, line 35 > Python Executable:/usr/bin/python > Python Version: 2.5.2 > Python Path: ['/usr/lib/python2.5', > '/usr/lib/python2.5/plat-linux2', > '/usr/lib/python2.5/lib-tk', > '/usr/lib/python2.5/lib-dynload', > '/usr/local/lib/python2.5/site-packages', > '/usr/lib/python2.5/site-packages', > '/var/lib/python-support/python2.5', > '/home/django-projects//apps'] > > Anyone knows whats that? > > On 13 апр, 02:56, dsx wrote: >> same here. >> >> On Apr 1, 12:48 am, nai wrote: >> >> >> >> > I posted the same question on stackoverflow >> > here:http://stackoverflow.com/questions/5509755/problem-with-django-syncdb... >> >> > Reproduced >> >> > Hi all, I'm trying to deploy my project on my EC2 instance. When I run >> > python manage.py validate I get this error Error: No module named >> >mysql.base. >> >> > I have already installed MySQL-python using yum install MySQL-python. >> > I can import MySQLdb successfully from the Python interpreter. >> >> > I can't seem to figure out what's wrong? >> >> > I am using Django 1.3 and Python 2.6 and MySQLdb 1.2.3c1 > > -- > You received this message because you are subscribed to the Google 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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: best practice override admin 1.2 "delete"?
glad it did work :) On Apr 15, 10:32 am, λq wrote: > Wow, this is exactly what I am looking for. Thanks a million! :D > > 2011/4/15 Mengu > > > > > > > > > Hi, > > > I've just asked in the #django channel. Read this > > >http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contri... > > . > > > On Apr 15, 6:27 am, λq wrote: > > > Thanks Mengu, > > > > I have another question: > > > > how to set admin's default view NOT to display items if is_deleted=True? > > > > Yes the super user can click a filter link, but I want to make it as > > default > > > as possible. > > > > On Thu, Apr 14, 2011 at 8:21 PM, Mengu wrote: > > > > you can override the delete method for your models and set a column > > > > ie, is_deleted to True or something else in there. so, subclass > > > > models.Model, override delete option and your models should extend > > > > your new subclass. > > > > > On Apr 14, 11:51 am, λq wrote: > > > > > Hi list, > > > > > > We have a production django app using the default admin view, but > > some of > > > > > the super users delete a record in a model and affect other related > > data, > > > > > this cause inconsistency and corruption. What's the best practice to > > > > > override django admin's default delete behavior and implement some > > kind > > > > of > > > > > "Recycle Bin" for models without harassing much the existing code? > > > > > > Any idea is appreciated. Thanks in advance! > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Django users" group. > > > > To post to this group, send email to django-users@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com. > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google 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. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django 1.3 and multilingual
Hello all, i updeted my app to django 1.3 and stop to work my custom admin. use_fieldsets = [ (None, {'fields': ('photo1', 'title',)}), ] i have this error Unknown field(s) (title) specified for HomePage when i dont use use_fieldsets the admin work but i need to custom the order of fields. other solutions for multilingual sites ? Thanks. Kind regards Andrea -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: best practice override admin 1.2 "delete"?
Wow, this is exactly what I am looking for. Thanks a million! :D 2011/4/15 Mengu > Hi, > > I've just asked in the #django channel. Read this > > http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.queryset > . > > On Apr 15, 6:27 am, λq wrote: > > Thanks Mengu, > > > > I have another question: > > > > how to set admin's default view NOT to display items if is_deleted=True? > > > > Yes the super user can click a filter link, but I want to make it as > default > > as possible. > > > > > > > > > > > > > > > > On Thu, Apr 14, 2011 at 8:21 PM, Mengu wrote: > > > you can override the delete method for your models and set a column > > > ie, is_deleted to True or something else in there. so, subclass > > > models.Model, override delete option and your models should extend > > > your new subclass. > > > > > On Apr 14, 11:51 am, λq wrote: > > > > Hi list, > > > > > > We have a production django app using the default admin view, but > some of > > > > the super users delete a record in a model and affect other related > data, > > > > this cause inconsistency and corruption. What's the best practice to > > > > override django admin's default delete behavior and implement some > kind > > > of > > > > "Recycle Bin" for models without harassing much the existing code? > > > > > > Any idea is appreciated. Thanks in advance! > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Django users" group. > > > To post to this group, send email to django-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google 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. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: best practice override admin 1.2 "delete"?
Hi, I've just asked in the #django channel. Read this http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.queryset. On Apr 15, 6:27 am, λq wrote: > Thanks Mengu, > > I have another question: > > how to set admin's default view NOT to display items if is_deleted=True? > > Yes the super user can click a filter link, but I want to make it as default > as possible. > > > > > > > > On Thu, Apr 14, 2011 at 8:21 PM, Mengu wrote: > > you can override the delete method for your models and set a column > > ie, is_deleted to True or something else in there. so, subclass > > models.Model, override delete option and your models should extend > > your new subclass. > > > On Apr 14, 11:51 am, λq wrote: > > > Hi list, > > > > We have a production django app using the default admin view, but some of > > > the super users delete a record in a model and affect other related data, > > > this cause inconsistency and corruption. What's the best practice to > > > override django admin's default delete behavior and implement some kind > > of > > > "Recycle Bin" for models without harassing much the existing code? > > > > Any idea is appreciated. Thanks in advance! > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google 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.