How to delete template fragment cache?
Hi all, I'm quite newbie in Django. I use template fragment caching ({% cache ...%}...{% endcache %}. This fragment changes rather seldom, changes originate only from admin site, są for me its obvious to delete cache at adding objects from admin, and use quite large tiemeout for my caches. How can I delete cache for particular fragments at saving objects? I know I should use cache.delete('a'), but how can I get key for particular fragment? What is better idea? Use signals (I do not know too mouch about them yet)or just overwrite model_save method? I use memcached backend. -- Pozdrawiam Bartek jid: [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: how to create json from template?
Oh, Yes. Good point. On Wed, Dec 3, 2008 at 09:49, David Zhou <[EMAIL PROTECTED]> wrote: > > On Wed, Dec 3, 2008 at 1:17 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > > > To trim last colon wrap it with if statement: > > > > {% if forloop.revcounter0 %},{% endif %} > > You can also do: > > {% if not forloop.last %},{% endif %} > > Which, IMO, is slightly more clear. > > > --- > 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: how to create json from template?
On Wed, Dec 3, 2008 at 1:17 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > To trim last colon wrap it with if statement: > > {% if forloop.revcounter0 %},{% endif %} You can also do: {% if not forloop.last %},{% endif %} Which, IMO, is slightly more clear. --- 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: how to create json from template?
To trim last colon wrap it with if statement: {% if forloop.revcounter0 %},{% endif %} On Wed, Dec 3, 2008 at 04:26, Viktor Nagy <[EMAIL PROTECTED]> wrote: > Hi, > > I know about the serialisation framework, but with MultiResponse[1] you > can't really use it (and anyway I don't know how to customise it > extensively). As a result I would like to create json with the django > template engine. > > An example code would be this: > > [{% for poll in data %} > {"question": "{{ poll.question }}"}, > [ {% for answer in poll.answer_set.all %} > {"answer": "{{ answer.answer }}", > "votes": {{ answer.votes }}, > "vote_url": "{% url multi_api_data data=answer.pk %}",}, > {% endfor %} ]}, > {% endfor %} ] > > But at parsing simplejson.py gives an error. The error is easy to > understand with the following example: > ["a"] <- this is fine for simplejson.loads > ["a",] <- this kills simplejson.loads > > Any ideas how to generate a for loop without the last colon(,)? Or how to > use json syntax in the template in general? > > thanks, V > > [1]: http://toastdriven.com/fresh/more-multiresponse > > -- > Viktor Nagy - http://viktornagy.com > PhD student > Toulouse School of Economics > > > > --~--~-~--~~~---~--~~ 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: change i18n language through hyperlinks
try this def set_language(request, lang_code): next = request.REQUEST.get('next', None) if not next: next = '/' response = http.HttpResponseRedirect(next) if lang_code and check_for_language(lang_code): settings.LANGUAGE_CODE=lang_code return response On Oct 12, 6:12 am, Chuck22 <[EMAIL PROTECTED]> wrote: > thanks Satheesh, the set_language function is partially working for > me. When I click the lauguage hyperlinks, only the word "Home" works, > but when I change the msgid to be "Home1", it stop working. It seems > that "Home" is a django preserved word which get auto-translated. > > 1. In my base.html, I have > > {% load i18n %} > > {% trans "Home1" %} > > 2. django.po and django.mo files are generated correctly for the > lauguages. > > msgid "Home1" > msgstr "My_Translation" > > 3. In my settings.py, I have > > USE_I18N = True > > LANGUAGE_CODE = 'en-us' > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.locale.LocaleMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > ) > > 4. syncdb is done, and session table is generated. > > 5. language preferrence selection is like the code below. > > I don't know which piece is missing. Anyone can suggest? Thanks. > > On Oct 10, 1:11 am, cschand <[EMAIL PROTECTED]> wrote: > > > Even then you want in get method you can use the below code. > > > In view > > > from django import http > > from django.utils.translation import check_for_language > > from django.conf import settings > > > def set_language(request, lang_code): > > """ > > Patched for Get method > > """ > > next = request.REQUEST.get('next', None) > > if not next: > > next = '/' > > response = http.HttpResponseRedirect(next) > > if lang_code and check_for_language(lang_code): > > if hasattr(request, 'session'): > > request.session['django_language'] = lang_code > > else: > > response.set_cookie(settings.LANGUAGE_COOKIE_NAME, > > lang_code) > > return response > > > And in template > > > > > {% for lang in LANGUAGES %} > > > {{ lang.1 }} > > > {% endfor %} > > > > > > in urls > > url(r'^setlang/(?P.*)/$', 'utils.views.set_language') > > > I dont know it is a good practice to do > > > Satheesh > > > On Oct 10, 9:30 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > > wrote: > > > > On Thu, 2008-10-09 at 23:51 -0400, Chuck Bai2 wrote: > > > > I want to allow user select language preference through clicking the > > > > language hyperlinks like "_English_ | _French_" switch. And I also want > > > > to redirect back to the previous page after clicking the language > > > > switch. Is it possible to use Django view: > > > > django.views.i18n.set_language? In the documentation, there is an > > > > example using form submit to select language using this view. > > > > > > > > > > > > > > > > > {% for lang in LANGUAGES %} > > > > {{ lang.1 }} > > > > {% endfor %} > > > > > > > > > > > > > > > > > But I want to implement this using hyperlinks and want to know how. > > > > You'll need to write your own view to handle this (you could look at > > > Django's view for inspiration). Django intentionally doesn't support > > > this because it's bad practice (using a GET request to initiate a state > > > change). > > > > Regards, > > > Malcolm- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 in Ubuntu 8.10, Segmentation Fault
Confirmed also. only happens on my 64-bit machine, and is not related to apache at all as I can reproduce it faithfully in ipython. On Dec 2, 8:32 pm, GRoby <[EMAIL PROTECTED]> wrote: > I can confirm that all of my seg faults were all on my 64 bit machine > but could not be duplicated when I tried to on my 32 bit test virtual > machines. > > On Dec 2, 7:40 pm, rcoup <[EMAIL PROTECTED]> wrote: > > > Posting to geos-devel, I got this reply from Paul > > Ramsey:http://lists.osgeo.org/pipermail/geos-devel/2008-December/003800.html > > > Leading me to:http://sgillies.net/blog/829/shapely-1-0-8/ > > > "The same problem [segfault] could afflict any python package that > > uses Ctypes on 64-bit systems without explicitly marking argument and > > return types. " > > > Looking back through the modwsgi thread and this one, everyone's on > > 64bit, except the CentOS guy who said it worked ok on 32bit but not on > > 64bit. > > > Maybe thats the problem with the ctypes+geos bindings in GeoDjango? > > I'm running something-pre-1.0, but I can try it on a trunk checkount > > to confirm the same symptoms. > > > Rob :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Preserving pretty HTML output
On Tue, 2008-12-02 at 18:39 -0800, Tonne wrote: > I am interested to see if anyone could share their solutions for > ensuring pretty HTML output. > > I have found achieving it to be a very uncomfortable compromise in > that I seem to need to make my templates almost unreadable to do so, > which isn't really a practical solution. > > Perhaps nicely formatted HTML markup is simply not a worthy priority > in the greater scheme of things Django. Which is a bit of a pity, as > I've always appreciated well-manicured HTML, and it has been a point > of professional pride to make my own handwritten HTML as readable as > possible. You're right: there's a trade-off. Almost every single piece of machine-generated HTML makes that trade-off. You trade off output formatting that hardly anybody will see for speed. Every professional worth their salt strives to write neat and tidy source. If we're writing HTML source, it will generally be neat and tidy. In Django, we're more regularly writing template source, so that's the bit that is edited over and over and is formatted for readability. There's been a bunch of discussion about this and the conclusion is this: if somebody came up with a way that wasn't eye-bleedingly ugly in the Python source to remove any blank lines that only contained template tags from the output, we would include it. However, it should not slow down template rendering. A few people tried to do this on a very old ticket and came up with 25 - 50% slow-downs, which is simply unacceptable. I had a shot once and got something that was close to comparable with the current speed, but it was really messy. Since then, it's been back-burnered as there are other things to be fixed in the template rendering space before worrying about stuff like this. The problem is much harder than it looks on the surface, so it's not out or orneriness that we have avoided including anything. By the time you factor in readable templates, nested templates, included HTMl from template tags, etc, the resulting generated HTML is only one aspect of a multi-faceted problem. However, if really regularly formatted HTML output is a requirement for you and you can pay the speed penalty, you could run the results through something like TidyLib (from the HTML tidy project) or similar before serving it. I could imagine it wouldn't be too hard to write a middleware that did this for all text/html (and similar) results. 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: admin css, is this still supported?
On Tue, 2008-12-02 at 08:21 -0800, John M wrote: > I've searched for the admin CSS guide, and found it deprecated (http:// > docs.djangoproject.com/en/dev/obsolete/admin-css/?from=olddocs), is > there a replacement? You can still customise the admin CSS. I suspect it just hasn't been documented for the newer admin yet. But you'll see a bunch of .css files in the django/contrib/admin/media/css/ directory and, if all else fails, poking around with something like Firebug will show the relevant classes fairly quickly. If you are playing around in that area, take notes as you go and you might be able to help us resurrect the old documentation and make it appropriate for the new admin. 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: admin.py -- AlreadyRegistered
Pardon me. I incorrectly followed the suggestion, should have been the following in admin.py: admin.site.register(Book) admin.site.register(Author) admin.site.register(Publisher) What is the difference between this and, say, class BookAdmin(admin.ModelAdmin): pass admin.site.register(Book, BookAdmin) When I entered just this class, it worked for me the first time around, though later adding more fields I still do not understand what provoked that error. Thanks for helping me get it running at any rate! On Dec 3, 4:39 am, djan <[EMAIL PROTECTED]> wrote: > Thanks for the replies. I restarted the dev server (and even my x > session). > I first tried: > > class BookAdmin(admin.ModelAdmin): > pass > #admin.site.register(Book, BookAdmin) > > class AuthorAdmin(admin.ModelAuthor): > pass > #admin.site.register(Author, AuthorAdmin) > > class PublisherAdmin(admin.ModelPublisher): > pass > #admin.site.register(Publisher, PublisherAdmin) > > And received the following error: > AttributeError: 'module' object has no attribute 'ModelAuthor' > > I then tried the second suggestion: > #class BookAdmin(admin.ModelAdmin): > # pass > admin.site.register(Book, BookAdmin) > > #class AuthorAdmin(admin.ModelAuthor): > # pass > admin.site.register(Author, AuthorAdmin) > > #class PublisherAdmin(admin.ModelPublisher): > # pass > admin.site.register(Publisher, PublisherAdmin) > > And receive the error: > File "$HOME/djcode/mysite/books/admin.py", line 6, in > admin.site.register(Book, BookAdmin) > NameError: name 'BookAdmin' is not defined > > Any other thoughts? > > On Dec 2, 10:21 am, "please smile" <[EMAIL PROTECTED]> wrote: > > > hi, > > > class BookAdmin(admin.ModelAdmin): > > pass > > # admin.site.register(Book, BookAdmin) > > > Just put '#' in front of admin.site.register(Book, BookAdmin) .Now run the > > server ,if it s ok then remove the # > > > On Tue, Dec 2, 2008 at 12:47 PM, Roland van Laar <[EMAIL PROTECTED]> wrote: > > > > djan wrote: > > > > Hello. > > > > > I'm following along with djangobook.com and trying to make necessary > > > > changes to port django to version 1.0. In Django's Site > > > > Administration, chapter 6, I run into the error: > > > > > Exception Type: AlreadyRegistered > > > > Exception Value: The model Book is already registered > > > > Exception Location: /usr/local/lib64/python2.5/site-packages/django/ > > > > contrib/admin/sites.py in register, line 64 > > > > Probably: > > > Try to restart the django development server. > > > The django dev server doesn't reload the admin.py file properly when it's > > > edited or when it encounters an error in that file. > > > > > I used the site administration site successfully with just "Book", and > > > > then when I attempted to add the other models (Auther, Publisher), I > > > > received the above error. > > > > > in admin.py I have: > > > > > from django.contrib import admin > > > > from models import Book, Author, Publisher > > > > On another note, you don't have to do this: > > > > > class BookAdmin(admin.ModelAdmin): > > > > pass > > > > admin.site.register(Book, BookAdmin) > > > > admin.site.register(Book) > > > > would suffice. > > > > > class AuthorAdmin(admin.ModelAuthor): > > > > pass > > > > admin.site.register(Author, AuthorAdmin) > > > > > class PublisherAdmin(admin.ModelPublisher): > > > > pass > > > > admin.site.register(Publisher, PublisherAdmin) > > > > > When I updated admin.py I ran: > > > > python manage.py syncdb > > > > > It is as if the database wasn't "synced" though, and that two > > > > instances of this model are trying to be created. > > > > > When I searched around for this error, I found instances of this > > > > occuring in 0.96, with the model being called several times. The Admin > > > > changes in 1.0 were said to resolve this, so perhaps it is something > > > > else. > > > > > I appreciate any help. Thanks! > > > > Regards, > > > > Roland --~--~-~--~~~---~--~~ 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.py -- AlreadyRegistered
Thanks for the replies. I restarted the dev server (and even my x session). I first tried: class BookAdmin(admin.ModelAdmin): pass #admin.site.register(Book, BookAdmin) class AuthorAdmin(admin.ModelAuthor): pass #admin.site.register(Author, AuthorAdmin) class PublisherAdmin(admin.ModelPublisher): pass #admin.site.register(Publisher, PublisherAdmin) And received the following error: AttributeError: 'module' object has no attribute 'ModelAuthor' I then tried the second suggestion: #class BookAdmin(admin.ModelAdmin): #pass admin.site.register(Book, BookAdmin) #class AuthorAdmin(admin.ModelAuthor): #pass admin.site.register(Author, AuthorAdmin) #class PublisherAdmin(admin.ModelPublisher): #pass admin.site.register(Publisher, PublisherAdmin) And receive the error: File "$HOME/djcode/mysite/books/admin.py", line 6, in admin.site.register(Book, BookAdmin) NameError: name 'BookAdmin' is not defined Any other thoughts? On Dec 2, 10:21 am, "please smile" <[EMAIL PROTECTED]> wrote: > hi, > > class BookAdmin(admin.ModelAdmin): > pass > # admin.site.register(Book, BookAdmin) > > Just put '#' in front of admin.site.register(Book, BookAdmin) .Now run the > server ,if it s ok then remove the # > > On Tue, Dec 2, 2008 at 12:47 PM, Roland van Laar <[EMAIL PROTECTED]> wrote: > > > > > djan wrote: > > > Hello. > > > > I'm following along with djangobook.com and trying to make necessary > > > changes to port django to version 1.0. In Django's Site > > > Administration, chapter 6, I run into the error: > > > > Exception Type: AlreadyRegistered > > > Exception Value: The model Book is already registered > > > Exception Location: /usr/local/lib64/python2.5/site-packages/django/ > > > contrib/admin/sites.py in register, line 64 > > > Probably: > > Try to restart the django development server. > > The django dev server doesn't reload the admin.py file properly when it's > > edited or when it encounters an error in that file. > > > > I used the site administration site successfully with just "Book", and > > > then when I attempted to add the other models (Auther, Publisher), I > > > received the above error. > > > > in admin.py I have: > > > > from django.contrib import admin > > > from models import Book, Author, Publisher > > > On another note, you don't have to do this: > > > > class BookAdmin(admin.ModelAdmin): > > > pass > > > admin.site.register(Book, BookAdmin) > > > admin.site.register(Book) > > > would suffice. > > > > class AuthorAdmin(admin.ModelAuthor): > > > pass > > > admin.site.register(Author, AuthorAdmin) > > > > class PublisherAdmin(admin.ModelPublisher): > > > pass > > > admin.site.register(Publisher, PublisherAdmin) > > > > When I updated admin.py I ran: > > > python manage.py syncdb > > > > It is as if the database wasn't "synced" though, and that two > > > instances of this model are trying to be created. > > > > When I searched around for this error, I found instances of this > > > occuring in 0.96, with the model being called several times. The Admin > > > changes in 1.0 were said to resolve this, so perhaps it is something > > > else. > > > > I appreciate any help. Thanks! > > > Regards, > > > Roland --~--~-~--~~~---~--~~ 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.py -- AlreadyRegistered
Thanks for the replies. I restarted the dev server (and even my x session). I first tried: class BookAdmin(admin.ModelAdmin): pass #admin.site.register(Book, BookAdmin) class AuthorAdmin(admin.ModelAuthor): pass #admin.site.register(Author, AuthorAdmin) class PublisherAdmin(admin.ModelPublisher): pass #admin.site.register(Publisher, PublisherAdmin) And received the following error: AttributeError: 'module' object has no attribute 'ModelAuthor' I then tried the second suggestion: #class BookAdmin(admin.ModelAdmin): #pass admin.site.register(Book, BookAdmin) #class AuthorAdmin(admin.ModelAuthor): #pass admin.site.register(Author, AuthorAdmin) #class PublisherAdmin(admin.ModelPublisher): #pass admin.site.register(Publisher, PublisherAdmin) And receive the error: File "$HOME/djcode/mysite/books/admin.py", line 6, in admin.site.register(Book, BookAdmin) NameError: name 'BookAdmin' is not defined Any other thoughts? On Dec 2, 10:21 am, "please smile" <[EMAIL PROTECTED]> wrote: > hi, > > class BookAdmin(admin.ModelAdmin): > pass > # admin.site.register(Book, BookAdmin) > > Just put '#' in front of admin.site.register(Book, BookAdmin) .Now run the > server ,if it s ok then remove the # > > On Tue, Dec 2, 2008 at 12:47 PM, Roland van Laar <[EMAIL PROTECTED]> wrote: > > > > > djan wrote: > > > Hello. > > > > I'm following along with djangobook.com and trying to make necessary > > > changes to port django to version 1.0. In Django's Site > > > Administration, chapter 6, I run into the error: > > > > Exception Type: AlreadyRegistered > > > Exception Value: The model Book is already registered > > > Exception Location: /usr/local/lib64/python2.5/site-packages/django/ > > > contrib/admin/sites.py in register, line 64 > > > Probably: > > Try to restart the django development server. > > The django dev server doesn't reload the admin.py file properly when it's > > edited or when it encounters an error in that file. > > > > I used the site administration site successfully with just "Book", and > > > then when I attempted to add the other models (Auther, Publisher), I > > > received the above error. > > > > in admin.py I have: > > > > from django.contrib import admin > > > from models import Book, Author, Publisher > > > On another note, you don't have to do this: > > > > class BookAdmin(admin.ModelAdmin): > > > pass > > > admin.site.register(Book, BookAdmin) > > > admin.site.register(Book) > > > would suffice. > > > > class AuthorAdmin(admin.ModelAuthor): > > > pass > > > admin.site.register(Author, AuthorAdmin) > > > > class PublisherAdmin(admin.ModelPublisher): > > > pass > > > admin.site.register(Publisher, PublisherAdmin) > > > > When I updated admin.py I ran: > > > python manage.py syncdb > > > > It is as if the database wasn't "synced" though, and that two > > > instances of this model are trying to be created. > > > > When I searched around for this error, I found instances of this > > > occuring in 0.96, with the model being called several times. The Admin > > > changes in 1.0 were said to resolve this, so perhaps it is something > > > else. > > > > I appreciate any help. Thanks! > > > Regards, > > > Roland --~--~-~--~~~---~--~~ 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: Why run two web-servers on the same host?
On Wednesday 03 Dec 2008 8:49:31 am Kenneth Gonsalves wrote: > > All the python frameworks seem to do this: one web-server for > > development, another for production. There may be a good reason for > > this, but I don't see it. > > it is not compulsory to use it - I develop and deploy using apache and > mod_python. btw, even RoR has a development server - so the 'disease' is > not confined to python frameworks alone. oops, I misunderstood your question - I do not think anyone develops on a production box. Most people develop using a working copy of a repository on their own box and commit changes to the repository. Periodically a release is made usually freezing the repository as a 'tag'. This is then tested using live data on a pre-production box and then the production box is updated from the repository. And this is done by all programmers in all languages AFAIK. There are no doubt a species that updates a production box directly or through ftp - but I would hesitate to call them programmers. -- 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: time help (again)
On Tuesday 02 Dec 2008 7:53:25 pm Praveen wrote: > second thing open your terminal write python > > >>import datetime > >>help(datetime) dir(datetime) -- 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: Why run two web-servers on the same host?
On Tuesday 02 Dec 2008 10:16:48 pm walterbyrd wrote: > All the python frameworks seem to do this: one web-server for > development, another for production. There may be a good reason for > this, but I don't see it. it is not compulsory to use it - I develop and deploy using apache and mod_python. btw, even RoR has a development server - so the 'disease' is not confined to python frameworks alone. -- 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: Non-displayed fields on admin form get overwritten
Thank you for your reply, Rajesh. The two fields in question are actually "pending_referrer_name" and "pending_referrer_email". In the admin class code below, I include them in the fields attribute. However, initially I did not and that is when the problem would occur. Here is the model code: class Resource(models.Model): first_name = models.CharField(maxlength=32) last_name = models.CharField(maxlength=64) resource_type = models.ForeignKey('ResourceType', verbose_name='Type of practice') title = models.CharField(maxlength=128, blank=True, null=True) practice_name = models.CharField(null=True, blank=True, maxlength=128) address1 = models.CharField(maxlength=128) address2 = models.CharField(maxlength=64, blank=True, null=True) city = models.CharField(maxlength=64) state_or_province = models.ForeignKey('State_Province') zip = models.CharField(maxlength=16) country = models.ForeignKey('Country') email = models.EmailField(unique=True) phone = models.CharField(maxlength=24) phone2 = models.CharField(maxlength=24, blank=True, null=True) description = models.TextField(maxlength=400, verbose_name='Short Description') photo = models.ImageField(upload_to='resourcesguide/photos', blank=True, null=True) site_url = models.URLField(verify_exists=False, blank=True, null=True, verbose_name='Website') office_hours = models.TextField(maxlength=200, blank=True, null=True) additional_locations = models.TextField(maxlength=200, blank=True, null=True) personal_statement = models.TextField(blank=True, null=True, maxlength=1500) services_and_specialties = models.TextField(blank=True, null=True, maxlength=1500) credentials = models.TextField(blank=True, null=True, maxlength=1500, verbose_name='Education and Credentials') affiliations = models.TextField(blank=True, null=True, maxlength=1500, verbose_name='Insurance and managed care') payment = models.TextField(blank=True, null=True, maxlength=1500, verbose_name='Payment policies') pending_referrer_name = models.CharField(maxlength=48, blank=True, null=True) pending_referrer_email = models.CharField(maxlength=64, blank=True, null=True) # From here down is for internal use only display_on_website = models.BooleanField() recommended_by = models.ForeignKey('Referrer', null=True, blank=True) paypal_number = models.CharField(maxlength=24, null=True, blank=True) initial_solicitation = models.DateField(null=True, blank=True) initial_invoice = models.DateField(blank=True, null=True) comments = models.TextField(blank=True, null=True, verbose_name='History') do_not_email = models.BooleanField() referrer_solicitation_email_sent = models.DateField(blank=True, null=True) And the admin code: class Admin: list_display = ('last_name', 'first_name', 'practice_name', 'email', 'phone', 'recommended_by_', 'display_on_website') search_fields = ('last_name', 'first_name', 'practice_name', 'recommended_by.name') list_filter = ('city', 'state_or_province', 'zip', 'country') fields = (('Service provider information', {'fields': ('resource_type', 'first_name', 'last_name', 'title', 'practice_name', 'address1', 'address2', 'city', 'state_or_province', 'zip', 'country', 'phone', 'phone2', 'email', 'site_url', 'description', 'additional_locations', 'office_hours', 'personal_statement', 'services_and_specialties', 'credentials', 'affiliations', 'payment', 'photo')}), #('Referral information', {'fields': ('recommended_by',)}), ('Administrative information', {'fields': ( 'display_on_website', 'do_not_email', 'initial_solicitation', 'initial_invoice', 'comments', 'paypal_number', 'pending_referrer_name', 'pending_referrer_email')})) On Dec 2, 4:27 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > > I am using Django v1.0. When I use the "fields" attribute in my model > > to tell the admin interface what fields to display on the change form, > > I find that any fields I leave out get truncated when I use the form > > to update a record. > > > For instance, say I have a model class called "Users" that has the > > following fields: > > > Name > > Email > > Phone > > > I use the fields attribute to display only the "Name" and "Email" > > fields on the admin change form page. > > > Using a custom form (not the admin interface), I then create a record > > as follows: > > > Name: Joe Smith > > Email: [EMAIL PROTECTED] > > Phone: 609-555-1212 > > > I confirm that the information is in the database. > > > I then navigate to the admin change form. I see only the
Re: XML templates
On Dec 2, 2008, at 5:50 PM, Vicky wrote: > > I did as you said. Still its giving the same error :( Do you have the correct permissions on the TEMPLATE_DIRS directories? Have you written the paths with forward slashes? That's all I can think of. E > > > > On Dec 2, 11:38 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: >> On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote: >>> I tried the code below: >> >>> from django.template import loader, Context >> >>> def NewspaperSelect(request,u_id): >>> t=loader.get_template(r'C:\django\noddler\news >>> \template.vxml') >>>c=Context({ 'topic':'news', 'content':pn }) >>>return HttpResponse(t.render(c), mimetype='application/xml') >> >>> I verified that the file is in the location. But when i compile it >>> keeps telling that template file does not exist. What to do? >> >> get_template() doesn't take a full path to a file. It takes the >> name of >> a template, possibly with some directories in front -- but it's a >> relative path. What the path is relative to depends on the template >> loader being used. Unless you've done anything special to your setup, >> Django will try the application loader first -- appending the path to >> /templates/ for each app_name that you have installed. >> Then it >> will try the filesystem loader, which will append the path to each >> diretcory in the TEMPLATE_DIRS setting and see if it exists. >> >> So you either need to set up TEMPLATE_DIRS or put the templates in a >> templates/ directory inside one (or more) of your applications. >> >> This ends up making the code very portable, by the way, since when >> you >> install it somewhere else, you only have to change the TEMPLATE_DIRS >> settings (at most) and all your templates will still load correctly. >> >> 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 -~--~~~~--~~--~--~---
Preserving pretty HTML output
I am interested to see if anyone could share their solutions for ensuring pretty HTML output. I have found achieving it to be a very uncomfortable compromise in that I seem to need to make my templates almost unreadable to do so, which isn't really a practical solution. Perhaps nicely formatted HTML markup is simply not a worthy priority in the greater scheme of things Django. Which is a bit of a pity, as I've always appreciated well-manicured HTML, and it has been a point of professional pride to make my own handwritten HTML as readable as possible. And older thread brought up this subject too, but no conclusive solutions were brought to light... http://groups.google.com/group/django-users/browse_thread/thread/c9e569f7370c9c80/f11e4c24d3517233?lnk=gst=output+whitespace#f11e4c24d3517233 --~--~-~--~~~---~--~~ 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 in Ubuntu 8.10, Segmentation Fault
I can confirm that all of my seg faults were all on my 64 bit machine but could not be duplicated when I tried to on my 32 bit test virtual machines. On Dec 2, 7:40 pm, rcoup <[EMAIL PROTECTED]> wrote: > Posting to geos-devel, I got this reply from Paul > Ramsey:http://lists.osgeo.org/pipermail/geos-devel/2008-December/003800.html > > Leading me to:http://sgillies.net/blog/829/shapely-1-0-8/ > > "The same problem [segfault] could afflict any python package that > uses Ctypes on 64-bit systems without explicitly marking argument and > return types. " > > Looking back through the modwsgi thread and this one, everyone's on > 64bit, except the CentOS guy who said it worked ok on 32bit but not on > 64bit. > > Maybe thats the problem with the ctypes+geos bindings in GeoDjango? > I'm running something-pre-1.0, but I can try it on a trunk checkount > to confirm the same symptoms. > > Rob :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: problem saving form data in sams "24 hour" book example
Thank you so much - that was a huge help! Margie On Dec 2, 5:17 pm, "Colin Bean" <[EMAIL PROTECTED]> wrote: > On Tue, Dec 2, 2008 at 5:09 PM, Margie <[EMAIL PROTECTED]> wrote: > > > I'm a new user to django and am attempting to go through the Sams > > "Teach Yourself Django in 24 hours" book and am having an issue > > related to the chapter on saving form data. I'm hoping someone can > > give me a hand. > > > I'm using Django 1.0 > > > Here's my model: > > > class Person(models.Model): > > userID = models.ForeignKey(User, unique=True) > > name = models.CharField('name', max_length=200) > > birthday = models.DateField('Birthday', blank = True, null=True) > > email=models.EmailField('Email', max_length=100, unique=True) > > > Here's what the book says to use for the form: > > > def person_form(request, pID='0'): > > p = get_object_or_404(Person, pk=pID) > > if request.method == 'POST': > > if request.POST['submit'] == 'update': > > message = 'Update Request for %s.' % p.name > > PersonForm = forms.form_for_instance(p) > > f = PersonForm(request.POST.copy()) > > if f.is_valid(): > > try: > > f.save() > > message += ' Updated.' > > except: > > message = ' Database Error.' > > else: > > message += ' Invalid.' > > > That seems to be the "old" way of doing forms (I found that > > forms_for_instance doesn't exist), > > so I've modified it to look like this: > > > class PersonForm(ModelForm): > > class Meta: > > model=Person > > > def person_form(request, pID='0'): > > p = get_object_or_404(Person, pk=pID) > > if request.method == 'POST': > > if request.POST['submit'] == 'update': > > message = 'Update Request for %s.' % p.name > > f = PersonForm(request.POST) > > if f.is_valid(): > > try: > > f.save() > > message += ' Updates.' > > except: > > message = ' Database Error.' > > else: > > message += ' Invalid.' > > > I hope my modications are correct here - they could be part of the > > issue. > > > The problem I have is that when I go to the form for a person, such as > >http://127.0.0.1:8000/people/Form/3/, and then modify a field such > > as the birthday, when I then click on the update button, the is_valid > > () > > method returns false and the errors that get printed to the form are: > > * Person with this UserID already exists > > * Person with this Email already exists > > > It seems like update is trying to create a new person with the > > same UserID, when really I want to just be modifying the person > > with that UserID. > > > Can anyone tell me what I'm doing wrong? > > > Thanks, > > > Margie > > Change the way you create your form from this: > > f = PersonForm(request.POST) > > to this: > > f = PersonForm(request.POST, instance=p) > > Then your form will be populated with the data from 'p', and update > that record instead of creating a new one. > > Colin- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 create json from template?
Hi, I know about the serialisation framework, but with MultiResponse[1] you can't really use it (and anyway I don't know how to customise it extensively). As a result I would like to create json with the django template engine. An example code would be this: [{% for poll in data %} {"question": "{{ poll.question }}"}, [ {% for answer in poll.answer_set.all %} {"answer": "{{ answer.answer }}", "votes": {{ answer.votes }}, "vote_url": "{% url multi_api_data data=answer.pk %}",}, {% endfor %} ]}, {% endfor %} ] But at parsing simplejson.py gives an error. The error is easy to understand with the following example: ["a"] <- this is fine for simplejson.loads ["a",] <- this kills simplejson.loads Any ideas how to generate a for loop without the last colon(,)? Or how to use json syntax in the template in general? thanks, V [1]: http://toastdriven.com/fresh/more-multiresponse -- Viktor Nagy - http://viktornagy.com PhD student Toulouse School of Economics --~--~-~--~~~---~--~~ 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: problem saving form data in sams "24 hour" book example
On Tue, Dec 2, 2008 at 5:09 PM, Margie <[EMAIL PROTECTED]> wrote: > > I'm a new user to django and am attempting to go through the Sams > "Teach Yourself Django in 24 hours" book and am having an issue > related to the chapter on saving form data. I'm hoping someone can > give me a hand. > > I'm using Django 1.0 > > Here's my model: > > class Person(models.Model): >userID = models.ForeignKey(User, unique=True) >name = models.CharField('name', max_length=200) >birthday = models.DateField('Birthday', blank = True, null=True) >email=models.EmailField('Email', max_length=100, unique=True) > > Here's what the book says to use for the form: > > def person_form(request, pID='0'): >p = get_object_or_404(Person, pk=pID) >if request.method == 'POST': >if request.POST['submit'] == 'update': >message = 'Update Request for %s.' % p.name >PersonForm = forms.form_for_instance(p) >f = PersonForm(request.POST.copy()) >if f.is_valid(): >try: >f.save() >message += ' Updated.' >except: >message = ' Database Error.' >else: >message += ' Invalid.' > > > That seems to be the "old" way of doing forms (I found that > forms_for_instance doesn't exist), > so I've modified it to look like this: > > class PersonForm(ModelForm): >class Meta: >model=Person > > def person_form(request, pID='0'): >p = get_object_or_404(Person, pk=pID) >if request.method == 'POST': >if request.POST['submit'] == 'update': >message = 'Update Request for %s.' % p.name >f = PersonForm(request.POST) >if f.is_valid(): >try: >f.save() >message += ' Updates.' >except: >message = ' Database Error.' >else: >message += ' Invalid.' > > I hope my modications are correct here - they could be part of the > issue. > > The problem I have is that when I go to the form for a person, such as > http://127.0.0.1:8000/people/Form/3/, and then modify a field such > as the birthday, when I then click on the update button, the is_valid > () > method returns false and the errors that get printed to the form are: > * Person with this UserID already exists > * Person with this Email already exists > > It seems like update is trying to create a new person with the > same UserID, when really I want to just be modifying the person > with that UserID. > > Can anyone tell me what I'm doing wrong? > > Thanks, > > Margie > > > > > > Change the way you create your form from this: f = PersonForm(request.POST) to this: f = PersonForm(request.POST, instance=p) Then your form will be populated with the data from 'p', and update that record instead of creating a new one. Colin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
problem saving form data in sams "24 hour" book example
I'm a new user to django and am attempting to go through the Sams "Teach Yourself Django in 24 hours" book and am having an issue related to the chapter on saving form data. I'm hoping someone can give me a hand. I'm using Django 1.0 Here's my model: class Person(models.Model): userID = models.ForeignKey(User, unique=True) name = models.CharField('name', max_length=200) birthday = models.DateField('Birthday', blank = True, null=True) email=models.EmailField('Email', max_length=100, unique=True) Here's what the book says to use for the form: def person_form(request, pID='0'): p = get_object_or_404(Person, pk=pID) if request.method == 'POST': if request.POST['submit'] == 'update': message = 'Update Request for %s.' % p.name PersonForm = forms.form_for_instance(p) f = PersonForm(request.POST.copy()) if f.is_valid(): try: f.save() message += ' Updated.' except: message = ' Database Error.' else: message += ' Invalid.' That seems to be the "old" way of doing forms (I found that forms_for_instance doesn't exist), so I've modified it to look like this: class PersonForm(ModelForm): class Meta: model=Person def person_form(request, pID='0'): p = get_object_or_404(Person, pk=pID) if request.method == 'POST': if request.POST['submit'] == 'update': message = 'Update Request for %s.' % p.name f = PersonForm(request.POST) if f.is_valid(): try: f.save() message += ' Updates.' except: message = ' Database Error.' else: message += ' Invalid.' I hope my modications are correct here - they could be part of the issue. The problem I have is that when I go to the form for a person, such as http://127.0.0.1:8000/people/Form/3/, and then modify a field such as the birthday, when I then click on the update button, the is_valid () method returns false and the errors that get printed to the form are: * Person with this UserID already exists * Person with this Email already exists It seems like update is trying to create a new person with the same UserID, when really I want to just be modifying the person with that UserID. Can anyone tell me what I'm doing wrong? Thanks, Margie --~--~-~--~~~---~--~~ 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 in Ubuntu 8.10, Segmentation Fault
On Dec 3, 1:40 pm, rcoup <[EMAIL PROTECTED]> wrote: > Leading me to:http://sgillies.net/blog/829/shapely-1-0-8/ > > "The same problem [segfault] could afflict any python package that > uses Ctypes on 64-bit systems without explicitly marking argument and > return types. " The relevant changeset in the shapely lib for the fix is: http://trac.gispython.org/lab/changeset/1145 Rob :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: GeoDjango in Ubuntu 8.10, Segmentation Fault
Posting to geos-devel, I got this reply from Paul Ramsey: http://lists.osgeo.org/pipermail/geos-devel/2008-December/003800.html Leading me to: http://sgillies.net/blog/829/shapely-1-0-8/ "The same problem [segfault] could afflict any python package that uses Ctypes on 64-bit systems without explicitly marking argument and return types. " Looking back through the modwsgi thread and this one, everyone's on 64bit, except the CentOS guy who said it worked ok on 32bit but not on 64bit. Maybe thats the problem with the ctypes+geos bindings in GeoDjango? I'm running something-pre-1.0, but I can try it on a trunk checkount to confirm the same symptoms. Rob :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to create and send a pdf attachment
Does anyone have a code sample that shows how to create a pdf document and then, without saving that document to disk, email it as an attachment? I am using the ReportLab PDF library at the platypus level for pdf creation. For emailing, I expect to use Django's EmailMessage class. 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: Adjusting PYTHONPATH for reusable django apps
Thanks for both tips. James I will trial the virtual environment and if I get stuck can use Dan's method. --~--~-~--~~~---~--~~ 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: Adjusting PYTHONPATH for reusable django apps
That would work but I put them right at the root of my project, not in an app folder so I just add 'blog' to my INSTALLED_APPS. Every distributable app I saw is meant to be put somewhere directly in the PYTHONPATH and not in a subpackage so I follow that rule. If you put them inside an folder name apps in your project directory to be more organized, you can do: from os.path import dirname, join from sys import path path.append(join(dirname(__file__), "apps")) You could always just do dirname(__file__) + "/apps" but os.path.join is os independant too and will join okay on Windows too. By the way, I also use the __file__ trick to put my database directly in my project's folder no matter where in the filesystem the project is and likewise with my templates. --~--~-~--~~~---~--~~ 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: Adjusting PYTHONPATH for reusable django apps
For what it's worth, I'm a huge fan of virtualenv: http://pypi.python.org/pypi/virtualenv and of Doug Hellmann's virtualenvwrapper: http://www.doughellmann.com/projects/virtualenvwrapper/ What virtualenv does, basically, is create an isolated Python environment into which you can install stuff without affecting any other Python software on your system. And virtualenvwrapper provides tools for easily creating, removing and working with virtualenvs. So my workflow these days goes something like this: mkvirtualenv somepythonproject (this creates a new virtualenv, named "somepythonproject", and drops me into it; if I come back later in another shell, "workon somepythonproject" will put me back in the virtualenv) >From there I have easy_install for installing Python packages I want to try out, or I can use the "add2virtualenv" function in virtualenvwrapper to add a directory to the virtualenv's Python path. For example: add2virtualenv ~/dev/my-django-apps/ Within the virtualenv, everything I've installed or added to it is available, but it doesn't affect anything else on my system; I can blow it away with no repercussions if I mess something up, or keep adding/tweaking stuff as needed. It's even getting easier to do real deployment with this, too; mod_wsgi supports a directive that lets you point it at a virtualenv to run a site out of a completely-sandboxed environment, so you can simply use normal tools within the virtualenv to set things up and not worry about clashing with anything else. If you haven't looked into this, I highly recommend it. And maybe in the 2nd edition of the book I'll try to explain this a bit more clearly... -- "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 -~--~~~~--~~--~--~---
modelformset_factory error: (Hidden field id) with this None already exists.
Hi all, I've been stumped by this error for the past few days and haven't made any progress. Could someone please help out? I've created a formset of seven entries, one for each day of the previous week. The first submission works fine; all seven entries are successfully submitted. Subsequent submissions, however, generate the following error for each of the seven entries: (Hidden field id) Status report with this None already exists. I found an django issue from a few months ago which might be related [1]. However, this bug was resolved back in Oct. and I'm running 1.0.2, so I assume the CL is included. Is there any way to be certain? Here are my models, simplified for space: class Vehicle(models.Model): number = models.IntegerField(unique=True) class StatusReport(models.Model): date = models.DateField() vehicle = models.ForeignKey(Vehicle, to_field='number') status= models.CharField ('status',max_length=8,choices=STATUS_REPORT_CHOICES) class Meta: unique_together = ("date", "vehicle") And here's my view: def GenerateReportDate(request, vehicle_id, date): # removed verification code for clarity # week_start = monday before date. # week_end = week_start + datetime.timedelta(7) for i in range(7): check_date = week_start + datetime.timedelta(i) obj, created = StatusReport.objects.get_or_create(vehicle = int (vehicle_id), date = check_date, defaults={'date': check_date, 'vehicle':vehicle[0]}) # Pull 7 reports for this week reports = StatusReport.objects.filter( vehicle__exact=vehicle_id ).filter( date__gte = week_start ).filter( date__lte = week_end ).order_by("date") ReportFormSet = modelformset_factory(StatusReport, extra=0) if request.method == 'POST': formset = ReportFormSet(request.POST, request.FILES) if formset.is_valid(): formset.save() return HttpResponseRedirect('../done/') # Redirect after POST else: formset = ReportFormSet(queryset=reports) return render_to_response('ops/report.html', {'formset': formset, 'number': vehicle_id, 'weekof': week_start}) Thanks for any help, -Josh [1] http://code.djangoproject.com/ticket/9039 --~--~-~--~~~---~--~~ 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: Adjusting PYTHONPATH for reusable django apps
Thanks for the reply I'll give that a try. Just one question does that mean you make a structure like so ? Project settings.py urls.py etc __init__.py (this is where above code goes) >>>apps >blog >>>__init__.py >>>models.py >>>views.py so that means in your installed_apps you can just call : " 'apps.blog', " cheers Andy --~--~-~--~~~---~--~~ 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: Adjusting PYTHONPATH for reusable django apps
I prefer to to just put the apps in the project's folder and put *that* folder on the PYTHONPATH then move it elsewhere only when I find out I actually need it elsewhere. To make it more portable, I find out where my project is in my filesystem at runtime so if I move it around, it's no problem. So, I put this code into the __init__.py of my project's folder: from os.path import dirname from sys import path path.append(dirname(__file__)) sys.path is a list that holds everything that is in your PYTHONPATH __file__ is a magic variable that holds where the file that's currently running is in the filesystem and os.path.dirname extract the directory name in an OS independant way. You can of course add any folder you want in your PYTHONPATH this way, not just the project's folder as I do. On Tue, Dec 2, 2008 at 6:07 PM, Opel <[EMAIL PROTECTED]> wrote: > > I have been following along to the excellent James Bennet Book, > Practical Django Projects and he suggests creating apps in a directory > that can be reusable for local development. > > I am working on OSX (tiger and Leopard on different machines) and I > have created a Django director inside my /User/Sites folder. Al m > django projects will be developed here and as per James suggestion I > was going to create and "Apps" sub directory i.e /Users/Sites/Django/ > Apps/ > > I have searched the web and even tried to use the pylink tool but I > cannot get my Python path to recognise this new "Apps" folder. > Whenever I try to include an app in my INSTALLED_APPS I get "module > not found error" > > Could anyone please help out or post a link to a tutorial please. > > 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 -~--~~~~--~~--~--~---
Adjusting PYTHONPATH for reusable django apps
I have been following along to the excellent James Bennet Book, Practical Django Projects and he suggests creating apps in a directory that can be reusable for local development. I am working on OSX (tiger and Leopard on different machines) and I have created a Django director inside my /User/Sites folder. Al m django projects will be developed here and as per James suggestion I was going to create and "Apps" sub directory i.e /Users/Sites/Django/ Apps/ I have searched the web and even tried to use the pylink tool but I cannot get my Python path to recognise this new "Apps" folder. Whenever I try to include an app in my INSTALLED_APPS I get "module not found error" Could anyone please help out or post a link to a tutorial please. 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: replacing a contrib class
> I did considered , but I could not see how to do it , the model I want > to inherit is from > contrib.Users and the model I want to replace is contrib.Users . > It looks to me like a circular reference ...?? > How can I use the inherited model in the model I inherited from ?? It's still not clear what you mean by "replacing a model". Let's say you derive your class MyUser from the django.contrib.auth.models.User class like this: class MyUser(User): pass What is it that you want to do in the MyUser inherited class now? -Rajesh D --~--~-~--~~~---~--~~ 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: Non-displayed fields on admin form get overwritten
> I am using Django v1.0. When I use the "fields" attribute in my model > to tell the admin interface what fields to display on the change form, > I find that any fields I leave out get truncated when I use the form > to update a record. > > For instance, say I have a model class called "Users" that has the > following fields: > > Name > Email > Phone > > I use the fields attribute to display only the "Name" and "Email" > fields on the admin change form page. > > Using a custom form (not the admin interface), I then create a record > as follows: > > Name: Joe Smith > Email: [EMAIL PROTECTED] > Phone: 609-555-1212 > > I confirm that the information is in the database. > > I then navigate to the admin change form. I see only the "Name" and > "Email" fields (which is what I want). I update the email field (say, > "[EMAIL PROTECTED]"). I click "Save". I go into the database and > what was in the phone field is gone. The Admin's default ModelForm updates only the declared fields if you do declare them explicitly (either via "fieldsets" or via "fields"/"exclude".) Can you share your model and admin code? -Rajesh D --~--~-~--~~~---~--~~ 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: testing template tags
Thanks a lot. For some reason I haven't noticed the relevant fragment in the docs... Cheers, -- Richard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: forms.ModelMultipleChoiceField
On Dec 2, 9:04 pm, "Alfredo Alessandrini" <[EMAIL PROTECTED]> wrote: > Hi, > > I've set the player form with: > > class PlayerForm(forms.Form): > challengeable = forms.BooleanField(required=False) > show_name = forms.BooleanField(required=False) > country = forms.ModelMultipleChoiceField(queryset=Country.objects.all()) > > and the template with: > > > > > I've a problem to set the field 'country': > > > thanks, > > Alfredo If you're using Django's form facilities to define the data, why don't you use it to output the HTML? Just use {{ form.as_p }}, or if you want to position each form element separately, do it like this: {{ form.challengeable }} {{ form.show_name }} {{ form.country }} -- 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 -~--~~~~--~~--~--~---
forms.ModelMultipleChoiceField
Hi, I've set the player form with: class PlayerForm(forms.Form): challengeable = forms.BooleanField(required=False) show_name = forms.BooleanField(required=False) country = forms.ModelMultipleChoiceField(queryset=Country.objects.all()) and the template with: I've a problem to set the field 'country': http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying items of a linked object in a template
@Daniel and Bruno, Thanks a lot it is working ! --~--~-~--~~~---~--~~ 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: replacing a contrib class
Hi , I did considered , but I could not see how to do it , the model I want to inherit is from contrib.Users and the model I want to replace is contrib.Users . It looks to me like a circular reference ...?? How can I use the inherited model in the model I inherited from ?? Sandro On Dec 2, 12:18 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > > I want to define a class inherited from a contrib class namely users > > and replace it with the new one . > > Long ago there was a replace_module keyword in the meta class of the > > model , any idea how to achieve > > this ? > > First of all, why do you want to replace the contrib User model with > your inherited version? Have you considered simply using your > inherited version? > > -Rajesh D --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Non-displayed fields on admin form get overwritten
Hi. I am using Django v1.0. When I use the "fields" attribute in my model to tell the admin interface what fields to display on the change form, I find that any fields I leave out get truncated when I use the form to update a record. For instance, say I have a model class called "Users" that has the following fields: Name Email Phone I use the fields attribute to display only the "Name" and "Email" fields on the admin change form page. Using a custom form (not the admin interface), I then create a record as follows: Name: Joe Smith Email: [EMAIL PROTECTED] Phone: 609-555-1212 I confirm that the information is in the database. I then navigate to the admin change form. I see only the "Name" and "Email" fields (which is what I want). I update the email field (say, "[EMAIL PROTECTED]"). I click "Save". I go into the database and what was in the phone field is gone. Thanks for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: GeoDjango in Ubuntu 8.10, Segmentation Fault
On Nov 26, 6:07 am, Justin Bronn <[EMAIL PROTECTED]> wrote: > I created an Ubuntu 8.10 VM to try and test out this problem. > However, the only way that I could reproduce your exact problem > (segfault upon HTTP request) is when using the mpm-worker (threaded) > Apache. When using the prefork, however, I was able to get both > mod_python and mod_wsgi to work with a simple demonstration app [1]. > I think mpm-worker is the default when you do `apt-get install > apache2`, so make sure you have it removed, e.g., `apt-get remove > apache2-mpm-worker; apt-get install apache2-mpm-prefork`. See my experiences with Intrepid/apache/GEOS: http://groups.google.co.nz/group/modwsgi/browse_thread/thread/a488d2551c4c7df0 The minimal WSGI/script (crashes under mod-python too) i can get to segfault is: from django.contrib.gis.geos import GEOSGeometry g = GEOSGeometry('POINT(0 0)') foo = g.wkt #segfault Let me know if you want more testing done. Rob :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Dreamhost django solution (script)
I worked in a script that makes a full django environment setup on dreamhost http://gabrielfalcao.com/2008/12/02/hosting-and-deploying-django-apps-on-dreamhost/ Hope whis help someone! -- :wq Atenciosamente __ Gabriel Falcão Jabber: [EMAIL PROTECTED] Blog: http://www.nacaolivre.org --~--~-~--~~~---~--~~ 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: Ordering a ManyToManyField with "through" relation
I'm coming late to this thread -- this example is exactly what I was looking for, so thanks for posting this. I'm doing something where I want admins to be able to define an arbitrary number of Collections which are just different orderings and combinations of a (relatively) small set of Things. What's a good way to write this into the default Admin for Django? i.e. an admin should be able to add a new collection or a new thing, and affect the order of things within a collection, but they shouldn't need to manipulate the Membership table directly (as the integer order field is meaningless for the user so long as the proper order is represented). I don't quite know where to start, as I'm new to django. 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: time help (again)
On Monday 01 December 2008 9:01:11 pm Bobby Roberts wrote: > > http://www.python.org/doc/2.5.2/lib/datetime-timedelta.html > > yeah i said I don't understand this. I found datetimes easier to deal with when I used the modules found here: http://labix.org/python-dateutil As as an example for the first value in you post you can get a datetime as follows: from dateutil.parser import * hittime= parse("2008-12-01 22:02:59") hittime datetime.datetime(2008, 12, 1, 22, 2, 59) nowtime=datetime.datetime.now() I wrote a simple function to extract the seconds from two datetimes: def timeDiff(dt_1,dt_2): """Calculate time difference between two datetimes. """ print 'dt_1 = '+ str(dt_1) print 'dt_2 = '+ str(dt_2) dt_diff = dt_2 - dt_1 days = dt_diff.days print 'Days= '+str(days) seconds = dt_diff.seconds print 'Seconds= '+str(seconds) total_secs = (days * 86400) + seconds return total_secs So: timeclkfunc.timeDiff(hittime,n) dt_1 = 2008-12-01 22:02:59 dt_2 = 2008-12-01 22:32:47.391199 Days= 0 Seconds= 1788 Out[17]: 1788 -- Adrian Klaver [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: Query API: get all users without a group
You could do User.objects.exclude(groups__in=Group.objects.all ().query) which will actually generate a subquery. Alex On Dec 2, 10:45 am, Thomas Guettler <[EMAIL PROTECTED]> wrote: > Hi, > > I want to get all objects where the corresponding many-to-many field is > empty. > > Example: get all users without a group > > My solution: > User.objects.exclude(groups__in=Group.objects.all()) > > I think this is not optimal, since Group.objects.all() gets evaluated. > > Resulting SQL: > > SELECT "auth_user"."id", "auth_user"."username", > "auth_user"."first_name", "auth_user"."last_name", > "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", > "auth_user"."is_active", "auth_user"."is_superuser", > "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE > NOT ("auth_user"."id" IN (SELECT U1."user_id" FROM "auth_user" U0 > INNER JOIN "auth_user_groups" U1 ON (U0."id" = U1."user_id") > WHERE U1."group_id" IN (9, 10, 11, 8))) LIMIT 21 > > Any better way to do this? > > Should the extra() method be used for this? > > Thomas > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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: Model similar to a spreadsheet
Bruno: Thanks, I think that is exactly what I needed. I thought that I might need a model for the entries (you called them PersonItem), but I wasn't sure since I'm new to this kind of programming and thought there might be a more efficient way. Dan: Just imagine a spreadsheet, like OpenOffice Calc or MS Excel. But with two values per intersection (cell) instead of one. Thank you both for the responses. --~--~-~--~~~---~--~~ 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: Database model fields question
Thanks for pointing me in the right direction. Here's the solution I came up with: import socket, struct class ipfield(models.Field): __metaclass__ = models.SubfieldBase def db_type(self): return 'integer' def to_python(self, value): return socket.inet_ntoa(struct.pack('!L', value)) class tbl(models.Model) ip_field = ipfield() Note that this only deals with pulling data from the database, I don't need to worry about putting data in. Thanks! -Sned On Dec 1, 11:44 am, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Dec 1, 6:48 pm, sned <[EMAIL PROTECTED]> wrote: > > > > > Is there a way to tell django to use a specific function when > > selecting data from a model? > > > The sql is relatively simple, but I don't know how to convert that to > > model syntax. > > > Here's the issue: a table I'm working with stores ip addresses as a > > 10 digit integer. To get the ip address out of that, the sql is > > simply SELECT inet_ntoa(ip_field) FROM tbl; > > > I'm assuming there's some way to tell django to do that cast in the > > model: > > > class tbl(models.Model) > > ip_field = models.IntegerField( what do i do here? ) > > > Anyone have an idea? > > > Thanks! > > -sned > > AFAIK you can't easily define custom SQL to be used when getting a > field from the database. One approach might be to create a custom > model field[1], and override the to_python method to do the inet_ntoa > call in Python[2] (and similarly use the db_prep_save method to > convert back using inet_aton). > > [1] Full instructions for custom model > fields:http://docs.djangoproject.com/en/dev/howto/custom-model-fields/ > > [2] Python's socket module actually converts to and from packed > strings, you need struct.pack/unpack to get to and from integers. See > a recipe here:http://code.activestate.com/recipes/66517/ > > -- > 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: Why run two web-servers on the same host?
On Dec 2, 4:46 pm, walterbyrd <[EMAIL PROTECTED]> wrote: > All the python frameworks seem to do this: one web-server for > development, another for production. There may be a good reason for > this, but I don't see it. > > If you are doing internet development, then you certainly have a > network. So why not develop on one box, and then move the files to > another? > > For example, this is what I do with php: I mirror my web-site on my > development box. When the files on my development box work the way I > want, I just ftp those files to the web-site. I find this method much > more simple, fast, and robust, than trying to juggle two web-servers > on the same box. > > Also, why is it that with Django I have to restart the web-server, or > touch all files, any time I make any change? Where do you think it says you have to run two webservers on the same box for development and production? There's certainly no reason to do this unless you want to. Really, your development machine should be completely separate from your production machine. -- 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: Configuring Paths for FileField ?
Thanks! That's really helpful. So, in a production environment, you'd set up the MEDIA_ROOT to be somewhere within the generally accessible web-root, right? -E On Dec 2, 3:28 am, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 2 déc, 08:58, Eric <[EMAIL PROTECTED]> wrote: > > > Hi! > > > I'm new at Django, but I've been having relatively good luck. I've > > recently hit a big of a wall using FileField. I have set up the paths > > correctly enough that I can upload files to /my_site/uploads/photos, > > but when I view the model containing the FileField in the admin > > interface, it shows the URL of the photo > > as:http://localhost:8000/uploads/photos/flier.jpg > > > Clicking on this link, of course, produces a 404 error. > > > Is there an accepted way to set up the routes to make this /uploads/ > > directory publicly accessible? > > A couple links to the > FineManual:http://docs.djangoproject.com/en/dev/howto/static-files/http://docs.djangoproject.com/en/dev/ref/settings/#media-roothttp://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-c... > > HTH > > > Thanks for your time. --~--~-~--~~~---~--~~ 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: Why run two web-servers on the same host?
On 2 déc, 17:46, walterbyrd <[EMAIL PROTECTED]> wrote: > All the python frameworks seem to do this: one web-server for > development, another for production. There may be a good reason for > this, but I don't see it. Err... Not breaking whatever on the production server, perhaps ? FWIW, this is nothing specific to Django nor Python - no one in his own mind would work directly on a production server. > For example, this is what I do with php: I mirror my web-site on my > development box. When the files on my development box work the way I > want, I just ftp those files to the web-site. So you have your development server on your own box ? Fine. That's what most of us do, FWIW. Having an intermediate 'pre-production' server is still usefull, for integration tests (team work), and to give the customer access to work-in-progress. > I find this method much > more simple, fast, and robust, than trying to juggle two web-servers > on the same box. ??? two web servers on the same box ??? > Also, why is it that with Django I have to restart the web-server, or > touch all files, any time I make any change? Because django runs as a long-running process, and does not rebuild the whole world on each and any request (which is what PHP do). As a side note : Django also comes with a builtin dev server that doesn't even require setting up apache or anything else, and that knows how to auto-restart when necessary. 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: Query API: get all users without a group
On 2 Gru, 16:45, Thomas Guettler <[EMAIL PROTECTED]> wrote: > Hi, > > I want to get all objects where the corresponding many-to-many field is > empty. > > Example: get all users without a group [...] The preferred solution is using the `isnull` filter: User.objects.filter(groups__isnull=True) It evaluates to a left join of the `auth_user` table with `auth_user_groups` and a simple `where` statement. fw --~--~-~--~~~---~--~~ 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 return Admin to previous filters after save?
Thanks, that's good to know. -Josh --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Why run two web-servers on the same host?
All the python frameworks seem to do this: one web-server for development, another for production. There may be a good reason for this, but I don't see it. If you are doing internet development, then you certainly have a network. So why not develop on one box, and then move the files to another? For example, this is what I do with php: I mirror my web-site on my development box. When the files on my development box work the way I want, I just ftp those files to the web-site. I find this method much more simple, fast, and robust, than trying to juggle two web-servers on the same box. Also, why is it that with Django I have to restart the web-server, or touch all files, any time I make any change? --~--~-~--~~~---~--~~ 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 css, is this still supported?
I've searched for the admin CSS guide, and found it deprecated (http:// docs.djangoproject.com/en/dev/obsolete/admin-css/?from=olddocs), is there a replacement? Thanks, John M --~--~-~--~~~---~--~~ 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 can I use more than 24 hours in TimeField?
Hi, Maybe my TimedeltaField helps you: http://www.djangosnippets.org/snippets/1060/ K*K schrieb: > As you know time data type in mysql allow to be used more than 24 > hours, but when there is a more than 24 hours record in the table > such as 72:00:00, and then query the table with Django ORM, it will > report 'ValueError hour must be in 0..23'. > > I'm porting a old program that record rum times of the machines to > Django, so 24 hours is not enough for my new program. > > How can I resolve it ? > > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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 randomize a sliced query set?
Worked like a charm... Thanks! > >> coupon_items = Item.objects.all()[:25] >> random.shuffle(coupon_items) >> >> doesn't word because a QuerySet object does not support item >> assignment, which is used by random.shuffle. > > You might be able to cast the queryset as a list and then use > random.shuffle: > > coupon_items = list(Item.objects.all()[:25]) > random.shuffle(coupon_items) > > -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Query API: get all users without a group
Hi, I want to get all objects where the corresponding many-to-many field is empty. Example: get all users without a group My solution: User.objects.exclude(groups__in=Group.objects.all()) I think this is not optimal, since Group.objects.all() gets evaluated. Resulting SQL: SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE NOT ("auth_user"."id" IN (SELECT U1."user_id" FROM "auth_user" U0 INNER JOIN "auth_user_groups" U1 ON (U0."id" = U1."user_id") WHERE U1."group_id" IN (9, 10, 11, 8))) LIMIT 21 Any better way to do this? Should the extra() method be used for this? Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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: Local flavor and admin (zip-code)
Dear Sergio, thank you very much for your reply. sergioh wrote: [...] > from django.contrib.localflavor.it.forms import ITZipCodeField > from django import forms > from django.utils.translation import ugettext_lazy as _ > > class DittaDipendentiAdmin(admin.ModelAdmin): > cap = ITZipCodeField(_('ZIP Code')) > > class Meta: > model= DittaDipendenti > > Just overriding the form field using the ITZipCodeField, works fine. If I write: class DittaProva(models.Model): cap = models.IntegerField("Cap",max_length=5) from django.contrib.localflavor.it.forms import ITZipCodeField from django import forms from django.utils.translation import ugettext_lazy as _ class DittaProvaAdmin(admin.ModelAdmin): cap = ITZipCodeField(_('ZIP Code')) class Meta: model= DittaProva then I get this error at the command line: $ python manage.py syncdb [...] class DittaProvaAdmin(admin.ModelAdmin): File "/home/fabio/my_django/arteak/../arteak/anagrafiche/models.py", line 20, in DittaProvaAdmin cap = ITZipCodeField(_('ZIP Code')) File "/home/fabio/my_django/django-trunk/django/contrib/localflavor/it/forms.py", line 18, in __init__ max_length=None, min_length=None, *args, **kwargs) TypeError: __init__() got multiple values for keyword argument 'max_length' Do I miss anything? Any other tips? Thanks again, 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: Many-to-Many to exists table
If I understood you problem: {{{ from django.contrib.auth.models import Group class Area(models.Model): groups=models.ManyToManyField(Group) }}} This creates a Many-To-May relation to Group. Copied from brain to keyboard (untested) HTH, Thomas nucles schrieb: > Hello Django-People, > > we use the embedded functionality of the user authentication in > Django. > We use folowing models: "user", "auth_group", "auth_user_group" and > other embedded models that does not matter in this context. > We would like to add the additional entity "area" with M-to-M relation > to the "user_auth_group" entity (please note: "user" has M-to-M > relation to "auth_group") > > How can we do this? The "user_auth_group" will be automatically > generate from Django, so we can not relate to this entity from any > other model. > > We can of cause create our own user authentication without embedded > user authentication in Django, but is this the best solution? > I hope you understand our problem. > > Thank you. > Regard > Nucles > > > > > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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: Question from django beginner
On Tue, Dec 2, 2008 at 3:42 AM, Vince <[EMAIL PROTECTED]> wrote: > 2. Is there any built-in opton in Django (0.97 version) to unzip There is no such thing as "Django 0.97". Releases of Django are as follows: 0.90 0.91 0.95 0.96 1.0 (with minor bugfix releases on several of them, like "0.96.1" and "1.0.2") -- "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 -~--~~~~--~~--~--~---
Re: time help (again)
Before getting the value you must check of its types which type is you can not find the difference between DateObject-StrObject so you have to have same kind of datatype second thing open your terminal write python >>import datetime >>help(datetime) which will list you all the function. there is one function strftime() to format your date. so you can discard nanoseconds >>result=date1-date2 On Dec 2, 10:50 am, humanstalker <[EMAIL PROTECTED]> wrote: > Hi > > Just thought i would help out anyway even though this is solved. > > d = datetime.datetime.now() - datetime.datetime.strptime > (dbValueHere,"%Y-%m-%d") # Does a date diff between today and the date > from the DB, change "%Y-%m-%d" to suit the format of you string.Also > make sure you set the dbValueHere or replace it with you own value. > > print d.seconds # Prints the seconds > print d.days #Prints the days > > This allows you to get the days and seconds , its not much different > than the other solutions presented. > > ~stalkerh --~--~-~--~~~---~--~~ 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: XML templates
On Dec 2, 2008, at 5:50 PM, Vicky wrote: > > I did as you said. Still its giving the same error :( Are you using forward slashes instead of backslashes? The docs indicate that's necessary... > > > > > > On Dec 2, 11:38 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: >> On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote: >>> I tried the code below: >> >>> from django.template import loader, Context >> >>> def NewspaperSelect(request,u_id): >>> t=loader.get_template(r'C:\django\noddler\news >>> \template.vxml') >>>c=Context({ 'topic':'news', 'content':pn }) >>>return HttpResponse(t.render(c), mimetype='application/xml') >> >>> I verified that the file is in the location. But when i compile it >>> keeps telling that template file does not exist. What to do? >> >> get_template() doesn't take a full path to a file. It takes the >> name of >> a template, possibly with some directories in front -- but it's a >> relative path. What the path is relative to depends on the template >> loader being used. Unless you've done anything special to your setup, >> Django will try the application loader first -- appending the path to >> /templates/ for each app_name that you have installed. >> Then it >> will try the filesystem loader, which will append the path to each >> diretcory in the TEMPLATE_DIRS setting and see if it exists. >> >> So you either need to set up TEMPLATE_DIRS or put the templates in a >> templates/ directory inside one (or more) of your applications. >> >> This ends up making the code very portable, by the way, since when >> you >> install it somewhere else, you only have to change the TEMPLATE_DIRS >> settings (at most) and all your templates will still load correctly. >> >> 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: Question from django beginner
> > 2. Is there any built-in opton in Django (0.97 version) to unzip > files. I would need to unzip the file to a folder once the upload has > been done. Python provides libraries to handle zip files. Here's the starting point: http://www.python.org/doc/2.5.2/lib/archiving.html -Rajesh D --~--~-~--~~~---~--~~ 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: replacing a contrib class
> > I want to define a class inherited from a contrib class namely users > and replace it with the new one . > Long ago there was a replace_module keyword in the meta class of the > model , any idea how to achieve > this ? First of all, why do you want to replace the contrib User model with your inherited version? Have you considered simply using your inherited version? -Rajesh D --~--~-~--~~~---~--~~ 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 randomize a sliced query set?
> coupon_items = Item.objects.all()[:25] > random.shuffle(coupon_items) > > doesn't word because a QuerySet object does not support item > assignment, which is used by random.shuffle. You might be able to cast the queryset as a list and then use random.shuffle: coupon_items = list(Item.objects.all()[:25]) random.shuffle(coupon_items) -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to randomize a sliced query set?
Hi, I'd like to have a sliced query set in random order. I tried coupon_items = Item.objects.order_by('?')[:25] ,it seemed to work first but than I noticed that coupon_items consists of doubled items (although all Item objects are distinct). coupon_items = Item.objects.all()[:25].order_by('?') doesn't work because you can't reorder a queryset once a slice has been taken. coupon_items = Item.objects.all()[:25] random.shuffle(coupon_items) doesn't word because a QuerySet object does not support item assignment, which is used by random.shuffle. The problem was also adressed by this thread http://groups.google.com/group/django-users/browse_thread/thread/1364d04127caff99 but I didn't get the answer... Regards, Benjamin --~--~-~--~~~---~--~~ 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: inline forms/subforms: how to use inlineformset_factory ?
> > I did read this documentation, and was confused because I read this: > > >>> from django.forms.models import inlineformset_factory > >>> BookFormSet = inlineformset_factory(Author, Book) > >>> author = Author.objects.get(name=u'Orson Scott Card') > >>> formset = BookFormSet(instance=author > > And thought, "ok, that works great in the interpreter, but how do I > put it into my system?" Does it go in forms.py? views.py? > > If it's forms.py, how do I structure it? > > I guess I'm just not getting it. Will try a load of trial and error > this evening see if I can get something to work. > > Cheers, > > Dominic Ok, I see this must be initiated just as shown in the documentation, in the views.py file. I have managed to get this far: from django.forms.models import inlineformset_factory #project view def project(request): ModelForm = inlineformset_factory(Project, Project_schedule) if request.method == 'POST': form = ProjectForm(request.POST) project = Project.objects.get(pk=request.pk) formset = ModelForm(instance=project) if form.is_valid(): form.save() return HttpResponseRedirect('') else: form = ProjectForm() formset = ModelForm() return render_to_response('sam_app/project.html', {'form': form, 'formset': formset}) At least I can now initialize a blank model inlineformset. However, I can't for the life of me work out how to tie the two together so that I can: 1) Validate both sets of data 2) save both to the database. As you can see, I tried request.pk, which I realize is really stupid as how can the thing have a PK when it's not even saved in the db? When I realized that, I hit a mental brick wall because without access to the pk how am I going to work with relations? Does the way to solve this involve: 1) saving the parent data (if it validates) 2) retrieve the pk from the db 3) use that pk to save the child data (if it validates) If so, what prevents the system from retrieving the incorrect pk, say in the case of heavy concurrent access of the db? This is all a bit confusing for a noob. If there was some kind of example code to look at I feel it would really help. I tried to dig through the admin code but found it a little heavy to follow. Cheers, Dominic --~--~-~--~~~---~--~~ 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: inline forms/subforms: how to use inlineformset_factory ?
> > Did you happen to read the official Django documentation on model > formsets? In model formsets there are two factory functions. > modelformset_factory and inlineformset_factory. The latter is a subset > of the former and makes it easier to work with related objects through > a foreign key. Therefore the only different between the two is how you > create them, but from then on they take on the same behavior and API. > With that in mind > readhttp://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1 > Brian, Thanks for you reply. I did read this documentation, and was confused because I read this: >>> from django.forms.models import inlineformset_factory >>> BookFormSet = inlineformset_factory(Author, Book) >>> author = Author.objects.get(name=u'Orson Scott Card') >>> formset = BookFormSet(instance=author And thought, "ok, that works great in the interpreter, but how do I put it into my system?" Does it go in forms.py? views.py? If it's forms.py, how do I structure it? I guess I'm just not getting it. Will try a load of trial and error this evening see if I can get something to work. Cheers, Dominic --~--~-~--~~~---~--~~ 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: Local flavor and admin (zip-code)
On Dec 1, 11:14 am, Fabio Natali <[EMAIL PROTECTED]> wrote: > Hi everybody! > > I'm having difficulties while trying to insert a zip-code field in one > of my models. I'd like to rely upon some italian local flavor stuff, > so to get some validation for free. > > Here comes my models.py: > > from django.contrib.localflavor.it import forms > > class DittaDipendenti(models.Model): > nome = models.CharField(max_length=30) > cap = models.IntegerField("Cap",max_length=5) > > class DittaDipendentiAdmin(admin.ModelAdmin): > def formfield_for_dbfield(self, db_field, **kwargs): > if db_field.name == "cap": > return forms.ITZipCodeField(**kwargs) > else: > return super(DittaDipendentiAdmin, > self).formfield_for_dbfield(db_field, **kwargs) from django.contrib.localflavor.it.forms import ITZipCodeField from django import forms from django.utils.translation import ugettext_lazy as _ class DittaDipendentiAdmin(admin.ModelAdmin): cap = ITZipCodeField(_('ZIP Code')) class Meta: model= DittaDipendenti Just overriding the form field using the ITZipCodeField, works fine. hope this works for you, Regards, Sergio > > I get this error: > > Request URL: http://localhost:8000/admin/anagrafiche/dittadipendenti/add/ > Exception Type: AttributeError > Exception Value: 'module' object has no attribute 'ITZipCodeField' > > Anyone who can kindly shed a bit of light on this? Or give me some > tips on the best way to get some zip-code field inside my model? I'll > provided more log/context if needed. > > Bye and thanks, 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: Custom inline form
I find the problem: The validation was performed also on new extra widget because I have added a field that was always valorized then the self.has_changed property was always true then the validation was performed also for the new extra widget. Now the field is empty by default. But now another problem, I would override the save_model method for the inline model to read the value of my custom widget. The problem is that if I put the save_model in ModelInline or in ModelAdmin class it is never executed...How can I read the property from my custom widget? mrsource ha scritto: > In the inline model option I have overriden the inline form with a > custom form where I only added a choices widget, now the validation > has a wrong behaviour...more precisely if I have set extra property to > 2 in inline model options, when I click "Save" django try to validate > even the two empty extra inline model that I have left blank and show > an error like "the primary key field must not be empty"... If I remove > my custom form all is ok. > > How can I avoid this validation on the empty extra filed? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
replacing a contrib class
Hi Everybody, I want to define a class inherited from a contrib class namely users and replace it with the new one . Long ago there was a replace_module keyword in the meta class of the model , any idea how to achieve this ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Question from django beginner
Hi everyone, I'm new to django so perhaps those are really simple questions so sorry about that: I had an php page already working (css formatted, imgs and everything), it's a very simple page for uploading zip files to a server. The server (system Apache 2.2.4 with django) has already the main app powered with django, so Apache is configured to go through django. I tried to do the fileupload through PHP, but couldn't figure out how to make main django app and php fileupload page working together. As soon as the \location tags of python,django were added to httpd.conf, PHP page stopped working. SetHandler python-program PythonPath "['D:\MainwebServer'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE server.settings PythonDebug On SetHandler None SetHandler None CARGAR MODULO PHP #Loadfile "D:/PHP/php5ts.dll" #PHPIniDir "D:/PHP/" #AddHandler application/x-httpd-php .php #AddHandler application/x-httpd-php-source .phps #AddType application/x-httpd-php .html So my first question goes here: Does anyone know how to share both PHP and django pages in the same web project ? Anyway, My 2nd move was to try to make the fileupload by using django itself, so here I already have a rather simple upload page, it works already but I want to add some more stuff: 1. As I had already the PHP page working I have all the design done (css, img, etc) I don't know how to easily "move" the html design to the django template (tried to point to MEDIA_ROOT but css doesn't apply) Here's my template Analyst DEMO server {% block body %} Subir fichero ZIP a servidor DEMO {{ form }} Resultados de subida. {% endblock %} and here's the old php page, it uses javascript to show/hide some labels once the fileupload was performed and if it was success or not: http://www.w3.org/1999/xhtml;> Main DEMO server Main DEMO server Subiendo fichero...
Fichero (zip): So: 2. Is there any built-in opton in Django (0.97 version) to unzip files. I would need to unzip the file to a folder once the upload has been done. Thanks a lot in advance for the help Vince --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Many-to-Many to exists table
Hello Django-People, we use the embedded functionality of the user authentication in Django. We use folowing models: "user", "auth_group", "auth_user_group" and other embedded models that does not matter in this context. We would like to add the additional entity "area" with M-to-M relation to the "user_auth_group" entity (please note: "user" has M-to-M relation to "auth_group") How can we do this? The "user_auth_group" will be automatically generate from Django, so we can not relate to this entity from any other model. We can of cause create our own user authentication without embedded user authentication in Django, but is this the best solution? I hope you understand our problem. Thank you. Regard Nucles --~--~-~--~~~---~--~~ 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: XML templates
I did as you said. Still its giving the same error :( On Dec 2, 11:38 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote: > > I tried the code below: > > > from django.template import loader, Context > > > def NewspaperSelect(request,u_id): > > t=loader.get_template(r'C:\django\noddler\news\template.vxml') > > c=Context({ 'topic':'news', 'content':pn }) > > return HttpResponse(t.render(c), mimetype='application/xml') > > > I verified that the file is in the location. But when i compile it > > keeps telling that template file does not exist. What to do? > > get_template() doesn't take a full path to a file. It takes the name of > a template, possibly with some directories in front -- but it's a > relative path. What the path is relative to depends on the template > loader being used. Unless you've done anything special to your setup, > Django will try the application loader first -- appending the path to > /templates/ for each app_name that you have installed. Then it > will try the filesystem loader, which will append the path to each > diretcory in the TEMPLATE_DIRS setting and see if it exists. > > So you either need to set up TEMPLATE_DIRS or put the templates in a > templates/ directory inside one (or more) of your applications. > > This ends up making the code very portable, by the way, since when you > install it somewhere else, you only have to change the TEMPLATE_DIRS > settings (at most) and all your templates will still load correctly. > > 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: admin.py -- AlreadyRegistered
hi, class BookAdmin(admin.ModelAdmin): pass # admin.site.register(Book, BookAdmin) Just put '#' in front of admin.site.register(Book, BookAdmin) .Now run the server ,if it s ok then remove the # On Tue, Dec 2, 2008 at 12:47 PM, Roland van Laar <[EMAIL PROTECTED]> wrote: > > djan wrote: > > Hello. > > > > I'm following along with djangobook.com and trying to make necessary > > changes to port django to version 1.0. In Django's Site > > Administration, chapter 6, I run into the error: > > > > > > Exception Type: AlreadyRegistered > > Exception Value: The model Book is already registered > > Exception Location: /usr/local/lib64/python2.5/site-packages/django/ > > contrib/admin/sites.py in register, line 64 > > > > > Probably: > Try to restart the django development server. > The django dev server doesn't reload the admin.py file properly when it's > edited or when it encounters an error in that file. > > > > I used the site administration site successfully with just "Book", and > > then when I attempted to add the other models (Auther, Publisher), I > > received the above error. > > > > in admin.py I have: > > > > from django.contrib import admin > > from models import Book, Author, Publisher > > > > > On another note, you don't have to do this: > > > class BookAdmin(admin.ModelAdmin): > > pass > > admin.site.register(Book, BookAdmin) > > > admin.site.register(Book) > > would suffice. > > > class AuthorAdmin(admin.ModelAuthor): > > pass > > admin.site.register(Author, AuthorAdmin) > > > > class PublisherAdmin(admin.ModelPublisher): > > pass > > admin.site.register(Publisher, PublisherAdmin) > > > > When I updated admin.py I ran: > > python manage.py syncdb > > > > It is as if the database wasn't "synced" though, and that two > > instances of this model are trying to be created. > > > > When I searched around for this error, I found instances of this > > occuring in 0.96, with the model being called several times. The Admin > > changes in 1.0 were said to resolve this, so perhaps it is something > > else. > > > > I appreciate any help. Thanks! > > > > > Regards, > > Roland > > > > > > --~--~-~--~~~---~--~~ 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: Using % with psycopg2
Siah schrieb: > Hi, > > The following code fails on windows, and works just fine on my unix > box. To fix the problem in windows, I must replace('%', '%%') so its > internal string formatting doesn't fail on me. Should I file this bug > for psycopg2? > > from django.db import connection > cursor=connection.cursor() > cursor.execute("select '%';") > print cursor.fetchall() > > Hi, I have seen this. See http://markmail.org/message/463cildcn777eltr See http://code.djangoproject.com/ticket/9055 I just saw, that the ticket still needs a testcase. Can you write one? Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ 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: Model similar to a spreadsheet
On 1 déc, 20:10, Stefan <[EMAIL PROTECTED]> wrote: > Hello, > > I'm new to Django and have some problems on how to create the models. > > What I want to do is something similar to a spreadsheet, but with more > than one data field per intersection. > > Basically like this: (http://dpaste.com/hold/95128/) > > Items/Members: Person_A | Person_B | Person_C > Item_1: x=1,y=3 | x=4,y=2 | x=7,y=5 > Item_2: x=8,y=2 | x=2,y=0 | x=8,y=4 > Item_3: x=4,y=9 | x=5,y=9 | x=3,y=1 > . > . > (and so on) > class CostSheet(models.Model): title=models.CharField(max_length=200) class Person(models.Model): name=models.CharField(max_length=200) class Item(models.Model): name=models.CharField(max_length=200) sheet=models.ForeignKey(CostSheet) class PersonItem(models.Model): person = models.ForeignKey(Person) item = models.ForeignKey(Item) x = models.IntegerField() y = models.IntegerField() Your specs are not enough detailed to make sure this is what you want, but this should at least get you started. --~--~-~--~~~---~--~~ 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: Configuring Paths for FileField ?
On 2 déc, 08:58, Eric <[EMAIL PROTECTED]> wrote: > Hi! > > I'm new at Django, but I've been having relatively good luck. I've > recently hit a big of a wall using FileField. I have set up the paths > correctly enough that I can upload files to /my_site/uploads/photos, > but when I view the model containing the FileField in the admin > interface, it shows the URL of the photo > as:http://localhost:8000/uploads/photos/flier.jpg > > Clicking on this link, of course, produces a 404 error. > > Is there an accepted way to set up the routes to make this /uploads/ > directory publicly accessible? A couple links to the FineManual: http://docs.djangoproject.com/en/dev/howto/static-files/ http://docs.djangoproject.com/en/dev/ref/settings/#media-root http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media HTH > Thanks for your time. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---