slow response when using manage runserver without Internet connection
Hi, I am using the Django built-in web server. The server's reponse time is nomal when connecting to Internet, once it's offline, the speed is extremely slow. Does anyone have experience how to fix it? 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 -~--~~~~--~~--~--~---
Re: Creating a "mostly static" site with Django -- dumb idea?
you might want to check out hugo's dbtemplate loader (which I updated to work with the current trunk) http://svn.zyons.python-hosting.com/trunk/zilbo/common/dbloader/ that way you can store the templates themselves in a database, which might make life a bit more easier. regards Ian On 22/08/2006, at 3:21 PM, Bryan Chow wrote: > > Hi Sean, > > No worries, glad to hear that you find TemplatePages useful :) > > To answer your question, you can write a custom inclusion tag to > insert snippets of dynamic content into your templates. > http://www.djangoproject.com/documentation/templates_python/ > #inclusion-tags > > Alternately, you could use a custom template processor to make > variables available to your templates, and handle the rendering in the > templates instead. > http://www.djangoproject.com/documentation/templates_python/ > #subclassing-context-requestcontext > http://www.b-list.org/weblog/2006/06/14/django-tips-template- > context-processors > > Check out the SiteRoot context processor in verdjnlib for a working > example of a custom context processor. > http://www.verdjn.com/wiki/Siteroot > > Cheers, > Bryan > > > On 8/21/06, Sean Schertell <[EMAIL PROTECTED]> wrote: >> Hi Brian, >> >> I also owe you a big thanks :-) >> >> I hope Adrian and friends will consider rolling this or something >> like it into the django core. We really need a nice clean way to >> serve up static files within the context of a django website. >> >> If you consider that people me tend to build out the static site >> first, then add the dynamic bits later, it only makes sense to build >> in functionality for static pages. >> >> One quick question: >> >> What if I have a bunch of static pages but they all include a bit of >> dynamic content in the sidebar (pulled from the database)? How can I >> include that without writing a view method for every page? >> >> Cheers, >> Sean > -- Ian Holsman [EMAIL PROTECTED] http://garden-gossip.com/ -- what's in your garden? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Admin section: Possible to integrate image manipulation?
Hi Sean, Well, the main advantage is that PhotoField has already been written :) If PhotoField doesn't provide you with what you need, you could easily modify it, or use it as an example of how to create a custom field. Also, _post_save() has been deprecated since M-R was merged [1]. Regarding PIL vs. pymagick, we chose to use PIL because we had more experience with it, it's generally more easily available, and it provided all of the functionality that we needed. Cheers, Bryan [1] http://code.djangoproject.com/wiki/RemovingTheMagic#Overridingsaveanddeletemodelmethods On 8/21/06, Sean Schertell <[EMAIL PROTECTED]> wrote: > Looks very interesting Bryan. But I wonder if you could tell me what > advantages this would offer over just using the Python Image Library. > Same question regarding Joe's suggestion of using pymagick. > > btw: Thanks Joe for answering my original question, a post-save hook > sounds like just what I need. > > Sean --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating a "mostly static" site with Django -- dumb idea?
Hi Sean, No worries, glad to hear that you find TemplatePages useful :) To answer your question, you can write a custom inclusion tag to insert snippets of dynamic content into your templates. http://www.djangoproject.com/documentation/templates_python/#inclusion-tags Alternately, you could use a custom template processor to make variables available to your templates, and handle the rendering in the templates instead. http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext http://www.b-list.org/weblog/2006/06/14/django-tips-template-context-processors Check out the SiteRoot context processor in verdjnlib for a working example of a custom context processor. http://www.verdjn.com/wiki/Siteroot Cheers, Bryan On 8/21/06, Sean Schertell <[EMAIL PROTECTED]> wrote: > Hi Brian, > > I also owe you a big thanks :-) > > I hope Adrian and friends will consider rolling this or something > like it into the django core. We really need a nice clean way to > serve up static files within the context of a django website. > > If you consider that people me tend to build out the static site > first, then add the dynamic bits later, it only makes sense to build > in functionality for static pages. > > One quick question: > > What if I have a bunch of static pages but they all include a bit of > dynamic content in the sidebar (pulled from the database)? How can I > include that without writing a view method for every page? > > Cheers, > Sean --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Admin section: Possible to integrate image manipulation?
Looks very interesting Bryan. But I wonder if you could tell me what advantages this would offer over just using the Python Image Library. Same question regarding Joe's suggestion of using pymagick. btw: Thanks Joe for answering my original question, a post-save hook sounds like just what I need. Sean On Aug 22, 2006, at 8:55 AM, Bryan Chow wrote: > > On 8/21/06, Sean Schertell <[EMAIL PROTECTED]> wrote: >> ... I need my client to be able to upload some images in >> the admin section, then have Python do some resizing >> and cropping behind the scenes ... > > Take a look at PhotoField. Sounds like it would provide exactly what > you're looking for. > > http://www.verdjn.com/wiki/PhotoField > > Cheers, > Bryan > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django cannot connect to mysql after upgrade
After upgrade mysql from 5.0.22 to 5.0.24, django cannot work with mysql. The error messages as following: Traceback (most recent call last): File "./manage.py", line 11, in ? execute_manager(settings) File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py", line 1343, in execute_manager execute_from_command_line(action_mapping, argv) File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py", line 1260, in execute_from_command_line action_mapping[action]() File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/management.py", line 448, in syncdb cursor = connection.cursor() File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/mysql/base.py", line 90, in cursor self.connection = Database.connect(**kwargs) File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 75, in Connect return Connection(*args, **kwargs) File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 207, in __init__ self.autocommit(False) _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") -- from czk. My old mail boxes([EMAIL PROTECTED], [EMAIL PROTECTED]) have been deprecated. Please contact with me using the following email address from now on: [EMAIL PROTECTED] If you want to attach word/excel/powerpoint files for me, please convert them to pdf. because i have no money to buy ms-office. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating a "mostly static" site with Django -- dumb idea?
Hi Brian, I also owe you a big thanks :-) I hope Adrian and friends will consider rolling this or something like it into the django core. We really need a nice clean way to serve up static files within the context of a django website. If you consider that people me tend to build out the static site first, then add the dynamic bits later, it only makes sense to build in functionality for static pages. One quick question: What if I have a bunch of static pages but they all include a bit of dynamic content in the sidebar (pulled from the database)? How can I include that without writing a view method for every page? Cheers, Sean On Aug 22, 2006, at 9:00 AM, Bryan Chow wrote: > > Cool! Glad to have helped. > > Cheers, > Bryan > > > On 8/21/06, Derek Hoy <[EMAIL PROTECTED]> wrote: >> Just put this up on a site I'm moving from static pages to Django, >> and >> it's just what I needed- I'd been doing something horrible with >> subdomains to get it working, and been thinking of doing something >> like this myself. >> >> One thing I had to do, because the old site has loads of .html files >> in the root, is put the url regex straight into the site's urls.py as >> the last line, eg >> (r'^(?P.*)$', 'verdjnlib.templatepages.views.templatepage'), >> >> Huge thanks to you both for making this available. > > > > > DataFly.Net Complete Web Services http://www.datafly.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can't get Django to work Apache + mod_python
I'm having problems getting Django to work with Apache. Evenything works with "./manage.py runserver", but I get the errors listed below when I try to load the project with Apache and mod_python. I consistently get the same error the first and second refresh, followed by the "Third+" the rest of the time (until I restart Apache). Versions of stuff: Django latest svn Python 2.3.5 Apache 2.0.52 mod_python 3.1.3 PostgreSQL 7.4.13 psycopg 1.1.21 # First and second refresh Mod_python error: "PythonHandler django.core.handlers.modpython" Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 163, in handler return ModPythonHandler()(req) File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 131, in __call__ self.load_middleware() File "/usr/lib/python2.3/site-packages/django/core/handlers/base.py", line 29, in load_middleware mod = __import__(mw_module, '', '', ['']) File "/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py", line 2, in ? from django.contrib.sessions.models import Session File "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line 3, in ? from django.db import models File "/usr/lib/python2.3/site-packages/django/db/__init__.py", line 11, in ? backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, '', '', ['']) File "/usr/lib/python2.3/site-packages/django/db/backends/postgresql/base.py", line 12, in ? raise ImproperlyConfigured, "Error loading psycopg module: %s" % e ImproperlyConfigured: Error loading psycopg module: No module named DateTime # Third+ refreshes Mod_python error: "PythonHandler django.core.handlers.modpython" Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 163, in handler return ModPythonHandler()(req) File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 131, in __call__ self.load_middleware() File "/usr/lib/python2.3/site-packages/django/core/handlers/base.py", line 35, in load_middleware raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname) ImproperlyConfigured: Middleware module "django.contrib.sessions.middleware" does not define a "SessionMiddleware" class # relevant http.conf ServerName example.com ServerAlias www.example.com # My project's name is 'example' and the project folder is located in /home/web/pro/ PythonPath "['/home/web/pro/'] + sys.path" # PythonPath "['/home/web/pro'] + sys.path" #tried just in case it matters SetHandler python-program # SetHandler mod_python # tried this too PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE example.settings PythonDebug On # python path [EMAIL PROTECTED] ./manage.py shell Python 2.3.5 (#1, Aug 25 2005, 09:17:44) (InteractiveConsole) >>> import sys >>> sys.path ['/home/web/pro/example', '/usr/lib/python23.zip', '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages', '/usr/lib/python2.3/site-packages/PIL'] # DateTime exists [EMAIL PROTECTED] ls /usr/lib/python2.3/site-packages/mx/DateTime/ ARPA.py Doc ISO.pyo Locale.pyo Parser.py __init__.py ARPA.pyc ExamplesLICENSE NIST.py Parser.pyc __init__.pyc ARPA.pyo Feasts.py LazyModule.py NIST.pycParser.pyo __init__.pyo COPYRIGHT Feasts.pyc LazyModule.pyc NIST.pyoREADME mxDateTime DateTime.py Feasts.pyo LazyModule.pyo ODMG.py Timezone.py timegm.py DateTime.pyc ISO.py Locale.py ODMG.pycTimezone.pyc timegm.pyc DateTime.pyo ISO.pyc Locale.pyc ODMG.pyoTimezone.pyo timegm.pyo # version of psycopg [EMAIL PROTECTED] strings /usr/lib/python2.3/site-packages/psycopgmodule.so | grep -B 1 version 1.1.21 __version__ --~--~-~--~~~---~--~~ 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 -~--~~~~--
Re: Distribute Django program to run on a local computer
On 8/22/06, Rob Hudson <[EMAIL PROTECTED]> wrote: > > I started the process of testing this on Windows and found that Python > is only about 12MB installed. Compared to about 120MB for Ruby. My > thinking now is that all we need is a local copy of Python, a wrapper > script to get Django up and running and to launch a browser at > localhost:8000, and we're golden. > > I've gotten Django to run on Windows with Pysqlite2 and set up a basic > app. My next step is to see if I can build an executable to launch > Django. I've got a run.py script but it launches Python in a command > window. Unless I can answer a couple questions I may make a custom > program to handle this: > > 1. From within my run.py script can I tell it where the Python > executable is, similar to a Linux machine and its "/usr/bin/python" > script header? I'm looking for a relative path along the lines of > "Python24\python.exe". You want sys.executable: http://docs.python.org/lib/module-sys.html#l2h-342 Also, did you look at Movable Python? For a few dollars per installation, it may save you some headaches: http://www.voidspace.org.uk/python/movpy/ > 2. Can I kick off Django via my run.py script but not have it throw up > a command window? I'm guessing maybe something with Tk/Tkinter but I'd > like to avoid those extra dependencies if I can. pythonw.exe (in your python install directory) is the same as python.exe, but without the console output. Alan. -- Alan Green [EMAIL PROTECTED] - http://bright-green.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 -~--~~~~--~~--~--~---
Re: Reproduce admin search functionality
So how will I get the queries if more than one word is used to search? The only reason I am using the way I am is in case people search multiple words. Can I run queries and add them together or something? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Editting both sides of self-referential m2m relationship
On 8/21/06, James Punteney <[EMAIL PROTECTED]> wrote: Thanks for the responses, and yeah Maciej is correct the m2mrelationship works fine without any errors, it's just that I can onlyedit the prey relationship (as Maciej text art does a much better jobof showing than my explanation). Ok. Now we're on the same page :-)When I try adding a predator field so I have this in my model: prey = models.ManyToManyField("self", related_name="predator",symmetrical=False)predator = models.ManyToManyField("self", related_name="prey",symmetrical=False) Then it gives the following errors:As you should expect. The related names clash with the existing fields - yielding the errors you receive. Django automatically adds the 'other' side of the m2m relation - you shouldn't (and are prevented) from manually adding it yourself. If this is something the admin interface can't do then any pointers onhow to customize it or where to look for more information would be great.To the best of my knowledge, no - the admin interface can't do this. This is a limitation of the automatic manipulator framework. If you pull apart the manipulators, they only represent value, OneToOne, ForeignKey and ManyToMany fields, plus the reverse direction of Foreign Keys. M2M objects are not traversed in reverse. As a result, the admin interface can't represent the reverse direction of the relation like you describe. The same is also true of your own views if you use the default Add/Change manipulators. However, if you are working with your own view, you can customize the default manipulators to do most of the heavy lifting for you. Here's how: 1) Obtain a default manipulator: manipulator = Animal.ChangeManipulator(id) 2) Tweak the 'fields' member of the manipulator, manually adding a field to represent the reverse field. choices = [( a.id, a) for a in Animal.objects.all()] predator_field = forms.SelectMultipleField('predator', choices=choices, size=min(max(len(choices),5),15)) manipulator.fields.append(predator_field) Choices is a list of (id, display value) tuples of available options. The size field is used in the rendering of the html element.3) Construct a form wrapper, extract post data, validate, and save as normal for a validator 4) Extract the data relating to the reverse field. Assuming that new_data is the duplicate of the post dictionary: if new_data.getlist('predator'): Animal.predator = Animals.objects.filter (id__in=new_data.getlist('predator')) This doesn't require an explicit save, because it is modifying a m2m descriptor (which automatically save). Side note - this example highlights a problem with your model - your related_field name should be a plural, as it describes a set of predators, not a single predator. Modify your template to include a {{ form.predator }} element, and you're in business. If you include both a {{ form.predator }} and {{ form.prey }} element in your template, be aware that you could get some interesting behaviour, as changing the selection in one input element won't change the selection in another. As a result, it is possible for a change in one input to be overwritten by a change in a different element. Yours,Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Distribute Django program to run on a local computer
I started the process of testing this on Windows and found that Python is only about 12MB installed. Compared to about 120MB for Ruby. My thinking now is that all we need is a local copy of Python, a wrapper script to get Django up and running and to launch a browser at localhost:8000, and we're golden. I've gotten Django to run on Windows with Pysqlite2 and set up a basic app. My next step is to see if I can build an executable to launch Django. I've got a run.py script but it launches Python in a command window. Unless I can answer a couple questions I may make a custom program to handle this: 1. From within my run.py script can I tell it where the Python executable is, similar to a Linux machine and its "/usr/bin/python" script header? I'm looking for a relative path along the lines of "Python24\python.exe". 2. Can I kick off Django via my run.py script but not have it throw up a command window? I'm guessing maybe something with Tk/Tkinter but I'd like to avoid those extra dependencies if I can. Thanks, 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 -~--~~~~--~~--~--~---
Re: Outer joins as extras()
On 8/22/06, Alan Green <[EMAIL PROTECTED]> wrote: Hi,Has anybody found a way to add an table to query with an outer join? Anybody got a different way to do it?It isn't really a documented feature, and I haven't worked through the details (so you will need to do a little code spelunking by yourself) but you might get some traction playing around with Q objects in django/db/models/query.py. Although there is a base Q object, the only contractual obligation of that object is that it has a get_sql method that returns a tuple (joins, where, params). The 'joins' member is itself a list of tuples, each member being of the form (alias, (table, join_type, condition)). Line 462 of _get_sql_clause() on QuerySet shows how this tuple is then composed into an SQL query when a QuerySet is evaluated. So; if you wanted to set up an outer join, you could write a Q object (or Q-like object) that has a get_sql that returns OUTER JOIN as the join type, and pack it into a filter/exclude as you would any other Q object. Like I said - I haven't tried this; if it breaks, you get to keep every single one of the pieces :-)Yours,Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Reproduce admin search functionality
Seth Buntin wrote: > I got it!: > > def search(request): > keywords = request.GET['keyword'].split() > sql = "" > first = True > for word in keywords: > if first: > sql += "(title LIKE '%%" + word + "%%' OR description > LIKE '%%" + > word + "%%')" > first = False > else: > sql += " AND (title LIKE '%%" + word + "%%' OR > description LIKE '%%" > + word + "%%')" > > results_list = Resource.objects.extra(where=[sql]) > return render_to_response('tick/base_results.html', {'results_list': > results_list}) Hiya Seth, Nice solution but I'd use the quoting ability for the sql database if you are going to let humans near your application. They could do nasty things to your application if you don't remove quotes and various control characters. The built in sql functions should quote your SQL so that extra bits of sql aren't injected into your database e.g. drop table x or in Microsoft SQL Server's case just about doing anything you want to the whole box and surrounding network. Look at the Django documentation on the Database API - at the bit about "params" and for examples of sql injection look at the OWASP article - http://www.owasp.org/index.php/SQL_injection. Sorry if you knew this but if you did it's worth pointing out to others tempted by your code snippet :-). Good luck, Shaun Laughey. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating a "mostly static" site with Django -- dumb idea?
Cool! Glad to have helped. Cheers, Bryan On 8/21/06, Derek Hoy <[EMAIL PROTECTED]> wrote: > Just put this up on a site I'm moving from static pages to Django, and > it's just what I needed- I'd been doing something horrible with > subdomains to get it working, and been thinking of doing something > like this myself. > > One thing I had to do, because the old site has loads of .html files > in the root, is put the url regex straight into the site's urls.py as > the last line, eg > (r'^(?P.*)$', 'verdjnlib.templatepages.views.templatepage'), > > Huge thanks to you both for making this available. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Admin section: Possible to integrate image manipulation?
On 8/21/06, Sean Schertell <[EMAIL PROTECTED]> wrote: > ... I need my client to be able to upload some images in > the admin section, then have Python do some resizing > and cropping behind the scenes ... Take a look at PhotoField. Sounds like it would provide exactly what you're looking for. http://www.verdjn.com/wiki/PhotoField Cheers, Bryan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Admin section: Possible to integrate image manipulation?
You could write a post-save hook that manipulates the file after they are saved. Consider using the following python tool: http://www.python.net/crew/zack/pymagick/ This requires you to have image magik on your server. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Admin section: Possible to integrate image manipulation?
I'm trying to decide whether to build my own admin section or use the free one. The thing is, I need my client to be able to upload some images in the admin section, then have Python do some resizing and cropping behind the scenes. Do I need to make my own admin section for this? Or is there some way to add that kind of functionality to the django admin section? Any tips would be very helpful (this is my first django project). Sean --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: how to assign permissions to users and groups?
Chris Long escreveu: > If I have a group instance called students and I wanted to add it to > the user instance bill I would use: > bill.groups.add(students) > > If you want to have a permission for a view, you will have to use the > has_perm method that is within the user model (user.has_perm) and check > for the permission you want at the beginning of the view. E.g.: > > def view_students(request): >if not request.user.has_perm("university.view_students"): > raise PermissionDenied > But, how can I assign permissions to groups and users? And regarding my example: from the manage.py shell: >>> >>> from django.contrib.auth.models import Permission >>> >>> p = Permission(codename='subsidios.pode_consultar') >>> >>> p.codename 'subsidios.pode_consultar' >>> >>> p.save() from the Intac class of the subsidios package: class Intac: (...) class Meta: permissions = (("pode_consultar", "Pode consultar"),) This is what I get from the auth_permission table in postgreSQL: # select * from auth_permission; 74 | Pode consultar | pode_consultar| 32 75 | | subsidios.pode_consultar | which way is correct in the auth_permission table? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: [Fwd: multiple forms]
On 8/21/06, Sean <[EMAIL PROTECTED]> wrote: > > Hi, > I'm trying to write a batch insert view that gets data from a > > object-template, does some modification to the template (increment some > counters) and displays a form for each new object to be created. (I'm > adding Media files which are selected in a previous view, that why I > iterate over files) > The view looks like this: > > manipulator = Media.AddManipulator() > > form_list=list() > errors = {} > for file in files: > #assign new value to template object > template.media_signature = > incSignature(template.media_signature) > new_data = template.__dict__ > new_data["filename"] = file > form = forms.FormWrapper(manipulator, new_data, errors) > form_list.append(form) > > When the loop finishes I end up with a list of identical formWrapper > Objects, which is not what I expected. Looks like each created instance of FormWrapper is sharing the same instance of the new_data dictionary. Instead of just referencing the dictionary, try copying it: new_data = dict(template.__dict__) By the way, be really careful about accessing the __dict__ attribute in Django code. Django sprinkles all kinds of interesting stuff into its own objects, so you may sometimes get a surprise. Alan. -- Alan Green [EMAIL PROTECTED] - http://bright-green.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 -~--~~~~--~~--~--~---
Re: limit_choices_to Users in a Group
I think you need to include django.core.exceptions And I think that the exception is ObjectDoesNotExist Corey On Aug 21, 2006, at 4:24 PM, Waylan Limberg wrote: > > I figured this out, thanks to a suggestion in another thread. It seems > I was misunderstanding something about how limit_choices_to works. > Anyway, the following works: > > from django.contrib.auth.models import User, Group > > class Project(models.Model): > coordinator = models.ForeignKey( > User, > limit_choices_to={'groups__pk' : > Group.objects.get(name='Coordinator').id} > ) > > The only problem is that if there is no Group named "Coordinator" in > the db, I get an error so I tried the following; > > def limit_to_group(group_name): > try: > g = Group.objects.get(name=group_name).id > except DoesNotExist: > g = 0 # this should result in no users listed (I think/hope) > return g > > class Project(models.Model): > ... > limit_choices_to={'groups__pk' : limit_to_group > ('Coordinator')} > ... > > Which returns an error that DoesNotExist is not defined. What am I > missing here? > > On 8/16/06, Waylan Limberg <[EMAIL PROTECTED]> wrote: >> I'm not sure if my problem is related to this thread[1] or if I'm >> just >> misunderstanding something with regard to limit_choices_to. >> >> First I tried this (in relevant part): >> >> from django.contrib.auth.models import User >> >> class Project(models.Model): >> coordinator = models.ForeignKey( >> User, >> limit_choices_to={'id__in' : >> User.objects.filter(groups__name='Coordinator')} >> ) >> >> As explained in the previously referenced thread, that currently >> doesn't work so I tried this: >> >> from django.contrib.auth.models import User, Group >> >> def users_in_group(group): >> g = Group.objects.get(name=group) >> return User.objects.filter(groups=g) >> >> class project(models.Model): >> ... >> limit_choices_to={'id__in' : users_in_group('Coordinator')} >> ... >> >> but that generates the same error. The Docs say I can use any Q >> object, so I understood that to mean either of the above should work. >> Am I using limit_choices_to is ways it's not intended or should I >> wait >> for the previously mentioned bugs to be worked out? >> >> [1] http://groups.google.com/group/django-users/browse_thread/ >> thread/6460e63e0e6c88d8/ >> -- >> >> Waylan Limberg >> [EMAIL PROTECTED] >> > > > -- > > Waylan Limberg > [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 -~--~~~~--~~--~--~---
Outer joins as extras()
Hi, Has anybody found a way to add an table to query with an outer join? I tried the Obvious Thing: queryset = Reader.objects.all().extras( select = {'other_name': 't.name'}, tables = ["left outer join other_table t on t.id = hr_reader.other_id"])) That results in the database complaining about an extra comma, because the tables list is simply put into the generated query's FROM cause with commas between each item. I'm currently working around this by creating a database VIEW that performs the outer join, then adding that view to the extras. It works, but it's ugly. Anybody got a different way to do it? Alan. -- Alan Green [EMAIL PROTECTED] - http://bright-green.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 -~--~~~~--~~--~--~---
Re: NULL for TextField
Why don't you: {% if form.myText.text %} My text: {{form.myText }} {% else %} No text yet. {% endif %} That will get a myText field passed in the post/get parameter. Corey On Aug 21, 2006, at 5:39 PM, cyberco wrote: > > Given the model: > === > myText = models.TextField(blank=True) > === > > In case this TextField has no text I want to hide it from my form. > Template code: > > === > {% if form.myText.text %} > My text: {{form.myText }} > {% else %} > No text yet. > {% endif %} > === > > But then saving the form gives an error saying it wants to save a NULL > value in a field that cannot be NULL. A solution could be adding > 'null=True' to the field: > > === > myText = models.TextField(blank=True, null=True) > === > > But this is discouraged by Django: > > http://www.djangoproject.com/documentation/model_api/#null > "Avoid using null on string-based fields such as CharField and > TextField unless you have an excellent reason. If a string-based field > has null=True, that means it has two possible values for "no data": > NULL, and the empty string. In most cases, it's redundant to have two > possible values for "no data;" Django convention is to use the empty > string, not NULL." > > What would be the proper way to do 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 -~--~~~~--~~--~--~---
Re: Foreign key spaghetti
On Mon, Aug 21, 2006 at 01:18:03PM -0400, Waylan Limberg wrote: > If a Customer can NOT have a LifeInsurance without a Mortgage, then > just link LifeInsurance to Mortgage which will then link to a > Customer. Of course, if having a Mortgage is not a requirement for > LifeInsurance, that won't work and you'll have to use your current > scheme with an additional ForiegnKey from LifeInsurance to Customer. They can have a LifeInsurance without a Mortgage too. > In either case, you may want to take a look at the limit_choices_to > argument of many-to-one fields[1]. I'll do that, thanks! -- Sybren Stüvel, B.Sc. Stüvel IT http://www.stuvel.eu/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: label and order of sub components in multiple table admin
Well the __str__ function doesn't help here. What I am talking about is I have is like this. Notice the __str__ def in BuyerAlcoholUse model. I would do OneToOne, because that is what it is, but I wanted it all on one page. These are all stored in seperate tables each model. I don't know if this is a case for a view. I'm pretty new to Django. The default admin for this lists a phrase "Buyer alcohol use #1". It does this I"m sure because of the ForeignKey, so it thinks it's has multiple key potential. The second issue is that the if there was another model like BuyerAlcoholUse called BuyerCrime I want the ability to list the BuyerCrime sub-section before the BuyerAlcoholUse on the default edit view of this model. class Buyer(models.Model): lastname = models.CharField(maxlength=100) firstname = models.CharField(maxlength=50) birthdate = models.DateField('Birthday') email = models.EmailField() phone = models.PhoneNumberField() address = models.CharField(maxlength=255) city = models.CharField(maxlength=50) state = models.USStateField() zip = models.IntegerField() gender = models.CharField(choices=GENDER_CHOICES, maxlength=6) buyer_num = models.CharField(maxlength=10) application_date = models.DateField('Application Date', null=True, blank=Tru e) def __str__(self): return self.buyer_num class Meta: db_table = 'buyers' class Admin: list_display = ('lastname', 'firstname', 'buyer_num',) search_fields = ['lastname','firstname','buyer_num',] list_filter = ('gender','application_date',) class BuyerAlcoholUse(models.Model): #buyer = models.ForeignKey(Buyer, edit_inline=models.STACKED, num_in_admin=1 , max_num_in_admin=1) buyer = models.ForeignKey(Buyer, edit_inline=models.STACKED, num_in_admin=1, max_num_in_admin=1) have_used = models.CharField(choices=ANSWER_CHOICES, maxlength=3, core=True) have_participated = models.CharField(choices=ANSWER_CHOICES, maxlength=3, co re=True) def __str__(self): return 'Alcohol Use' class Meta: db_table = 'buyer_alcohol_uses' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
When using the production environment I don't get anything returned
I have been trying to get Django working and have been playing around with it using the development server. I have followed the tutorial up to the admin stage (I have gone for the smallest test to eliminate variables) and I can see it working on the using the development server so I know that is all correct. I followed the docs for production and it seems to have gone well but when I go to the admin section the response I get back is empty. The URL is: http://www.chris-cooke.com/cgi-bin/python/ (I know the /cgi-bin/python are not needed but this is a test) Which shows you the debug 404 message - So it appears to be working. Now when you go to: http://www.chris-cooke.com/cgi-bin/python/admin/ You get nothing When I do this with the development server I get the expected user log in box. Some details of the server OS: RedHat ES3 httpd: 2.0.59-1 mod_python: 3.2.7 The important part of the apache config: SetHandler mod_python PythonHandler django.core.handlers.modpython PythonPath "['/home/httpd/vhosts/chris-cooke.com/cgi-bin/python'] + sys.path" SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonDebug On The file perms: -bash-2.05b$ pwd /home/httpd/vhosts/chris-cooke.com/cgi-bin/python -bash-2.05b$ ls -l total 4 drwxr-xr-x3 chrispsacln 4096 Aug 21 14:01 mysite -bash-2.05b$ ls -l mysite/ total 28 -rw-r--r--1 chrispsacln 0 Aug 21 13:38 __init__.py -rw-r--r--1 chrispsacln158 Aug 21 13:42 __init__.pyc -rw-r--r--1 chrispsacln546 Aug 21 13:38 manage.py drwxr-xr-x2 chrispsacln 4096 Aug 21 13:47 polls -rw-r--r--1 chrispsacln 2477 Aug 21 13:45 settings.py -rw-r--r--1 chrispsacln 1972 Aug 21 13:45 settings.pyc -rw-r--r--1 chrispsacln303 Aug 21 14:01 urls.py -rw-r--r--1 chrispsacln370 Aug 21 13:52 urls.pyc -bash-2.05b$ Note: I have restarted the httpd server each time :) I am now at a bit of a lose end as to what to try next. Can anyone offer any advice as to what to what might be wrong or something to try? Thanks in advance, -- Christopher Cooke --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
NULL for TextField
Given the model: === myText = models.TextField(blank=True) === In case this TextField has no text I want to hide it from my form. Template code: === {% if form.myText.text %} My text: {{form.myText }} {% else %} No text yet. {% endif %} === But then saving the form gives an error saying it wants to save a NULL value in a field that cannot be NULL. A solution could be adding 'null=True' to the field: === myText = models.TextField(blank=True, null=True) === But this is discouraged by Django: http://www.djangoproject.com/documentation/model_api/#null "Avoid using null on string-based fields such as CharField and TextField unless you have an excellent reason. If a string-based field has null=True, that means it has two possible values for "no data": NULL, and the empty string. In most cases, it's redundant to have two possible values for "no data;" Django convention is to use the empty string, not NULL." What would be the proper way to do 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 -~--~~~~--~~--~--~---
Re: Reproduce admin search functionality
I got it!: def search(request): keywords = request.GET['keyword'].split() sql = "" first = True for word in keywords: if first: sql += "(title LIKE '%%" + word + "%%' OR description LIKE '%%" + word + "%%')" first = False else: sql += " AND (title LIKE '%%" + word + "%%' OR description LIKE '%%" + word + "%%')" results_list = Resource.objects.extra(where=[sql]) return render_to_response('tick/base_results.html', {'results_list': results_list}) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Reproduce admin search functionality
I am trying to reproduce the admin search functionality tell me what you think and how I can 1) fix it because it isn't working 2) improve it. Here is my view: keywords = request.GET['keyword'].split() sql = "" first = True for word in keywords: if first: sql += "(title LIKE '%" + word + "%' OR description LIKE '%" + word + "%')" first = False else: sql += " AND (title LIKE '%" + word + "%' OR description LIKE '%" + word + "%')" results_list = Resource.objects.extra(where=[sql]) return render_to_response('tick/base_results.html', {'results_list': results_list}) Any ideas? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: limit_choices_to Users in a Group
I figured this out, thanks to a suggestion in another thread. It seems I was misunderstanding something about how limit_choices_to works. Anyway, the following works: from django.contrib.auth.models import User, Group class Project(models.Model): coordinator = models.ForeignKey( User, limit_choices_to={'groups__pk' : Group.objects.get(name='Coordinator').id} ) The only problem is that if there is no Group named "Coordinator" in the db, I get an error so I tried the following; def limit_to_group(group_name): try: g = Group.objects.get(name=group_name).id except DoesNotExist: g = 0 # this should result in no users listed (I think/hope) return g class Project(models.Model): ... limit_choices_to={'groups__pk' : limit_to_group('Coordinator')} ... Which returns an error that DoesNotExist is not defined. What am I missing here? On 8/16/06, Waylan Limberg <[EMAIL PROTECTED]> wrote: > I'm not sure if my problem is related to this thread[1] or if I'm just > misunderstanding something with regard to limit_choices_to. > > First I tried this (in relevant part): > > from django.contrib.auth.models import User > > class Project(models.Model): > coordinator = models.ForeignKey( > User, > limit_choices_to={'id__in' : > User.objects.filter(groups__name='Coordinator')} > ) > > As explained in the previously referenced thread, that currently > doesn't work so I tried this: > > from django.contrib.auth.models import User, Group > > def users_in_group(group): > g = Group.objects.get(name=group) > return User.objects.filter(groups=g) > > class project(models.Model): > ... > limit_choices_to={'id__in' : users_in_group('Coordinator')} > ... > > but that generates the same error. The Docs say I can use any Q > object, so I understood that to mean either of the above should work. > Am I using limit_choices_to is ways it's not intended or should I wait > for the previously mentioned bugs to be worked out? > > [1] > http://groups.google.com/group/django-users/browse_thread/thread/6460e63e0e6c88d8/ > -- > > Waylan Limberg > [EMAIL PROTECTED] > -- Waylan Limberg [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 -~--~~~~--~~--~--~---
Re: label and order of sub components in multiple table admin
On 8/21/06, hoangelos <[EMAIL PROTECTED]> wrote: > I would like to control the label of the subcomponents. BuyerClothes > says "buyer clothes #1". http://www.djangoproject.com/documentation/model_api/#str > I also would like to make sure that > BuyerOccupations is listed on the Buyer Admin before the subsection for > BuyerClothes. If your referring to the list of models in the main admin page, I do not believe this is possible. However, if you are referring to items within the model see: http://www.djangoproject.com/documentation/model_api/#ordering -- Waylan Limberg [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 -~--~~~~--~~--~--~---
Re: Process forking issues
I wrote some code that might help you out: it in the thread:http://groups.google.com/group/django-users/browse_frm/thread/b36f4ca10a424161/c5131410e5d548b1Depending on how you spawn a process, it can either wait for each, or become a child process.Calling the daemonize method with the appropriate parameters, should launch a new independent process. You could call it several times and get several independent processes.CoreyOn Aug 21, 2006, at 1:06 PM, tomass wrote:Well, limited success. I was able to get the code working throughclosing the django db connection just after I'd forked my processes,but it seems that what I thought I was doing wasn't really what Ithought I was doing.Essentially I wanted to be able to run multiple tasks simultaneously. Ithought forking x numbers of processes would do this for me, but itseems not. It looks to me like what happens in this case is that if youtry to fork 10 processes simultaneously it actually waits for the firstforked process to finish before starting the second one.I think what I need to look into is multi-threading instead, but thatcould be kind of complicated... More investigation needed.Thanks, Tom --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
label and order of sub components in multiple table admin
I have a Buyer model that has seperate one to one tables based on different organizational units. Maybe things like this: BuyerClothes BuyerOccupations and many more I would like to control the label of the subcomponents. BuyerClothes says "buyer clothes #1". I also would like to make sure that BuyerOccupations is listed on the Buyer Admin before the subsection for BuyerClothes. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Editting both sides of self-referential m2m relationship
On Mon, 2006-08-21 at 09:36 -0400, James Punteney wrote: > Right now if I add say a "rabbit" I'd have to go to edit every other > animal that is a predator of the rabbit to specify that the rabbit is > prey for those other animals vs just selecting the predators on the > rabbit edit page. Which is obviously less than ideal. I thought that someone else would respond with a more clever solution, but since nobody did, I'll tell how I did it. I just wrote a small web interface with a view that allowed additions and deletions. It didn't allow to enter any other information, just the relationship changes. So I didn't use the admin interface, I just rolled my own. If anybody has a better idea, please share it, because how I did it was neither clever nor pretty. -- Maciej Bliziński http://automatthias.wordpress.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 -~--~~~~--~~--~--~---
Overriding .save and Image upload
Hi django users, I am currently trying to make a model `Image` create a thumbnail on save(). I know that there is a third party ImageWithThumbField, but (a) I'd like to make and (b) I am curious how my problem would be solved. As mentioned in the topic, I override the save method of my model. On to the code. IMAGE_UPLOAD_DIR = "..." IMAGE_THUMB_DIR = "..." class Image(models.Model): resource = models.ImageField(upload_to=IMAGE_UPLOAD_DIR) def save(self): # save to the db first super(Image, self).save() # get reference to the saved file to create thumb # is True self.resource == "" # results in IOError create_thumb(self.resource) I tried get_resource_filename, but got an empty string too. I don't believe I can use save_Image_file() due to the fact that this is called by super(...).save() already. Googling and searching the group did not lead to any help, but maybe I just missed it. Hope someone can help me, Regards, -Justin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: how to assign permissions to users and groups?
If I have a group instance called students and I wanted to add it to the user instance bill I would use: bill.groups.add(students) If you want to have a permission for a view, you will have to use the has_perm method that is within the user model (user.has_perm) and check for the permission you want at the beginning of the view. E.g.: def view_students(request): if not request.user.has_perm("university.view_students"): raise PermissionDenied Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
how to assign permissions to users and groups?
Hi, What I want to do is to let users access some views but not others. Users can fit in groups. I've not set up the admin interface for this package because I don't find it useful for my purpose, at least yet. Users can already register themselves for the site. But they will only be able to access this package, and others, after I give them permission to it (either directly or by group membership). I've added the decorator user_passes_test that prevents any user to access the view that has no access. At the present time, no user has access besides the superuser. I've read the authentication.txt from beggining to the end, but couldn't find the way to assign permissions to individual users or to groups. I really miss a tutorial about this subject. After trying to set permissions through user and group instances' methods, all failed, I came across the Permission object, and found out something else that I don't understand either: from the manage.py shell: >>> from django.contrib.auth.models import Permission >>> p = Permission(codename='subsidios.pode_consultar') >>> p.codename 'subsidios.pode_consultar' >>> p.save() from the Intac class of the subsidios package: class Intac: (...) class Meta: permissions = (("pode_consultar", "Pode consultar"),) This is what I get from the auth_permission table in postgreSQL: # select * from auth_permission; 74 | Pode consultar | pode_consultar| 32 75 | | subsidios.pode_consultar | The line 74 (origined in the Intac class model) doesn't have the package name before the permission codename. Are both entries correct? What I really need is that someone could show me an example of: - assigning a user to a group; - assign a user permission to a view; - assign a group permission to a view. Sorry if this is a very trivial problem, but I really need an example to help understand how this works. Luis P. Mendes --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Foreign key spaghetti
If a Customer can NOT have a LifeInsurance without a Mortgage, then just link LifeInsurance to Mortgage which will then link to a Customer. Of course, if having a Mortgage is not a requirement for LifeInsurance, that won't work and you'll have to use your current scheme with an additional ForiegnKey from LifeInsurance to Customer. In either case, you may want to take a look at the limit_choices_to argument of many-to-one fields[1]. [1] http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships On 8/21/06, Sybren Stüvel <[EMAIL PROTECTED]> wrote: > > So one CustomerData object can have multiple Mortgage and > LifeInsurance objects. > > Now I want to have an extra relation: a LifeInsurance object has to be > linked to a single Mortgage object of the same CustomerData object. > > Is this possible with Django? If so, how? > -- Waylan Limberg [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 -~--~~~~--~~--~--~---
Re: Process forking issues
Well, limited success. I was able to get the code working through closing the django db connection just after I'd forked my processes, but it seems that what I thought I was doing wasn't really what I thought I was doing. Essentially I wanted to be able to run multiple tasks simultaneously. I thought forking x numbers of processes would do this for me, but it seems not. It looks to me like what happens in this case is that if you try to fork 10 processes simultaneously it actually waits for the first forked process to finish before starting the second one. I think what I need to look into is multi-threading instead, but that could be kind of complicated... More investigation needed. Thanks, Tom --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Efficient ways to limit_choices_to
Hey Seemant, Sorry about not getting back to you sooner to work on this. Been finishing off last minute details with my SoC project. Here is what I've come up w/ that (w/ my limited testing) seems to work: preacher = models.ForeignKey ( Person, limit_choices_to = { 'role__pk': Role.objects.get(name='Pastor').id} ) Might want to put that into a method that has a try and except for the DoesNotExist exception to handle it. Otherwise, it looks like django may not show the page if the exception is caused. Hope that helps. Chris (aka clong) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Creating a "mostly static" site with Django -- dumb idea?
On 8/15/06, Bryan Chow <[EMAIL PROTECTED]> wrote: > > Ian Clelland and I wrote a Django app that does just that (mapping > URLs to mostly-static templates). Our code also takes several other > issues into consideration, such as sanitizing the URL so that > arbitrary files on the filesystem won't be served. > > http://www.verdjn.com/wiki/TemplatePages Just put this up on a site I'm moving from static pages to Django, and it's just what I needed- I'd been doing something horrible with subdomains to get it working, and been thinking of doing something like this myself. One thing I had to do, because the old site has loads of .html files in the root, is put the url regex straight into the site's urls.py as the last line, eg (r'^(?P.*)$', 'verdjnlib.templatepages.views.templatepage'), Huge thanks to you both for making this available. -- Derek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Global Variables
On Aug 21, 2006, at 3:59 AM, Thomas wrote: > An example would be something like displaying the > First name and Last name of a user that is logged in accross all my > pages. If you need to display information about the logged in user in your template, see this page: http://www.djangoproject.com/documentation/authentication/ #authentication-data-in-templates Don --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Global Variables
On 8/21/06, Thomas <[EMAIL PROTECTED]> wrote: > but I am sure there must be a simpler way of retrieving the same > information site wide and on each page where needed? Below is an > example extract from my views.py file...see what I mean? I seem to be > calling / using the "c = Context({" too many times. Is this the best > way of doing things? An example would be something like displaying the > First name and Last name of a user that is logged in accross all my > pages. Take a look below: Well, first of all the repeated template loads and context instantiations can be avoided by using the 'render_to_response' function, which is documented in the official tutorial[1] And if you've got certain variables which need to appear in the context of *every* page, you probably want to write a context processor function[2] and use RequestContext instead of Context (you can still use render_to_response -- just add the extra argument 'context_instance=RequestContext(request)' to it). The built-in context processor django.core.context_processors.auth is enabled by default for every RequestContext, and will add the current user to the template context for you automatically, so that's one of your variables taken care of already :) [1] http://www.djangoproject.com/documentation/tutorial3/#a-shortcut-render-to-response [2] http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Global Variables
On 8/21/06, Thomas <[EMAIL PROTECTED]> wrote: > I seem to be > calling / using the "c = Context({" too many times. Is this the best > way of doing things? An example would be something like displaying the > First name and Last name of a user that is logged in accross all my > pages. Take a look below: > Perhaps you could create a custom middelware which adds those variables to the context. You'd probaly want to use a process_responce middleware[1]. Sure beats repeating the code in every view. http://www.djangoproject.com/documentation/middleware/#process-response -- Waylan Limberg [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 -~--~~~~--~~--~--~---
Foreign key spaghetti
Hi folks, I want to have the following, but I'm not sure on how to do that. This is the layout of the models: CustomerData - name - age - etc. Mortgage - Many-to-one key to CustomerData - start date - end date - sum - etc. LifeInsurance - Many-to-one key to CustomerData - start date - end date - sum - etc. So one CustomerData object can have multiple Mortgage and LifeInsurance objects. Now I want to have an extra relation: a LifeInsurance object has to be linked to a single Mortgage object of the same CustomerData object. Is this possible with Django? If so, how? Greetings, -- Sybren Stüvel, B.Sc. Stüvel IT http://www.stuvel.eu/ signature.asc Description: Digital signature
Efficient ways to limit_choices_to
Hi All, I've been struggling with this issue for a few days now. In IRC, clong got me the closest I've been to a solution, but things are still erroring out. I have two inital models: class Person( models.Model ): name = models.CharField (maxlength = 100) user = models.ForeignKey ( User, verbose_name="Associated admin user", null = True, blank = True ) role = models.ManyToManyField ('Role') def get_people_in_role( roles ): list = [] for x in Person.objects.all (): for role in x.role.get_query_set(): if role.name in roles: list.insert (0,x) return list def __str__( self ): return self.name class Meta: ordering = ('name',) verbose_name_plural = 'people' class Admin: pass class Role( models.Model ): name = models.CharField (maxlength = 20) def __str__( self ): return self.name class Meta: ordering = ('name',) class Admin: pass The Roles will be stuff like "pastors" and "acolytes" etc etc. (The associated admin user thing is thanks to the code at 23 excuses). I'd like to use this in, for example, this class: from people.models import Person, Role class Sermon( models.Model ): title = models.CharField (maxlength = 200) day = models.CharField (maxlength = 200) date = models.DateField () slug = models.SlugField (prepopulate_from = ('day', 'date')) passage = models.CharField (maxlength = 200) body = models.TextField () preacher = models.ForeignKey ( Person, limit_choices_to = { 'role__pk': Role.objects.filter(name = 'Pastor')} ) def __str__( self ): return self.title class Admin: list_display = ('title', 'day', 'date') search_fields = ('title', 'day', 'body', 'preacher') list_filter = ('date', 'day') clong gave me that limit_choices_to, but it still errors out. Basically, I'd like to define roles, and then limit the people choices to those people who "play" that role. For example, sermons can only be associated with Pastors, services also to Pastors, flowers to Flower Bearers, and so on and so forth. There are probably 10 or so different roles. All this is for the "admin" interface, by the way. I'd love some help (any help!) on doing this successfully. Praetorian found this message: http://groups.google.com/group/django-users/browse_thread/ thread/6460e63e0e6c88d8/ and it may well be related, but I'm not sure. Even so, I'd love a workaround until the proper solution is implemented. Thanks for your time! Seemant --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Global Variables
Hi all, I have been scouring the docs but with no joy, or perhaps just my own stupidity. I am fairly new to Django / Python as a whole. I am developing a site where I need to set or pass a global variable between pages. Currently I am simply requesting it each time in my views.py file...but I am sure there must be a simpler way of retrieving the same information site wide and on each page where needed? Below is an example extract from my views.py file...see what I mean? I seem to be calling / using the "c = Context({" too many times. Is this the best way of doing things? An example would be something like displaying the First name and Last name of a user that is logged in accross all my pages. Take a look below: "... c = Context({ 'device_list': device_list, 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) index = login_required(index) #--- def indexJobs(request, device_id): """ Shows a list of all the jobs for a given device """ job_list = jobs.get_list(device__id__exact=device_id) t = loader.get_template('devicemanager/jobs') c = Context({ 'job_list': job_list, 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) indexJobs = login_required(indexJobs) #--- [EMAIL PROTECTED] def editDevice(request, device_id): device = devices.get_object(id__exact=device_id) t = loader.get_template('devicemanager/edit') c = Context({ 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), 'device' : device, }) return HttpResponse(t.render(c)) editDevice = login_required(editDevice) #--- [EMAIL PROTECTED] def editDeviceSite(request, device_id): t = loader.get_template('devicemanager/edit_site') c = Context({ 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDeviceSite = login_required(editDeviceSite) #--- [EMAIL PROTECTED] def editDeviceConfig(request, device_id): t = loader.get_template('devicemanager/edit_config') c = Context({ 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDeviceConfig = login_required(editDeviceConfig) #--- [EMAIL PROTECTED] def editDeviceStats(request, device_id): t = loader.get_template('devicemanager/edit_stats') c = Context({ 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDeviceStats = login_required(editDeviceStats) #--- [EMAIL PROTECTED] def editDevicePurse(request, device_id): t = loader.get_template('devicemanager/edit_purse') c = Context({ 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDevicePurse = login_required(editDevicePurse) #--- [EMAIL PROTECTED] def editDeviceAlerts(request, device_id): t = loader.get_template('devicemanager/edit_alerts') device = devices.get_object(id__exact=device_id) alert_list = device.get_alert_list() c = Context({ 'alert_list' : alert_list, 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDeviceAlerts = login_required(editDeviceAlerts) #--- [EMAIL PROTECTED] def editDeviceHistory(request, device_id): t = loader.get_template('devicemanager/edit_history') device = devices.get_object(id__exact=device_id) event_list = device.get_event_list() c = Context({ 'event_list' : event_list, 'online_user' : request.user, 'online_group_name' : getOnlineGroupName(request), }) return HttpResponse(t.render(c)) editDeviceHistory = login_required(editDeviceHistory) #--- ..." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users"
[slightly OT] A rose by another name
hi, it was suggested describing django as 'Snakes on Planes', i just thought of SOS - SnakesOnSpeed -- regards kg http://lawgon.livejournal.com http://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: URLField limitations
On 8/21/06, Cole Tuininga <[EMAIL PROTECTED]> wrote: > 1) The URLField type is being restricted to 200 characters. Is there > a reason for this? Can it be overridden? Not really. URLField subclasses CharField (because that's how it goes into the database), which means that no matter what there's going to be a hard limit of around 250 characters enforced by the DB. > 2) The validator is enforcing that the URL must currently be active. > I want to use the check to make sure that the url is properly > formatted, but I don't want to enforce that the url must respond. Is > there a way to get around this with the default validation? Or will I > need to write my own validator that will check the syntax of the url? Use the 'verify_exists' argument, set to False, as explained in the docs: http://www.djangoproject.com/documentation/model_api/#urlfield -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Re: URLField limitations
Cut off while I was writing... Anyway, what I was going to suggest was that if you need the ability to take in URLs of arbitrarily extreme lengths, you're probably better off using a TextField for the URL and using the 'validator_list' argument to pass in validators which will check that it's a URL (e.g., the built-in 'isValidURL' validator). -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
URLField limitations
Hi folks - I'll preface this by saying that I'm a complete newbie, writing my first Django app. Partially for the experience, and partially driven by small need, I'm implementing an inhouse version of tinyurl (http://www.tinyurl.com/). The model is pretty simple - it looks like: # Create your models here. class ShortURL(models.Model): tag = models.CharField( maxlength = 10, unique = True, editable = False, blank = False ) url = models.URLField( unique = True ) created = models.DateTimeField( auto_now_add = True, editable = False ) ip_addy = models.IPAddressField( editable = False, blank = False ) I'm running into a couple problems. 1) The URLField type is being restricted to 200 characters. Is there a reason for this? Can it be overridden? 2) The validator is enforcing that the URL must currently be active. I want to use the check to make sure that the url is properly formatted, but I don't want to enforce that the url must respond. Is there a way to get around this with the default validation? Or will I need to write my own validator that will check the syntax of the url? Thanks in advance, and to the authors of and contributors to Django - keep up the great work. It's much appreciated. -- Cole Tuininga http://www.tuininga.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 -~--~~~~--~~--~--~---
Re: Editting both sides of self-referential m2m relationship
Thanks for the responses, and yeah Maciej is correct the m2m relationship works fine without any errors, it's just that I can only edit the prey relationship (as Maciej text art does a much better job of showing than my explanation). Right now if I add say a "rabbit" I'd have to go to edit every other animal that is a predator of the rabbit to specify that the rabbit is prey for those other animals vs just selecting the predators on the rabbit edit page. Which is obviously less than ideal. When I try adding a predator field so I have this in my model: prey = models.ManyToManyField("self", related_name="predator", symmetrical=False) predator = models.ManyToManyField("self", related_name="prey", symmetrical=False) Then it gives the following errors: Validating models... animals.animal: Accessor for m2m field 'prey' clashes with m2m field 'Animal.predator'. Add a related_name argument to the definition for 'prey'. animals.animal: Reverse query name for m2m field 'prey' clashes with m2m field 'Animal.predator'. Add a related_name argument to the definition for 'prey'. animals.animal: Accessor for m2m field 'predator' clashes with m2m field 'Animal.prey'. Add a related_name argument to the definition for 'predator'. animals.animal: Reverse query name for m2m field 'predator' clashes with m2m field 'Animal.prey'. Add a related_name argument to the definition for 'predator'. If this is something the admin interface can't do then any pointers on how to customize it or where to look for more information would be great. Thanks, --James On 8/21/06, Maciej Bliziñski <[EMAIL PROTECTED]> wrote: > > On Mon, 2006-08-21 at 08:12 +0800, Russell Keith-Magee wrote: > > And it works as expected except I can only edit the "prey" > > part of the > > relationship. Ideally I'd like to be able to specify both > > predator and > > prey when adding or editing an animal. Is that possible to do? > > > > It should be possible. The m2m_recursive modeltests should give an > > example of what you can do. > > > > To help diagnose your problem - what exactly is failing? Where error > > message are you getting? > > I think there is no error message. If I understood James correctly, the > animal edit form displays a list of preys of currently edited animal, > while James would like to edit both sets: preys and predators. > > More graphically, James sees: > > --- > Editing Animal > Animal name: Frog > ... > Preys: > [v] Fly > [v] Mosquito > [ ] Stork > --- > > While he wants to see: > > --- > Editing Animal > Animal name: Frog > ... > Preys: > [v] Fly > [v] Mosquito > [ ] Stork > > Predators: > [ ] Fly > [ ] Mosquito > [v] Stork > --- > > > -- > Maciej Bliziñski > http://automatthias.wordpress.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 -~--~~~~--~~--~--~---
Re: extract keywords from model
thanks, that worked 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 -~--~~~~--~~--~--~---
Re: how to add content of the page's textarea in django ?
You might find this useful: http://www.djangoproject.com/documentation/faq/#how-do-i-use-image-and-file-fieldsEmmet On 8/20/06, rock <[EMAIL PROTECTED]> wrote: how to upload a picture ,then add the url link of the picture to thepage's textarea content. Some bbs can do this . But how can I do likethis in django, any advice would be appreciated --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: extract keywords from model
On 8/21/06, richard mendes <[EMAIL PROTECTED]> wrote: > > Thanks for all advices, > > I looked at the objects.values() from the api before and that's what i > want. The only problem there is that it will give you back a empty > list when there are no values in de DB. > > Offcourse there is a option to put some values in the DB to begin with > but that's not really a good solution. > > The other advice Test._meta.fields.keys() is not working because it's > a list but if i try Test._meta.fields[0] it will return a object. The > question that follows is how can i read the keys from this object. > > richard > It should be: s = [] for f in Test._meta.fields: s.append(f.column) -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: extract keywords from model
Thanks for all advices, I looked at the objects.values() from the api before and that's what i want. The only problem there is that it will give you back a empty list when there are no values in de DB. Offcourse there is a option to put some values in the DB to begin with but that's not really a good solution. The other advice Test._meta.fields.keys() is not working because it's a list but if i try Test._meta.fields[0] it will return a object. The question that follows is how can i read the keys from this object. 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 -~--~~~~--~~--~--~---
[Fwd: multiple forms]
Hi, I'm trying to write a batch insert view that gets data from a object-template, does some modification to the template (increment some counters) and displays a form for each new object to be created. (I'm adding Media files which are selected in a previous view, that why I iterate over files) The view looks like this: manipulator = Media.AddManipulator() form_list=list() errors = {} for file in files: #assign new value to template object template.media_signature = incSignature(template.media_signature) new_data = template.__dict__ new_data["filename"] = file form = forms.FormWrapper(manipulator, new_data, errors) form_list.append(form) When the loop finishes I end up with a list of identical formWrapper Objects, which is not what I expected. If i put in some debugging code to display the current form it shows that the form object is created correctly but also changes all the other form entries already on the list (which seemingly all point to the same instance of the form object) Does this have something to do with lazy evaluation and if yes, is there any way to create the form object right away? This is probably more a python question than a django-related one Any help appreciated, Sean --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: extract keywords from model
On 8/21/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello django users, > > sorry for this probably simple question but i couldn't find the answer > in the api nor this forum. > > suppose i have a model with 2 keywords like > > class Test(models.Model): >result_id = models.IntegerField(maxlength=10) > lab_id = models.IntegerField(maxlength=10) > > is there a method to extract all the keywords from this class. > So in this example i actually want [result_id,lab_id] > > thanks in advance for your help > > richard > maybe Test._meta.fields.keys() -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Special Tag Parser - A How-To
The Tutorial: http://code.djangoproject.com/wiki/contentBBCode_parser It describes how to make a pluggable special tag parser that is simillar to BBCode but it can do dynamic things, react on passed atributs :) For example this: [rk:codder lang="python"] for foo in bar: print foo [/rk:codder] Could get higlighted in the language we pass as a lang attribute :) The result could look like this: http://www.fotosik.pl/showFullSize.php?id=4a82e9c901329a06 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: extract keywords from model
[EMAIL PROTECTED] wrote: > suppose i have a model with 2 keywords like > > class Test(models.Model): >result_id = models.IntegerField(maxlength=10) > lab_id = models.IntegerField(maxlength=10) > > is there a method to extract all the keywords from this class. > So in this example i actually want [result_id,lab_id] I dont see any 'keywords' here. Just some integer fields. Are you sure you dont really want to make it a CharField with some "choices" argument? class Foo(models.Model): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) Barry --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: extract keywords from model
On 21-Aug-06, at 4:16 PM, [EMAIL PROTECTED] wrote: > sorry for this probably simple question but i couldn't find the answer > in the api nor this forum. > > suppose i have a model with 2 keywords like > > class Test(models.Model): >result_id = models.IntegerField(maxlength=10) > lab_id = models.IntegerField(maxlength=10) > > is there a method to extract all the keywords from this class. > So in this example i actually want [result_id,lab_id] http://www.djangoproject.com/documentation/db_api/#values-fields -- regards kg http://lawgon.livejournal.com http://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
extract keywords from model
Hello django users, sorry for this probably simple question but i couldn't find the answer in the api nor this forum. suppose i have a model with 2 keywords like class Test(models.Model): result_id = models.IntegerField(maxlength=10) lab_id = models.IntegerField(maxlength=10) is there a method to extract all the keywords from this class. So in this example i actually want [result_id,lab_id] thanks in advance for your help 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 -~--~~~~--~~--~--~---
Re: i18n: Translating include names
Yes, that would work AND would keep me from having presentation details in the view implementation. Cool. Thanks for the link! I hadn't found that yet. Daniel --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Editting both sides of self-referential m2m relationship
On Mon, 2006-08-21 at 08:12 +0800, Russell Keith-Magee wrote: > And it works as expected except I can only edit the "prey" > part of the > relationship. Ideally I'd like to be able to specify both > predator and > prey when adding or editing an animal. Is that possible to do? > > It should be possible. The m2m_recursive modeltests should give an > example of what you can do. > > To help diagnose your problem - what exactly is failing? Where error > message are you getting? I think there is no error message. If I understood James correctly, the animal edit form displays a list of preys of currently edited animal, while James would like to edit both sets: preys and predators. More graphically, James sees: --- Editing Animal Animal name: Frog ... Preys: [v] Fly [v] Mosquito [ ] Stork --- While he wants to see: --- Editing Animal Animal name: Frog ... Preys: [v] Fly [v] Mosquito [ ] Stork Predators: [ ] Fly [ ] Mosquito [v] Stork --- -- Maciej Bliziński http://automatthias.wordpress.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 -~--~~~~--~~--~--~---
Re: Login not working: Site matching query does not exist.
Thank you very much! That was indeed the issue. There was a site in the db, but apparently things were corrupt. Removing all sites and adding a new one via the admin interface solved the problem. Not sure if that is a bug or a feature :) Your query works as well (although 'domain' and 'name' should be switched: insert into django_site(id,domain,name) values (N,'example.com', 'example') Cheers Berco --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: i18n: Translating include names
On 8/21/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Um, yes. I realize that would work. I guess I was looking for a more > "automagical" solution (which would not force me to change the template > when I come up with a French or Kisuaheli version of trogger :-) ). > > I think I'll go with passing the name of the file to include in the > Context and then just translate that in my view using _("welcome.html") > -- that would keep working when ading additional languages. This > approach just has the drawback of putting stuff that belongs in the > display template (which HTML files to include in order to render the > page) into the view implementation, where i feel it doesn't really > belong. > > Daniel > > See expr http://code.djangoproject.com/wiki/ExprTag -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Login not working: Site matching query does not exist.
your missing the site record. go into your database and create a record with the site_id from your project file eg. insert into django_site(id,name,domain) values (N, 'example','example.com') where 'N' is your SITE_ID. On 21/08/2006, at 6:40 PM, cyberco wrote: > > I'm still having this problem (neglected it for a while, but now is > the > time I MUST solve it). Has anybody here a suggestion in which > direction > to search? > > > > -- Ian Holsman [EMAIL PROTECTED] http://garden-gossip.com/ -- what's in your garden? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: i18n: Translating include names
Um, yes. I realize that would work. I guess I was looking for a more "automagical" solution (which would not force me to change the template when I come up with a French or Kisuaheli version of trogger :-) ). I think I'll go with passing the name of the file to include in the Context and then just translate that in my view using _("welcome.html") -- that would keep working when ading additional languages. This approach just has the drawback of putting stuff that belongs in the display template (which HTML files to include in order to render the page) into the view implementation, where i feel it doesn't really belong. Daniel --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Login not working: Site matching query does not exist.
I'm still having this problem (neglected it for a while, but now is the time I MUST solve it). Has anybody here a suggestion in which direction to search? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: django db models in other app
Thanks for your help, it's working 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 -~--~~~~--~~--~--~---