Re: how to implement multiple choices in model
On Nov 18, 2:56 am, Canhua <[EMAIL PROTECTED]> wrote: > hi, I am trying to create such a kind of field in a model. The field > can only take one or more values from a set of value, each seperated > by such as commas. It seems that there is no built-in field type in > Django. How may I implement this? Any clue is greatly appreciated. > > Best wishes > > Can-Hua Chen Usually you'd do this as a ManyToMany field. However I know you sometimes do want to do it in a custom model field - I've just posted my implementation at djangosnippets: http://www.djangosnippets.org/snippets/1200/ -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Default custom settings
Wiadomość napisana w dniu 2008-11-18, o godz. 03:29, przez mdnesvold: > > I'm writing an application that adds several app-specific settings. As > I'm developing, I'm just adding them to the end of my settings.py > file: > > MY_APP_FOO = 'foo' > MY_APP_BAR = ( > 'bar', > 'bam', > 'baz', > ) > # and so on > > So far, I have eleven such settings over 21 lines and expect to add > several more. I don't want to make any new users of this app cut-and- > paste a block of code into their settings.py just to get the app > working, especially since some are "advanced settings" and will rarely > be changed. Is there any way to specify default values for these > settings? That way, my app requires less work to set up and still > allows flexibility. I usually add separate settings for application, then do from myapp.settings import * in main settings module. Of course, all settings have defaults (I'm doing getattr(settings, 'MY_SETTING', 'foo')) and are documented. -- We read Knuth so you don't have to. - Tim Peters Jarek Zgoda, R, Redefine [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: public html?
yeah - that's the way I'd normally do it (with Apache)... but this development server thing was what was throwing. On Nov 18, 5:12 pm, Jonathan Lin <[EMAIL PROTECTED]> wrote: > By the way, that is the way to get django's development server to serve > up you files, and not necessarily the best way to go when you want to > deploy your site. > > Your best bet is some sort of webserver like apache or lighttpd > > Jonathan > --~--~-~--~~~---~--~~ 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: public html?
By the way, that is the way to get django's development server to serve up you files, and not necessarily the best way to go when you want to deploy your site. Your best bet is some sort of webserver like apache or lighttpd Jonathan Horus Kol wrote: > On Nov 18, 2:24 pm, Horus Kol <[EMAIL PROTECTED]> wrote: > >> I've searched through and through the documentation at the Django >> site, but can't find any information about this: >> >> What's the recommended setup for things like stylesheets and >> javascripts? >> >> How do you setup the redirects? Anything special to dealt with it in >> the framework. >> > > Answered my own question (after a bit of mucking about): > > r'^styles/(?P.*)$', 'django.views.static.serve', > {"document_root": "F:/projects/dvdgeist/public_html/styles"}), > > > > --~--~-~--~~~---~--~~ 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: How to access the request object in a decorator
Thanks a lot Bruno! That really helped :) On Nov 17, 3:20 am, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 17 nov, 10:02, TH <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > I wanted to redirect a logged in user if he access certain page. For > > example i do not want the user to access registration page if he is > > logged in. > > > A simple way to do this is: > > > def register(request): > > if request.user.is_authenticated(): > > return HttpResponseRedirect('/ > > some_nice_page_for_logged_in_user') > > ... > > > The problem is i have lot of pages that only anonymous user can > > access. So i wanted to write a decorator so that i can do something > > like that > > > @anonymous_only > > def register(request): > > A "decorator" is just a function (or any other callable) that takes a > function as argument and returns a function (or any other callable). > The @decorator syntax is only syntactic sugar. > > In most cases, the returned function is just a wrapper around the > decorated one, and this is obviously what you want: > > def anonymous_only(view): > # 'view' is the view function to decorate > # since we decorate views, we know the first parameter > # is always going to be the current request > # > # '_wrapper' is the function that will be used instead > # of 'view'. > def _wrapper(request, *args, **kw): > # here we can access the request object and > # either redirect or call 'view' > if request.user.is_authenticated(): > return HttpResponseRedirect('/page_for_logged_in_user') > return view(request, *args, **kw) > > # this part is not mandatory, but it may help debugging > _wrapper.__name__ = view.__name___ > _wrapper.__doc__ = view.__doc__ > > # and of course we need to return our _wrapper so > # it replaces 'view' > return _wrapper > > Note that this example assume you always want to redirect to the same > page if the user is logged in, which might not be the case. Things get > a bit more complicated if you want your decorator to takes the > redirection url as param, since we'll then need one more indirection, > IOW : a function that takes an url and returns a function that takes a > function and returns a 'wrapper': > > def anonymous_only(redirect_to): > def deco(view): > def _wrapper(request, *args, **kw): > if request.user.is_authenticated(): > return HttpResponseRedirect(redirect_to) > return view(request, *args, **kw) > > _wrapper.__name__ = view.__name___ > _wrapper.__doc__ = view.__doc__ > return _wrapper > > return deco > > Then you use it that way: > > @anonymous_only('/page_for_logged_in_user') > def register(request): > # code here > > HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: public html?
On Nov 18, 2:24 pm, Horus Kol <[EMAIL PROTECTED]> wrote: > I've searched through and through the documentation at the Django > site, but can't find any information about this: > > What's the recommended setup for things like stylesheets and > javascripts? > > How do you setup the redirects? Anything special to dealt with it in > the framework. Answered my own question (after a bit of mucking about): r'^styles/(?P.*)$', 'django.views.static.serve', {"document_root": "F:/projects/dvdgeist/public_html/styles"}), --~--~-~--~~~---~--~~ 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: Update Values to Null
But of course! Thank you. On Nov 17, 8:25 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 17, 2008 at 9:06 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > I cannot figure out how to update a foreign key to a null value. > > Thanks. > > > models.py > > > > group = models.ForeignKey(group, null=True, blank=True) > > > >>> from redirect.models import * > > >>> Links = Link.objects.filter(group = 6) > > >>> Links.update(group = NULL) > > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'NULL' is not defined > > > >>> Links.update(group = 'NULL') > > ... > > ProgrammingError: invalid input syntax for integer: "NULL" > > Try None instead of NULL. > > 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: Built-in Reference - docutils
James, Thanks for that - worked a treat. --~--~-~--~~~---~--~~ 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: New Django install on Win Vista-problem
On Mon, Nov 17, 2008 at 9:58 PM, DSS <[EMAIL PROTECTED]> wrote: > > I just installed Django 2.6 on my Vista machine; followed installation > instructions explicitly. Python imports Django sucessfully. When I > try to run django-admin.py startproject ..., it does not run at the > command prompt. I suspect it needs to be in the system path, but I'm > not sure. > > Yes, unless you want to specify the full path at the command line to django-admin.py, you have to either put it in a place that is in your system path or add its location to your system path. 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: Built-in Reference - docutils
On Mon, Nov 17, 2008 at 10:26 PM, Horus Kol <[EMAIL PROTECTED]> wrote: > TemplateDoesNotExist at /admin/doc/ > > Anyone got any ideas? It helps to have the admin docs application (which is *not* 'django.contrib.admin', but rather 'django.contrib.admindocs') in your INSTALLED_APPS, so that its bundled templates will be picked up. -- "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 -~--~~~~--~~--~--~---
Built-in Reference - docutils
I've installed docutils and gotten past one error when trying to access the built-in reference documentation from admin site, but now I'm getting another error message: TemplateDoesNotExist at /admin/doc/ Anyone got any ideas? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
public html?
I've searched through and through the documentation at the Django site, but can't find any information about this: What's the recommended setup for things like stylesheets and javascripts? How do you setup the redirects? Anything special to dealt with it in the framework. --~--~-~--~~~---~--~~ 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: Update Values to Null
On Mon, Nov 17, 2008 at 9:06 PM, Merrick <[EMAIL PROTECTED]> wrote: > > I cannot figure out how to update a foreign key to a null value. > Thanks. > > models.py > > group = models.ForeignKey(group, null=True, blank=True) > > >>> from redirect.models import * > >>> Links = Link.objects.filter(group = 6) > >>> Links.update(group = NULL) > > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'NULL' is not defined > > >>> Links.update(group = 'NULL') > ... > ProgrammingError: invalid input syntax for integer: "NULL" > > > Try None instead of NULL. 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 -~--~~~~--~~--~--~---
New Django install on Win Vista-problem
I just installed Django 2.6 on my Vista machine; followed installation instructions explicitly. Python imports Django sucessfully. When I try to run django-admin.py startproject ..., it does not run at the command prompt. I suspect it needs to be in the system path, but I'm not sure. Any clues? thx, --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Default custom settings
I'm writing an application that adds several app-specific settings. As I'm developing, I'm just adding them to the end of my settings.py file: MY_APP_FOO = 'foo' MY_APP_BAR = ( 'bar', 'bam', 'baz', ) # and so on So far, I have eleven such settings over 21 lines and expect to add several more. I don't want to make any new users of this app cut-and- paste a block of code into their settings.py just to get the app working, especially since some are "advanced settings" and will rarely be changed. Is there any way to specify default values for these settings? That way, my app requires less work to set up and still allows flexibility. --~--~-~--~~~---~--~~ 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: ImageField upload_to not workin
Hi Javier, I am experiencing the same problem with 'upload_to'. Have you found the problem? Thx, elm On 14 nov, 18:31, Javier <[EMAIL PROTECTED]> wrote: > Hi, > > I've create a model: > > class ImagenesLugar(models.Model): > archivo = models.ImageField(upload_to="imageneslugar/") > texto = models.CharField(max_length=400) > > The thing is that when i create a new instance of this model and > assign instance.archivo to a file then instance.archivo.path does not > contain myupload_toparameter: > > Ie: > > my media root is :"/home/media" > my uploadto is "imageneslugar" > my file is "image.jpg" > > I do: > instance.archivo = "image.jpg" > > then: > instance.archivo.path is: > /home/media/image.jpg > instead of > /home/media/imageneslugar/image.jpg > > what am I missing? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
how to implement multiple choices in model
hi, I am trying to create such a kind of field in a model. The field can only take one or more values from a set of value, each seperated by such as commas. It seems that there is no built-in field type in Django. How may I implement this? Any clue is greatly appreciated. Best wishes Can-Hua Chen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Update Values to Null
I cannot figure out how to update a foreign key to a null value. Thanks. models.py group = models.ForeignKey(group, null=True, blank=True) >>> from redirect.models import * >>> Links = Link.objects.filter(group = 6) >>> Links.update(group = NULL) Traceback (most recent call last): File "", line 1, in ? NameError: name 'NULL' is not defined >>> Links.update(group = 'NULL') ... ProgrammingError: invalid input syntax for integer: "NULL" --~--~-~--~~~---~--~~ 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: imagefield write error
Ok, I figured that one out. I should be writing to within my Django project. How would I get this to work with apache permission? On Nov 17, 8:51 pm, prem1er <[EMAIL PROTECTED]> wrote: > Trying to write an image to my server for a user. I keep getting the > error 'SuspiciousOperation, Attempted access to '.../' denied. I > tried adding read write and execute permissions to this directory and > still no luck. > > from django.db import models > > class user(models.Model): > avatar = models.ImageField(upload_to='/tmp') > > def __unicode__(self): > return self.userName --~--~-~--~~~---~--~~ 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: avoid cascade delete
Thank you for all of the advice, it is nice to have so many options. I ended up using: group.link_set.clear() group.delete() On Nov 17, 7:57 am, "David Zhou" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 17, 2008 at 10:46 AM, Randy Barlow <[EMAIL PROTECTED]> wrote: > > > On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]> > > declared: > >> I have two models, links and groups. A Link has an optional foreign > >> key Group. > > >> When I delete a Group, Django by default deletes all Links that > >> referenced the Group that is being deleted. > > >> How do I avoid the default behavior that does a cascade delete. Of > >> course I could use the cursor but would am hoping there is some option > >> I don't know of for delete(). > > > I would argue this is more desireable than using clear() explicitly, > > because you don't have to know anything about your models with this > > method. Any time you have to remember to set a certain > > relationship to null, you are bound to forget about another > > relationship between your objects, and you'll get cascading delete on > > something you didn't expect, and you won't have even noticed that it > > happened! > > But that just means you'll need to explicitly set cascade on those > models you *do* want to cascade delete. And, IMO, the vast majority > of foreign key use cases do benefit from an auto cascading delete. > > For the specific Links/Groups example, personally I'd just do it with > a many to many relation. It's entirely feasible that in the future, > Links will need the ability to associate itself to multiple groups. > For now, I'd just limit a link to one group via some custom > validation. > > -- > --- > David Zhou > [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Tips for reading The Django Book in light of Django 1.0
Pretty sure forms has changed. That is, the way admin forms are created/customized. In the book there is a brief explanation of upcoming changes involving what was at that time termed "newforms." I am fairly new to Django so can't be much more specific than that. -Ryan On Nov 17, 8:11 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > On Tuesday 18 November 2008 02:38:03 am Ian Fitzpatrick wrote: > > > Can anyone recommend areas of The Django Book to skip over, or point > > out areas that are potentially irrelevant/misleading given we are now > > at Django 1.0? I am a stubborn pursuer of dead ends, so am trying to > > save myself some grief here. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
imagefield write error
Trying to write an image to my server for a user. I keep getting the error 'SuspiciousOperation, Attempted access to '.../' denied. I tried adding read write and execute permissions to this directory and still no luck. from django.db import models class user(models.Model): avatar = models.ImageField(upload_to='/tmp') def __unicode__(self): return self.userName --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Javascript and same origin policy
Hello, I'm having a problem with TinyMCE integration, but let me first describe how my current development setup looks like. Directory structure is like this: project.com |-project |--all the django stuff |-static |--static stuff including javascript and some php The thing is that the whole project.com is served by apache because of php in static dir which is there for TinyMCE file browser - TinyBrowser. The address for apache virtual host is http://localhost and I use it only for static files, for serving Django files I use Django development server in "project" directory and address http://localhost:8000. And I think that this is a problem. Whenever TinyMCE wants to open a new popup window, it's blank and I think that "same origin policy for javascript" [1] is reason for this. I've read that this should be easily solved by using document.domain javascript statement but it somehow doesn't work for me. Did anyone have similar problems or has any idea how to solve it? Thanks, Matic Žgur [1] https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript --~--~-~--~~~---~--~~ 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: Tips for reading The Django Book in light of Django 1.0
On Tuesday 18 November 2008 02:38:03 am Ian Fitzpatrick wrote: > Can anyone recommend areas of The Django Book to skip over, or point > out areas that are potentially irrelevant/misleading given we are now > at Django 1.0? I am a stubborn pursuer of dead ends, so am trying to > save myself some grief here. both the book and the current documentation are written by the same people - only difference is that the current documentation is current. So stick with that. When you have done that, and if you have nothing better to do, you could write a guide on what parts of the book are to be avoided ;-) -- regards KG http://lawgon.livejournal.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 -~--~~~~--~~--~--~---
Re: geodjango importing existing data - pointfields
> > 1,1,'Edinburgh Castle','Edinburgh','Lothian','EH1 2NG','POINT > (-3.20277400 55.95415500)' > > I've tried multiple variations on the POINT syntax (GeomFromText > etc...) but no joy. > > What am I doing wrong!!? > > Thanks in advance Have you tried the following EWKT? 'SRID=32632;POINT(-3.20277400 55.95415500);' > > > > > > > > > --~--~-~--~~~---~--~~ 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: Order of Middleware
Peter wrote: > When I run django admin and do startproject I get a settings file that > has: > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > ) > > In the global_settings.py file there is: > > # List of middleware classes to use. Order is important; in the > request phase, > # this middleware classes will be applied in the order given, and in > the > # response phase the middleware will be applied in reverse order. > > MIDDLEWARE_CLASSES = ( > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > # 'django.middleware.http.ConditionalGetMiddleware', > # 'django.middleware.gzip.GZipMiddleware', > 'django.middleware.common.CommonMiddleware', > ) > > Order is declared to be important so which is the correct order? > > I'd assume that they are installed in the correct order until you have evidence to the contrary. regards Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
validate fields in the admin as some local flavor form fields
I'm writing an app with some italian zip and vat number fields and also a province select field can i force the admin class to validate the fields like class it.forms.ITVatNumberField class it.forms.ITZipCodeField class it.forms.ITProvinceSelect ?? --~--~-~--~~~---~--~~ 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: Tips for reading The Django Book in light of Django 1.0
I do keep reading the Django book + DjangoDocs of the same topic at the moment. As first one is easier to read, the second one represents 1.0 version better. Also always check the DjangoBook's comment's - most of deprecated features are mentioned there and updated with more recent ones. Anyway, can't wait for 2nd edition of DjangoBook :) BTW, has anyone tried Python Web Development with Django http://is.gd/7Tni, which, it seems, offers the examples suitable for 1.0? good luck, J On Nov 17, 11:08 pm, Ian Fitzpatrick <[EMAIL PROTECTED]> wrote: > Hi All, > > I read through the Django Book just as the book went 1.0 a little less > than a year ago, but as these things go I got sidetracked and never > got to work on any substantial Django projects. Having forgotten a > lot of what I learned, I'm thinking to work my way back through this > book, but I know a lot has changed with the advent of Django 1.0. > > Can anyone recommend areas of The Django Book to skip over, or point > out areas that are potentially irrelevant/misleading given we are now > at Django 1.0? I am a stubborn pursuer of dead ends, so am trying to > save myself some grief here. > > Found this doc already, for what it's worth: > > http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/ > > Thanks, > Ian --~--~-~--~~~---~--~~ 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: Sessions
On Mon, Nov 17, 2008 at 10:15 AM, srn <[EMAIL PROTECTED]> wrote: > > Hi, > I'm trying to work with the session object in my application but it > doesn't work as expected. > So in my settings.py I have: > > MIDDLEWARE_CLASSES = ( >'django.middleware.gzip.GZipMiddleware', >'django.middleware.common.CommonMiddleware', >'django.contrib.sessions.middleware.SessionMiddleware', >'django.contrib.auth.middleware.AuthenticationMiddleware', >'django.middleware.doc.XViewMiddleware', >'django.middleware.transaction.TransactionMiddleware', > ) > > TEMPLATE_CONTEXT_PROCESSORS = ( >"django.core.context_processors.auth", >"django.core.context_processors.debug", >"django.core.context_processors.i18n", >"django.core.context_processors.media", >"django.core.context_processors.request", > ) > > INSTALLED_APPS = ( >'django.contrib.admin', >'django.contrib.auth', >'django.contrib.contenttypes', >'django.contrib.sessions', >'django.contrib.sites', >'mySite', > ) > > > With this I can access the 'user' object in my templates if for > example I try authenticating a user in, > but not some other variables I set mannualy with request.session > ['aVariable']='aValue'. > I use this for rendering : render_to_response('template.html', > context_instance=RequestContext(request)). > And in my templates: {{ request.session.aVariable }} > Not sure what's going on here, since I don't see anything wrong in what you have described. > And there's some other thing that's not clear to me: > From the above configuration I understand that django stores the > sessions in the database so if I want > to use file storage I'll have to add this to my settings.py : > > SESSION_ENGINE = 'django.contrib.sessions.backends.file' > SESSION_COOKIE_AGE = 7200 > SESSION_COOKIE_NAME = 'acookie' > SESSION_FILE_PATH = '/temp/django' > > but then all the "session" thing stops working. > Is there something that I should enable or disable from my settings > file? > > Are you on Windows? There's an open ticket that on Windows the file backend for sessions is not working: http://code.djangoproject.com/ticket/9084 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: Python and/or django book
> "prem1er" == prem1er <[EMAIL PROTECTED]> writes: prem1er> Just trying to figure out what the best book to purchase for a prem1er> newcomer to Django and python. Thanks for your suggestions. Check this one - http://withdjango.com/ - I got it few days ago. Sincerely, Gour -- Gour | Zagreb, Croatia | GPG key: C6E7162D pgpPso1XMsZWG.pgp Description: PGP signature
Re: django unicode error
Karen, thank You su much for the help! after executing "show create table' i realised there was a problem in my character_set+collation, changed it from latin1_swedish_ci (can't remember which charset it was)to utf8+utf8_general_ci, and now everything works like a charm. Thanks once again! all the best, JamesM On Nov 16, 5:41 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > Please tell us: > > 1 - What is the output from 'show create table' in a mysql command prompt > for the table containing this data. > 2 - Exactly what does your model's __unicode__ method look like? > 3 - When you say "When i SELECT this row from mysql, it's displayed > correctly" what do you mean exactly? If you mean when you SELECT in a mysql > shell, what OS is the shell running on? > > 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: Items tree in Django
Gustavo Picón wrote: [...] > Disclaimer: I'm the author of django-treebeard Hi Gustavo, thanks for your reply and for your django-treebeard, which I'll surely use very soon! > You can look at the treebeard benchmarks in > http://django-treebeard.googlecode.com/svn/docs/index.html#module-tbbench I see that my adjacency list is by far the worst bet as a matter of speed (I'll have to read from the tree most of the time). My only hope is that this speed overhead won't be significant for my small tree and that I can rely on my own naive code for this small project. > -tabo Thanks and regards, Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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: Items tree in Django
Hi Malcom! And thank you very much for your kind reply. Malcolm Tredinnick wrote: [...] > 500 leaves is really nothing for the database. If you want to do > anything with that size tree, you can easily just use a simple nested > hierarchy like this, pull all the rows back into Python and work with > them there. Particularly since you only have three levels in the tree: > queries on name or parent__name or parent__parent__name are as bad as > it's going to get (thereby meaning you can often filter to just the > branches you want). Sorry Malcom, but I am not a native and I am not 100% sure I got your line. When you say "a simple nested hierarchy like this", do you refer to my naive adjacency list implementation? > Regards, > Malcolm Thanks and regards, -- Fabio Natali --~--~-~--~~~---~--~~ 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: Python and/or django book
I would probably second Alley's suggestion if only because buying a book to learn a language when its already out of date is a huge pain. I made that mistake with RoR. The book Alley linked apparently (judging by the cover) is up to date with 1.0. -justin On Mon, Nov 17, 2008 at 3:33 PM, Alley <[EMAIL PROTECTED]> wrote: > > One book i have sound useful to learn django has been Python Web > Development with Django (http://www.amazon.com/gp/product/0132356139/ > ref=s9sdps_c1_14_at4-rfc_g1-frt_g1-3237_p_si5? > pf_rd_m=ATVPDKIKX0DER_rd_s=center-1_rd_r=1MF7GP27Q2DEWVDH8S5F_rd_t=101_rd_p=463383351_rd_i=507846) > > With this book I am currently in the middle of refactoring a customers > website to use django. > The chapters have been clear and concise. This book also includes real > examples that will help you with your application. > > Thanks, > Alley > > On Nov 17, 2:21 pm, prem1er <[EMAIL PROTECTED]> wrote: >> I mean, yes they are always there, but I always like a good physical >> reference. I have experience in OO languages, but not much server- >> side programming just a little ASP .Net. >> >> On Nov 17, 3:09 pm, bruno desthuilliers >> >> <[EMAIL PROTECTED]> wrote: >> > On 17 nov, 20:53, prem1er <[EMAIL PROTECTED]> wrote: >> >> > > Just trying to figure out what the best book to purchase for a >> > > newcomer to Django and python. >> >> > Depends on your background... But if you have prior experience with >> > 1/ another (preferably but not necessarily object oriented) language >> > and 2/ server-side web programming, the 'official' tutorials and docs >> > might be enough. > > > -- Justin Lilly Web Developer/Designer http://justinlilly.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 -~--~~~~--~~--~--~---
Re: Can't access the development server
On 17 nov, 14:14, Ben <[EMAIL PROTECTED]> wrote: > Hi, > > I'm completely new to python and Django, although fairly familiar with > programming and web servers in general. > > I'm struggling to get Django up and running, at the moment, and I'd be > really grateful if someone could help. > > I'm following this tutorial, after having successfully installed > Django: > > http://docs.djangoproject.com/en/dev/intro/tutorial01 > > I start the development server using: > > python manage.py runserver > > which seems to work ok: > > Validating models... > 0 errors found > > Django version 1.1 pre-alpha SVN-9479, using settings > 'prototype.settings' > Development server is running athttp://127.0.0.1:8000/ > Quit the server with CONTROL-C. > > In fact, on that server, I can telnet to the development server fine. > However, if I try to access it in my browser, nothing happens. (snip) > As far as I know there are > no firewalls between me and the server (it's a shared hosting server > with Site5). Err... If I get you right, you're not running the dev server process on your own machine ? If so, it looks like your familiarity with web servers is lacking one important point: 127.0.0.1 is the loopback IP address - IOW, it's an IP address that connect one machine *to itself* !-). Try starting the dev server with the real IP address for your server, and you should be fine, ie if your server machine IP is AAA.BBB.CCC.DDD, start the dev server with python manage.py AAA.BBB.CCC.DDD:8000 > I'm assuming that when I try to connect to port 8000 this will go > directly to the development server and apache settings etc should be > irrelevant? To make a long story short: yes. (To make it a bit longer : apache could be configured to listen to port 8000, but then you couldn't run any other process listening on this same port...) --~--~-~--~~~---~--~~ 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: Python and/or django book
On Nov 17, 7:53 pm, prem1er <[EMAIL PROTECTED]> wrote: > Just trying to figure out what the best book to purchase for a > newcomer to Django and python. Thanks for your suggestions. I always use Alex Matelli''s Python in a Nutshell (2nd edition now). You can access that and the Django book mentioned here using a Safari subscription through DevX for about $9 per month. This is a good idea to see if you like a book enough to buy it! Cheers, Peter --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Tips for reading The Django Book in light of Django 1.0
Hi All, I read through the Django Book just as the book went 1.0 a little less than a year ago, but as these things go I got sidetracked and never got to work on any substantial Django projects. Having forgotten a lot of what I learned, I'm thinking to work my way back through this book, but I know a lot has changed with the advent of Django 1.0. Can anyone recommend areas of The Django Book to skip over, or point out areas that are potentially irrelevant/misleading given we are now at Django 1.0? I am a stubborn pursuer of dead ends, so am trying to save myself some grief here. Found this doc already, for what it's worth: http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/ Thanks, Ian --~--~-~--~~~---~--~~ 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't access the development server
On Mon, Nov 17, 2008 at 8:14 AM, Ben <[EMAIL PROTECTED]> wrote: > > [snip] > > I start the development server using: > > python manage.py runserver > > which seems to work ok: > > Validating models... > 0 errors found > > Django version 1.1 pre-alpha SVN-9479, using settings > 'prototype.settings' > Development server is running at http://127.0.0.1:8000/ > Quit the server with CONTROL-C. > > [snip > As far as I know there are > no firewalls between me and the server (it's a shared hosting server > with Site5). > [snip] If you're trying to connect to the server from a machine other than the one you are running it on, you need to tell it to listen on all the machine's addresses, not just local-loopback (127.0.0.1), which is the default. Try: python manage.py runserver 0.0.0.0:8000 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: Can't access the development server
I think the issue is that your server is only listening for incoming calls from the local (host) machine. The 127.0.0.1 is a kind of magic number that just means in IP-speak 'this machine'. Try running it as python manage.py runserver www.yourhost.yourdomain.com:8000 (suitably replaced by your domain name of course). This will make it listen for connections from other machines as well. If you are using the 8000 port number, your browser should connect to it when you type in http://www.yourhost.yourdomain.com If the 8000 port is already taken (by some other server eg. apache running), you should get an error message. Then try with another port, e.g. python manage.py runserver www.yourhost.yourdomain.com:8900 and type something like http://www.yourhost.yourdomain.com:8900 into your browser. The 3000 port number you mention is almost certainly wrong. There is nothing super magic about ports: they are just a number, but client and server need to use the same... HTH Ludwig 2008/11/17 Ben <[EMAIL PROTECTED]> > > Hi, > > I'm completely new to python and Django, although fairly familiar with > programming and web servers in general. > > I'm struggling to get Django up and running, at the moment, and I'd be > really grateful if someone could help. > > I'm following this tutorial, after having successfully installed > Django: > > http://docs.djangoproject.com/en/dev/intro/tutorial01 > > I start the development server using: > > python manage.py runserver > > which seems to work ok: > > Validating models... > 0 errors found > > Django version 1.1 pre-alpha SVN-9479, using settings > 'prototype.settings' > Development server is running at http://127.0.0.1:8000/ > Quit the server with CONTROL-C. > > In fact, on that server, I can telnet to the development server fine. > However, if I try to access it in my browser, nothing happens. The > access doesn't show up on the server output and the browser fails to > connect at all. I've tried starting it on different ports, with no > success. I am able to access the thing on port 3000, although at the > moment I'm not quite sure what this is... As far as I know there are > no firewalls between me and the server (it's a shared hosting server > with Site5). > > I'm assuming that when I try to connect to port 8000 this will go > directly to the development server and apache settings etc should be > irrelevant? How about python settings? Is it possible that I've got > something misconfigured that would cause this behaviour? > > Any more information I can provide? > > Thanks in advance! > > Ben > > > > > --~--~-~--~~~---~--~~ 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't access the development server
Hi, I'm completely new to python and Django, although fairly familiar with programming and web servers in general. I'm struggling to get Django up and running, at the moment, and I'd be really grateful if someone could help. I'm following this tutorial, after having successfully installed Django: http://docs.djangoproject.com/en/dev/intro/tutorial01 I start the development server using: python manage.py runserver which seems to work ok: Validating models... 0 errors found Django version 1.1 pre-alpha SVN-9479, using settings 'prototype.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. In fact, on that server, I can telnet to the development server fine. However, if I try to access it in my browser, nothing happens. The access doesn't show up on the server output and the browser fails to connect at all. I've tried starting it on different ports, with no success. I am able to access the thing on port 3000, although at the moment I'm not quite sure what this is... As far as I know there are no firewalls between me and the server (it's a shared hosting server with Site5). I'm assuming that when I try to connect to port 8000 this will go directly to the development server and apache settings etc should be irrelevant? How about python settings? Is it possible that I've got something misconfigured that would cause this behaviour? Any more information I can provide? Thanks in advance! Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Order of Middleware
When I run django admin and do startproject I get a settings file that has: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) In the global_settings.py file there is: # List of middleware classes to use. Order is important; in the request phase, # this middleware classes will be applied in the order given, and in the # response phase the middleware will be applied in reverse order. MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', # 'django.middleware.http.ConditionalGetMiddleware', # 'django.middleware.gzip.GZipMiddleware', 'django.middleware.common.CommonMiddleware', ) Order is declared to be important so which is the correct order? --~--~-~--~~~---~--~~ 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: Python and/or django book
One book i have sound useful to learn django has been Python Web Development with Django (http://www.amazon.com/gp/product/0132356139/ ref=s9sdps_c1_14_at4-rfc_g1-frt_g1-3237_p_si5? pf_rd_m=ATVPDKIKX0DER_rd_s=center-1_rd_r=1MF7GP27Q2DEWVDH8S5F_rd_t=101_rd_p=463383351_rd_i=507846) With this book I am currently in the middle of refactoring a customers website to use django. The chapters have been clear and concise. This book also includes real examples that will help you with your application. Thanks, Alley On Nov 17, 2:21 pm, prem1er <[EMAIL PROTECTED]> wrote: > I mean, yes they are always there, but I always like a good physical > reference. I have experience in OO languages, but not much server- > side programming just a little ASP .Net. > > On Nov 17, 3:09 pm, bruno desthuilliers > > <[EMAIL PROTECTED]> wrote: > > On 17 nov, 20:53, prem1er <[EMAIL PROTECTED]> wrote: > > > > Just trying to figure out what the best book to purchase for a > > > newcomer to Django and python. > > > Depends on your background... But if you have prior experience with > > 1/ another (preferably but not necessarily object oriented) language > > and 2/ server-side web programming, the 'official' tutorials and docs > > might be enough. --~--~-~--~~~---~--~~ 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: Passing values to template
On 17 nov, 16:45, Alex Jonsson <[EMAIL PROTECTED]> wrote: > Hey guys, > > I have a news application that I would like some help with. > > My view generates a list with objects mixed with dictionaries with two > objects. (snip) > Or is there a better way of doing this other > than mixing objects and dictionaries in the list? Others already gave you practical answers, so this will be mostly a more general ('conceptual' ?) advice: don't mix heterogenous data (objects, whatever) in a list. If you have a compelling reason (ie : ordering) to have heterogenous data, wrap them all in a same 'meta' data structure. David's answer is one possible solution, but it still requires 'type' testing on each item of the collection. The (potential) problem with this solution is that each new 'type' will require a modification of the template. A more OO solution is to use another level of indirection, ie: make your view return a list of {data:whatever, template:'path/to/specifictemplate'} dict, so the template's loop doesn't have to make any test: {% for stuff in mylist %} {% with stuff.data as object %} {% include stuff.template %} {% endwith %} {% endfor %} This might be overkill for your concrete use case, and (like any solution based on indirection FWIW) has some impact on performances, but it's often worth the price when it comes to maintainance. My 2 cents... --~--~-~--~~~---~--~~ 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: Python and/or django book
2008/11/17 prem1er <[EMAIL PROTECTED]> > > I mean, yes they are always there, but I always like a good physical > reference. I have experience in OO languages, but not much server- > side programming just a little ASP .Net. > > On Nov 17, 3:09 pm, bruno desthuilliers > <[EMAIL PROTECTED]> wrote: > > On 17 nov, 20:53, prem1er <[EMAIL PROTECTED]> wrote: > > > > > Just trying to figure out what the best book to purchase for a > > > newcomer to Django and python. > > > > Depends on your background... But if you have prior experience with > > 1/ another (preferably but not necessarily object oriented) language > > and 2/ server-side web programming, the 'official' tutorials and docs > > might be enough. > > > For python is recommended http://diveintopython.org/ and about django the book is ok for start, always remember IRC channel #django or #python. Best regards, -- [b]question = (to) ? be : !be; .[/b] --~--~-~--~~~---~--~~ 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: Python and/or django book
I mean, yes they are always there, but I always like a good physical reference. I have experience in OO languages, but not much server- side programming just a little ASP .Net. On Nov 17, 3:09 pm, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 17 nov, 20:53, prem1er <[EMAIL PROTECTED]> wrote: > > > Just trying to figure out what the best book to purchase for a > > newcomer to Django and python. > > Depends on your background... But if you have prior experience with > 1/ another (preferably but not necessarily object oriented) language > and 2/ server-side web programming, the 'official' tutorials and docs > might be enough. --~--~-~--~~~---~--~~ 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: Python and/or django book
On 17 nov, 20:53, prem1er <[EMAIL PROTECTED]> wrote: > Just trying to figure out what the best book to purchase for a > newcomer to Django and python. Depends on your background... But if you have prior experience with 1/ another (preferably but not necessarily object oriented) language and 2/ server-side web programming, the 'official' tutorials and docs might be enough. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Python and/or django book
Just trying to figure out what the best book to purchase for a newcomer to Django and python. Thanks for your suggestions. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Views triggering twice
> you've used the value "#fff", that will be interpreted by the browser as > a reference to the current page (#fff being an anchor, and not passed to > the server). Ergo, a second request is made. Wow, thanks. Just reading through your step by step taught me some things I didn't know :) > The moral is (again) "don't put style elements in your HTML", I guess. > :-) Yeah, I'm not sure why I was doing that (in fact, I have the color issued as part of the site-wide CSS), and I suspect I would have continued to overlook that over and over and over again. Erg ... but thanks. -J --~--~-~--~~~---~--~~ 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: link to ForeignKey in Admin's change list page
On Nov 17, 4:42 pm, Paolo Corti <[EMAIL PROTECTED]> wrote: > Hi > maybe this is trivial, but i can't find a way to get it (and from what > i can see it seems not possible): > > my model: > > class Project(models.Model): > name = models.CharField('name', max_length=255) > > #relationship > projectowner = models.ForeignKey(Person) > > in admin.py: > > class ProjectAdmin(admin.ModelAdmin): > model = Project > list_display = ['name', ..., 'projectowner'] > list_display_links = ['name'] > list_filter = ['name', 'projectowner'] > > list_display_links will put a link at the 'name' field to the > Project's page, like this one:http://localhost:8000/admin/projects/project/1/ > > is there a way to the the same result for the foreign key? > > I would like that at the 'projectowner' field there would be a link > like this one:http://localhost:8000/admin/projects/person/2/ > > thanks! Your best bet would be to define a method on the Project model that returns a snippet of HTML with the link and text. You need to set allow_tags=True. def projectowner_link(self): return u'%s' % (self.projectowner.id, self.projectowner.name) projectowner_link.allow_tags = True list_display = ['name', ..., 'projectowner_link'] -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Setting Up Django on Vista and Creating a Database
The other thing that comes to mind is, have you installed the MySQLdb python library? If you want to connect to a database from a Python app, you must also install a library that bridges Python and the database. (I apologize in advance if you've already done so). ---Peter On 11/17/08, Karen Tracey <[EMAIL PROTECTED]> wrote: > On Mon, Nov 17, 2008 at 3:13 AM, John Antony <[EMAIL PROTECTED]> wrote: > >> >> I have currently created a database with the following details: >> DATABASE_ENGINE = 'mysql' >> DATABASE_NAME = 'myforum' >> DATABASE_USER = 'root' >> DATABASE_PASSWORD = 'myforum' >> DATABASE_HOST = 'localhost' >> DATABASE_PORT = '' >> > > Is this a cut and paste from your actual setting files? Because that > setting for DATABASE_ENGINE -- all lowercase mysql -- is correct. > > >> I used phpMyadmin to create the database >> >> I have updated C:\projects\myforum\settings.py in the similar >> fashion >> >> However when i run the the following command i get: >> >> C:\projects\myforum>python manage.py runserver >> Validating models... >> Unhandled exception in thread started by > 0x027CC670> >> Traceback (most recent call last): >> File "C:\Python26\Lib\site-packages\django\core\management\commands >> \runserver. >> py", line 48, in inner_run >>self.validate(display_num_errors=True) >> File "C:\Python26\Lib\site-packages\django\core\management\base.py", >> line 122, >> in validate >>num_errors = get_validation_errors(s, app) >> File "C:\Python26\Lib\site-packages\django\core\management >> \validation.py", lin >> e 22, in get_validation_errors >>from django.db import models, connection >> File "C:\Python26\Lib\site-packages\django\db\__init__.py", line 34, >> in > e> >>(settings.DATABASE_ENGINE, ", ".join(map(repr, >> available_backends)), e_user) >> >> django.core.exceptions.ImproperlyConfigured: 'MySQL' isn't an >> available database >> backend. Available options are: 'dummy', 'mysql', 'oracle', >> 'postgresql', 'post >> gresql_psycopg2', 'sqlite3' >> Error was: No module named MySQL.base >> > > Whereas what this is saying is that you have 'MySQL' set as your > DATABASE_ENGINE, and that is not correct. Case matters. What you have in > your settings file needs to be all lower case for the DATABASE_ENGINE > setting. > > 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: Items tree in Django
Disclaimer: I'm the author of django-treebeard > I am glad to hear that the naive way could possibly fit my 3-levels > tree, or at least that it deserves a try. I'll have some benchmarks as > you suggest. You can look at the treebeard benchmarks in http://django-treebeard.googlecode.com/svn/docs/index.html#module-tbbench I'll take as an example the results of reading branches in postgresql 8.3 in unordered trees: - Nested sets:5840ms - Materialized Path: 7132ms - Adjacency List:50682ms So as you can see, your approach (adjacency list) is by far the slowest. The only advantage of the adjacency list model is for trees that are mostly write-only, look at the benchmark results for insertions in an ordered tree with transactions (the optimal use for AL trees): - Nested sets: 10941ms - Materialized path: 3942ms - Adjacency List: 896ms So the usual recommendation is: - if you're going to insert a lot more than you read, use adjacency list - if, as is the most common case, you're going to read your tree more than you insert nodes, use nested sets or materialized path -tabo --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Getting the most comment for integer id object
Hi, I have a integer id model and I want to get the most comment (django.contrib.comments) for the model. I use postgres and I got the error about comparing integer(my model) and text (comment object_pk). Someone have any solution? 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: psycopg2 Visual Studio installation error on XP
Hi DJ, Psycopg2 has a C extension wrapped by Python. That C extension must be compiled with the same compiler used to compile the Python compiler itself. This is not a Django issue, this is a psycopg issue. You should ask for assistance on the psycopg mailing list, they'll be better able to help you. You should also look around for pre-compiled binaries of psycopg2 for Windows, as the packagers will have taken this compiler mismatch issue into account. ---Peter On 11/17/08, dj <[EMAIL PROTECTED]> wrote: > > Hello All, > > I am django novice and i am very, very ,very, very green. > > I am trying to setup the PostgresSQL database with the psycopg2 > library. I downloaded the psycopg2-2.0.8.tar file. > Opened the tar with Winzip and installed the library from the command > line using python setup.py. I got this really strange error message. > > error: Python built with Visual Studio 2003; extensions must be built > with a complier than can generate compatiable binaries. Visual Studio > 2003 was not found on this system. If you have Cygwin installed, you > can tru compiling with MingW32, by passing "-c mingw32 to setup.py" > > I am not using Visual Studio for any of my development, I am using the > python. > Do I need to install Cywgin or is there a work around ? > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Running multiple sites
Noob question here. My web host allows one long running process per account for the plan I am on. So I can run one django process. The setup is using fastcgi if that matters (we don't have control over this--we are assigned a fastcgi port or something and this is the command we use to run our django process: django-admin.py runfcgi method=threaded host=127.0.0.1 port= pidfile=$PIDFILE, and I export DJANGO_SETTINGS_MODULE in my environment). So, I am wondering if I can run multiple django websites given this setup? I have read a little about the django.contrib.sites app, but am not clear if this would help in my situation. Or do I have to have one instance of "django-admin.py" running per website? Thanks for any clarification. -Chris PS I found this after some googling, but not sure it is still relevant/applicable. It's an old post: http://effbot.org/zone/django-multihost.htm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
psycopg2 Visual Studio installation error on XP
Hello All, I am django novice and i am very, very ,very, very green. I am trying to setup the PostgresSQL database with the psycopg2 library. I downloaded the psycopg2-2.0.8.tar file. Opened the tar with Winzip and installed the library from the command line using python setup.py. I got this really strange error message. error: Python built with Visual Studio 2003; extensions must be built with a complier than can generate compatiable binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can tru compiling with MingW32, by passing "-c mingw32 to setup.py" I am not using Visual Studio for any of my development, I am using the python. Do I need to install Cywgin or is there a work around ? --~--~-~--~~~---~--~~ 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: automatically save latitude and longitude of the address.
I can see several causes here why you're not getting the desired result. The biggest one is you declare fnclatitude as taking a single argument, called location - but when you call the function from your save() method you're passing no arguments to it. Second, you're returning element 3 (which is longitude) and calling it latitude. There are two possible ways to rewrite the code to work: 1: (bring the call to Google into the save() method, which is perfectly acceptable if this is the only model that requires geocoding) Code at: http://dpaste.com/91472/ 2: (keep it seperate, which is more useful if other models in your system will require geocoding. I'd definitely rename the function though because it's doing more than just returning latitude at that point.) Code at: http://dpaste.com/91483/ Adam On Mon, Nov 17, 2008 at 3:19 AM, please smile <[EMAIL PROTECTED]> wrote: > HI All, > > How can I add automatically latitude and longitude of the physical address. > for exp if, fnclatitude('Chennai') returns latitude and longitude of > chenai. > > Please help > > This is my model (models.py) > > def fnclatitude(location): > key = settings.GOOGLE_KEY > output = "csv" > location = urllib.quote_plus(location) > request = "http://maps.google.com/maps/geo?q=%s=%s=%s; % > (location, output, key) > data = urllib.urlopen(request).read() > dlist = data.split(',') > if dlist[0] == '200': > return "%s" % (dlist[3]) > #return "%s, %s" % (dlist[2], dlist[3]) > else: > return '' > > class Business(models.Model): > physicaladdr_street1 = models.CharField("Street 1", max_length=25) > modified_date = models.DateTimeField() > latitude = models.DecimalField(max_digits=11, decimal_places=6, > null=True, blank=True) > longitude = models.DecimalField(max_digits=11, decimal_places=6, > null=True, blank=True) > > > > def save(self, force_insert=False, force_update=False): > self.modified_date = datetime.datetime.now() > self.latitude = fnclatitude() > # here I need to automatically add latitude and longitude of the > physical address. > # for exp if, fnclatitude('Chennai') returns latitude and > longitude of chenai. > super(Business, self).save(force_insert, force_update) > > > > > --~--~-~--~~~---~--~~ 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: required checkboxes issue
> Without looking at any docs or code, it seems you have a mismatch in the > number of values expected by the form (one) and what will be returned by the > widget (multiple). Are you sure you don't really want to be using a > MultipleChoiceField? > > Karen That appears to have done it. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
required checkboxes issue
I have a problem with one of my forms in regard to a series of checkboxes. They are displaying properly on the page with the right values in the checkboxes. I have this set to REQUIRED in my form. However, whether I check one box, or check them all, I still get this message: "Select a valid choice. That choice is not one of the available choices." My forms.py code for this form field is as follows: Designations_Choices = ( ('1','1'), ('2','2'), ('3','3'), ('4','4'), ) Designations = forms.ChoiceField (choices=Designations_Choices,required=True, label = "Gift Designations", widget=forms.CheckboxSelectMultiple(attrs= {'class':'designations'})) Any ideas why this won't validate correctly even when 1/4 or 4/4 boxes are selected? --~--~-~--~~~---~--~~ 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: required checkboxes issue
On Mon, Nov 17, 2008 at 11:37 AM, Bobby Roberts <[EMAIL PROTECTED]> wrote: > > I have a problem with one of my forms in regard to a series of > checkboxes. They are displaying properly on the page with the right > values in the checkboxes. I have this set to REQUIRED in my form. > However, whether I check one box, or check them all, I still get this > message: > > > "Select a valid choice. That choice is not one of the available > choices." > > > My forms.py code for this form field is as follows: > > Designations_Choices = ( >('1','1'), >('2','2'), >('3','3'), >('4','4'), > ) > >Designations = forms.ChoiceField > (choices=Designations_Choices,required=True, label = "Gift > Designations", widget=forms.CheckboxSelectMultiple(attrs= > {'class':'designations'})) > > > Any ideas why this won't validate correctly even when 1/4 or 4/4 boxes > are selected? > > Without looking at any docs or code, it seems you have a mismatch in the number of values expected by the form (one) and what will be returned by the widget (multiple). Are you sure you don't really want to be using a MultipleChoiceField? 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: Passing values to template
Thanks to both of you! David's suggestion fits my application perfectly. Again, big 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 -~--~~~~--~~--~--~---
link to ForeignKey in Admin's change list page
Hi maybe this is trivial, but i can't find a way to get it (and from what i can see it seems not possible): my model: class Project(models.Model): name = models.CharField('name', max_length=255) #relationship projectowner = models.ForeignKey(Person) in admin.py: class ProjectAdmin(admin.ModelAdmin): model = Project list_display = ['name', ..., 'projectowner'] list_display_links = ['name'] list_filter = ['name', 'projectowner'] list_display_links will put a link at the 'name' field to the Project's page, like this one: http://localhost:8000/admin/projects/project/1/ is there a way to the the same result for the foreign key? I would like that at the 'projectowner' field there would be a link like this one: http://localhost:8000/admin/projects/person/2/ 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: Frustration with custom Inline forms
Thank you thank you thank you! I knew I was doing something simple wrong. :) I've been enjoying my experience using Django so far, but one thing I have noticed is that the error messages (or in this case lack of error messages) can be frustrating. It sometimes takes me quite a while to figure out what caused an exception especially if there are no line numbers of my own code. In this case, it's actually the Python syntax and I'm not sure what Django could do if your syntax is wrong, but I sure spent a while tracking this down Cheers, Ben --~--~-~--~~~---~--~~ 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: Passing values to template
Hi Alex, > I have a news application that I would like some help with. > > My view generates a list with objects mixed with dictionaries with two > objects. Then in my template, I want to loop through this list and > output each value. However, when it encounters a dictionary in the > list I want it to loop through it separately with a different > formatting. > > This is an example of a dict passed to my template: > > http://dpaste.com/91439/ > > So the question is: how do I check (in the template) if the object > that is being run in the for loop is a dictionary, so that I in turn > can run a for loop on it? Or is there a better way of doing this other > than mixing objects and dictionaries in the list? You could create a relatively simple custom template tag that knows how to render an element from your list. The templatetag is Python code, so you would be able to test for the type of the element being rendered. -RD --~--~-~--~~~---~--~~ 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: Serializing models to JSON
Hi, > In my application I'm trying to serialize the following model to json: > > class Node(models.Model): > name = models.CharField(db_column="NAME", > max_length=30, > db_index=True) > description = models.CharField(db_column="DESCRIPTION", > db_index=True, > max_length=255) > registrationDate=models.DateField(db_column="REGISTRATION_DATE", > db_index=True) > parentNodeObject = models.ForeignKey("self", db_column="PARENT", > related_name="parent_fk") > > rootNodeObject= models.ForeignKey("self", db_column="ROOT", > related_name="root_fk") > > Before I serialize the instances to json I retreived all the nodes: > models.Node.objects.select_related > ('parentNodeObject','rootNodeObject') > The problem is that for all the parentNodeObjects and rootNodeObjects > retrieved from DB, in the json string appears only the model's id. > I don't know if this is normal or not but I'd like to have access to > all the properties of all the objects retrieved, > even if the final json string is huge. This is normal behaviour -- the built-in model serializers traverse only over local fields of the model and not over foreign keys. > Is this possible? Yes. In two ways: 1. If you are willing to write your own serializer, take a look at the SERIALIZATION_MODULES setting and the interface you will need to implement. To implement the interface, you would normally extend the abstract base class: django.core.serializers.Serializer defined in django/core/serializers/base.py 2. Create a list of dictionaries for your result set. Where each list element represents one row of data and each row contains a dictionary of the fields you are interested in. Then use django.utils.simplejson.dumps to convert that list to a JSON string. -RD --~--~-~--~~~---~--~~ 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: Passing values to template
On Mon, Nov 17, 2008 at 10:45 AM, Alex Jonsson <[EMAIL PROTECTED]> wrote: > So the question is: how do I check (in the template) if the object > that is being run in the for loop is a dictionary, so that I in turn > can run a for loop on it? Or is there a better way of doing this other > than mixing objects and dictionaries in the list? What about making it a list of tuples, and including a type? {'articles': [('single', ), ('multiple', {1: , 2: }), ('single', )]} Then you could just do a {% for type, article in articles %}, and have a conditional on the type. -- --- David Zhou [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Frustration with custom Inline forms
On Nov 17, 2:01 pm, Ben Gerdemann <[EMAIL PROTECTED]> wrote: > Ok, so I just noticed that the a55_id field which is the primary key, > was declared as an IntegerField instead of an AutoField which is why > it was showing up on the inline form, but I still can't get any of the > other fields excluded from the inline form so the problem is still > there. > > Also, if it helps for understanding Pais = Parents and Visitas = > Visits in Portuguese. > > Thanks again for any and all help. > > Cheers, > Ben The only thing I can see in your code that might cause problems is the value for exclude: exclude = ('a55_id') This is not what you think it is. It's not a single-element tuple. It is actually a single string, which will be treated as if it were a list of characters ie ['a', '5', '5', '_', 'i', 'd']. Naturally, the admin doesn't recognise this as a field, so won't exclude it. I think what you meant was exclude = ('a55_id',) - note the extra comma, which is how you define a single-element tuple. There's no reason you can't have custom forms in an inline formset - I do this all the time, using very similar code to the above. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Passing values to template
Hey guys, I have a news application that I would like some help with. My view generates a list with objects mixed with dictionaries with two objects. Then in my template, I want to loop through this list and output each value. However, when it encounters a dictionary in the list I want it to loop through it separately with a different formatting. This is an example of a dict passed to my template: http://dpaste.com/91439/ So the question is: how do I check (in the template) if the object that is being run in the for loop is a dictionary, so that I in turn can run a for loop on it? Or is there a better way of doing this other than mixing objects and dictionaries in the list? --~--~-~--~~~---~--~~ 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: avoid cascade delete
On Mon, Nov 17, 2008 at 10:46 AM, Randy Barlow <[EMAIL PROTECTED]> wrote: > > On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]> > declared: >> I have two models, links and groups. A Link has an optional foreign >> key Group. >> >> When I delete a Group, Django by default deletes all Links that >> referenced the Group that is being deleted. >> >> How do I avoid the default behavior that does a cascade delete. Of >> course I could use the cursor but would am hoping there is some option >> I don't know of for delete(). > > I would argue this is more desireable than using clear() explicitly, > because you don't have to know anything about your models with this > method. Any time you have to remember to set a certain > relationship to null, you are bound to forget about another > relationship between your objects, and you'll get cascading delete on > something you didn't expect, and you won't have even noticed that it > happened! But that just means you'll need to explicitly set cascade on those models you *do* want to cascade delete. And, IMO, the vast majority of foreign key use cases do benefit from an auto cascading delete. For the specific Links/Groups example, personally I'd just do it with a many to many relation. It's entirely feasible that in the future, Links will need the ability to associate itself to multiple groups. For now, I'd just limit a link to one group via some custom validation. -- --- David Zhou [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Serializing models to JSON
Hi, In my application I'm trying to serialize the following model to json: class Node(models.Model): name = models.CharField(db_column="NAME", max_length=30, db_index=True) description = models.CharField(db_column="DESCRIPTION", db_index=True, max_length=255) registrationDate=models.DateField(db_column="REGISTRATION_DATE", db_index=True) parentNodeObject = models.ForeignKey("self", db_column="PARENT", related_name="parent_fk") rootNodeObject= models.ForeignKey("self", db_column="ROOT", related_name="root_fk") Before I serialize the instances to json I retreived all the nodes: models.Node.objects.select_related ('parentNodeObject','rootNodeObject') The problem is that for all the parentNodeObjects and rootNodeObjects retrieved from DB, in the json string appears only the model's id. I don't know if this is normal or not but I'd like to have access to all the properties of all the objects retrieved, even if the final json string is huge. Is this possible? I'll appreciate any thoughts regarding this subject. Thank you, srn --~--~-~--~~~---~--~~ 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: avoid cascade delete
On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]> declared: > I have two models, links and groups. A Link has an optional foreign > key Group. > > When I delete a Group, Django by default deletes all Links that > referenced the Group that is being deleted. > > How do I avoid the default behavior that does a cascade delete. Of > course I could use the cursor but would am hoping there is some option > I don't know of for delete(). Funny that you ask this question, because I just spent two days undoing the Django cascading delete on my end. If you look at the delete() method in the Django code, it only makes three calls. The first two gather a list of all the objects that Django wants to delete. Basically, I wrote a new delete() method that iterates through those objects, finds all the references to the object that you want to delete and sets them to null. It then saves them. After this, you need to run those first two lines again to regather the objects you want to delete (this time, only the one object should appear), and then you can finally delete them. I would argue this is more desireable than using clear() explicitly, because you don't have to know anything about your models with this method. Any time you have to remember to set a certain relationship to null, you are bound to forget about another relationship between your objects, and you'll get cascading delete on something you didn't expect, and you won't have even noticed that it happened! -- Randy Barlow http://electronsweatshop.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 -~--~~~~--~~--~--~---
Re: Frustration with custom Inline forms
There's a problem with the exclude statements above, you've got tuple- trouble, missing trailing commas: exclude = ('a55_id') should be ('a55_id',) or ['a55_id'] easy mistake, search for "tuple" in this group and you'll see you have company. Kip. On Nov 17, 2:01 pm, Ben Gerdemann <[EMAIL PROTECTED]> wrote: > Ok, so I just noticed that the a55_id field which is the primary key, > was declared as an IntegerField instead of an AutoField which is why > it was showing up on the inline form, but I still can't get any of the > other fields excluded from the inline form so the problem is still > there. > > Also, if it helps for understanding Pais = Parents and Visitas = > Visits in Portuguese. > > Thanks again for any and all help. > > Cheers, > Ben --~--~-~--~~~---~--~~ 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: admin site problem
On Nov 17, 12:41 pm, Vicky <[EMAIL PROTECTED]> wrote: > I found the problem.. I used : > > def __unicode__(self): > > function in my model. so it a can return only sting values. So if i > need to return a column of type integer or contains a foreign key how > should i do it?? > return u'%s' % self.my_integer_attribute or return unicode(self.my_integer_attribute) This is fairly basic Python. I'd recommend going through a Python tutorial if you don't know any of this: www.diveintopython.org is a great one. For foreign keys, Django uses the unicode of the related model anyway. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom form/formset for edit inline
I'm having exactly the same problem which I posted about here http://groups.google.com/group/django-users/browse_thread/thread/bb4c792f13b2eceb# Have you figured out how to do this? Yours is the third message I've read by someone trying to customize an inline form without any solution. I'm beginning to think this probably isn't possible in the admin interface... :( --~--~-~--~~~---~--~~ 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: admin site problem
You need to turn it into a string, this will do it: def __unicode(self): return '%s' % self.integer_column On Nov 17, 12:41 pm, Vicky <[EMAIL PROTECTED]> wrote: > I found the problem.. I used : > > def __unicode__(self): > > function in my model. so it a can return only sting values. So if i > need to return a column of type integer or contains a foreign key how > should i do it?? > > On Nov 17, 4:28 pm, Lars Stavholm <[EMAIL PROTECTED]> wrote: > > > Vicky wrote: > > > I tried to add some values to my table from admin site. Table has 3 > > > columns one of integer type and other two of string type. When i tried > > > to save my entries it giving an error as: > > > > "coercing to Unicode: need string or buffer, int found" > > > > How to solve it? > > > That all depends on what your model looks like? > > /L --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sessions
Hi, I'm trying to work with the session object in my application but it doesn't work as expected. So in my settings.py I have: MIDDLEWARE_CLASSES = ( 'django.middleware.gzip.GZipMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.middleware.transaction.TransactionMiddleware', ) TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.request", ) INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'mySite', ) With this I can access the 'user' object in my templates if for example I try authenticating a user in, but not some other variables I set mannualy with request.session ['aVariable']='aValue'. I use this for rendering : render_to_response('template.html', context_instance=RequestContext(request)). And in my templates: {{ request.session.aVariable }} And there's some other thing that's not clear to me: >From the above configuration I understand that django stores the sessions in the database so if I want to use file storage I'll have to add this to my settings.py : SESSION_ENGINE = 'django.contrib.sessions.backends.file' SESSION_COOKIE_AGE = 7200 SESSION_COOKIE_NAME = 'acookie' SESSION_FILE_PATH = '/temp/django' but then all the "session" thing stops working. Is there something that I should enable or disable from my settings file? Thank you, srn --~--~-~--~~~---~--~~ 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: Custom Inline Forms with InlineFormsets
I'm having a similar problem that I posted about here: http://groups.google.com/group/django-users/browse_thread/thread/bb4c792f13b2eceb# Did you find a solution that works for you? Sorry, I couldn't figure out from your post exactly what you did. I tried using inlineformset_factory() like you described, but I couldn't get it to work. Are you working inside the admin interface? Perhaps that is my problem Cheers, Ben On Nov 10, 6:49 pm, John Boxall <[EMAIL PROTECTED]> wrote: > I take it back. > > I over thought it - > > Instead of using a custominlineform model just pass the parameters > directly to inlineformset_factory as per it's spec: > def inlineformset_factory(parent_model, model, form=ModelForm, > formset=BaseInlineFormSet, fk_name=None, > fields=None, exclude=None, > extra=3, can_order=False, can_delete=True, > max_num=0, > formfield_callback=lambda f: > f.formfield()): > > On Nov 10, 12:47 pm, John Boxall <[EMAIL PROTECTED]> wrote: > > > Heyo Django Users, > > > I'm in a bit of a pickle with InlineFormsets - > > > I'm following the example at the Django > > Docs:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-i... > > > I've got two models: > > > > class Author(models.Model): > > name = models.CharField(max_length=100) > > > class Book(models.Model): > > author = models.ForeignKey(Author) > > title = models.CharField(max_length=100) > > description = models.CharField(max_length=255) > > > > > And I want to have aninlineformsets to edit authors & booksinline. > > > What I want to do is just show the title field of the Book so I have > > a custom ModelForm for that: > > > > > class BookModelForm(forms.ModelForm): > > class Meta: > > model = Book > > fields = ('title',) > > > > > Everything looks good, I'm all ready to construct my > > inlinemodelformset using inlineformset_factory... > > > > from django.forms.models import inlineformset_factory > > # ??? > > BookFormSet = inlineformset_factory(Author, Book) > > > > > And doh! inlineformset_factory doesn't seem to want to let me set the > > form for > > theinlinemodel.http://code.djangoproject.com/browser/django/trunk/django/forms/model... > > > Anyone have any luck with this? > > > Thanks, > > > John --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
geodjango importing existing data - pointfields
I have a legacy database that consists of a number of addresses with pre-geocoded WKT points. I'm trying to import these directly into a GeoDjango setup - postgres db, either by csv or psql csv copy - doesn't matter which. First problem is I get this error 'new row for relation "site_locations" violates check constraint "enforce_srid_point" - if I delete that constraint it imports but then I get a whole heap of new problems displaying that data on a map (tranforming SRID etc to work on a commercial map provider). I'm guessing Geodjango tags the srid to the pointfield when saving a new location in the admin, which must mean my syntax for the WKT imports is missing that vital info to make it all work sweetly: 1,1,'Edinburgh Castle','Edinburgh','Lothian','EH1 2NG','POINT (-3.20277400 55.95415500)' I've tried multiple variations on the POINT syntax (GeomFromText etc...) but no joy. What am I doing wrong!!? Thanks in advance --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Frustration with custom Inline forms
Ok, so I just noticed that the a55_id field which is the primary key, was declared as an IntegerField instead of an AutoField which is why it was showing up on the inline form, but I still can't get any of the other fields excluded from the inline form so the problem is still there. Also, if it helps for understanding Pais = Parents and Visitas = Visits in Portuguese. Thanks again for any and all help. Cheers, Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Is there a place from where I can get the completed code for the Django 4-part tutorial?
Is there a place where I can get the app completed as part of http://docs.djangoproject.com/en/dev/intro/tutorial04/#intro-tutorial04 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Frustration with custom Inline forms
I'm trying to customize the inline forms of a model that are displayed when I'm editing it's parent, but I can't get anything to work! Can someone help? First, here are my models: class T22Pais(models.Model): a22_id = models.AutoField(primary_key=True) a22_nome_1 = models.CharField("Nome Responsavel #1",max_length=255) class T55Visitas(models.Model): a55_id = models.IntegerField(primary_key=True) a55_visita_agendada = models.DateTimeField(null=True, blank=True) a22 = models.ForeignKey(T22Pais,verbose_name="Pais") The documentation says "The InlineModelAdmin class is a subclass of ModelAdmin so it inherits all the same functionality as well as some of its own," so first I tried this: class T22PaisAdmin(admin.ModelAdmin): inlines = [T55VisitasInline] class T55VisitasInline(admin.StackedInline): exclude = ('a55_id') model = T55Visitas but nothing changes. I tried a couple variations of the name without and without quotes and adding the model hierarchy exclude= ('T55Visitas.a55_id') but nothing worked. Then I noticed that the documentation refers to form and formset fields in InlineModelAdmin. The documentation isn't very clear how to use these, but I tried the following things and nothing had any effect: the inline form was always rendered with all of its fields: class T55VisitasInlineForm(forms.ModelForm): class Meta: model = T55Visitas exclude = ('a55_id') class T55VisitasInline(admin.StackedInline): model = T55Visitas form = T55VisitasInlineForm tried adding a formset: class T55VisitasInline(admin.StackedInline): model = T55Visitas form = T55VisitasInlineForm formset = inlineformset_factory( T22Pais, T55Visitas, exclude = ('a55_id') ) adding the same form back into the formset even though I'm already setting T55VisitasInline.form, but no dice. :( class T55VisitasInline(admin.StackedInline): model = T55Visitas form = T55VisitasInlineForm formset = inlineformset_factory( T22Pais, T55Visitas, form = T55VisitasInlineForm, exclude = ('a55_id') ) How can I get this to work??? Grrr... Ideally, I'd like to have a fully custom inline form using "fieldsets," but for now I'll settle for just hiding fields. Cheers, Ben --~--~-~--~~~---~--~~ 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: admin site problem
I found the problem.. I used : def __unicode__(self): function in my model. so it a can return only sting values. So if i need to return a column of type integer or contains a foreign key how should i do it?? On Nov 17, 4:28 pm, Lars Stavholm <[EMAIL PROTECTED]> wrote: > Vicky wrote: > > I tried to add some values to my table from admin site. Table has 3 > > columns one of integer type and other two of string type. When i tried > > to save my entries it giving an error as: > > > "coercing to Unicode: need string or buffer, int found" > > > How to solve it? > > That all depends on what your model looks like? > /L --~--~-~--~~~---~--~~ 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: ManyToMany and save method
On Mon, 2008-11-17 at 12:49 +0100, Marco Minutoli wrote: > I have this model: > > class Ticket(models.Model): > ## ForeignKey > project = models.ForeignKey ( > 'Project', > null=True, > blank=True, > verbose_name="Project", > ) > submitter = models.ForeignKey ( > User, > related_name="submitter", > verbose_name="Submitter", > ) > assigned_to = models.ManyToManyField ( > User, > blank=True, > null=True, > verbose_name="Assigned to", > ) > > > I would like to send an email to all 'assigned_to' when a ticket is > created. So i've override the Ticket Model's save method: > > def save(self): > super(Ticket, self).save() > print self.assigned_to.all() > print self.submitter.username > > But the "self.assigned_to.all()" is always empty, whilst > self.submitter.username is correct. Because something cannot be included as part of a many-to-many relation until is has a primary key value -- which means it has to be saved first. So the new Ticket instance must be saved and *then* the many-to-many saving happens. That is, after Ticket.save() has returned. At some point in the future we'll most likely add a signal that you can use to process things when a many-to-many is updated, but at the moment, the way to do this is to manually trigger the emailing wherever the many-to-many is updated (in your view code). It's not a perfect solution, but it works. Regards, Malcolm --~--~-~--~~~---~--~~ 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: ManyToMany and save method
Related objects save after `host`. So insertion into M2M table happens after save method of host object has executed. In your example - after `Ticket.save` On Mon, Nov 17, 2008 at 14:49, Marco Minutoli <[EMAIL PROTECTED]>wrote: > > I have this model: > > class Ticket(models.Model): >## ForeignKey >project = models.ForeignKey ( >'Project', >null=True, >blank=True, >verbose_name="Project", >) >submitter = models.ForeignKey ( >User, >related_name="submitter", >verbose_name="Submitter", >) >assigned_to = models.ManyToManyField ( >User, >blank=True, >null=True, >verbose_name="Assigned to", >) > > > I would like to send an email to all 'assigned_to' when a ticket is > created. So i've override the Ticket Model's save method: > >def save(self): >super(Ticket, self).save() >print self.assigned_to.all() >print self.submitter.username > > But the "self.assigned_to.all()" is always empty, whilst > self.submitter.username is correct. > P.S The assigned_to is correctly insert into the db. > Why? > > Sorry for my bad English.. > Marco. > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ManyToMany and save method
I have this model: class Ticket(models.Model): ## ForeignKey project = models.ForeignKey ( 'Project', null=True, blank=True, verbose_name="Project", ) submitter = models.ForeignKey ( User, related_name="submitter", verbose_name="Submitter", ) assigned_to = models.ManyToManyField ( User, blank=True, null=True, verbose_name="Assigned to", ) I would like to send an email to all 'assigned_to' when a ticket is created. So i've override the Ticket Model's save method: def save(self): super(Ticket, self).save() print self.assigned_to.all() print self.submitter.username But the "self.assigned_to.all()" is always empty, whilst self.submitter.username is correct. P.S The assigned_to is correctly insert into the db. Why? Sorry for my bad English.. Marco. --~--~-~--~~~---~--~~ 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: Setting Up Django on Vista and Creating a Database
On Mon, Nov 17, 2008 at 3:13 AM, John Antony <[EMAIL PROTECTED]> wrote: > > I have currently created a database with the following details: > DATABASE_ENGINE = 'mysql' > DATABASE_NAME = 'myforum' > DATABASE_USER = 'root' > DATABASE_PASSWORD = 'myforum' > DATABASE_HOST = 'localhost' > DATABASE_PORT = '' > Is this a cut and paste from your actual setting files? Because that setting for DATABASE_ENGINE -- all lowercase mysql -- is correct. > I used phpMyadmin to create the database > > I have updated C:\projects\myforum\settings.py in the similar > fashion > > However when i run the the following command i get: > > C:\projects\myforum>python manage.py runserver > Validating models... > Unhandled exception in thread started by 0x027CC670> > Traceback (most recent call last): > File "C:\Python26\Lib\site-packages\django\core\management\commands > \runserver. > py", line 48, in inner_run >self.validate(display_num_errors=True) > File "C:\Python26\Lib\site-packages\django\core\management\base.py", > line 122, > in validate >num_errors = get_validation_errors(s, app) > File "C:\Python26\Lib\site-packages\django\core\management > \validation.py", lin > e 22, in get_validation_errors >from django.db import models, connection > File "C:\Python26\Lib\site-packages\django\db\__init__.py", line 34, > in e> >(settings.DATABASE_ENGINE, ", ".join(map(repr, > available_backends)), e_user) > > django.core.exceptions.ImproperlyConfigured: 'MySQL' isn't an > available database > backend. Available options are: 'dummy', 'mysql', 'oracle', > 'postgresql', 'post > gresql_psycopg2', 'sqlite3' > Error was: No module named MySQL.base > Whereas what this is saying is that you have 'MySQL' set as your DATABASE_ENGINE, and that is not correct. Case matters. What you have in your settings file needs to be all lower case for the DATABASE_ENGINE setting. 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: admin site problem
Vicky wrote: > I tried to add some values to my table from admin site. Table has 3 > columns one of integer type and other two of string type. When i tried > to save my entries it giving an error as: > > "coercing to Unicode: need string or buffer, int found" > > How to solve it? That all depends on what your model looks like? /L --~--~-~--~~~---~--~~ 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: Items tree in Django
On Mon, 2008-11-17 at 11:46 +0100, Fabio Natali wrote: [...] > The point is, how can I create the root of my tree? Should I add some > "blank=True, null=True" properties to my Node model? So to have: > > class Node(models.Model): > name = models.CharField(max_length=50) > parent = models.ForeignKey('self', blank=True, null=True) > > And then consider the "null-parented" node as the root one? That's the usual method. > > Does my code make any sense? Do you think it will turn out as too slow > for my hierarchy? Should I better rely on django-treebeard or > django-mptt? 500 leaves is really nothing for the database. If you want to do anything with that size tree, you can easily just use a simple nested hierarchy like this, pull all the rows back into Python and work with them there. Particularly since you only have three levels in the tree: queries on name or parent__name or parent__parent__name are as bad as it's going to get (thereby meaning you can often filter to just the branches you want). Things like the modified pre-order tree traversal data structures just speed up the retrieval so that you don't have to retrieve all the rows and become useful for large trees, or trees with deep (and unknown) levels of nesting. So start with something simple, by all means. It's fun, it's a learning experience, it will probably work very well in practice. And if you later decide to switch to one of the other packages, it won't take a lot of changes to move things to the new model (it will take some changes, but it's not really that difficult). Regards, Malcolm --~--~-~--~~~---~--~~ 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: Items tree in Django
bruno desthuilliers wrote: [...] > > I've been told to use django-treebeard > > That's what I was about to suggest !-) > If you are really confident that your hierarchy will never grow deeper > than three levels, the above solution might be good enough. But it's > still less efficient than the materialized path or the nested sets > patterns when it comes to reading a whole branch. Dear Bruno, thank you so much for your fast and detailed reply. I am glad to hear that the naive way could possibly fit my 3-levels tree, or at least that it deserves a try. I'll have some benchmarks as you suggest. All the best, Fabio. -- Fabio Natali --~--~-~--~~~---~--~~ 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: How to access the request object in a decorator
On 17 nov, 10:02, TH <[EMAIL PROTECTED]> wrote: > Hello, > > I wanted to redirect a logged in user if he access certain page. For > example i do not want the user to access registration page if he is > logged in. > > A simple way to do this is: > > def register(request): > if request.user.is_authenticated(): > return HttpResponseRedirect('/ > some_nice_page_for_logged_in_user') > ... > > The problem is i have lot of pages that only anonymous user can > access. So i wanted to write a decorator so that i can do something > like that > > @anonymous_only > def register(request): A "decorator" is just a function (or any other callable) that takes a function as argument and returns a function (or any other callable). The @decorator syntax is only syntactic sugar. In most cases, the returned function is just a wrapper around the decorated one, and this is obviously what you want: def anonymous_only(view): # 'view' is the view function to decorate # since we decorate views, we know the first parameter # is always going to be the current request # # '_wrapper' is the function that will be used instead # of 'view'. def _wrapper(request, *args, **kw): # here we can access the request object and # either redirect or call 'view' if request.user.is_authenticated(): return HttpResponseRedirect('/page_for_logged_in_user') return view(request, *args, **kw) # this part is not mandatory, but it may help debugging _wrapper.__name__ = view.__name___ _wrapper.__doc__ = view.__doc__ # and of course we need to return our _wrapper so # it replaces 'view' return _wrapper Note that this example assume you always want to redirect to the same page if the user is logged in, which might not be the case. Things get a bit more complicated if you want your decorator to takes the redirection url as param, since we'll then need one more indirection, IOW : a function that takes an url and returns a function that takes a function and returns a 'wrapper': def anonymous_only(redirect_to): def deco(view): def _wrapper(request, *args, **kw): if request.user.is_authenticated(): return HttpResponseRedirect(redirect_to) return view(request, *args, **kw) _wrapper.__name__ = view.__name___ _wrapper.__doc__ = view.__doc__ return _wrapper return deco Then you use it that way: @anonymous_only('/page_for_logged_in_user') def register(request): # code here HTH --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: How to access the request object in a decorator
Wiadomość napisana w dniu 2008-11-17, o godz. 10:02, przez TH: > I wanted to redirect a logged in user if he access certain page. For > example i do not want the user to access registration page if he is > logged in. > > A simple way to do this is: > > def register(request): >if request.user.is_authenticated(): >return HttpResponseRedirect('/ > some_nice_page_for_logged_in_user') >... > > The problem is i have lot of pages that only anonymous user can > access. So i wanted to write a decorator so that i can do something > like that > > > @anonymous_only > def register(request): Take a look at the content of django.contrib.auth.decorators module (the _CheckLogin class, a call in user_passes_test and login_required). -- We read Knuth so you don't have to. - Tim Peters Jarek Zgoda, R, Redefine [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Items tree in Django
On 17 nov, 11:46, Fabio Natali <[EMAIL PROTECTED]> wrote: > Hi everybody out there! :-) > > I have to cope with a few hundreds item tree/hierarchy in my Django > project. Specifically, I'll have 500 hundreds leaves in a 3-levels > tree with a dozen branches. > > I won't need much writing over this tree, I'll just need to read it > and show data in a drop down menu. > > I've been told to use django-treebeard That's what I was about to suggest !-) > or django-mptt to speed up > things, but I wrote down a first draft on my own: > > class Node(models.Model): > name = models.CharField(max_length=50) > parent = models.ForeignKey('self') > > class Product(models.Model): > name = models.CharField(max_length=50) > parent = models.ForeignKey(Node) > [some more info here] > > The point is, how can I create the root of my tree? Should I add some > "blank=True, null=True" properties to my Node model? So to have: > > class Node(models.Model): > name = models.CharField(max_length=50) > parent = models.ForeignKey('self', blank=True, null=True) > > And then consider the "null-parented" node as the root one? That's the canonical solution when using the adjacency list pattern, yes. > Does my code make any sense? Do you think it will turn out as too slow > for my hierarchy? If you are really confident that your hierarchy will never grow deeper than three levels, the above solution might be good enough. But it's still less efficient than the materialized path or the nested sets patterns when it comes to reading a whole branch. > Should I better rely on django-treebeard or > django-mptt? Well... I'm not sure there's any clearcut answer here. If you have enough time, you may want to do a couple benchmarks on representative data and use cases. My 2 cents... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
admin site problem
I tried to add some values to my table from admin site. Table has 3 columns one of integer type and other two of string type. When i tried to save my entries it giving an error as: "coercing to Unicode: need string or buffer, int found" How to solve it? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to access the request object in a decorator
Hello, I wanted to redirect a logged in user if he access certain page. For example i do not want the user to access registration page if he is logged in. A simple way to do this is: def register(request): if request.user.is_authenticated(): return HttpResponseRedirect('/ some_nice_page_for_logged_in_user') ... The problem is i have lot of pages that only anonymous user can access. So i wanted to write a decorator so that i can do something like that @anonymous_only def register(request): --~--~-~--~~~---~--~~ 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: unchecked checkboxes not accessed through request.POST['check_name']
As far as i remember according to the HTML specs the unchecked values are not sent with form post. So you can use some logic in your server side code to deduce the unchecked values. (Since you render them in the first place so may be you have a list of items from database) or if you really want to sent them from HTML form use some javascript to set those uncheck values in a hidden field. Hope this helps. On Nov 16, 11:56 pm, limas <[EMAIL PROTECTED]> wrote: > hello all > I am doing a project in Django. > I want to create a list by clicking upon a link, it will open up a new > window using javascript window.open() method. > I have two tables for list. > class Saved_list(models.Model): > description=models.CharField(max_length=100) > number_entries=models.IntegerField() > date_created=models.DateTimeField(auto_now_add=True) > date_modified=models.DateTimeField(auto_now=True) > > class Saved_list_entry(models.Model): > saved_list=models.ForeignKey(Saved_list) > date_created=models.DateTimeField(auto_now_add=True) > > Onload all entries in the Saved_list is listed with description and > number entries with a check box in front of it. > I want to create new Saved_list. I have done it with a a link. > When any one of the Checkbox is checked I want to increment the > number_entries field and insert a new row in Saved_list_entry. > > my view is : > def add_to_list(request): > saved_list=Saved_list.objects.all() > lists=saved_list.values() > if request.method=='POST': > name='' > for lst in lists: > if request.POST[lst['description']]=='On': > name=lst['description'] > break > if name!='': > try: > slist1=Saved_list.objects.get > (description=name) > except KeyError: > pass > slist_entry=Saved_list_entry > (saved_list_id=slist1.id) > slist1.number_entries=slist1.number_entries+1; > slist1.save() > else: > slist=Saved_list(description=request.POST > ['listname'],number_entries=0) > slist.save() > else: > pass > return render_to_response('candidates/add_to_list.html', > {'list':lists}) > > and my template is: > > {% for l in list %} > > {{ l.description }} ({{ l.number_entries }}) > {% endfor %} > > Save > name="Add > To List"> > name="cancel" > onClick="window.close();"> > > > But i can't retrieve the unchecked checkboxes > please help me.. > thanks in advance > Lima --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Items tree in Django
Hi everybody out there! :-) I have to cope with a few hundreds item tree/hierarchy in my Django project. Specifically, I'll have 500 hundreds leaves in a 3-levels tree with a dozen branches. I won't need much writing over this tree, I'll just need to read it and show data in a drop down menu. I've been told to use django-treebeard or django-mptt to speed up things, but I wrote down a first draft on my own: class Node(models.Model): name = models.CharField(max_length=50) parent = models.ForeignKey('self') class Product(models.Model): name = models.CharField(max_length=50) parent = models.ForeignKey(Node) [some more info here] The point is, how can I create the root of my tree? Should I add some "blank=True, null=True" properties to my Node model? So to have: class Node(models.Model): name = models.CharField(max_length=50) parent = models.ForeignKey('self', blank=True, null=True) And then consider the "null-parented" node as the root one? Does my code make any sense? Do you think it will turn out as too slow for my hierarchy? Should I better rely on django-treebeard or django-mptt? Any help appreciated, thank you so much! Regards, -- Fabio Natali --~--~-~--~~~---~--~~ 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: Apache Segmentation Fault on succesful authentication
Can you try building mod_wsgi instead and see if it picks up the correct library? If it doesn't work, post the output from running 'configure' script and running 'make' for mod_wsgi. I trust mod_wsgi build process more than I do mod_python. Graham On Nov 17, 9:04 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > ls -ltr /usr/local/lib/python2.5/config/libpython2.5.so > > lrwxrwxrwx 1 root root 21 Nov 12 10:48 /usr/local/lib/python2.5/config/ > libpython2.5.so -> ../../libpython2.5.so > > ls -ltr /usr/local/lib > > -r-xr-xr-x 1 root root 4806649 Nov 11 11:22 libpython2.5.a > -r-xr-xr-x 1 root root 4806649 Nov 12 12:49 libpython2.5.so.1.0 > lrwxrwxrwx 1 root root 19 Nov 12 12:49 libpython2.5.so -> > libpython2.5.so.1.0 > drwxr-xr-x 21 root root 20480 Nov 12 12:50 python2.5 > > ldd /usr/local/apache2/modules/mod_python.so > > libpthread.so.0 => /lib64/libpthread.so.0 (0x2b2d9e698000) > libdl.so.2 => /lib64/libdl.so.2 (0x2b2d9e8b2000) > libutil.so.1 => /lib64/libutil.so.1 (0x2b2d9eab6000) > libm.so.6 => /lib64/libm.so.6 (0x2b2d9ecba000) > libc.so.6 => /lib64/libc.so.6 (0x2b2d9ef3d000) > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > echo $LD_LIBRARY_PATH > > /usr/local/lib > > On Nov 14, 5:17 am, Graham Dumpleton <[EMAIL PROTECTED]> > wrote: > > > Did you do a 'ls -L' on the symlink to validate it pointed at > > something? > > > The relative location of where the .so will be is more a hint as for > > different systems it may not be in same relative location. > > > Graham > > > On Nov 13, 10:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > > My apologies. I forgot to mention that I already tried what was > > > suggested in the article you pointed me at. I created a symlink in / > > > usr/local/lib/python2.5/config as directed however recompiling > > > mod_python still links to the library statically. Unless I missed a > > > step in the article I am starting to wonder if mod_python just > > > includes this library statically by default. Still, thanks for all the > > > help so far. I really appreciate it. > > > > On Nov 13, 9:55 am, Graham Dumpleton <[EMAIL PROTECTED]> > > > wrote: > > > > > Because you have created the symlink for the .so file so it appears > > > > next to the static library. It is arguably a a failing of standard > > > > Python installer that it doesn't do this. What to do is explained in > > > > document I previously pointed you at: > > > > > http://code.google.com/p/modwsgi/wiki/InstallationIssues > > > > > Yes I know this is for mod_wsgi but same applies to mod_python. > > > > > Graham > > > > > On Nov 13, 8:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > > > > ls -ltr /usr/local/lib > > > > > > -r-xr-xr-x 1 root root 4806649 Nov 11 11:22 libpython2.5.a > > > > > -r-xr-xr-x 1 root root 4806649 Nov 12 12:49 libpython2.5.so.1.0 > > > > > lrwxrwxrwx 1 root root 19 Nov 12 12:49 libpython2.5.so -> > > > > > libpython2.5.so.1.0 > > > > > > echo $LD_LIBRARY_PATH > > > > > > /usr/local/lib > > > > > > ldd /usr/local/bin/python > > > > > > libpython2.5.so.1.0 => /usr/local/lib/libpython2.5.so.1.0 > > > > > (0x2b6d8efc5000) > > > > > libpthread.so.0 => /lib64/libpthread.so.0 (0x0039a4a0) > > > > > libdl.so.2 => /lib64/libdl.so.2 (0x0039a460) > > > > > libutil.so.1 => /lib64/libutil.so.1 (0x0039b340) > > > > > libm.so.6 => /lib64/libm.so.6 (0x0039a420) > > > > > libc.so.6 => /lib64/libc.so.6 (0x0039a3e0) > > > > > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > > > > > recompile mod_python and do ldd /usr/local/apache2/modules/ > > > > > mod_python.so > > > > > > libpthread.so.0 => /lib64/libpthread.so.0 (0x2b74c34f7000) > > > > > libdl.so.2 => /lib64/libdl.so.2 (0x2b74c3711000) > > > > > libutil.so.1 => /lib64/libutil.so.1 (0x2b74c3915000) > > > > > libm.so.6 => /lib64/libm.so.6 (0x2b74c3b19000) > > > > > libc.so.6 => /lib64/libc.so.6 (0x2b74c3d9c000) > > > > > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > > > > > I still don't get why the library is being compiled in statically. > > > > > > On Nov 13, 12:11 am, Graham Dumpleton <[EMAIL PROTECTED]> > > > > > wrote: > > > > > > > On Nov 12, 11:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > > > > > > echo '/usr/local/lib' >> /etc/ld.so.conf > > > > > > > > more /etc/ld.so.conf > > > > > > > > include ld.so.conf.d/*.conf > > > > > > > /usr/local/lib > > > > > > > > ldd /usr/local/bin/python > > > > > > > > libpython2.5.so.1.0 => not found > > > > > > > libpthread.so.0 => /lib64/libpthread.so.0 > > > > > > > (0x0039a4a0) > > > > > > > libdl.so.2 => /lib64/libdl.so.2 (0x0039a460) > > > > > > > libutil.so.1 => /lib64/libutil.so.1 (0x0039b340) > > > > > > > libm.so.6 => /lib64/libm.so.6 (0x0039a420) > >
Re: Apache Segmentation Fault on succesful authentication
ls -ltr /usr/local/lib/python2.5/config/libpython2.5.so lrwxrwxrwx 1 root root 21 Nov 12 10:48 /usr/local/lib/python2.5/config/ libpython2.5.so -> ../../libpython2.5.so ls -ltr /usr/local/lib -r-xr-xr-x 1 root root 4806649 Nov 11 11:22 libpython2.5.a -r-xr-xr-x 1 root root 4806649 Nov 12 12:49 libpython2.5.so.1.0 lrwxrwxrwx 1 root root 19 Nov 12 12:49 libpython2.5.so -> libpython2.5.so.1.0 drwxr-xr-x 21 root root20480 Nov 12 12:50 python2.5 ldd /usr/local/apache2/modules/mod_python.so libpthread.so.0 => /lib64/libpthread.so.0 (0x2b2d9e698000) libdl.so.2 => /lib64/libdl.so.2 (0x2b2d9e8b2000) libutil.so.1 => /lib64/libutil.so.1 (0x2b2d9eab6000) libm.so.6 => /lib64/libm.so.6 (0x2b2d9ecba000) libc.so.6 => /lib64/libc.so.6 (0x2b2d9ef3d000) /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) echo $LD_LIBRARY_PATH /usr/local/lib On Nov 14, 5:17 am, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > Did you do a 'ls -L' on the symlink to validate it pointed at > something? > > The relative location of where the .so will be is more a hint as for > different systems it may not be in same relative location. > > Graham > > On Nov 13, 10:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > My apologies. I forgot to mention that I already tried what was > > suggested in the article you pointed me at. I created a symlink in / > > usr/local/lib/python2.5/config as directed however recompiling > > mod_python still links to the library statically. Unless I missed a > > step in the article I am starting to wonder if mod_python just > > includes this library statically by default. Still, thanks for all the > > help so far. I really appreciate it. > > > On Nov 13, 9:55 am, Graham Dumpleton <[EMAIL PROTECTED]> > > wrote: > > > > Because you have created the symlink for the .so file so it appears > > > next to the static library. It is arguably a a failing of standard > > > Python installer that it doesn't do this. What to do is explained in > > > document I previously pointed you at: > > > > http://code.google.com/p/modwsgi/wiki/InstallationIssues > > > > Yes I know this is for mod_wsgi but same applies to mod_python. > > > > Graham > > > > On Nov 13, 8:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > > > ls -ltr /usr/local/lib > > > > > -r-xr-xr-x 1 root root 4806649 Nov 11 11:22 libpython2.5.a > > > > -r-xr-xr-x 1 root root 4806649 Nov 12 12:49 libpython2.5.so.1.0 > > > > lrwxrwxrwx 1 root root 19 Nov 12 12:49 libpython2.5.so -> > > > > libpython2.5.so.1.0 > > > > > echo $LD_LIBRARY_PATH > > > > > /usr/local/lib > > > > > ldd /usr/local/bin/python > > > > > libpython2.5.so.1.0 => /usr/local/lib/libpython2.5.so.1.0 > > > > (0x2b6d8efc5000) > > > > libpthread.so.0 => /lib64/libpthread.so.0 (0x0039a4a0) > > > > libdl.so.2 => /lib64/libdl.so.2 (0x0039a460) > > > > libutil.so.1 => /lib64/libutil.so.1 (0x0039b340) > > > > libm.so.6 => /lib64/libm.so.6 (0x0039a420) > > > > libc.so.6 => /lib64/libc.so.6 (0x0039a3e0) > > > > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > > > > recompile mod_python and do ldd /usr/local/apache2/modules/ > > > > mod_python.so > > > > > libpthread.so.0 => /lib64/libpthread.so.0 (0x2b74c34f7000) > > > > libdl.so.2 => /lib64/libdl.so.2 (0x2b74c3711000) > > > > libutil.so.1 => /lib64/libutil.so.1 (0x2b74c3915000) > > > > libm.so.6 => /lib64/libm.so.6 (0x2b74c3b19000) > > > > libc.so.6 => /lib64/libc.so.6 (0x2b74c3d9c000) > > > > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > > > > I still don't get why the library is being compiled in statically. > > > > > On Nov 13, 12:11 am, Graham Dumpleton <[EMAIL PROTECTED]> > > > > wrote: > > > > > > On Nov 12, 11:44 pm, huw_at1 <[EMAIL PROTECTED]> wrote: > > > > > > > echo '/usr/local/lib' >> /etc/ld.so.conf > > > > > > > more /etc/ld.so.conf > > > > > > > include ld.so.conf.d/*.conf > > > > > > /usr/local/lib > > > > > > > ldd /usr/local/bin/python > > > > > > > libpython2.5.so.1.0 => not found > > > > > > libpthread.so.0 => /lib64/libpthread.so.0 > > > > > > (0x0039a4a0) > > > > > > libdl.so.2 => /lib64/libdl.so.2 (0x0039a460) > > > > > > libutil.so.1 => /lib64/libutil.so.1 (0x0039b340) > > > > > > libm.so.6 => /lib64/libm.so.6 (0x0039a420) > > > > > > libc.so.6 => /lib64/libc.so.6 (0x0039a3e0) > > > > > > /lib64/ld-linux-x86-64.so.2 (0x0039a2c0) > > > > > > Where is libpython2.5.so installed? What are the permissions on it? > > > > > > What do you get for: > > > > > > echo $LD_LIBRARY_PATH > > > > > > just prior to running 'ld'? > > > > > > Graham > > > > > > > On Nov 12, 11:57 am, marco ghidinelli <[EMAIL PROTECTED]> wrote: > > > > > > > > On Wed, Nov 12, 2008 at 03:22:02AM -0800,
automatically save latitude and longitude of the address.
HI All, How can I add automatically latitude and longitude of the physical address. for exp if, fnclatitude('Chennai') returns latitude and longitude of chenai. Please help This is my model (models.py) def fnclatitude(location): key = settings.GOOGLE_KEY output = "csv" location = urllib.quote_plus(location) request = "http://maps.google.com/maps/geo?q=%s=%s=%s; % (location, output, key) data = urllib.urlopen(request).read() dlist = data.split(',') if dlist[0] == '200': return "%s" % (dlist[3]) #return "%s, %s" % (dlist[2], dlist[3]) else: return '' class Business(models.Model): physicaladdr_street1 = models.CharField("Street 1", max_length=25) modified_date = models.DateTimeField() latitude = models.DecimalField(max_digits=11, decimal_places=6, null=True, blank=True) longitude = models.DecimalField(max_digits=11, decimal_places=6, null=True, blank=True) def save(self, force_insert=False, force_update=False): self.modified_date = datetime.datetime.now() self.latitude = fnclatitude() # here I need to automatically add latitude and longitude of the physical address. # for exp if, fnclatitude('Chennai') returns latitude and longitude of chenai. super(Business, self).save(force_insert, force_update) --~--~-~--~~~---~--~~ 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: In forms, how add dynamic initial values out of reach for clients?
I've already read that and can't get the first one working: instance = Instance(required_field='value') form = InstanceForm(request.POST, instance=instance) new_instance = form.save() In my case, shouldn't it look like this: user = request.user discussion = Discussion.objects.get(pk=discussion_pk) form = CommentForm(request.POST, user=user, discussion=discussion) form = form.save() Or am I wrong? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Setting Up Django on Vista and Creating a Database
I have currently created a database with the following details: DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'myforum' DATABASE_USER = 'root' DATABASE_PASSWORD = 'myforum' DATABASE_HOST = 'localhost' DATABASE_PORT = '' I used phpMyadmin to create the database I have updated C:\projects\myforum\settings.py in the similar fashion However when i run the the following command i get: C:\projects\myforum>python manage.py runserver Validating models... Unhandled exception in thread started by Traceback (most recent call last): File "C:\Python26\Lib\site-packages\django\core\management\commands \runserver. py", line 48, in inner_run self.validate(display_num_errors=True) File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 122, in validate num_errors = get_validation_errors(s, app) File "C:\Python26\Lib\site-packages\django\core\management \validation.py", lin e 22, in get_validation_errors from django.db import models, connection File "C:\Python26\Lib\site-packages\django\db\__init__.py", line 34, in (settings.DATABASE_ENGINE, ", ".join(map(repr, available_backends)), e_user) django.core.exceptions.ImproperlyConfigured: 'MySQL' isn't an available database backend. Available options are: 'dummy', 'mysql', 'oracle', 'postgresql', 'post gresql_psycopg2', 'sqlite3' Error was: No module named MySQL.base Was my update in "settings.py" right what do i do...?? On Nov 14, 9:17 am, John Antony <[EMAIL PROTECTED]> wrote: > Thank you Karen and Marcelo, I had actually not set the path for > "django-admin.py". > To set the Windows PATH in Vista click the following: > Start>Control Panel>System>Advanced System > Settings>Advanced>Environment Variable > > On Nov 13, 9:59 pm, Danny R <[EMAIL PROTECTED]> wrote: > > > > > John, > > > Setting the paths in Vista is quirky. I also cannot make it work. > > > As a workaround whenever I open a new command prompt, i do the > > following command: > > > set path=C:\Python25\Lib\site-packages\django\bin\;C: > > \Python25\ > > > then, when i create an app or a project, i do this instead: > > > python C:\Python25\Lib\site-packages\django\bin\django- > > admin.py startproject djangoapps > > > On Nov 12, 7:40 pm, John Antony <[EMAIL PROTECTED]> wrote: > > > > I have now used all your suggestions.. > > > 1) Installed in C:\Python25\ (Marcelo Barbero) > > > 2)Installed Python 2.5 instead of Python 2.6 (Karen Tracey) > > > and finally > > > 3)Added the environment variables in "path" (not PATH, should i create > > > a new one named PATH) for both django and python. > > > > I installed django and postgreSQL following it stepwise from > > > >http://thinkhole.org/wp/django-on-windows/ > > > > but however > > > now when i reach the command of testing django i still am getting the > > > following error > > > > C:\Python25\Lib\site-packages\django>django-admin.py startproject > > > testproject > > > 'django-admin.py' is not recognized as an internal or external > > > > command, > > > operable program or batch file. > > > > what sholud i do now > > > On Nov 11, 6:19 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > > > > > On Tue, Nov 11, 2008 at 1:40 AM, John Antony <[EMAIL PROTECTED]> wrote: > > > > > > I am currently using Vista OS > > > > > I have installed Python in the path > > > > > D:\Python26\ > > > > > and extracted the tarred file downloaded fromwww.djangoprojects.com > > > > > ie "Django-1.0.tar.gz" in the path > > > > > D:\Python26\Django-1.0\Django-1.0 > > > > > I am however unable to intall Django > > > > > on typing the following command in command prompt I get this error: > > > > > > D:\Python26\Django-1.0\Django-1.0>python setup.py install > > > > > 'python' is not recognized as an internal or external command, > > > > > operable program or batch file. > > > > > The Python installer did not put the directory containing the python.exe > > > > executable in the Windows PATH environment variable. That is why all > > > > the > > > > Django instructions for Windows generally drop the 'python' from such > > > > commands, since on Windows usually all you can count on when writing > > > > instructions is that the Python installer set up an association between > > > > '.py' files and the python executable. So, if you drop the python from > > > > the > > > > front of the command, that should work. > > > > > However, I have heard reports that the association created by the > > > > Python 2.6 > > > > installer on Vista is broken, see here: > > > > >http://groups.google.com/group/django-users/msg/1d00809e826fa8c3 > > > > > So, you may need to fix that as described in that message. > > > > > You can also put the path to python.exe in your Windows system path, so > > > > that > > > > you can use the 'python whatever' form of commands. In older versions > > > > of > > > > Windows you would do that by going to Start->Settings->Control Panel, > > > > choosing "System", selecting the "Advanced"