Re: django storage chinese failed to mysql!!
On wo, 2010-07-28 at 09:11 +0800, pengbo xue wrote: > hi all, > > I can register from my django web page in english,but it can't storage > chinese to django mysql database. > > please give me advice. thx Check your table definition to see whether the field you try to store is a latin1 or utf8 field. If it is latin1, it will not support chinese characters. -- Dennis K. They've gone to plaid! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
implementing next and previous of the object
Hi all, Need help, advice on how the have a next and previous link on a object detail page. For example fomr a object list page a user chose an object, and in the object page instead of going back to the list to view other object the user just click either next or previous. Any idea how to implement it? Thanks, James -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
private models and inheriting model permission?
Hi all, I'm new to Django and Python. I have a small project I want to tackle and was after some advice on where to start. Simply the project will be a site to manage 'Projects' and their associated 'Tasks', however each project and their related tasks should be private (authenticated users can only see the tasks for the projects they have access to). Use Case: Prerequisites: - Three projects, "Project A", "Project B" and "Project C" exist. - Three groups, "Project A", "Project B" and "Project C" exist. - One user, "User A" exists and is assigned to the group "Project A" and "Project C" Scenario 1: 1. 'User A' logs in to site, clicks "my projects", 'Project A' and 'Project C' is listed. 2. 'User A' clicks "new task" and new task form is loaded. 3. 'User A' adds a task "Title", selects the "Project" combo and selects 'Project A' from a choice of 'Project A' and 'Project C'. 'User A' clicks 'Submit'. 4. 'User A' selects "show all tasks", tasks for 'Project A' and 'Project C' only are shown. What have I done so far: Basically I have done the easy stuff. I have a Project model and a Task model. At the moment any new task can be created against any project (no security in place). Where should I start? I've looked around for a app which does this but haven't had any luck. Perhaps i'm not using the correct keywords to find the right answer? Any help of advice you could provide will be very helpful, and much appreciated. Cheers, Jamie -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
Finally figured out what's going on. My hypothesis: An HTTP request with POST method sent to a Django view wrapped with @csrf_exempt will still raise a 403 CSRF error if the wrapped view raises an Http404 exception. In this specific case, we raise 404 when there is no valid video_id passed in the POST request: 264 # Make sure there's at least one 265 if len(distro_list) < 1: 266 raise Http404 Raising a 403 was obviously not the result behavior we expected, instead we would have expected the 404 to be raised without CSRF interfering given the initial view was properly wrapped with @csrf_exempt. Further contributing, this was rather difficult to diagnose due to the opaque 403 error message even when DEBUG = True. Is this expected Django behavior? If not, can we please address this in a future release? Is there a better way to provide debugging information for 403 errors raised from the built-in CSRF methods? All the best and thanks for a great framework. Kieran On Jul 27, 6:54 pm, Kieran Farr wrote: > Further research shows that CSRF is enabled regardless of my > settings.py if we use Django's built-in auth. > > Obviously, we need to still use Django's auth, so we can't just > disable CSRF site-wide like this > hack:http://stackoverflow.com/questions/1650941/django-csrf-framework-cann... > ...or this hack...http://djangosnippets.org/snippets/2069/ > > Obviously also, we have no control over the third-party server sending > the POST request, so we can't resort to this > hack:http://stackoverflow.com/questions/2405353/having-a-postable-api-and-... > > The decorator @csrf_exempt does not work as described in the docs as > our view always returns a 403 when any content is POSTed. > > Very confusing! > > Kieran > > On Jul 27, 1:32 pm, Kieran Farr wrote: > > > > > Raj sorry I misread your question. This initial response is in re: my > > listener. > > > The "sender" of this POST request is a third party server that we have > > no control over. > > > However, even when debugging with wget we receive the 403. > > > Here is the wget command I've been testing with: > > > $ wgethttp://www.url.com/subdir/listener/--post-data"?test=test"; -U > > "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/ > > 533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16" > > > --2010-07-27 20:06:36-- http://www.url.com/subdir/listener/ > > Resolving [URL] ... [IP ADDRESS] > > Connecting to [URL]|[IP ADDRESS]|:80... connected. > > HTTP request sent, awaiting response... 403 Forbidden > > 2010-07-27 20:06:37 ERROR 403: Forbidden. > > > However, if I send without the post-data, here's the response: > > > $ wgethttp://www.url.com/subdir/listener/ > > > --2010-07-27 20:31:14-- http://www.url.com/subdir/listener/ > > Resolving [URL]... [IP ADDRESS] > > Connecting to [URL|[IP ADDRESS]|:80... connected. > > HTTP request sent, awaiting response... 200 OK > > Length: unspecified [text/plain] > > Saving to: `index.html.1' > > > [ <=> > > ] > > 27 --.-K/s in 0s > > > 2010-07-27 20:31:14 (1.84 MB/s) - `index.html.1' saved [27] > > > On Jul 27, 11:34 am, Kieran Farr wrote: > > > > This is intended not to be protected by auth, so this page is publicly > > > accessible, no login required. > > > > Here's the function in its entirety: > > > > 255 @csrf_response_exempt > > > 256 def DistroHeySpreadListener(request): > > > 257 if request.method == 'POST': > > > 258 post = request.POST > > > 259 raw = request.raw_post_data > > > 260 remote_media_id = post.get("video_id", "") > > > 261 # Try to fetch the distros for this > > > remote_media_id > > > 262 distro_list = > > > Distro.objects.filter(remote_media_id__exact=remote_media_id) > > > 263 > > > 264 # Make sure there's at least one > > > 265 if len(distro_list) < 1: > > > 266 raise Http404 > > > 267 > > > 268 # For each distro instance, check to see if > > > there's a response in this api call > > > 269 for distro in distro_list: > > > 270 # Prepare logging > > > 271 log = distro.log > > > 272 log += "Raw data from POST" + str(raw) > > > 273 distro.log = log > > > 274 distro.save() > > > 275 > > > 276 # Get distro short name > > > 277 dest_short_name = > > > distro.credential.destination.short_name > > > 278 > > > 279 # From short_name, return either error or > > > link starting with http:// > > > 280 response = post.get('link[%s]' % > > > dest_short_name, False) or post.get('error[%s]' % dest_sh
Re: how to debug restful django apps?
Do you have access to the Django app? Can you set settings.DEBUG = True to get the full traceback? If you set the ADMINS tuple in the settings you also can get an email with the traceback when DEBUG = False. The email backend can also be configured with the EMAIL_BACKENDS setting, so you can, for example, write to a log file instead [1]. Hope this helps, -Roberto. [1] http://docs.djangoproject.com/en/dev/topics/email/#e-mail-backends On Jul 27, 2:06 am, ff wrote: > I have a python script that creates and then uploads a file to a > django app. Sometimes the django app will error out and my script will > just return this: > > Traceback (most recent call last): > File "/home/chris/bin/upload.py", line 318, in > send_request(tmpzip, var1, var2, options.meta, url) > File "/srv/the_system/scripts/multipart.py", line 89, in > send_request > print urllib2.urlopen(request).read() > File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) > File "/usr/lib/python2.6/urllib2.py", line 397, in open > response = meth(req, response) > File "/usr/lib/python2.6/urllib2.py", line 510, in http_response > 'http', request, response, code, msg, hdrs) > File "/usr/lib/python2.6/urllib2.py", line 435, in error > return self._call_chain(*args) > File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > result = func(*args) > File "/usr/lib/python2.6/urllib2.py", line 518, in > http_error_default > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR > > Its very hard to pinpoint what exactly went wrong with just a big > "ERROR 500" message... > > Does anyone have any tips on how to get the full fancy traceback when > interfacing with a django app in this way? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
Further research shows that CSRF is enabled regardless of my settings.py if we use Django's built-in auth. Obviously, we need to still use Django's auth, so we can't just disable CSRF site-wide like this hack: http://stackoverflow.com/questions/1650941/django-csrf-framework-cannot-be-disabled-and-is-breaking-my-site ...or this hack... http://djangosnippets.org/snippets/2069/ Obviously also, we have no control over the third-party server sending the POST request, so we can't resort to this hack: http://stackoverflow.com/questions/2405353/having-a-postable-api-and-djangos-csrf-middleware The decorator @csrf_exempt does not work as described in the docs as our view always returns a 403 when any content is POSTed. Very confusing! Kieran On Jul 27, 1:32 pm, Kieran Farr wrote: > Raj sorry I misread your question. This initial response is in re: my > listener. > > The "sender" of this POST request is a third party server that we have > no control over. > > However, even when debugging with wget we receive the 403. > > Here is the wget command I've been testing with: > > $ wgethttp://www.url.com/subdir/listener/--post-data "?test=test" -U > "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/ > 533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16" > > --2010-07-27 20:06:36-- http://www.url.com/subdir/listener/ > Resolving [URL] ... [IP ADDRESS] > Connecting to [URL]|[IP ADDRESS]|:80... connected. > HTTP request sent, awaiting response... 403 Forbidden > 2010-07-27 20:06:37 ERROR 403: Forbidden. > > However, if I send without the post-data, here's the response: > > $ wgethttp://www.url.com/subdir/listener/ > > --2010-07-27 20:31:14-- http://www.url.com/subdir/listener/ > Resolving [URL]... [IP ADDRESS] > Connecting to [URL|[IP ADDRESS]|:80... connected. > HTTP request sent, awaiting response... 200 OK > Length: unspecified [text/plain] > Saving to: `index.html.1' > > [ <=> > ] > 27 --.-K/s in 0s > > 2010-07-27 20:31:14 (1.84 MB/s) - `index.html.1' saved [27] > > On Jul 27, 11:34 am, Kieran Farr wrote: > > > > > This is intended not to be protected by auth, so this page is publicly > > accessible, no login required. > > > Here's the function in its entirety: > > > 255 @csrf_response_exempt > > 256 def DistroHeySpreadListener(request): > > 257 if request.method == 'POST': > > 258 post = request.POST > > 259 raw = request.raw_post_data > > 260 remote_media_id = post.get("video_id", "") > > 261 # Try to fetch the distros for this > > remote_media_id > > 262 distro_list = > > Distro.objects.filter(remote_media_id__exact=remote_media_id) > > 263 > > 264 # Make sure there's at least one > > 265 if len(distro_list) < 1: > > 266 raise Http404 > > 267 > > 268 # For each distro instance, check to see if > > there's a response in this api call > > 269 for distro in distro_list: > > 270 # Prepare logging > > 271 log = distro.log > > 272 log += "Raw data from POST" + str(raw) > > 273 distro.log = log > > 274 distro.save() > > 275 > > 276 # Get distro short name > > 277 dest_short_name = > > distro.credential.destination.short_name > > 278 > > 279 # From short_name, return either error or > > link starting with http:// > > 280 response = post.get('link[%s]' % > > dest_short_name, False) or post.get('error[%s]' % dest_short_name, > > False) > > 281 > > 282 if response.startswith('http://'): > > 283 # If response starts with http > > then success, populate as link > > 284 distro.destination_url = response > > 285 distro.state = TRANSCODE_SUCCESS > > 286 log += '\nSUCCESS, url = %s' % > > response > > 287 else: > > 288 # Else, change state to error and > > log error message > > 289 log += '\nERROR, error = %s' % > > response > > 290 distro.state = TRANSCODE_ERROR > > 291 > > 292 distro.log = log > > 293 distro.save() > > 294 > > 295 > > 296 h = HttpResponse("Thanks, HeySpread! We love > > you.", mimetype="text/plain", status=200) > > 297 h.csrf_exempt = True > > 298 return h > > 299 # return HttpResponse("Thanks, HeySpread! We love > > you.", mimetype="text/plain", status=200) > > 300 else: > > 301
updating admin values with other fields
I have a save override in my admin file that catches a value from one field and applies it to another. The values it grabs from a manytomany field. I can get it to work, but only when I save twice. It looks like it needs the manytomany to update with the new values and then it needs to second save to assigne the values to the other field. Here is the method override: def save_model(self, request, obj, form, change): obj.primary_winner_r = obj.primary_advance_r.values_list('id', flat=True) obj.primary_winner_d = obj.primary_advance_d.values_list('id', flat=True) obj.primary_winner_np = obj.primary_advance_np.values_list('id', flat=True) obj.save() -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
django storage chinese failed to mysql!!
hi all, I can register from my django web page in english,but it can't storage chinese to django mysql database. please give me advice. thx -- cowboy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
testing with multiple databases
Hello Djangonauts, I am using django in an application that has multiple distinct databases, each with unique data (i.e. not master/slave type configuration). I've created an app (django-admin.py startapp) for each database and the settings.py defines DATABASE_ROUTERS where I specify what database a table belongs in depending on the application a model is in. This configuration has a few bumps when testing. First, loading fixture data into a database other than the default, does not work with the 'fixtures' list in a TestCase. I tracked the problem down to the fixtures only being loaded into the default database. If the fixture is for data in another database, no go. I believed I was clever by adding the following to my TestCase's setUp() function: management.call_command('loaddata', 'mydata.json', database='otherdb', verbosity=0) Then I ran into a problem where databases other than the default are not cleared per test. Subsequent tests are failing due to additional data being in the database already. Is there something I am doing wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
[ot] good practices questions, using django
Hello Guys, I'm relatively new to django. I have some doubt about good practices, using it. 1 - I have some helpers that I use on all apps. For this I created a app called helpers (./manager.py startapp helpers) it don't have any view, or model. And then I created some files like: misc.py choices.py use.py and inside choices.py I have for example: from content.models import Publication, Issue, Article, Comment, Image OBJ_HANDLER = { 'publication': Publication, 'issue': Issue, 'article': Article, 'comment': Comment, 'image': Image, } PERMISSION_CHOICES = ( (0, 'None'), (1, 'Read/Comment'), (2, 'Edit/Comment'), (4, 'Read'), ) Is it ok, if I create 'empty' apps, like that ? 2 - There are some commands that I like to think that I will always use: for example: add, remove, view, edit and browse For that I created a file (handlers.py) insie my app (content) And I use like this: content/urls.py: urlpatterns = patterns('', (r'^browse/(?P.*)/(?P.*)/', 'content.views.browse'), (r'^(?P.*)/(?P.*)/(?P.*)/(.*)', 'content.handlers.url'), ) content/handlers.py: import views def url(request, cmd, obj, key=0): f_name = obj+ '_' +cmd call = getattr(views, f_name.lower()) return call(request, key) content/views.py: def publication_edit(request, key): do_something() So, I can use: /content/edit/publication// Is it ok, if I create other files in the app's directory, like this ? (I have a file called 'forms' too). 3 - Is there any problem if I use the OBJ_HANDLER (from helpers/choices.py) like this:? entries_list = OBJ_HANDLER[obj].objects.all().filter('public =', True) 4 - I have a form that has a create() method. class IssueForm(djangoforms.ModelForm): #... code def create(self, data): return Issue(publication = data['publication']).save() Is it ok if I return saved objects in forms ? Is all of this, or some of this, good practices ? Thank you a lot :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
File sharing service on Django?
Is there any painless way to make Django able to serve files with one- time urls, like in RapidShare? First thought - use django.views.static.serve with some tweeks. But is there a way to track status of download (dropped\complited)? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: MySQL error -1
On di, 2010-07-27 at 13:49 -0700, shacker wrote: > On Jul 27, 3:10 am, Dennis Kaarsemaker wrote: > > > > > Start with checking/repairing the table that causes this error to be > > thrown. > > All tables analyzed, optimized, and repaired. No errors found. But the > " error -1 from storage engine" reports continue a few minutes later > (not for every page request - just a dozen or so per day, but I know > those users are being served 500 pages and would like to get to the > bottom of it). Are the tracebacks all the same? Can you share a traceback? -- Dennis K. They've gone to plaid! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: MySQL error -1
On Jul 27, 3:10 am, Dennis Kaarsemaker wrote: > > Start with checking/repairing the table that causes this error to be > thrown. All tables analyzed, optimized, and repaired. No errors found. But the " error -1 from storage engine" reports continue a few minutes later (not for every page request - just a dozen or so per day, but I know those users are being served 500 pages and would like to get to the bottom of it). Thanks, Scot -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
Raj sorry I misread your question. This initial response is in re: my listener. The "sender" of this POST request is a third party server that we have no control over. However, even when debugging with wget we receive the 403. Here is the wget command I've been testing with: $ wget http://www.url.com/subdir/listener/ --post-data "?test=test" -U "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/ 533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16" --2010-07-27 20:06:36-- http://www.url.com/subdir/listener/ Resolving [URL] ... [IP ADDRESS] Connecting to [URL]|[IP ADDRESS]|:80... connected. HTTP request sent, awaiting response... 403 Forbidden 2010-07-27 20:06:37 ERROR 403: Forbidden. However, if I send without the post-data, here's the response: $ wget http://www.url.com/subdir/listener/ --2010-07-27 20:31:14-- http://www.url.com/subdir/listener/ Resolving [URL]... [IP ADDRESS] Connecting to [URL|[IP ADDRESS]|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/plain] Saving to: `index.html.1' [ <=> ] 27 --.-K/s in 0s 2010-07-27 20:31:14 (1.84 MB/s) - `index.html.1' saved [27] On Jul 27, 11:34 am, Kieran Farr wrote: > This is intended not to be protected by auth, so this page is publicly > accessible, no login required. > > Here's the function in its entirety: > > 255 @csrf_response_exempt > 256 def DistroHeySpreadListener(request): > 257 if request.method == 'POST': > 258 post = request.POST > 259 raw = request.raw_post_data > 260 remote_media_id = post.get("video_id", "") > 261 # Try to fetch the distros for this > remote_media_id > 262 distro_list = > Distro.objects.filter(remote_media_id__exact=remote_media_id) > 263 > 264 # Make sure there's at least one > 265 if len(distro_list) < 1: > 266 raise Http404 > 267 > 268 # For each distro instance, check to see if > there's a response in this api call > 269 for distro in distro_list: > 270 # Prepare logging > 271 log = distro.log > 272 log += "Raw data from POST" + str(raw) > 273 distro.log = log > 274 distro.save() > 275 > 276 # Get distro short name > 277 dest_short_name = > distro.credential.destination.short_name > 278 > 279 # From short_name, return either error or > link starting with http:// > 280 response = post.get('link[%s]' % > dest_short_name, False) or post.get('error[%s]' % dest_short_name, > False) > 281 > 282 if response.startswith('http://'): > 283 # If response starts with http > then success, populate as link > 284 distro.destination_url = response > 285 distro.state = TRANSCODE_SUCCESS > 286 log += '\nSUCCESS, url = %s' % > response > 287 else: > 288 # Else, change state to error and > log error message > 289 log += '\nERROR, error = %s' % > response > 290 distro.state = TRANSCODE_ERROR > 291 > 292 distro.log = log > 293 distro.save() > 294 > 295 > 296 h = HttpResponse("Thanks, HeySpread! We love > you.", mimetype="text/plain", status=200) > 297 h.csrf_exempt = True > 298 return h > 299 # return HttpResponse("Thanks, HeySpread! We love > you.", mimetype="text/plain", status=200) > 300 else: > 301 return HttpResponse("Oops, something went wrong.", > mimetype="text/plain", status=200) > > On Jul 27, 11:30 am, raj wrote: > > > > > Most probably it has something to do with permissions. Go thru the > > exact code block which tries to post the data. Is the login successful > > and does the logged-in user have got all necessary permissions > > required? Post that part of the code if you can't find out. > > > Rajeesh. > > > On Jul 27, 11:20 pm, Kieran Farr wrote: > > > > Further, debugging 403s is nearly impossible. It'd be very helpful > > > when in DEBUG mode to reveal who/what/why raised the 403. > > > > > What am I doing wrong/missing? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.
Re: save a values_list to a charfield
It is a bit of a last minute deal and will be changed after today, but we had a handful of "improvements" handed down to us from management and this was the fastest thing we could come up with using some old mysql query logic and several already built templates for output. I appreciate the help. On Jul 27, 2:49 pm, ringemup wrote: > ', '.join(primary_ids) > > The fact that you're doing this with foreign keys, though, suggests to > me that you may have a database normalization problem. > > On Jul 27, 3:26 pm, Nick wrote: > > > I am getting this to save but I can't get it to output properly > > > it's outputting as [16L, 451L, 521L] for a list of id's, which it > > should according to documentation. However, how can I output it like > > this 16, 451, 521 > > > On Jul 27, 12:11 pm, Nick wrote: > > > > I am needing to do some duct taping for a project that is going on > > > right now. In it I need to take a values_list of id's from a > > > ManyToMany field and save those values to a varchar field so a mysql > > > query can access the values. I am working with two different sets of > > > developers and this is the best we can come up with in such a short > > > period of time > > > > Here is the model: > > > > Candidate > > > filing_id = models.IntegerField() > > > name = models.CharField() > > > > Race: > > > name = models.CharField() > > > primary_advance = models.ManyToManyField('Candidate') > > > primary_advnace_list = models.CahrField() > > > > def(save, *args, **kwargs): > > > primary_ids = self.primary_advace.values_list('id', flat=True) > > > if primary_ids.count() > 0: > > > primary_advance_list = primary_ids > > > else: > > > primary_advance_list = [] > > > super(Race, self).save(*args, **kwargs) > > > > I've tried this but I'm coming back with empty values for the list > > > fields. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: save a values_list to a charfield
', '.join(primary_ids) The fact that you're doing this with foreign keys, though, suggests to me that you may have a database normalization problem. On Jul 27, 3:26 pm, Nick wrote: > I am getting this to save but I can't get it to output properly > > it's outputting as [16L, 451L, 521L] for a list of id's, which it > should according to documentation. However, how can I output it like > this 16, 451, 521 > > On Jul 27, 12:11 pm, Nick wrote: > > > I am needing to do some duct taping for a project that is going on > > right now. In it I need to take a values_list of id's from a > > ManyToMany field and save those values to a varchar field so a mysql > > query can access the values. I am working with two different sets of > > developers and this is the best we can come up with in such a short > > period of time > > > Here is the model: > > > Candidate > > filing_id = models.IntegerField() > > name = models.CharField() > > > Race: > > name = models.CharField() > > primary_advance = models.ManyToManyField('Candidate') > > primary_advnace_list = models.CahrField() > > > def(save, *args, **kwargs): > > primary_ids = self.primary_advace.values_list('id', flat=True) > > if primary_ids.count() > 0: > > primary_advance_list = primary_ids > > else: > > primary_advance_list = [] > > super(Race, self).save(*args, **kwargs) > > > I've tried this but I'm coming back with empty values for the list > > fields. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: save a values_list to a charfield
I am getting this to save but I can't get it to output properly it's outputting as [16L, 451L, 521L] for a list of id's, which it should according to documentation. However, how can I output it like this 16, 451, 521 On Jul 27, 12:11 pm, Nick wrote: > I am needing to do some duct taping for a project that is going on > right now. In it I need to take a values_list of id's from a > ManyToMany field and save those values to a varchar field so a mysql > query can access the values. I am working with two different sets of > developers and this is the best we can come up with in such a short > period of time > > Here is the model: > > Candidate > filing_id = models.IntegerField() > name = models.CharField() > > Race: > name = models.CharField() > primary_advance = models.ManyToManyField('Candidate') > primary_advnace_list = models.CahrField() > > def(save, *args, **kwargs): > primary_ids = self.primary_advace.values_list('id', flat=True) > if primary_ids.count() > 0: > primary_advance_list = primary_ids > else: > primary_advance_list = [] > super(Race, self).save(*args, **kwargs) > > I've tried this but I'm coming back with empty values for the list > fields. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
This is intended not to be protected by auth, so this page is publicly accessible, no login required. Here's the function in its entirety: 255 @csrf_response_exempt 256 def DistroHeySpreadListener(request): 257 if request.method == 'POST': 258 post = request.POST 259 raw = request.raw_post_data 260 remote_media_id = post.get("video_id", "") 261 # Try to fetch the distros for this remote_media_id 262 distro_list = Distro.objects.filter(remote_media_id__exact=remote_media_id) 263 264 # Make sure there's at least one 265 if len(distro_list) < 1: 266 raise Http404 267 268 # For each distro instance, check to see if there's a response in this api call 269 for distro in distro_list: 270 # Prepare logging 271 log = distro.log 272 log += "Raw data from POST" + str(raw) 273 distro.log = log 274 distro.save() 275 276 # Get distro short name 277 dest_short_name = distro.credential.destination.short_name 278 279 # From short_name, return either error or link starting with http:// 280 response = post.get('link[%s]' % dest_short_name, False) or post.get('error[%s]' % dest_short_name, False) 281 282 if response.startswith('http://'): 283 # If response starts with http then success, populate as link 284 distro.destination_url = response 285 distro.state = TRANSCODE_SUCCESS 286 log += '\nSUCCESS, url = %s' % response 287 else: 288 # Else, change state to error and log error message 289 log += '\nERROR, error = %s' % response 290 distro.state = TRANSCODE_ERROR 291 292 distro.log = log 293 distro.save() 294 295 296 h = HttpResponse("Thanks, HeySpread! We love you.", mimetype="text/plain", status=200) 297 h.csrf_exempt = True 298 return h 299 # return HttpResponse("Thanks, HeySpread! We love you.", mimetype="text/plain", status=200) 300 else: 301 return HttpResponse("Oops, something went wrong.", mimetype="text/plain", status=200) On Jul 27, 11:30 am, raj wrote: > Most probably it has something to do with permissions. Go thru the > exact code block which tries to post the data. Is the login successful > and does the logged-in user have got all necessary permissions > required? Post that part of the code if you can't find out. > > Rajeesh. > > On Jul 27, 11:20 pm, Kieran Farr wrote: > > > > > Further, debugging 403s is nearly impossible. It'd be very helpful > > when in DEBUG mode to reveal who/what/why raised the 403. > > > > What am I doing wrong/missing? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
Most probably it has something to do with permissions. Go thru the exact code block which tries to post the data. Is the login successful and does the logged-in user have got all necessary permissions required? Post that part of the code if you can't find out. Rajeesh. On Jul 27, 11:20 pm, Kieran Farr wrote: > Further, debugging 403s is nearly impossible. It'd be very helpful > when in DEBUG mode to reveal who/what/why raised the 403. > > > What am I doing wrong/missing? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HTTP POST sent from app to Django Server returns 403 Forbidden
Hi, were having the exact same problem. We're integrating with a third-party API that sends "pings" via simple POST requests to our server to give us updates re: status video conversion processes. We're running Django 1.2.1 with Apache mod_python on Ubuntu 9.04. I've disabled ALL csrf related middleware for debugging purposes in settings.py, although we'll want that enabled on production. I've been attempting to debug with wget. When I hit the listener URL, it works fine if no post data is sent. However, as soon as I add the -- post-data tag with ANY text, a 403 is always returned. Even tried @csrf_exempt and @csrf_response_exempt AND adding csrf_exempt = True to the response object. This is quite frustrating as we're following all the docs for disabling CSRF and this is getting in the way of what would be a very simple task. Further, debugging 403s is nearly impossible. It'd be very helpful when in DEBUG mode to reveal who/what/why raised the 403. Any ideas? Kieran On Jul 26, 8:30 am, etone wrote: > Hi there, > > I'm trying to sent a HTTP POST from a client application to my Django > app. Django does indeed receive the HTTP POST as I do hit > _HandleRequest(), however it returns a 403 Forbidden, instead of > hitting my handler function. I experimented and sent a HTTP GET from > my client application and in this case I am able to hit my handler > function. I would like to use HTTP POST as I want to upload some data > to my Django app. > > What am I doing wrong/missing? > > Here is my settings.py in my django app: > > try: > from djangoappengine.settings_base import * > has_djangoappengine = True > except ImportError: > has_djangoappengine = False > DEBUG = True > TEMPLATE_DEBUG = DEBUG > > import os > > INSTALLED_APPS = ( > 'djangotoolbox', > # 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > ) > > if has_djangoappengine: > INSTALLED_APPS = ('djangoappengine',) + INSTALLED_APPS > > ADMIN_MEDIA_PREFIX = '/media/admin/' > MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media') > TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), > 'templates'),) > > ROOT_URLCONF = 'urls' -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: "TypeError iteration over non-sequence" after deploying
hi. stupid me, was registering a form in admin... didn't see that I had this error locally also (*only* the first time though, reloading was working fine). thanks ! _y On Jul 27, 6:45 pm, Shawn Milochik wrote: > There's your error. The value of model_or_iterable is not iterable. > Perhaps it's a model (based on your naming convention). > > Try logging the value of model_or_iterable right before that line to > see what it contains. Once you've done that, figure out why it > contains that instead of something that's iterable. > > Once you've done that, figure out whether it should never contain that > value or whether the value is correct but you should be treating it > differently (do something other than trying to put it in a 'for' > loop). > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
save a values_list to a charfield
I am needing to do some duct taping for a project that is going on right now. In it I need to take a values_list of id's from a ManyToMany field and save those values to a varchar field so a mysql query can access the values. I am working with two different sets of developers and this is the best we can come up with in such a short period of time Here is the model: Candidate filing_id = models.IntegerField() name = models.CharField() Race: name = models.CharField() primary_advance = models.ManyToManyField('Candidate') primary_advnace_list = models.CahrField() def(save, *args, **kwargs): primary_ids = self.primary_advace.values_list('id', flat=True) if primary_ids.count() > 0: primary_advance_list = primary_ids else: primary_advance_list = [] super(Race, self).save(*args, **kwargs) I've tried this but I'm coming back with empty values for the list fields. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to debug restful django apps?
On 27.07.2010 19:07, ff wrote: how on earth is django-toolbar going to help me at all here? Did you even read any of my post? On Jul 27, 7:15 am, lzzzing wrote: Try Django debug toolbar. On Jul 27, 5:06 pm, ff wrote: I have a python script that creates and then uploads a file to a django app. Sometimes the django app will error out and my script will just return this: Traceback (most recent call last): File "/home/chris/bin/upload.py", line 318, in send_request(tmpzip, var1, var2, options.meta, url) File "/srv/the_system/scripts/multipart.py", line 89, in send_request print urllib2.urlopen(request).read() File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib/python2.6/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.6/urllib2.py", line 435, in error return self._call_chain(*args) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR Its very hard to pinpoint what exactly went wrong with just a big "ERROR 500" message... Does anyone have any tips on how to get the full fancy traceback when interfacing with a django app in this way? Here is a good post about debugging django http://simonwillison.net/2008/May/22/debugging/ regards -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to debug restful django apps?
how on earth is django-toolbar going to help me at all here? Did you even read any of my post? On Jul 27, 7:15 am, lzzzing wrote: > Try Django debug toolbar. > > On Jul 27, 5:06 pm, ff wrote: > > > I have a python script that creates and then uploads a file to a > > django app. Sometimes the django app will error out and my script will > > just return this: > > > Traceback (most recent call last): > > File "/home/chris/bin/upload.py", line 318, in > > send_request(tmpzip, var1, var2, options.meta, url) > > File "/srv/the_system/scripts/multipart.py", line 89, in > > send_request > > print urllib2.urlopen(request).read() > > File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen > > return _opener.open(url, data, timeout) > > File "/usr/lib/python2.6/urllib2.py", line 397, in open > > response = meth(req, response) > > File "/usr/lib/python2.6/urllib2.py", line 510, in http_response > > 'http', request, response, code, msg, hdrs) > > File "/usr/lib/python2.6/urllib2.py", line 435, in error > > return self._call_chain(*args) > > File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > > result = func(*args) > > File "/usr/lib/python2.6/urllib2.py", line 518, in > > http_error_default > > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > > urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR > > > Its very hard to pinpoint what exactly went wrong with just a big > > "ERROR 500" message... > > > Does anyone have any tips on how to get the full fancy traceback when > > interfacing with a django app in this way? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Best way to present N items in table row for list
Hello. I have a list that i want to present in a table. Each row should have 5 items. For now i create the function that returns me new grouped list, that i use later in a template. def groupListByRow(list): cnt=0 rows=[] while cnthttp://groups.google.com/group/django-users?hl=en.
Re: "TypeError iteration over non-sequence" after deploying
There's your error. The value of model_or_iterable is not iterable. Perhaps it's a model (based on your naming convention). Try logging the value of model_or_iterable right before that line to see what it contains. Once you've done that, figure out why it contains that instead of something that's iterable. Once you've done that, figure out whether it should never contain that value or whether the value is correct but you should be treating it differently (do something other than trying to put it in a 'for' loop). Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help:How to post data to the admin form by urllib2 ?
Hi: I build a website and want to login the admin form by python code. I have disabled the CSRF in my project and use urllib2 to post data. here are my codes: import urllib import urllib2 import cookielib cj = cookielib.CookieJar() url_login ='http://127.0.0.1:8000/admin/' body = {'csrfmiddlewaretoken':'f85a33be11bd85108a1030fcce96a5ea','username':'root','password':'mypass','this_is_the_login_form':'1'} opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders = [('User-agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')] urllib2.install_opener(opener) req=urllib2.Request(url_login,urllib.urlencode(body)) u=urllib2.urlopen(req) print u.read() print urllib2.urlopen("http://127.0.0.1:8000/admin/sites/ site/").read() but the codes don't seem to work,here is some part of the response --- Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again. Username: Password: Could anyone give some suggestion? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: "TypeError iteration over non-sequence" after deploying
some more details: Exception Type: TypeError Exception Value:iteration over non-sequence Exception Location: ../projects/django/contrib/admin/sites.py in register, line 76 and /django/contrib/admin/sites.py: 74if isinstance(model_or_iterable, ModelBase): 75model_or_iterable = [model_or_iterable] 76for model in model_or_iterable: 77 if model in self._registry: 78raise AlreadyRegistered('The model %s is already registered' % model.__name__) thanks. _y -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DateTimeField Validation Error
Doah! Thanks. On Jul 27, 2:04 am, Daniel Roseman wrote: > On Jul 27, 6:34 am, strayhand wrote: > > > I don't get why I'm getting a validation error with my code. I thought > > that all of the built in fields are referenced inside of "from > > django.db import models". Thanks for any help that you may offer. > > > > > status = models.CharField(max_length=7, choices=STATUS_OPTIONS) > > submit_date = DateTimeField(auto_now_add=True) > > change_date = DateTimeField(auto_now=True) > > They are, but you're not referring to it there. Everywhere else, you > use models.Field - but for some reason on these two > DateTimeFields you've missed off the 'models.' reference. > -- > 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
"TypeError iteration over non-sequence" after deploying
Hello sorry for the n00b post... I just updated my project on my host (OVH), got it running with cgi but I have this error on every page I try to load: TypeError at [whatever] iteration over non-sequence I guess this might be a url problem but I'm pretty new to django/python so I have no clue of where to look... my files architecture is: /projects/blog # my django project /projects/django /www/.htaccess /www/django.cgi here are some infos: # .htaccess -- RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ django.cgi/$1 [L] # EOF -- # django.cgi -- #!/usr/bin/env python # encoding: utf-8 import os, sys sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'django')) sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'projects')) import django.core.handlers.wsgi def run_with_cgi(application): environ = dict(os.environ.items()) environ['wsgi.input']= sys.stdin environ['wsgi.errors'] = sys.stderr environ['wsgi.version'] = (1,0) environ['wsgi.multithread'] = False environ['wsgi.multiprocess'] = True environ['wsgi.run_once'] = True if environ.get('HTTPS','off') in ('on','1'): environ['wsgi.url_scheme'] = 'https' else: environ['wsgi.url_scheme'] = 'http' headers_set = [] headers_sent = [] def write(data): if not headers_set: raise AssertionError("write() before start_response()") elif not headers_sent: # Before the first output, send the stored headers status, response_headers = headers_sent[:] = headers_set sys.stdout.write('Status: %s\r\n' % status) for header in response_headers: sys.stdout.write('%s: %s\r\n' % header) sys.stdout.write('\r\n') sys.stdout.write(data) sys.stdout.flush() def start_response(status,response_headers,exc_info=None): if exc_info: try: if headers_sent: # Re-raise original exception if headers sent raise exc_info[0], exc_info[1], exc_info[2] finally: exc_info = None # avoid dangling circular ref elif headers_set: raise AssertionError("Headers already set!") headers_set[:] = [status,response_headers] return write result = application(environ, start_response) try: for data in result: if data:# don't send headers until body appears write(data) if not headers_sent: write('') # send headers now if body was empty finally: if hasattr(result,'close'): result.close() # Change this to the directory above your site code. #sys.path.append("/home/mycode") # Change mysite to the name of your site package os.environ['DJANGO_SETTINGS_MODULE'] = 'blog.settings' try: run_with_cgi(django.core.handlers.wsgi.WSGIHandler()) except Exception, inst: print "Content-type: text/html\n\n" print inst # EOF -- # urls.py -- import os def rel(*x): return os.path.join(os.path.abspath(os.path.dirname(__file__)), *x) from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^$', 'blog.posts.views.intro'), (r'^contact/$', 'blog.posts.views.contactview'), (r'^contact/thanks/$', 'blog.posts.views.thanks'), (r'^(?P\w+)/$', 'blog.posts.views.dispatch'), (r'^(?P\w+)/(?P\w+)/$', 'blog.posts.views.sublist'), ) # EOF -- sorry for the long post... any help greatly apreciated ! cheers, _y ps: this project works perfectly locally pps: django rules ! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Case insensitive non ascii chars
On Jul 27, 10:26 am, Robert wrote: > Hi, > > For phrase "POLAŃSKI" I cannot get results when posting "polań" in my > search form. > > I'm using the 1.2.1. Django version on PostgreSQL 8.3 with both > (SQL_ASCII) and UTF8 encoding. In my settings DEFAULT_CHARSET is set > for UTF8. > > After debugging it looks like PostgreSQL can't do the UPPER() > properly. > > Is there any chance I can get that working ? > > Thanks, > Robert I don't know Postgres at all, but generally in a database the thing that determines what characters match and how upper-casing works is the collation, not the character set. Try looking in the PG documentation for that. -- 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Cherokee on ubuntu problem.
Hello, I try to make server which will be able to serve both static and dynamic files. I have installed id from launchpad and watch screen cast but there is problem. I add vserver reinstall and when i type in my browser nickname of the vserwer i see externam www.example.com. I thought that adding 127.0.0.1 www.example.com to /etc/hosts will help but i just get localhost page that tells me cherokee is running:/ Any one can help? Best regards Miles -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
On 27 juil, 14:37, Torsten Bronger wrote: (snip) > Well, it could map them possibly ... granted that there would be no > reason for it. Okay, then I must be more precise: > > If I have a model with an implicit primary key, and values of this > key are used to identify associated files on disk, is this safe? > Safe as far as restoring SQL backups, re-loading fixtures, and south > migrations are concerned? It's safe for reloading fixtures AFAICT (as long as your fixtures include the existing IDs, which is the default if you create them dumpdata IIRC). It should be safe for restoring SQL backups, unless your RDBMS implementation is severely broken !-). WRT/ South, I never used it so far so I just can't tell, so you'd better check this out by reading to source code or asking the authors (or on the project's group or ML). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
Hallöchen! Steve Holden writes: > On 7/27/2010 12:38 PM, Torsten Bronger wrote: >> Hallöchen! >> >> bruno desthuilliers writes: >> >>> On 27 juil, 07:19, Torsten Bronger >>> wrote: >>> Currently, our Django app relies on the stability of various auto ID fields which are implicitly generated by Django/database backend. >>> >>> [...] From a practical POV, starting from a mint empty DB and >>> inserting records in the same order without any other client app >>> accessing to the DB, you should probably get the same IDs, but >>> there's absolutely no garantee. >> >> At least, they are explicitly mentioned in a "manage.py dumpdata" >> fixture, and probably in a SQL dump, too. But the DB may ignore >> autofields when loading that data, right? > > It couldn't do that without ruining the relationships, could it? A > dump includes the numerical values for the foreign keys, so the > related primary keys have to stay the same to maintain relational > integrity. Well, it could map them possibly ... granted that there would be no reason for it. Okay, then I must be more precise: If I have a model with an implicit primary key, and values of this key are used to identify associated files on disk, is this safe? Safe as far as restoring SQL backups, re-loading fixtures, and south migrations are concerned? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de or http://bronger-jmp.appspot.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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
On 27 juil, 13:38, Torsten Bronger wrote: > Hall chen! > > bruno desthuilliers writes: > > On 27 juil, 07:19, Torsten Bronger > > wrote: > > >> Currently, our Django app relies on the stability of various auto > >> ID fields which are implicitly generated by Django/database > >> backend. > > > [...] From a practical POV, starting from a mint empty DB and > > inserting records in the same order without any other client app > > accessing to the DB, you should probably get the same IDs, but > > there's absolutely no garantee. > > At least, they are explicitly mentioned in a "manage.py dumpdata" > fixture, and probably in a SQL dump, too. But the DB may ignore > autofields when loading that data, right? Still a SQL DB question, but anyway: auto ID fields (at the DB level) are only autogenerated when not explicitely provided during an insert. Else - as Steve mentionned - you couldn't dump a db and restore it !-) Sorry to have forgotten about this when fisrt answering your question. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
On 7/27/2010 12:38 PM, Torsten Bronger wrote: > Hallöchen! > > bruno desthuilliers writes: > >> On 27 juil, 07:19, Torsten Bronger >> wrote: >> >>> Currently, our Django app relies on the stability of various auto >>> ID fields which are implicitly generated by Django/database >>> backend. >> >> [...] From a practical POV, starting from a mint empty DB and >> inserting records in the same order without any other client app >> accessing to the DB, you should probably get the same IDs, but >> there's absolutely no garantee. > > At least, they are explicitly mentioned in a "manage.py dumpdata" > fixture, and probably in a SQL dump, too. But the DB may ignore > autofields when loading that data, right? > It couldn't do that without ruining the relationships, could it? A dump includes the numerical values for the foreign keys, so the related primary keys have to stay the same to maintain relational integrity. regards Steve -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Override QuerySet.none()
On 27 juil, 10:37, gs794 wrote: > Thanks for the reply. > > I previously had a look at how QuerySet.none (in > Django.db.models.query) was implemented, and that didn 't give me any > clues - hence the post. So I worked it out by looking at > http://seanmonstar.com/post/708862164/extending-django-models-manager... > which explains how QuerySet and manager methods are called through the > QuerySetManager. Did you actually read the source code for Manager.none() in /django/db/ manager.py ? I bet not, else you would already have solved your problem !-) > __getattr__ will be called prior to throwing an AttributeError to try > an find a manager method that isn't already implemented by the manager > **or any of its base classes**. That is, I think it's pulling none > from the base class implementation. Don't think, make sure !-) Now the mere fact I mentionned the implementation of *Manager.none* (nont "Queryset.None") is an answer in itself. FWIW, you could have just logged calls to your manager's __getattr__ method, so you would have noticed that it didn't get called for "none". > This might not be the most elegant solution. I'll look into the > Manager implementation as you suggested. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
Hallöchen! bruno desthuilliers writes: > On 27 juil, 07:19, Torsten Bronger > wrote: > >> Currently, our Django app relies on the stability of various auto >> ID fields which are implicitly generated by Django/database >> backend. > > [...] From a practical POV, starting from a mint empty DB and > inserting records in the same order without any other client app > accessing to the DB, you should probably get the same IDs, but > there's absolutely no garantee. At least, they are explicitly mentioned in a "manage.py dumpdata" fixture, and probably in a SQL dump, too. But the DB may ignore autofields when loading that data, right? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: torsten.bron...@jabber.rwth-aachen.de or http://bronger-jmp.appspot.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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: single point of entry to a webpage
On 07/27/10 03:08, bruno desthuilliers wrote: A django *project* is composed of * one or more apps. * templates * static resources (css, images etc) ...and one or more "utils.py" files... :-) (tips his hat in the direction of JKM and makes a hasty exit...) -tkc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form validation
Send your model and form codes, than it will be easier to see what is wrong. On Tue, Jul 27, 2010 at 4:45 AM, S.Selvam wrote: > Hi all, > I have two model fields (text and file ) and i want either one of the field > to be filled out. > > I set null=True,blank=True for both fields in model. > > Still the form validation requires both fields. > > In form i tried to have required=False attribute, which makes it impossible > to upload file(via HTTP Post from a applet ) > > > -- > Regards, > S.Selvam > > " I am because we are " > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to debug restful django apps?
Try Django debug toolbar. On Jul 27, 5:06 pm, ff wrote: > I have a python script that creates and then uploads a file to a > django app. Sometimes the django app will error out and my script will > just return this: > > Traceback (most recent call last): > File "/home/chris/bin/upload.py", line 318, in > send_request(tmpzip, var1, var2, options.meta, url) > File "/srv/the_system/scripts/multipart.py", line 89, in > send_request > print urllib2.urlopen(request).read() > File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) > File "/usr/lib/python2.6/urllib2.py", line 397, in open > response = meth(req, response) > File "/usr/lib/python2.6/urllib2.py", line 510, in http_response > 'http', request, response, code, msg, hdrs) > File "/usr/lib/python2.6/urllib2.py", line 435, in error > return self._call_chain(*args) > File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > result = func(*args) > File "/usr/lib/python2.6/urllib2.py", line 518, in > http_error_default > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR > > Its very hard to pinpoint what exactly went wrong with just a big > "ERROR 500" message... > > Does anyone have any tips on how to get the full fancy traceback when > interfacing with a django app in this way? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error 500 & 404 / date time isnot defined
tanx daniel . On Tue, Jul 27, 2010 at 2:37 PM, Daniel Roseman wrote: > On Jul 27, 10:13 am, "yalda.nasirian" > wrote: > > hi ,please help me , i realy dont know what can i do for this error i > > cant see my web page . > > another question : i have datetime error (i import date time in shell > > but this error exist ) > > tanx > > please help ! error > > Page not found > > > > We're sorry, but the requested page could not be found. > > [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 > > > > > my models : > > from django.db import models > > > > class Poll(models.Model): > > question = models.CharField(max_length=200) > > pub_date = models.DateTimeField('date published') > > def was_published_today(self): > > return self.pub_date.date() == datetime.date.today() > > It would be easier if you enabled DEBUG and included the traceback, > but presumably this is the problem. You haven't imported datetime in > your models.py. > -- > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error 500 & 404 / date time isnot defined
thank you so much hector but still i have error ! Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 1. ^polls/$ 2. ^polls/(?P\d+)/$ 3. ^polls/(?P\d+)/results/$ 4. ^polls/(?P\d+)/vote/$ The current URL, admin/, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. On Tue, Jul 27, 2010 at 2:37 PM, Daniel Roseman wrote: > On Jul 27, 10:13 am, "yalda.nasirian" > wrote: > > hi ,please help me , i realy dont know what can i do for this error i > > cant see my web page . > > another question : i have datetime error (i import date time in shell > > but this error exist ) > > tanx > > please help ! error > > Page not found > > > > We're sorry, but the requested page could not be found. > > [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 > > > > > my models : > > from django.db import models > > > > class Poll(models.Model): > > question = models.CharField(max_length=200) > > pub_date = models.DateTimeField('date published') > > def was_published_today(self): > > return self.pub_date.date() == datetime.date.today() > > It would be easier if you enabled DEBUG and included the traceback, > but presumably this is the problem. You haven't imported datetime in > your models.py. > -- > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: MySQL error -1
On di, 2010-07-27 at 00:14 -0700, shacker wrote: > One of my Django sites has been throwing occasional 500 errors, I > believe related to mysql: > > OperationalError: (1030, 'Got error -1 from storage engine') > > I'm never able to catch it in the act - I just see the 500 email > reports. This is not connected to any particular page - it seems to > happen to random pages across the site. The site is not busy at all > (it does a fraction of the mysql traffic of other sites on the same > server). The server itself is not overloaded. > > I'm not sure where to begin with this one. Anyone seen similar? Start with checking/repairing the table that causes this error to be thrown. -- Dennis K. They've gone to plaid! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error 500 & 404 / date time isnot defined
On Jul 27, 10:13 am, "yalda.nasirian" wrote: > hi ,please help me , i realy dont know what can i do for this error i > cant see my web page . > another question : i have datetime error (i import date time in shell > but this error exist ) > tanx > please help ! error > Page not found > > We're sorry, but the requested page could not be found. > [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 > > my models : > from django.db import models > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() It would be easier if you enabled DEBUG and included the traceback, but presumably this is the problem. You haven't imported datetime in your models.py. -- 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error 500 & 404 / date time isnot defined
You should first of all set DEBUG and TEMPLATE_DEBUG to True in your settings.py, so you can have a traceback of what is happening. If you still don't have a clue, post the traceback. H. Hector Garcia - Web developer, musician http://nomadblue.com/ On Tue, Jul 27, 2010 at 11:13 AM, yalda.nasirian wrote: > hi ,please help me , i realy dont know what can i do for this error i > cant see my web page . > another question : i have datetime error (i import date time in shell > but this error exist ) > tanx > please help ! error > Page not found > > We're sorry, but the requested page could not be found. > [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 > > my setting.py : > > DEBUG = False > TEMPLATE_DEBUG = False > SEND_BROKEN_LINK_EMAILS = False > > DATABASES = { > 'default': { > 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', > 'postgresql', 'mysql', 'sqlite3' or 'oracle'. > 'NAME': 'db.dev', # Or path to database > file if using sqlite3. > 'USER': '', # Not used with sqlite3. > 'PASSWORD': '', # Not used with sqlite3. > 'HOST': '', # Set to empty string for > localhost. Not used with sqlite3. > 'PORT': '', # Set to empty string for > default. Not used with sqlite3. > } > } > TIME_ZONE = 'America/Chicago' > > SITE_ID = 1 > > USE_I18N = True > > USE_L10N = True > > MEDIA_ROOT = '' > > MEDIA_URL = '' > > ADMIN_MEDIA_PREFIX = '/media/' > > TEMPLATE_LOADERS = ( > 'django.template.loaders.filesystem.Loader', > 'django.template.loaders.app_directories.Loader', > # 'django.template.loaders.eggs.Loader', > ) > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > ) > > ROOT_URLCONF = 'mysite.urls' > > TEMPLATE_DIRS = ( > '/home/yalda/Desktop/mytemplates' > ) > > INSTALLED_APPS = ( > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.admin', > 'samir', > ) > my urls : > from django.conf.urls.defaults import * > from django.contrib import admin > admin.autodiscover() > handler404 = 'django.views.defaults.page_not_found' > handler500 = 'django.views.defaults.server_error' > urlpatterns = patterns('mysite.samir.views', > (r'^polls/$', 'index'), > (r'^polls/(?P\d+)/$', 'detail'), > (r'^polls/(?P\d+)/results/$', 'results'), > (r'^polls/(?P\d+)/vote/$', 'vote'), > ) > my models : > from django.db import models > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField() > def __unicode__(self): > return self.choice > > my view : > > from django.shortcuts import render_to_response, get_object_or_404 > from mysite.samir.models import Poll > > def index(request): > latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5] > return render_to_response('polls/index.html', {'latest_poll_list': > latest_poll_list}) > > def detail(request, poll_id): > p = get_object_or_404(Poll, pk=poll_id) > return render_to_response('polls/detail.html', {'poll': p}) > > def results(request, poll_id): > return HttpResponse("You're looking at the results of poll %s." % > poll_id) > > def vote(request, poll_id): > return HttpResponse("You're voting on poll %s." % poll_id) > > my admin.py : > from django.contrib import admin > from mysite.samir.models import Poll > from mysite.samir.models import Choice > > > class ChoiceInline(admin.StackedInline): > model = Choice > extra = 3 > > class PollAdmin(admin.ModelAdmin): > fieldsets = [ > (None, {'fields': ['question']}), > ('Date information', {'fields': ['pub_date'], 'classes': > ['collapse']}), > ] > inlines = [ChoiceInline] > list_display = ('question', 'pub_date') > list_filter = ['pub_date'] > search_fields = ['question'] > date_hierarchy = 'pub_date' > > admin.site.register(Poll, PollAdmin) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "D
Re: Stability of auto IDs
On 7/27/2010 8:40 AM, bruno desthuilliers wrote: > On 27 juil, 07:19, Torsten Bronger > wrote: >> Hall chen! >> >> Currently, our Django app relies on the stability of various auto ID >> fields which are implicitly generated by Django/database backend. > > auto ID are a RDBMS feature, Django is not involved. They are usually > just sequential long ints. And as the name imply, they are meaningless > and automatically generated, so whatever language / techno you use for > the frontend, you just can't rely on auto ID. From a practical POV, > starting from a mint empty DB and inserting records in the same order > without any other client app accessing to the DB, you should probably > get the same IDs, but there's absolutely no garantee. > Quite right. The major purpose of an auto ID is to be guaranteed unique. We mostly look things up by primary key across relationships: to select a user or a product then selection on the other attributes leads to a much more satisfactory user experience. POOR: Change the price of widget #345,231 to $3.14 GOOD: Change the price of the "2 cm left-handed tap widget" to $3.14 regards Steve -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Case insensitive non ascii chars
Hi, For phrase "POLAŃSKI" I cannot get results when posting "polań" in my search form. I'm using the 1.2.1. Django version on PostgreSQL 8.3 with both (SQL_ASCII) and UTF8 encoding. In my settings DEFAULT_CHARSET is set for UTF8. After debugging it looks like PostgreSQL can't do the UPPER() properly. Is there any chance I can get that working ? Thanks, Robert -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
error 500 & 404 / date time isnot defined
hi ,please help me , i realy dont know what can i do for this error i cant see my web page . another question : i have datetime error (i import date time in shell but this error exist ) tanx please help ! error Page not found We're sorry, but the requested page could not be found. [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 my setting.py : DEBUG = False TEMPLATE_DEBUG = False SEND_BROKEN_LINK_EMAILS = False DATABASES = { 'default': { 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'db.dev', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } TIME_ZONE = 'America/Chicago' SITE_ID = 1 USE_I18N = True USE_L10N = True MEDIA_ROOT = '' MEDIA_URL = '' ADMIN_MEDIA_PREFIX = '/media/' TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) ROOT_URLCONF = 'mysite.urls' TEMPLATE_DIRS = ( '/home/yalda/Desktop/mytemplates' ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'samir', ) my urls : from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() handler404 = 'django.views.defaults.page_not_found' handler500 = 'django.views.defaults.server_error' urlpatterns = patterns('mysite.samir.views', (r'^polls/$', 'index'), (r'^polls/(?P\d+)/$', 'detail'), (r'^polls/(?P\d+)/results/$', 'results'), (r'^polls/(?P\d+)/vote/$', 'vote'), ) my models : from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def was_published_today(self): return self.pub_date.date() == datetime.date.today() class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice my view : from django.shortcuts import render_to_response, get_object_or_404 from mysite.samir.models import Poll def index(request): latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5] return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list}) def detail(request, poll_id): p = get_object_or_404(Poll, pk=poll_id) return render_to_response('polls/detail.html', {'poll': p}) def results(request, poll_id): return HttpResponse("You're looking at the results of poll %s." % poll_id) def vote(request, poll_id): return HttpResponse("You're voting on poll %s." % poll_id) my admin.py : from django.contrib import admin from mysite.samir.models import Poll from mysite.samir.models import Choice class ChoiceInline(admin.StackedInline): model = Choice extra = 3 class PollAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields': ['question']}), ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}), ] inlines = [ChoiceInline] list_display = ('question', 'pub_date') list_filter = ['pub_date'] search_fields = ['question'] date_hierarchy = 'pub_date' admin.site.register(Poll, PollAdmin) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to debug restful django apps?
I have a python script that creates and then uploads a file to a django app. Sometimes the django app will error out and my script will just return this: Traceback (most recent call last): File "/home/chris/bin/upload.py", line 318, in send_request(tmpzip, var1, var2, options.meta, url) File "/srv/the_system/scripts/multipart.py", line 89, in send_request print urllib2.urlopen(request).read() File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib/python2.6/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.6/urllib2.py", line 435, in error return self._call_chain(*args) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR Its very hard to pinpoint what exactly went wrong with just a big "ERROR 500" message... Does anyone have any tips on how to get the full fancy traceback when interfacing with a django app in this way? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DateTimeField Validation Error
On Jul 27, 6:34 am, strayhand wrote: > I don't get why I'm getting a validation error with my code. I thought > that all of the built in fields are referenced inside of "from > django.db import models". Thanks for any help that you may offer. > > > status = models.CharField(max_length=7, choices=STATUS_OPTIONS) > submit_date = DateTimeField(auto_now_add=True) > change_date = DateTimeField(auto_now=True) They are, but you're not referring to it there. Everywhere else, you use models.Field - but for some reason on these two DateTimeFields you've missed off the 'models.' reference. -- 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: What goes in 500.html?
hi , please help me , i realy dont know what can i do for this error i cant see my web page . another question : i have datetime error (i import date time in shell but this error exist ) tanx please help ! error Page not found We're sorry, but the requested page could not be found. [27/Jul/2010 03:48:34] "GET / HTTP/1.1" 404 1612 my setting.py : DEBUG = False TEMPLATE_DEBUG = False SEND_BROKEN_LINK_EMAILS = False DATABASES = { 'default': { 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'db.dev', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } TIME_ZONE = 'America/Chicago' SITE_ID = 1 USE_I18N = True USE_L10N = True MEDIA_ROOT = '' MEDIA_URL = '' ADMIN_MEDIA_PREFIX = '/media/' TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) ROOT_URLCONF = 'mysite.urls' TEMPLATE_DIRS = ( '/home/yalda/Desktop/mytemplates' ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'samir', ) my urls : from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() handler404 = 'django.views.defaults.page_not_found' handler500 = 'django.views.defaults.server_error' urlpatterns = patterns('mysite.samir.views', (r'^polls/$', 'index'), (r'^polls/(?P\d+)/$', 'detail'), (r'^polls/(?P\d+)/results/$', 'results'), (r'^polls/(?P\d+)/vote/$', 'vote'), ) my models : from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def was_published_today(self): return self.pub_date.date() == datetime.date.today() class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice my view : from django.shortcuts import render_to_response, get_object_or_404 from mysite.samir.models import Poll def index(request): latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5] return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list}) def detail(request, poll_id): p = get_object_or_404(Poll, pk=poll_id) return render_to_response('polls/detail.html', {'poll': p}) def results(request, poll_id): return HttpResponse("You're looking at the results of poll %s." % poll_id) def vote(request, poll_id): return HttpResponse("You're voting on poll %s." % poll_id) my admin.py : from django.contrib import admin from mysite.samir.models import Poll from mysite.samir.models import Choice class ChoiceInline(admin.StackedInline): model = Choice extra = 3 class PollAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields': ['question']}), ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}), ] inlines = [ChoiceInline] list_display = ('question', 'pub_date') list_filter = ['pub_date'] search_fields = ['question'] date_hierarchy = 'pub_date' admin.site.register(Poll, PollAdmin) On Mon, Jul 26, 2010 at 9:45 PM, Michael Hipp wrote: > Thanks for a helpful and complete answer, David. > Michael > > > On 7/26/2010 6:24 AM, David De La Harpe Golden wrote: > >> On 24/07/10 20:14, Michael Hipp wrote: >> >>> What should go in a proper 500.html page? >>> >> >> As little as you can get away with; it's for when your server has >> screwed up. >> >> However, you probably want to make it distinguishable from the >> apache-level 500 page, in a manner you can ask a user reporting a >> failure a single simple question to tell the difference. At one stage I >> had the bright idea of making them look the exact same for appearances' >> sake. That was dumb. >> >> Is some content fed to it that >>> should be displayed? >>> >>> Not really, it's intended to be pretty static, something that django has >> a hope of outputting even in a royally messed up config. >> >> Similarly for 404.html? >>> >>> >> That's a bit different, put pictures of kittens o
Re: Override QuerySet.none()
Thanks for the reply. I previously had a look at how QuerySet.none (in Django.db.models.query) was implemented, and that didn 't give me any clues - hence the post. So I worked it out by looking at http://seanmonstar.com/post/708862164/extending-django-models-managers-and-querysets which explains how QuerySet and manager methods are called through the QuerySetManager. __getattr__ will be called prior to throwing an AttributeError to try an find a manager method that isn't already implemented by the manager **or any of its base classes**. That is, I think it's pulling none from the base class implementation. So I guess a solution could be to create a class where overrides are implemented, and let your QuerySetManager and custom QuerySet implementations inherit from it - to save having to implement your methods in the manager and your custom QuerySet. This might not be the most elegant solution. I'll look into the Manager implementation as you suggested. Thanks. On Jul 27, 5:50 pm, bruno desthuilliers wrote: > On 27 juil, 06:27, gs794 wrote: > > > > > Hi all, > > > I'm having trouble overriding QuerySet.none() (code below)... Works > > if I rename the method to almost anything but "none". > > > class QuerySetManager(models.Manager): > > def get_query_set(self): > > return self.model.QuerySet(self.model) > > def __getattr__(self, name): > > return getattr(self.get_query_set(), name) > > > class NewNoneQuerySet(models.query.QuerySet): > > def none(self): > > print 'NewNone\n\n\n\n' > > return self.filter(pk__in=[]) > > > class TestNone(models.Model): > > name = models.CharField(max_length=20) > > objects = QuerySetManager() > > class QuerySet(NewNoneQuerySet): > > pass > > > TestNone.objects.none() > > > No output of 'NewNone\n\n\n\n'... Using the inherited method in other > > tests... Is there something special about the none method? > > Django is open-source, so you can read the source and find out by > yourself why your code doesn't work as expected (I just did, and took > me about 2 minutes). > > FWIW, you want to have a look at how Manager.none is implemented (in / > django/db/manager.py) > > HTH. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: single point of entry to a webpage
On 26 juil, 18:00, owidjaya wrote: > how do i write custom template tag that is available to all my apps. > not tied to a particular app? You don't have to make your templatetags "available to all your apps" - this would make each app dependants on the others, which is exactly what you don't want (unless you like spaghetti code and maintanance nightmares of course). A django *project* is composed of * one or more apps. * templates * static resources (css, images etc) Most of these apps are designed to provide a specific (and if possible reusable) feature set (blog, news, rss, auth, regitration, contactfrom, whatever). Note that an app doesn't have to provide models - you can have an app that only provides templatetags and filters, or context processors, or middleware, etc... These apps ares usually designed to be as decoupled as possible so you can reuse them from project to project. This of course means that you'll have to do the "integration" works to make these apps work together. This integration work starts in the templates - even if a pluggable app provides it's own, these are usually only defaults / example / starting points. But templates are, well, templates (that is, only presentation logic), and you'll usually need more than this (override pluggable apps views, write your own specific templateetags and filters, whatever...). The obvious solution is to write a project- specific app that'll host all the project-specific code. In your case, put your custom templatetags there, and call them from *your* templates (you do use project-specific templates, don't you ? http://docs.djangoproject.com/en/1.2/ref/templates/api/#the-template-dirs-setting) HTH -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Override QuerySet.none()
On 27 juil, 06:27, gs794 wrote: > Hi all, > > I'm having trouble overriding QuerySet.none() (code below)... Works > if I rename the method to almost anything but "none". > > class QuerySetManager(models.Manager): > def get_query_set(self): > return self.model.QuerySet(self.model) > def __getattr__(self, name): > return getattr(self.get_query_set(), name) > > class NewNoneQuerySet(models.query.QuerySet): > def none(self): > print 'NewNone\n\n\n\n' > return self.filter(pk__in=[]) > > class TestNone(models.Model): > name = models.CharField(max_length=20) > objects = QuerySetManager() > class QuerySet(NewNoneQuerySet): > pass > > TestNone.objects.none() > > No output of 'NewNone\n\n\n\n'... Using the inherited method in other > tests... Is there something special about the none method? Django is open-source, so you can read the source and find out by yourself why your code doesn't work as expected (I just did, and took me about 2 minutes). FWIW, you want to have a look at how Manager.none is implemented (in / django/db/manager.py) HTH. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Form validation
Hi all, I have two model fields (text and file ) and i want either one of the field to be filled out. I set null=True,blank=True for both fields in model. Still the form validation requires both fields. In form i tried to have required=False attribute, which makes it impossible to upload file(via HTTP Post from a applet ) -- Regards, S.Selvam " I am because we are " -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Stability of auto IDs
On 27 juil, 07:19, Torsten Bronger wrote: > Hall chen! > > Currently, our Django app relies on the stability of various auto ID > fields which are implicitly generated by Django/database backend. auto ID are a RDBMS feature, Django is not involved. They are usually just sequential long ints. And as the name imply, they are meaningless and automatically generated, so whatever language / techno you use for the frontend, you just can't rely on auto ID. From a practical POV, starting from a mint empty DB and inserting records in the same order without any other client app accessing to the DB, you should probably get the same IDs, but there's absolutely no garantee. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
MySQL error -1
One of my Django sites has been throwing occasional 500 errors, I believe related to mysql: OperationalError: (1030, 'Got error -1 from storage engine') I'm never able to catch it in the act - I just see the 500 email reports. This is not connected to any particular page - it seems to happen to random pages across the site. The site is not busy at all (it does a fraction of the mysql traffic of other sites on the same server). The server itself is not overloaded. I'm not sure where to begin with this one. Anyone seen similar? Thanks, Scot -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
checking sessions from another domain
I have a few domains currently pointed to the same website. Im only using one of my domains to store sessions. When I try to access a session when someone types in a domain other then the one that I am using sessions for, I can't because the domain name isnt the same (obviously). Is there any way I can access the sessions through some sort of function without having to do a redirect to the domain that i use to store the sessions. I know I could store sessions for all of the individual domains but that wont work with my experiment. Is there any way to access a session stored for another domain, keeping in mind they are all pointed to the same website. thanks for any advice, Tony -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: errors serving text files using templates and static files
I suggest you install firebug and check the differences in HTTP headers/html content with it. It's weird :) On ma, 2010-07-26 at 18:18 -0400, Josh Boon wrote: > Oops, swapped it and it still didn't work. Right now I have it > writing to a file and then redirecting and having Apache serve the > file which works. My code looks like this: > > def bootmenu(request, username): > user = User.objects.get(username=username) > user_bootimage_list = Bootimage.objects.filter(person=user)[:5] > t = loader.get_template('netboot/menu.cfg') > c = Context({ > 'user_bootimage_list': user_bootimage_list, > }) > f = > open('/home/jboon/Lesson1/templates/netboot/static/dynamicmenu.cfg', > 'w') > menu_file = File(f) > menu_file.write(t.render(c)) > return HttpResponseRedirect('/netboot/dynamicmenu.cfg') > > It works but it's a strange workaround. Serving it directly causes > gPXE to break. Any thoughts? > > On Mon, Jul 26, 2010 at 18:04, Dennis Kaarsemaker > wrote: > On ma, 2010-07-26 at 09:21 -0700, Josh wrote: > > return HttpResponse(menu, mimetype="plain/text") > > > > What makes Django's text serving different? What can I do > to > > troubleshoot this issue further? Am I just missing > something about > > how text files are served? > > > The correct mimetype is text/plain. I don't know how strict > gpxe checks > that. > -- > Dennis K. > > They've gone to plaid! > > > -- > You received this message because you are subscribed to the > Google Groups "Django users" group. > To post to this group, send email to > django-us...@googlegroups.com. > To unsubscribe from this group, send email to django-users > +unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > > > -- > You received this message because you are subscribed to the Google > Groups "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to django-users > +unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- Dennis K. They've gone to plaid! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.