summary of two models+detailed view--how to structure?
Hi, I have two basic models for a book-production site: book configuration build reports I want to display information for a particular book so you can drill- down from a summary of its configuration and build to a detailed view of its configuration and build report. The way I have it set up now is with three urls: bookname/summary (aggregates data from both models) bookname/configuration bookname/build-report People always view the site starting with the summary. So I hit the database once for that, and then again for each of the other views when they drill-down. I read the docs on caching, but I'm no expert--is caching the smart way to handle this? Should I worry about it? thanks, --Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: summary of two models+detailed view--how to structure?
On Jan 30, 2:21 pm, Daniel Roseman wrote: > On Jan 30, 4:15 pm, Tim Arnold wrote: > > > > > > > Hi, I have two basic models for abook-productionsite: > >bookconfiguration > > build reports > > > I want to display information for a particularbookso you can drill- > > down from a summary of its configuration and build to a detailed view > > of its configuration and build report. > > > The way I have it set up now is with three urls: > > bookname/summary (aggregates data from both models) > > bookname/configuration > > bookname/build-report > > > People always view the site starting with the summary. So I hit the > > database once for that, and then again for each of the other views > > when they drill-down. > > > I read the docs on caching, but I'm no expert--is caching the smart > > way to handle this? Should I worry about it? > > thanks, > > --Tim > > Short answers: no, caching isn't the way to handle it; and no, you > shouldn't worry about it. > > Caching is best for repeated views of the same page, or multiple pages > where there are repeated complex elements. This isn't your use case - > the only link between the summary and the other pages is that they > refer to the same bookname. The number of repeated elements is very > low, and best handled by simply getting the relevant database objects > each time (this is, after all, what databases do best). > > Unless you're expecting a huge number of views, or have extremely low- > powered database hardware, I wouldn't worry. > -- > DR.- Hide quoted text - > > - Show quoted text - thanks a lot for taking a look at it. This will be a low traffic site. usually I don't worry about optimizing until later in a project, but I'm so new at django I didn't want to start out doing something stupid. thanks again, --Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
manipulate header before sending response
hi, I have a static webpage which is out of my control (created in some other process). I want to show the page to the user, but I need to add a stylesheet to the header first. Is there a way to receive the request, add the to the header for the stylesheet and then serve the webpage? thanks, --Tim -- 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: manipulate header before sending response
On Apr 19, 3:12 pm, Shawn Milochik wrote: > You can create your own middleware. > > http://docs.djangoproject.com/en/1.1/topics/http/middleware/ > > 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 > athttp://groups.google.com/group/django-users?hl=en. Thanks, that looks exactly like what I need. I've got this so far. Additional details: the file I'm serving is actually xml, and I want to always have it rendered using a special css stylesheet: --- middleware.py - css = '/media/css/XSL/driver.css' class XMLMiddleware(object): def process_response(self, request, response): if request.path.endswith('.xml'): response['xml-stylesheet'] = css return response I'm not sure about that code yet (i.e, not tested) but what I want the file to look like when it gets to the browser is this: http://docbook.org/ns/docbook"; version="5.0"> etc. thanks, --Tim -- 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.
middleware question
Hi, I want to serve some raw xml files, but add a stylesheet to the response so the user can view it better. The raw xml begins like this: http://docbook.org/ns/docbook"; version="5.0"> etc. I want to create some middleware to serve them like this: http://docbook.org/ns/docbook"; version="5.0"> etc. I've got this as a starting point but I have my doubts about it. Even if it works, my guess is it will put an xml-stylesheet as an element, not as a processing instruction. - css = '/media/css/XSL/driver.css' class XMLMiddleware(object): def process_response(self, request, response): if request.path.endswith('.xml'): response['xml-stylesheet'] = css return response I haven't wired anything up to test yet; I thought I'd ask if this is the right way to do it before going much further. thanks, --Tim -- 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.
multiple django instances, one database?
hi, Until now I've been working on a single Freebsd server, hosting a couple of Django apps. Now we've bought another machine to provide load balancing and I'm wondering how to accomplish that. I guess the django code can be shared on the same drive, but the django instances running separately of course (apache/mod_python). Is it possible to have two instances accessing the same database? How do you handle load-balancing? thanks, --Tim -- 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: multiple django instances, one database?
On Apr 22, 1:22 pm, Andy McKay wrote: > On 2010-04-22, at 9:52 AM, Tim Arnold wrote: > > > hi, > > Until now I've been working on a single Freebsd server, hosting a > > couple of Django apps. Now we've bought another machine to provide > > load balancing and I'm wondering how to accomplish that. > > I guess the django code can be shared on the same drive, but the > > django instances running separately of course (apache/mod_python). > > > Is it possible to have two instances accessing the same database? How > > do you handle load-balancing? > > Yes you can. There's lots of options,http://www.apsis.ch/pound/is but one. > -- > Andy McKay, @andymckay > Django Consulting, Training and Support > I just googled that which led to some interesting pages and notes, thanks. So, just to make sure I understand: browser -> pound --> apache1(mysqldb) +django --> apache2(mysqldb) +django and it will just work? One database, two django instances and they won't clobber each other on db write? I guess the writes will block, correct? thanks, --Tim -- 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: multiple django instances, one database?
On Apr 22, 2:25 pm, Tom Evans wrote: > On Thu, Apr 22, 2010 at 7:00 PM, Tim Arnold wrote: > > On Apr 22, 1:22 pm, Andy McKay wrote: > >> On 2010-04-22, at 9:52 AM, Tim Arnold wrote: > > >> > hi, > >> > Until now I've been working on a single Freebsd server, hosting a > >> > couple of Django apps. Now we've bought another machine to provide > >> > load balancing and I'm wondering how to accomplish that. > >> > I guess the django code can be shared on the same drive, but the > >> > django instances running separately of course (apache/mod_python). > > >> > Is it possible to have two instances accessing the same database? How > >> > do you handle load-balancing? > > >> Yes you can. There's lots of options,http://www.apsis.ch/pound/isbut one. > >> -- > >> Andy McKay, @andymckay > >> Django Consulting, Training and Support > > > I just googled that which led to some interesting pages and notes, > > thanks. > > So, just to make sure I understand: > > > browser -> pound --> apache1(mysqldb) +django > > --> apache2(mysqldb) +django > > > and it will just work? One database, two django instances and they > > won't clobber each other on db write? > > I guess the writes will block, correct? > > If you just want to run two instances of django against the same > database, then just do so. How you hook it into your hosting mechanism > depends on what mechanism you are using. Typically there would be no > need for multiple apache instances or a load balancer in front. > > I'm not sure I understand your last statement '..they wont clobber > each other on db write'. If you edit the same object at the same time > on multiple django instances, it is the same as if you edited the same > object at the same time on a single django instance. Django does no > locking - apart from atomicity of objects - to ensure that the earlier > saved object does not get updated. > > I just re-read that, and even I don't understand it so heres an example: > > User A loads a page with a form to edit object instance O > User B loads a page with a form to edit object instance O > User A changes O.active from True to False and saves the form > User B changes O.name from '' to 'Bob' and saves the form > > Note that I haven't mentioned what instance of django they are running > on - it is irrelevant > > In this scenario, after B has saved the form, O.active is True, and > O.name is 'Bob'. B does not get any warning that the object instance > he is editing has changed out from underneath him. > > If you require that sort of behaviour, you need to track the revision > of the object, and implement it when anything on the model changes - > that's behind the scope of this discussion ;) > > Cheers > > Tom Hi, Thanks for that explanation. I think I understand it now. --Tim -- 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.
modeling a book repository
Hi, I have a model for a Book that contains Chapters. My problem is figuring out the ordered sequence of Chapters in a Book. I first tried setting Chapter up as a linked list with pointers to the previous Chapter and next Chapter. That worked okay, but when I need to delete a Chapter, the prev/next links cascade through and it wants to delete all the chapters. I'm now thinking of adding a 'sequence number' to the chapter model which I suppose will work okay, but if want to add or delete a chapter later on, I'll have to renumber all the later chapters in the database. This is a little tricky--does anyone have a better solution? thanks, --Tim Arnold -- 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: modeling a book repository
Thanks for both these great answers. After thinking about it, I think either way I go I'll need to modify both the add and delete methods. The linked list seems more natural to me, but since my writers will be using the interface, the sequence number may be a better choice for them. More to think about... thanks again! --Tim On Jun 15, 12:48 pm, Dan Harris wrote: > Hi Tim, > > You can probably override the Chapter model's delete method. Inside > this overridden delete method you can swap around your FK's of > previous and next chapters before calling the super classes delete. > Basically do your linked list management inside the delete method > before the calling the super class delete. This way when the cascades > go through it doesn't have links to next or previous chapters and not > everything is deleted. > > Hope this helps, > > Dan Harris > dih0...@gmail.com > > On Jun 15, 12:11 pm, Tim Arnold wrote: > > > > > Hi, > > I have a model for a Book that contains Chapters. My problem is > > figuring out the ordered sequence of Chapters in a Book. I first tried > > setting Chapter up as a linked list with pointers to the previous > > Chapter and next Chapter. That worked okay, but when I need to delete > > a Chapter, the prev/next links cascade through and it wants to delete > > all the chapters. > > > I'm now thinking of adding a 'sequence number' to the chapter model > > which I suppose will work okay, but if want to add or delete a chapter > > later on, I'll have to renumber all the later chapters in the > > database. > > > This is a little tricky--does anyone have a better solution? > > thanks, > > --Tim Arnold -- 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: modeling a book repository
One more reply after doing some more research. Apparently this has been discussed quite a bit and a solution may appear in the 1.3 release: http://code.djangoproject.com/ticket/7539 But, to handle the situation where you want to avoid a cascade delete (which was my problem with my previous/next linked list of chapters), override the delete method on the class: def delete(self): self.previous_set.clear() self.next_set.clear() super(Chapter,self).delete() This works only if the ForeignKey can be null, so for example, the fields look like this: previous = models.ForeignKey('self', blank=True,null=True,related_name='a') next = models.ForeignKey('self', blank=True,null=True,related_name='b') Note however, I haven't tested this code yet, caveat emptor. From what I can glean from the docs and the forums though, it's close to correct. thanks, --Tim On Jun 15, 1:41 pm, Tim Arnold wrote: > Thanks for both these great answers. After thinking about it, I think > either way I go I'll need to modify both the add and delete methods. > The linked list seems more natural to me, but since my writers will be > using the interface, the sequence number may be a better choice for > them. More to think about... > > thanks again! > --Tim > > On Jun 15, 12:48 pm, Dan Harris wrote: > > > > > Hi Tim, > > > You can probably override the Chapter model's delete method. Inside > > this overridden delete method you can swap around your FK's of > > previous and next chapters before calling the super classes delete. > > Basically do your linked list management inside the delete method > > before the calling the super class delete. This way when the cascades > > go through it doesn't have links to next or previous chapters and not > > everything is deleted. > > > Hope this helps, > > > Dan Harris > > dih0...@gmail.com > > > On Jun 15, 12:11 pm, Tim Arnold wrote: > > > > Hi, > > > I have a model for a Book that contains Chapters. My problem is > > > figuring out the ordered sequence of Chapters in a Book. I first tried > > > setting Chapter up as a linked list with pointers to the previous > > > Chapter and next Chapter. That worked okay, but when I need to delete > > > a Chapter, the prev/next links cascade through and it wants to delete > > > all the chapters. > > > > I'm now thinking of adding a 'sequence number' to the chapter model > > > which I suppose will work okay, but if want to add or delete a chapter > > > later on, I'll have to renumber all the later chapters in the > > > database. > > > > This is a little tricky--does anyone have a better solution? > > > thanks, > > > --Tim Arnold -- 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.
paypal ipn change
Hi, I started having trouble with paypal IPN on Sept. 4 (a week ago), but didn't know it until they notified me yesterday that my endpoint url was failing. Well, I had just upgraded to Django 1.2.1 and figured it had to be that or some code refactoring I had done. However, as far as I can tell, the problems were due to a change in paypal's mechanism. What I did was change my endpoint to accept data from either a POST or a GET. Previously it only accepted POST data. When I made that change the IPN started coming through again. Just for completeness, here's my endpoint code. Note that yes, I'm not doing anything special with the data now, just writing it to a file so I can see the last transaction's data: @csrf_exempt def endpoint(request): def verify(data): newparams={} for key in data.keys(): newparams[key]=data[key] newparams["cmd"]="_notify-validate" params=urllib.urlencode(newparams) req = urllib2.Request(verify_url) req.add_header("Content-type", "application/x-www-form- urlencoded") fo = urllib2.urlopen(verify_url, params) return fo.read() def process(data): f = open('/home/myuser/mydata.txt','wb') f.write('%r valid' % data) f.close() return HttpResponse('Ok') def process_invalid(data): f = open('/home/myuser/myerrors.txt','wb') f.write('%r error' % data) f.close() return HttpResponse('NOT Ok') default_response_text = 'Nothing to see here' verify_url = "https://www.paypal.com/cgi-bin/webscr"; if request.method == 'POST': data = request.POST elif request.method == 'GET': data = request.GET if verify(data): process(data) else: process_invalid(data) return HttpResponse(default_response_text) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
multiple servers one database
hi, I have two machines for a Django-powered site and they are setup to be duplicates to provide redundancy. Each one runs its own apache instance and accesses the same Django apps on a shared disk. The problem I have is that I need a single database. The users should not need to know which machine they're actually connecting to. As I understand it, I can't do that with MySQL. I can make one a master and one a slave, but that's not duplication of machines. I tried making a symlink from /usr/local/mysql/var to a shared disk location for both MySQL servers, but that is a Bad Idea (from what I read this weekend). So finally, my question is how to solve the problem and maybe whether SQLite would be a better database since AIUI, it is simply file-based. thanks, --Tim Arnold -- 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: multiple servers one database
Hi Steve, That would definitely be the easiest and simplest answer. Unfortunately I only have power over these two machines. What I'm trying to do is create a site that if one machine dies/hangs, the system will continue to work on the alternate server. I just read about the master-master mysql server setup and though that seems a little complicated, I suppose my desires are more difficult than I thought at first. Any other ideas out there? Is SQLite a possibility or is master-master the way to go? thanks, --Tim On Sep 20, 9:22 pm, Steve Holden wrote: > On 9/20/2010 11:11 AM, Tim Arnold wrote:> hi, I have two machines for a > Django-powered site and they are setup > > to be duplicates to provide redundancy. Each one runs its own apache > > instance and accesses the same Django apps on a shared disk. > > > The problem I have is that I need a single database. The users should > > not need to know which machine they're actually connecting to. As I > > understand it, I can't do that with MySQL. I can make one a master and > > one a slave, but that's not duplication of machines. I tried making a > > symlink from /usr/local/mysql/var to a shared disk location for both > > MySQL servers, but that is a Bad Idea (from what I read this weekend). > > > So finally, my question is how to solve the problem and maybe whether > > SQLite would be a better database since AIUI, it is simply file-based. > > If the two web servers are sharing a disk they are presumably fairly > local to each other. Why not just a single database server with each > Django server connecting to it over a LAN? You may need to think more > deeply abut transaction isolation. Just an idea ... > > regards > Steve > -- > DjangoCon US 2010 September 7-9http://djangocon.us/ -- 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.
entering scores (one model) for a list of students (another model)
I'm creating a form that students fill in as they arrive at class. Just name, email, etc. When the class is over I want to display a form for the teacher to enter the grades. So, no problem on the students entering their info, I just have a Student model. I have a Score model that has the score and a ForeignKey to the student. That makes sense to me, but I'm have bunches of trouble figuring out how to display the form to the teacher I want a list of student names with an form for each grade. So I'm figuring a formset is what I need, based on the Score model. But I don't get how to associate the student with the score the teacher enters. thanks for any pointers. --Tim Arnold -- 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: entering scores (one model) for a list of students (another model)
On Feb 4, 4:07 pm, Tim Arnold wrote: > I'm creating a form that students fill in as they arrive at class. > Just name, email, etc. > When the class is over I want to display a form for the teacher to > enter the grades. > > So, no problem on the students entering their info, I just have a > Student model. > I have a Score model that has the score and a ForeignKey to the > student. > > That makes sense to me, but I'm have bunches of trouble figuring out > how to display the form to the teacher > > I want a list of student names with an form for each grade. So > I'm figuring a formset is what I need, based on the Score model. But I > don't get how to associate the student with the score the teacher > enters. > > thanks for any pointers. > --Tim Arnold To make my question more clear, what I don't know how to do is to display the student objects on the same page as a list of Score forms and connect each entered score to the Student object. thanks, --Tim -- 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: entering scores (one model) for a list of students (another model)
Aha! thanks. I should have one model that contains the student and the score. Then I can use a form for the each student to fill out, and a formset for the teacher to provide the scores for each student in the class. That makes sense (I hope I'm understanding you correctly). Thanks for taking the time to set me straight. --Tim On Feb 5, 10:03 am, Preston Holmes wrote: > Assuming you want to create a score per class - you should have > students go to a form that: > > creates a student and first score if student does not already exist > > creates a score for the student for that class and date > > Basically the students should be creating the 'blank' scores when they > come in. > > -Preston > > On Feb 5, 5:35 am, Tim Arnold wrote: > > > > > On Feb 4, 4:07 pm, Tim Arnold wrote: > > > > I'm creating a form that students fill in as they arrive at class. > > > Just name, email, etc. > > > When the class is over I want to display a form for the teacher to > > > enter the grades. > > > > So, no problem on the students entering their info, I just have a > > > Student model. > > > I have a Score model that has the score and a ForeignKey to the > > > student. > > > > That makes sense to me, but I'm have bunches of trouble figuring out > > > how to display the form to the teacher > > > > I want a list of student names with an form for each grade. So > > > I'm figuring a formset is what I need, based on the Score model. But I > > > don't get how to associate the student with the score the teacher > > > enters. > > > > thanks for any pointers. > > > --Tim Arnold > > > To make my question more clear, what I don't know how to do is to > > display the student objects on the same page as a list of Score forms > > and connect each entered score to the Student object. > > thanks, > > --Tim -- 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.
custom authentication for admin
Hi, I've read about the custom authentication you can do so you can use upstream validators for your views. And a snippet that helps do that is here http://www.djangosnippets.org/snippets/1723/ But will that work for the admin panels? It doesn't look like it to me...I have a database of users behind a firewall so I can authenticate just fine, but I need nearly all of the users (1000's) to be able to add/edit/delete records. I'd rather not write forms specifically for them since the admin is exactly what I need to offer. Is there a way to authenticate and pass it on to the admin views? thanks, --Tim -- 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.