Django Performance Discoveries Part 1
Hey Everybody, I've been using django for almost a year now and I've been spending some time recently trying to optimize the slicehost VPS(s) that I use to run several django sites I've developed. I wanted to share my findings with the larger group in hopes that my oversights can be pointed out and whatever 'findings' I've made can be useful to folks who are just starting off. I've been developing a blow-by-blow of my slicehost setup - I gained a lot from the "dreamier django dream server" blog post a while back. But to make things brief for the first post, I'll just summarize my setup here: 512 meg slicehost slice w/ Hardy Heron memcached with cmemcached bindings doin' its cache thang with 256 megs of RAM nginx on port 80 serving static files apache mpm worker on 8080 w / mod_wsgi serving dynamic content postgres 8.3 w/ geo libraries django_gis (thanks justin!) my application I'll keep it to 3 sections of musings for this post: triage troubles memcached musings context-processor conundrum triage troubles At pycon someone asked Jacob KM what he used to performance test his websites and he said "siege". A quick google search turned it up (http://www.joedog.org/JoeDog/Siege). I seem to recall Jacob mentioning that this was his preferred method because it was more of a "real life" test than perhaps benchmarking tools that would profile the code. Compiling and using siege was a snap. My test was of a site I wrote that does a lot of database queries to draw up any given page (mostly because of a complex sidebar) when I turned it on, real easy like, to a dev server, the server crumbled with only 10 simultaneous users and anything higher than 5 clicks per user. Observation #1: Make sure your debug settings are turned off. After I turned debug settings off, performance maybe doubled, but still was nothing that could handle even moderate traffic gracefully. 20 simultaneous users on 3 clicks per user were getting up into the 20+ second wait for a response range. Basically awful. Not shocked, because I knew that my db querying was horrendously inefficient. This was OK, because I had memcached up my sleeve. An observation that I made on the first test that was constant throughout all subsequent tests, was that initial queries were the fastest and subsequent queries became progressively slower and slower. I'm assuming this is because of something like queries queuing up at that db, or running through memory, but I don't have enough context or knowledge of the whole stack to isolate the problem, more on this later. memcached musings I went on and compiled cmemcache because the consensus opnion on the internets is that its fastest. I'll just assume that's so because it has 'c' in the name and if you read it on the internets, it must be true. I put in all the cache settings, put in the Cache middleware and ran siege again, waiting for the glorius results. Blam. Exactly the same. Actually, a little worse. I scratched my head for about 3 hours before I realized that I had mistyped the memcached port number in the settings. After that, much improved. I could do 300 simultaneous visitors doing 3-5 clicks apiece with tolerable performace. 1000 visits doing 1 click each also held up very well, the longest response time being in the 4-6 second range. Without fail, the earliest requests were the shortest wait, many well under a second, the last requests were the longest waits. Also, as I ratcheted up pressure from siege, I was running top on the 'beseiged' server watching the running processes. I notice a ton of postgres processes. This challenged my notion of how memcached worked. I thought that memcached would take the resulting page for a given view and spit it back out if the url was requested again with no database involved. I was still hitting the db _alot_. Observation #2 Is this thing on?: Memcached really does dramatically improve your sites responsiveness under load, if you don't see massive improvement, you haven't gotten memcached configured correctly. context-processor conundrum Then I remembered that I had written a custom context processor that was doing the bulk of the nasty database querying. I reckon that whatever the order of operations was for request / response handling, the result of the context processing was not getting cached. So I wrote 4-5 lines to check / set the cache in my custom context_processors.py and voila, that instantly knocked all queries to the db down to zero. Despite the absense of postgres processes stacking up, the same phenom of early queries fast, subsequent queries slow still applied, at this point I'm not exactly sure what's causing it. It's not that it's surprising, its just that I'd like to understand exactly why its happening. Observation #3: Low level cachin' works well in cases like context_processors, or other expensive non-view functions. OK - I'll stop here for now, I hope this was useful or at least amusing. I'd love to hear
Re: Queryset-refactor branch has been merged into trunk
Mmmm... model inheritance... multiple OneToOne fields mmm Thanks for all your hard work, Malcolm! Beers are owed to you! On Apr 26, 2008, at 8:30 PM, Prairie Dogg wrote: > > Malcolm: Sorry - it's late over here, didn't mean to mis-type your > name. > > File this and previous under: damn-life's-work-with-faint-praise > > > > On Apr 26, 11:29 pm, Prairie Dogg <[EMAIL PROTECTED]> wrote: >> Malcom, >> >> Thanks so much for your tremendous effort and success on this! >> >> You rock! >> >> On Apr 26, 11:04 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> >> wrote: >> >>> I merged queryset-refactor into trunk just now. This was changeset >>> r7477. >> >>> There are still a couple of enhancements to do, but I've decided >>> they're >>> not worth holding up the entire branch for. I can just as easily >>> do them >>> on trunk. >> >>> Thanks to everybody who reported bugs and tested things. Thanks >>> especially to Justin Bronn and Ian Kelly for lots of patches and >>> testing >>> to get the Oracle backend up to scratch on the branch. >> >>> Detailed list of changes is in the branch's wiki page ([1]) and if >>> you're interested in seeing the documentation additions and >>> changes, you >>> can view [2]. >> >>> [1]http://code.djangoproject.com/wiki/QuerysetRefactorBranch >>> [2]http://code.djangoproject.com/changeset?new=django%2Ftrunk >>> %2Fdocs% >>> 407477=django%2Ftrunk%2Fdocs%407411 >> >>> No more bugs should now be reported against the queryset-refactor >>> version. The branch is closed. >> >>> Regards, >>> Malcolm >> >>> -- >>> On the other hand, you have different >>> fingers.http://www.pointy-stick.com/blog/ > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Queryset-refactor branch has been merged into trunk
Malcolm: Sorry - it's late over here, didn't mean to mis-type your name. File this and previous under: damn-life's-work-with-faint-praise On Apr 26, 11:29 pm, Prairie Dogg <[EMAIL PROTECTED]> wrote: > Malcom, > > Thanks so much for your tremendous effort and success on this! > > You rock! > > On Apr 26, 11:04 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > I merged queryset-refactor into trunk just now. This was changeset > > r7477. > > > There are still a couple of enhancements to do, but I've decided they're > > not worth holding up the entire branch for. I can just as easily do them > > on trunk. > > > Thanks to everybody who reported bugs and tested things. Thanks > > especially to Justin Bronn and Ian Kelly for lots of patches and testing > > to get the Oracle backend up to scratch on the branch. > > > Detailed list of changes is in the branch's wiki page ([1]) and if > > you're interested in seeing the documentation additions and changes, you > > can view [2]. > > > [1]http://code.djangoproject.com/wiki/QuerysetRefactorBranch > > [2]http://code.djangoproject.com/changeset?new=django%2Ftrunk%2Fdocs% > > 407477=django%2Ftrunk%2Fdocs%407411 > > > No more bugs should now be reported against the queryset-refactor > > version. The branch is closed. > > > Regards, > > Malcolm > > > -- > > On the other hand, you have different > > fingers.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Queryset-refactor branch has been merged into trunk
Malcom, Thanks so much for your tremendous effort and success on this! You rock! On Apr 26, 11:04 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > I merged queryset-refactor into trunk just now. This was changeset > r7477. > > There are still a couple of enhancements to do, but I've decided they're > not worth holding up the entire branch for. I can just as easily do them > on trunk. > > Thanks to everybody who reported bugs and tested things. Thanks > especially to Justin Bronn and Ian Kelly for lots of patches and testing > to get the Oracle backend up to scratch on the branch. > > Detailed list of changes is in the branch's wiki page ([1]) and if > you're interested in seeing the documentation additions and changes, you > can view [2]. > > [1]http://code.djangoproject.com/wiki/QuerysetRefactorBranch > [2]http://code.djangoproject.com/changeset?new=django%2Ftrunk%2Fdocs% > 407477=django%2Ftrunk%2Fdocs%407411 > > No more bugs should now be reported against the queryset-refactor > version. The branch is closed. > > Regards, > Malcolm > > -- > On the other hand, you have different > fingers.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Disabling autoescaping when calling render_to_string
On Sun, 2008-04-27 at 12:37 +0930, Darryl Ross wrote: > James Bennett wrote: > > On Sat, Apr 26, 2008 at 9:38 PM, Darryl Ross <[EMAIL PROTECTED]> wrote: > >> So my question is, is there an argument which will disable auto-escaping? > >> If not, would there be some merit to adding some functionality that allows > >> this, either as an argument or perhaps to make the auto-escaping only > >> auto-escape if the template filename ends in '.html'? > > > > No, and probably not. One of the key things about Django's > > autoescaping is that, since it applies in the template, you can look > > at the template to find out what's going on. Introducing lots of other > > places where you'd need to look, transforming it from "look at the > > template to see if the autoescape tag or the safe filter are used" to > > "look at the template, then look at this argument, then look at this > > setting, then..." would be a disaster. > > I can see your point, but I disagree for two reasons. > > The first is that to find out what template is being used, you most > likely need to look in the view for the urls file, so having an argument > there is obvious. No, it isn't obvious. Somebody writing a template should know exactly how it is going to be parsed. That person isn't necessarily the person writing the view (code). To keep the designer/developer separation clean, we made auto-escaping controllable via the template. > The second reason is that the auto-escaping was, correct me if I'm > wrong, to help prevent cross-site vulnerabilities caused by browsers > interpreting HTML. There are other uses for the templating besides > generating content for browsers, such as sending emails and generating > other files, like CSV or XML. Which is why the autoescaping template tag exists. It enables you to disable things. You are bringing up points that were hashed out again and again on the developers list leading up to autoescaping being committed. Yes, there are differing opinions. There's no way to reach unanimous consensus here and we picked one, quite usable, method for the implementation. Malcolm -- Always try to be modest and be proud of it! http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Disabling autoescaping when calling render_to_string
James Bennett wrote: On Sat, Apr 26, 2008 at 9:38 PM, Darryl Ross <[EMAIL PROTECTED]> wrote: So my question is, is there an argument which will disable auto-escaping? If not, would there be some merit to adding some functionality that allows this, either as an argument or perhaps to make the auto-escaping only auto-escape if the template filename ends in '.html'? No, and probably not. One of the key things about Django's autoescaping is that, since it applies in the template, you can look at the template to find out what's going on. Introducing lots of other places where you'd need to look, transforming it from "look at the template to see if the autoescape tag or the safe filter are used" to "look at the template, then look at this argument, then look at this setting, then..." would be a disaster. I can see your point, but I disagree for two reasons. The first is that to find out what template is being used, you most likely need to look in the view for the urls file, so having an argument there is obvious. The auto-escaping based on file extension was just something I was throwing out there and I don't think it's a particularly good idea myself. The second reason is that the auto-escaping was, correct me if I'm wrong, to help prevent cross-site vulnerabilities caused by browsers interpreting HTML. There are other uses for the templating besides generating content for browsers, such as sending emails and generating other files, like CSV or XML. Regards Darryl signature.asc Description: OpenPGP digital signature
Queryset-refactor branch has been merged into trunk
I merged queryset-refactor into trunk just now. This was changeset r7477. There are still a couple of enhancements to do, but I've decided they're not worth holding up the entire branch for. I can just as easily do them on trunk. Thanks to everybody who reported bugs and tested things. Thanks especially to Justin Bronn and Ian Kelly for lots of patches and testing to get the Oracle backend up to scratch on the branch. Detailed list of changes is in the branch's wiki page ([1]) and if you're interested in seeing the documentation additions and changes, you can view [2]. [1] http://code.djangoproject.com/wiki/QuerysetRefactorBranch [2] http://code.djangoproject.com/changeset?new=django%2Ftrunk%2Fdocs% 407477=django%2Ftrunk%2Fdocs%407411 No more bugs should now be reported against the queryset-refactor version. The branch is closed. Regards, Malcolm -- On the other hand, you have different fingers. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Disabling autoescaping when calling render_to_string
On Sat, Apr 26, 2008 at 9:38 PM, Darryl Ross <[EMAIL PROTECTED]> wrote: > So my question is, is there an argument which will disable auto-escaping? > If not, would there be some merit to adding some functionality that allows > this, either as an argument or perhaps to make the auto-escaping only > auto-escape if the template filename ends in '.html'? No, and probably not. One of the key things about Django's autoescaping is that, since it applies in the template, you can look at the template to find out what's going on. Introducing lots of other places where you'd need to look, transforming it from "look at the template to see if the autoescape tag or the safe filter are used" to "look at the template, then look at this argument, then look at this setting, then..." would be a disaster. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Disabling autoescaping when calling render_to_string
Hi All, I'm using the templating system to send emails, but the templates are being autoescaped. Now, I know I can use {% autoescape off %} in my template files, but the logic I use to build the email body is similar to: template_name = 'emails/generic.txt' if condition1: template_name = 'emails/template1.txt' elif condition2: template_name = 'emails/template2.txt' elif condition3: template_name = 'emails/template3.txt' body = render_to_string(template_name, context_vars) The reason I'm shying away from using the autoescape tag is that it breaks DRY in my mind, but it also means that there's more places to miss it and it also seems unnecessary as this is for plain text emails. I've been reading through the code in django/template to try and work out how the auto-escaping is done, but I have to admit defeat, I can't follow it through at the moment. So my question is, is there an argument which will disable auto-escaping? If not, would there be some merit to adding some functionality that allows this, either as an argument or perhaps to make the auto-escaping only auto-escape if the template filename ends in '.html'? Regards Darryl signature.asc Description: OpenPGP digital signature
Re: Django voting with jellyrool
*Sorry for confusing,my English is bad also. The problem is django-voting is not provide templatetags to access vote for particular object. Instead it provide templatetags to access only template context variable (Correct me if I'm wrong). See bebow, score_for_object Retrieves the total score for an object and the number of votes it's received, storing them in a context variable which has ``score`` and ``num_votes`` properties. Example usage:: {% score_for_object widget as score %} {{ score.score }} point{{ score.score|pluralize }} after {{ score.num_votes }} vote{{ score.num_votes|pluralize }} In my case, I'm fine if I have something like this {% load generic_content%} {% load voting_tags %} {% get_latest_objects blog.post 10 as latest_post %} So, I can, {% scores_for_objects **latest_post** as scores %} {% for post in latest_post%} {% dict_entry_for_item post from scores as vote %} {{post}} has {{vote.score}}. {% endfor %} For my case, {% for item in latest_item%} ... I cannot use dict_entry_for_item because each item doesn't has vote. {% endfor %} For now, my sulotion is, implement additional templatetag to allow retrival vote of any model . For example, {% get_latest_objects aggregate.item 10 as latest_items %} {% for item in latest_items %} {% ifequal item.content_type.model "post" %} {% score_by_pk blog.post item.object.pk as score%} {# my own template tag#} {{ post }} has {{score.score}} {% endif %} {% endfor %} Umm, it look complicate** and ugly? Regards * 2008/4/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > What exactly is your problem? Is latest_items empty in the template? > > On Apr 26, 2:10 am, chatchai <[EMAIL PROTECTED]> wrote: > > Hi all, > > > > I use a modified version ofhttp://jellyroll.googlecode.com/by adding > > my own models into follow list (jellyrool.models.Item). For example, > > > > Item.objects.follow_model(Post) > > > > After that, I added django-voting (http://django- > > voting.googlecode.com/) to my application list. > > > > The problem is, at the index page. I want to list latest item. If > > latest item is Post and it has Vote as well, I will show post and its > > vote. I also use template_utils (http://django-template- > > utils.googlecode.com/svn/trunk). My code look like this, > > > > {% load generic_content%} > > {% load voting_tags %} > > {% get_latest_objects aggregate.item 10 as latest_items %} > > > > I try to access voting for post in latest_items and cannot find any > > solution. > > > > Any idea is my appreciated. > > > > Thanks > > > > Chatchai > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Template Tags Inside 'ifequals'
On Sat, 2008-04-26 at 11:56 -0700, Szaijan wrote: > I'm trying to create an ifequals tag in a template to check if > request.path equals the URL for a particular view. Either this is not > possible, or I just can't find the right syntax. As I haven't been > able to find an example via Google, does anyone know hoe to do this > correctly? > > {% ifequals request.path url('site.app.view_file.view_fn') %} > code > {% end ifequals %} > > It's the url code I can't seem to get right. More generally, Is there > a way to use a tag value inside a template comparison clause, and if > so, what's the correct syntax? To me, this seems like a very common > task within a template, especially for use in menus and nav bars. You can't do this (use function calls with arguments in templates. It's intentionally designed to prevent programming in templates and your fragment shows exactly why: you've now tightly coupled your template to a single view and file structure. Instead, pass in the URL you're wanting to test as a variable to the template. Then test against the template variable. Regards, Malcolm -- Save the whales. Collect the whole set. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django voting with jellyrool
What exactly is your problem? Is latest_items empty in the template? On Apr 26, 2:10 am, chatchai <[EMAIL PROTECTED]> wrote: > Hi all, > > I use a modified version ofhttp://jellyroll.googlecode.com/by adding > my own models into follow list (jellyrool.models.Item). For example, > > Item.objects.follow_model(Post) > > After that, I added django-voting (http://django- > voting.googlecode.com/) to my application list. > > The problem is, at the index page. I want to list latest item. If > latest item is Post and it has Vote as well, I will show post and its > vote. I also use template_utils (http://django-template- > utils.googlecode.com/svn/trunk). My code look like this, > > {% load generic_content%} > {% load voting_tags %} > {% get_latest_objects aggregate.item 10 as latest_items %} > > I try to access voting for post in latest_items and cannot find any > solution. > > Any idea is my appreciated. > > Thanks > > Chatchai --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can Django have unique user homepage?
And that's just one way, of course. On Apr 26, 5:01 pm, Bret W <[EMAIL PROTECTED]> wrote: > Sure. > > You'd need to create a profile model where this information could be > stored.http://www.djangoproject.com/documentation/authentication/#storing-ad... > > You'd then just create forms for inputing the parameters you wanted to > let users > control.http://www.djangoproject.com/documentation/newforms/#generating-forms... > > After you've allowed users to input preferences in their profile, > you'd just need to get the profile (see Django book), and use the > stored parameters in your template. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can Django have unique user homepage?
Sure. You'd need to create a profile model where this information could be stored. http://www.djangoproject.com/documentation/authentication/#storing-additional-information-about-users You'd then just create forms for inputing the parameters you wanted to let users control. http://www.djangoproject.com/documentation/newforms/#generating-forms-for-models After you've allowed users to input preferences in their profile, you'd just need to get the profile (see Django book), and use the stored parameters in your template. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Login issue
I have a login form on my homepage: Username: Password: The homepage uses template fragment caching, but this block is not cached (although I don't know why it couldn't be). I'm not using CSRF middleware. There are many times when I can enter a username and password, click the "login" button, and get the username/password don't match error. The error page (/accounts/login, using example template from docs) automatically fills in the username and password fields, and I can just hit "login" again and I'm successfully logged in. This means my credentials were posted correctly. What could causing this sporadic failure? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File upload with no database - Fantasy or reality?
On Apr 26, 8:13 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > upload_form = None > upload_result = '' > > if request.method == 'POST': > upload_form = FileUploadForm(request.POST, request.FILES) > if upload_form.is_valid(): > # get file name and contents from request: > file_name = request.FILES['txt_file']['filename'] > file_content=request.FILES['txt_file']['content'] > # save the file. something like: > f=open("C:\\" + file_name, 'w') > f.writelines(file_content) > f.close() > else: > upload_form = FileUploadForm() > > You've got the creation of the blank FileUploadForm nested in the else for > if upload_form.is_valid(). So it appears you do not create a FileUploadForm > when request.method is anything other than POST (unless there is more > relevant code that follows this snippet). It looks like the else that you > have should be un-dented one level, so that a blank FileUploadForm is > generated for display when request.method is, say, GET. > > It's also normal to return an HttpResponseRedirect to a different page when > is_valid() processing completes, which you don't seem to be doing. Finally > nowhere in here do you set upload_result, which seems to be expected by your > template. Your initial code seemed to be using that to display errors, > which is not necessary if you go the normal route of re-displaying the > invalid form (which will have error messages printed by each field that did > not validate) when is_valid returns False. So perhaps you just want to > remove the upload_result reference from your template. > > Karen Yes, of course! You were right! Un-indenting the else fixed the problem. Thanks 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Can Django have unique user homepage?
Hi, I saw, and please tell me if I am right, the is not self- authentication system that comes with Django. The admin has to create users, groups, etc. I also saw there are people that have developed a user registration module for Django. The next thing that seemed in order was a unique homepage for users. I couldn't find anything. I was looking for something either that users could pick colors or other modules. I guess like a CMS, but not sure. Was looking for direction. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Template Tags Inside 'ifequals'
I'm trying to create an ifequals tag in a template to check if request.path equals the URL for a particular view. Either this is not possible, or I just can't find the right syntax. As I haven't been able to find an example via Google, does anyone know hoe to do this correctly? {% ifequals request.path url('site.app.view_file.view_fn') %} code {% end ifequals %} It's the url code I can't seem to get right. More generally, Is there a way to use a tag value inside a template comparison clause, and if so, what's the correct syntax? To me, this seems like a very common task within a template, especially for use in menus and nav bars. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Unicode broken if using a custom primary key?
On Sat, Apr 26, 2008 at 1:56 PM, plamen.dragozov <[EMAIL PROTECTED]> wrote: > > Hi, > I'm having a realy weird problem. I created Django models for some > legacy data and I'm doing some tests on Windows XP with Django 0.96.1 > and sqlite. > I'm parsing the data (a few big CSV text files) and generating a JSON > fixture file, which I use to initialize the database. The file is > quite big (~250 MB) and Django's error messages are not very helpful, > so it took me a few hours of head-scratching until I found out what's > wrong, but I managed to reduce it to the simple problem bellow: > 1. An application "testapp" > 2. A models.py file: > > ## -*- coding: utf-8 -*- > > from django.db import models > > class Test(models.Model): >#id = models.PositiveIntegerField(primary_key=True) >f1 = models.CharField(maxlength=65, blank=True, null=True) > > 3. A test.json file: > > [{"pk": "203", "model": "testapp.Test", >"fields": >{"f1": "\u00c3"}}] > > 4. I delete the db file and then from the command line I run: > python manage.py syncdb testapp > python manage.py loaddata fixtures/test.json > > If I leave the line with the custom primary key commented everything > is fine and I get: > Installed 1 object(s) from 1 fixture(s) > > However if I use a custom primary key, i.e. uncommented the line in > models.py I get an error: > Problem installing fixture 'fixtures/test.json': 'ascii' codec can't > decode byte 0xc3 in position 0: ordinal not in range(128) > > It's really strange, as I'm not changing anything else and can't see > how the type of the primary key has any connection to the database > unicode support. > Any ideas? Is it a known problem and is it SQLite only? > One thing: the Django 0.96 release is not fully unicode enabled. Full unicode support did not arrive until after the 0.96 release, so if you want unicode support you need to be using an SVN checkout, not one of the older releases. Now, I don't know why you'd get the results you are describing, with a problem only when you override the primary key specification, but I doubt you will find anyone interested in investigating a unicode problem on the 0.96 release, so your first step needs to be an upgrade to a unicode-enabled version. Then, if the problem does not just go away, post again and someone will likely be able to help. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File upload with no database - Fantasy or reality?
On Sat, Apr 26, 2008 at 1:18 PM, python_fan <[EMAIL PROTECTED]> wrote: > > > On Apr 26, 3:54 am, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > > > or better still, please paste your full current view and template. > > Also it would be easier to handle the thread if you did not top post ;-) > > Ok, will do. :) > Here is the code: http://dpaste.com/47029/ upload_form = None upload_result = '' if request.method == 'POST': upload_form = FileUploadForm(request.POST, request.FILES) if upload_form.is_valid(): # get file name and contents from request: file_name = request.FILES['txt_file']['filename'] file_content=request.FILES['txt_file']['content'] # save the file. something like: f=open("C:\\" + file_name, 'w') f.writelines(file_content) f.close() else: upload_form = FileUploadForm() You've got the creation of the blank FileUploadForm nested in the else for if upload_form.is_valid(). So it appears you do not create a FileUploadForm when request.method is anything other than POST (unless there is more relevant code that follows this snippet). It looks like the else that you have should be un-dented one level, so that a blank FileUploadForm is generated for display when request.method is, say, GET. It's also normal to return an HttpResponseRedirect to a different page when is_valid() processing completes, which you don't seem to be doing. Finally nowhere in here do you set upload_result, which seems to be expected by your template. Your initial code seemed to be using that to display errors, which is not necessary if you go the normal route of re-displaying the invalid form (which will have error messages printed by each field that did not validate) when is_valid returns False. So perhaps you just want to remove the upload_result reference from your template. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Unicode broken if using a custom primary key?
Hi, I'm having a realy weird problem. I created Django models for some legacy data and I'm doing some tests on Windows XP with Django 0.96.1 and sqlite. I'm parsing the data (a few big CSV text files) and generating a JSON fixture file, which I use to initialize the database. The file is quite big (~250 MB) and Django's error messages are not very helpful, so it took me a few hours of head-scratching until I found out what's wrong, but I managed to reduce it to the simple problem bellow: 1. An application "testapp" 2. A models.py file: ## -*- coding: utf-8 -*- from django.db import models class Test(models.Model): #id = models.PositiveIntegerField(primary_key=True) f1 = models.CharField(maxlength=65, blank=True, null=True) 3. A test.json file: [{"pk": "203", "model": "testapp.Test", "fields": {"f1": "\u00c3"}}] 4. I delete the db file and then from the command line I run: python manage.py syncdb testapp python manage.py loaddata fixtures/test.json If I leave the line with the custom primary key commented everything is fine and I get: Installed 1 object(s) from 1 fixture(s) However if I use a custom primary key, i.e. uncommented the line in models.py I get an error: Problem installing fixture 'fixtures/test.json': 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) It's really strange, as I'm not changing anything else and can't see how the type of the primary key has any connection to the database unicode support. Any ideas? Is it a known problem and is it SQLite only? Best, Plamen Dragozov --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: File upload with no database - Fantasy or reality?
On Apr 26, 3:54 am, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > or better still, please paste your full current view and template. > Also it would be easier to handle the thread if you did not top post ;-) Ok, will do. :) Here is the code: http://dpaste.com/47029/ Thanks a lot, Kenneth! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Caching and comments
This may be exceedingly obvious, but it took me a little bit of Googling for "template fragment caching expiry" before I realized there was an easier way to do what I was looking for. I use template fragment caching (so simple!), but it's annoying when someone comments and his comments don't show up for several minutes. In order to create a new cached block when a new comment is received, one simply needs to put the comment_count into the cache tag's list of arguments. - E.g. - {% get_free_comment_count for blog.entry object.id as comment_count %} {% cache 300 entry_comments object.id user.is_authenticated comment_count %} The two downsides that I see are: * the need to hit the database to get the comment count * the creation of a new cache object while retaining the old one If you are receiving hundreds of comments a minute, this system would quickly balloon out of control, but it's a nice, simple solution for a personal site. Does anyone have a better way to do this, excluding using the low- level cache API? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Does request.is_ajax() really work?
Oh, thanks Louis. I tried again by using your method. It really works! I mean, request.is_ajax() is working now. Also, I found the real cause why I encountered that problem. I used 'GET' method to request a view in ajax but that view is CACHED by my browser before ajax request it, so I get the same result even I really used ajax. I changed to 'POST' method in ajax function and that works fine. Again, thanks all you guys. On Fri, Apr 25, 2008 at 11:07 PM, Louis Orenstein <[EMAIL PROTECTED]> wrote: > Could you print out what the request.META.get('HTTP_X_REQUESTED_WITH') > method returns? Maybe the request doesn't have that property set correctly, > or maybe the HTTP_X_REQUESTED_WITH value isn't the proper thing to "get" > from META ? > > > Patrick Lv wrote: > > Hi Alex, > > What I am talking about is this: > > http://code.djangoproject.com/ticket/6616 > > On Sat, Apr 19, 2008 at 10:28 PM, Alex Koshelev <[EMAIL PROTECTED]> > wrote: > > > > > What is `is_ajax` method? > > > > On Apr 19, 4:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > I have made up a view to check a request is ajax or not, but the > > > function is_ajax() always return false. I used prototype to fire the > > > ajax request and I confirmed it with Firebug. The request header > > > really contains "X-Requested-With" and its value is "XMLHttpRequest". > > > I tried it many times on different machines (Win XP+Django dev server > > > and Debian+Apache 2+FastCGI) but the problem remained as the same. I > > > checked the request.META, but can not find any string like ""X- > > > Requested-With", so I think that is the real cause. > > > > > > Does anyone see the same problem as me? > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: WSGIRequest and is_ajax?
On Sat, 2008-04-26 at 08:32 -0700, Reinhard Freiler wrote: > > I have written a view in which should return a JSON string or a HTTPResponse, > either the request is ajax or not, so I've tried to check this via the > is_ajax() method > of the request object like it is said in the documentation > (http://www.djangoproject.com/documentation/request_response/#httpresponse-objects). > > But I got an AttributeError: > > 'WSGIRequest' object has no attribute 'is_ajax' > > So I looked for methods of WSGIRequests and found this: > http://djangoapi.matee.net/django.core.handlers.wsgi.WSGIRequest-class.html > > Here is mentioned that WSGIRequest inherit from HTTPRequest (including > is_ajax method). > > So why I'm getting this Error? > Can anyone tell me what I'm doing wrong? Sounds like you're using a version of Django from before the is_ajax() method was added. What version are you using? This method was added in r7334 (March 20, this year). Regards, Malcolm -- A conclusion is the place where you got tired of thinking. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
WSGIRequest and is_ajax?
I have written a view in which should return a JSON string or a HTTPResponse, either the request is ajax or not, so I've tried to check this via the is_ajax() method of the request object like it is said in the documentation (http://www.djangoproject.com/documentation/request_response/#httpresponse-objects). But I got an AttributeError: 'WSGIRequest' object has no attribute 'is_ajax' So I looked for methods of WSGIRequests and found this: http://djangoapi.matee.net/django.core.handlers.wsgi.WSGIRequest-class.html Here is mentioned that WSGIRequest inherit from HTTPRequest (including is_ajax method). So why I'm getting this Error? Can anyone tell me what I'm doing wrong? Thanks. -- View this message in context: http://www.nabble.com/WSGIRequest-and-is_ajax--tp16912620p16912620.html Sent from the django-users mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
using Managers in the admin interface
Hi. I am new to Django using a recent svn branch on Windows with mysql any python 2.51. I am trying solve the following puzzle: I am trying to override the default behavior of one of my models by using a Manager. My eventual goal is to only allow a certain class of users access to this model and I would like to place the logic for this in the model. Here is the code: I have a (simplified) Department class that looks like this: class Department(models.Model): name = models.CharField(max_length=200) objects = DepartmentManager() As you can see I am setting objects to DepartmentManager. I am doing this so anything that calls Department.objects.all() will use this manager instead of the standard one. The DepartmentManager class looks like this: class DepartmentManager(models.Manager): def get_query_set(self): return super(DepartmentManager,self).get_query_set().filter(name__startswith='O') So I am setting the default query to do something else. This works in the console. So if I do: >>> from dash.models import Department >>> a = Department.objects.all() >>> len(a) I get 1 - which is correct. If that were not there I would get a lot more than just the one entry. So, I am doing this so I can eventually give the admin interface a little more granular permissions. I have to 2 questions about this approach. First, after this change, when I go into the admin interface and click on the Department item, it still pulls back ALL the departments instead of just the one as I would have expected (I am assuming that the admin interface calls Department.objects.all() to get the list). This is puzzling because my approach is also mentioned in the book here (specifically mentioning the admin interface in fact) so I would think it should work. Here is the quote from the book: If you use custom Manager objects, take note that the first Manager Django encounters (in order by which they’re defined in the model) has a special status. Django interprets the first Manager defined in a class as the “default” Manager. Certain operations — such as Django’s admin site — use the default Manager to obtain lists of objects, so it’s generally a good idea for the first Manager to be relatively unfiltered. In the last example, the people Manager is defined first — so it’s the default Manager. So, does anyone know what is going on here? Why am I still seeing all the Department models? I have restarted the server, etc. Is there any way to see what SQL the admin interface is calling as it executes? Second, I eventually would like to have the user object available directly to that DepartmentManager class so I can expand the get_query_set().filter - I am not actually interested in limiting results to 'O' :-) I have seen a "hack" using this: http://lukeplant.me.uk/blog.php?id=1107301634 Is this still the best way to get the request user object or is there some other way. It was unclear in the comments. I also tried to explore newforms-admin a bit to see if that would help but it is quite a lot to grasp right now because of my Django newbie status and the current lack of documentation. Also, as far as I can tell it has not and many not be integrated into django and I am sure if I want to use it until it at least makes it into the main svn trunk. Thanks very much for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: fieldsets in form ( ticket #6630 )
hai On 4/26/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Hello Django Users, > > I'm a bit struggling with the newforms library, I'm creating multiple > forms where fieldsets need to be defined. I was looking into the > newforms documentation and didn't see anything there about widgets > creating fieldsets. > > By searching in google i saw a ticket ( nr 6630 ) that probably > contains exactly what i need. The only thing is that i didn't really > understand how it worked. Did anyone already used the fieldset > combined with the newforms library. > > If so can you send me a example of how you defined your form classes. > > Thanks in advance, > > Richard > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
fieldsets in form ( ticket #6630 )
Hello Django Users, I'm a bit struggling with the newforms library, I'm creating multiple forms where fieldsets need to be defined. I was looking into the newforms documentation and didn't see anything there about widgets creating fieldsets. By searching in google i saw a ticket ( nr 6630 ) that probably contains exactly what i need. The only thing is that i didn't really understand how it worked. Did anyone already used the fieldset combined with the newforms library. If so can you send me a example of how you defined your form classes. Thanks in advance, Richard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: possible workarounds for bug #3951 (double invocation of signal handlers)
On Sat, 2008-04-26 at 14:57 +0200, chris vigelius wrote: > hi, > > trying to work around bug #3951 (http://code.djangoproject.com/ticket/3951), > I've found two possible approaches which both seem to solve my problem (I > send a notification mail in response to the signal and I don't want the mail > to be sent twice). > > The first approach would be to add a flag to the instance: > > def signal_handler(sender, instance, **kwargs): > if hasattr(instance, 'my_secret_flag'): > return > # normal signal handler follows here > # ... > instance.my_secret_flag = True I don't think this will work, although it depends on what signal you're responding to. It kind of relies on the assumption that you'll only ever trigger the signal once per instance, which may or may not be true. For example, if something's done every time the instance is saved and you call save() then do something, then call save() again ,the second save() call won't trigger the signal handling. Maybe that works in your case, but it's probably a bit fragile. > The second, and possibly more elegant solution would be to compare __name__ > against the full module path (as I understand it, #3951 is caused by > importing the module once with an absolute path and once with a relative > one): There are many ways something can be imported. Not everything just has a two-level hierachy (project/appname/), so it's more complicated than this in the general case. However, if this is the sort of directory structure you have, it will do as a workaround. Regards, Malcolm -- Experience is something you don't get until just after you need it. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
possible workarounds for bug #3951 (double invocation of signal handlers)
hi, trying to work around bug #3951 (http://code.djangoproject.com/ticket/3951), I've found two possible approaches which both seem to solve my problem (I send a notification mail in response to the signal and I don't want the mail to be sent twice). The first approach would be to add a flag to the instance: def signal_handler(sender, instance, **kwargs): if hasattr(instance, 'my_secret_flag'): return # normal signal handler follows here # ... instance.my_secret_flag = True The second, and possibly more elegant solution would be to compare __name__ against the full module path (as I understand it, #3951 is caused by importing the module once with an absolute path and once with a relative one): if __name__ == 'myproject.myapp': dispatcher.connect(signal_handler, ...) Both approaches seem to work fine (in the local test server), however since I am neither an experienced python nor django programmer, I'd welcome any opinions from more seasoned programmers about the possible up- and downsides (or even unintended side-effects) of these two approaches. thanks, chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FTP upload of files threw django
Thank you all for the responses, I will start looking into it and see if there is a solution for this. I will ask the developer again who saw this once before. Regards, Richard On Apr 26, 10:16 am, pgb <[EMAIL PROTECTED]> wrote: > Hi, > I am also not an expert but personaly I would use javascript/ajax with > files smaller then 100MB, > for larger files I would try a Java applet. Either ways use another > webserver/s. > > Please keep us up to date. > > pawciobiel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
newforms extensions
Hi, We have developed a few extensions to newforms library, and published it for public use. It is more just a simple snippet, so I decided to have a SVN repository and publish it on our website. I've started writing documentation (please tell me if its good enough to start ?): http://public.halogen-dg.com/wiki/newforms_py What it does, shortly: - vertical layout for form (so you can edit a few recods of same type in a single form) - child-forms (so you can embed a form in a single field with JS popup) Regards, Alex V. Koval --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: mod_python or fcgi
On Apr 25, 9:47 am, Don Spaulding <[EMAIL PROTECTED]> wrote: > On Apr 24, 6:34 am, Rufman <[EMAIL PROTECTED]> wrote: > > > Hey Graham > > > thanks for the insight > > > Stephane > > I won't debate any of what Graham has said, as it's a pretty standard > answer from what I've seen, and he's a lot smarter than me. I just > want to note that fastcgi makes a nice separation between app and web > server for my needs. I hated having to restart apache to restart my > app, and fastcgi on lighttpd made app deployment stupidly easy (not > that apache/mod_python is rocket science). When you use mod_wsgi daemon mode, to restart your Python web application, which can potentially be running across multiple processes, you just need to touch (ie. update its modification time) the WSGI script file which is its entry point and process will be restarted automatically the next time a requests arrives for them. In other words, with mod_wsgi daemon mode you do not have to restart the whole of Apache when you change the code just for your Python web application. Thus, just as stupidly easy as some fast fastcgi implementations/configurations. :-) Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Confused on a foriegnkey error
Excuse me for not writing back earlier - travelling isn't always easy. I have however, figured out the cause of this problem and fixed it. I believe it had to do with using ModelMultipleChoiceField instead of ModelChoiceField. Thanks for clearing that up. I will also make a note to be more precise with the snippets I put up in the future. I still need some help with selecting multiple options, but since it doesn't exactly fit under this topic, I'll post a new message up. Thanks, R On Tue, Apr 22, 2008 at 9:41 PM, Karen Tracey <[EMAIL PROTECTED]> wrote: > > On Mon, Apr 21, 2008 at 12:06 PM, Rishabh Manocha <[EMAIL PROTECTED]> > wrote: > > > > > > Thanks for writing back, Karen. I guess the snippets of code I > > inserted were a little misleading. I have many other modelforms too, > > which all have a user = ForeignKey(User) defined. Problem is that I > > have to use multiple instances of these forms (for example, I need I > > have a ModelForm called PrevoiusOrganisation. Each instance represents > > one org, but I want the user to be able to enter multiple previous > > organisations ) which all have to have their "user" set. An example > > is: > > > > if request.POST: > >new_user = UserDetailsForm(request.POST, request.FILES, > instance=User()) > >prevorgforms = [PrevOrgsForm(request.POST, > > prefix="prevorgs"+str(x), instance = PrevOrgs()) for x in range(0, 3)] > >prevorgprojsforms = [PrevOrgProjsForm(request.POST, > > prefix="prevorgprojs"+str(x), instance = PrevOrgProjs()) for x in > > range(0, 4)] > >if new_user.is_valid() and all([prevorgform.is_valid() for > > prevorgform in prevorgforms]) and ...: > >new_user_id = new_user.save() > >set_user_id(prevorgforms,new_user_id) > >set_user_id(prevorgprojsforms,new_user_id) > >... > > > > def set_user_id(the_list, the_user_id): > >for list_elem in the_list: > >new_list_elem = list_elem.save(commit=False) > >new_list_elem.user = the_user_id > >new_list_elem.save() > > > > I have not had any issues with this function and my other modelforms, > > so I don't think I'm doing something wrong here. I suspect something > > is missing either during the Ajax call or later when I set the > > queryset for each list on submission. > > > > Hope that clears up my problem a little bit more. > > > > Well no, that didn't really clear things up. You were asking about trouble > saving a SkillListForm and now are posting about how set_user_id is called > when you are doing things with a UserDetailsForm and some different > organization forms with multiple instances, which is confusing since it > seems entirely unrelated to the original problem. I gather what you are > trying to say, though, is that this same set_user_id function is called when > you are doing the processing to save a SkillListForm? If so I'm not sure > why you didn't just post the code involved when saving a SkillListForm. > > Anyway, on closer inspection of the SkillListForm I do notice a problem: you > override skill like so: > > > skill = forms.ModelMultipleChoiceField(required = True, label = "Technical > Skill",queryset = A.objects.none()) > > This should be a ModelChoiceField, not a ModelMultipleChoiceField. (Also > the queryset should be tied to the B model, not A, since skill is a > ForeignKey specifying a B model instance.) > > However, though this error would produce exactly the symptom you describe, > I'm not entirely sure that is the cause of your problem because you say your > form displays two drop-down boxes and a ModelMultipleChoiceField wouldn't > have a drop-down widget, so I am not sure the code you posted really matches > what you are running (there are also some typos in the ForeignKey > definitions, so it seems you re-typed vs. cut-and-pasted your code). > People are much more likely to be able to provide useful help when you post > exactly the code you are running. If you feel it is too complicated by all > means try to simplify it, but verify you still hit the problem with the > simplified code. Oftentimes in the process of simplifying you can identify > what is causing the problem. > > Karen > > > > > Best, > > > > R > > > > > > > > > > > > On Mon, Apr 21, 2008 at 6:38 PM, Karen Tracey <[EMAIL PROTECTED]> wrote: > > > > > > On Mon, Apr 21, 2008 at 2:53 AM, Rishabh Manocha <[EMAIL PROTECTED]> > wrote: > > > > > > > > > > > > > > Hey Guys, > > > > > > > > I have 4 models working something like this: > > > > > > > > class User(models.Model): > > > > name = models.CharField() > > > > email = models.EmailField() > > > > ... > > > > > > > > class A(models.Model): > > > > domainname = models.CharField() > > > > > > > > class B(models.Model): > > > > domain = models.ForigenKey(A) > > > > name = models.CharField() > > > > > > > > class C(models.Model): > > > > user = models.ForiegnKey(User) > > > > skill = models.ForeignKey(B) > > > > years = models.IntegerField() > > > > > > > > The reason
Re: Complex Django Hosting
> I'm working on what will end up being a large, high-traffic, multi- > site project. Currently we're just using a basic Webfaction account > for hosting during development and testing, but I'm trying to figure > out what would be the best approach to hosting moving forward. You can probably stay at webfaction. Their shared accounts can handle quite a bit of traffic and if you outgrow one shared account they can load-balance your site between multiple shared accounts on different machines. They also offer dedicated servers although they are more expensive than "bare" dedicated servers because they are managed by webfaction (IMHO the convenience is worth the extra price). Kevin. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FTP upload of files threw django
Hi, I am also not an expert but personaly I would use javascript/ajax with files smaller then 100MB, for larger files I would try a Java applet. Either ways use another webserver/s. Please keep us up to date. pawciobiel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django voting with jellyrool
Hi all, I use a modified version of http://jellyroll.googlecode.com/ by adding my own models into follow list (jellyrool.models.Item). For example, Item.objects.follow_model(Post) After that, I added django-voting (http://django- voting.googlecode.com/) to my application list. The problem is, at the index page. I want to list latest item. If latest item is Post and it has Vote as well, I will show post and its vote. I also use template_utils (http://django-template- utils.googlecode.com/svn/trunk). My code look like this, {% load generic_content%} {% load voting_tags %} {% get_latest_objects aggregate.item 10 as latest_items %} I try to access voting for post in latest_items and cannot find any solution. Any idea is my appreciated. Thanks Chatchai --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---