dumpdata and loaddata as simple DB migration tool?
Hi, About Django database migration. I know there's a couple of tools available (South, evolution, dmigration, etc), but I am pondering an alternative here. Hope good discussion entails. This is what I am doing manually now for my database migration needs. 1. Use Django's management command "dumpdata" to get the JSON representative of an app. Save the JSON into a file (oldmodel.json). 2. Git pull the latest code. And do a reset to the app. So the database will have the new model schema now. 3. Use the python shell to migrate the JSON file to match the new model representation. Save the new JSON into a file (newmodel.json). 4. Use management command "loaddata" to populate the new model with the newmodel.json. This has work well so far for my use with PostgreSQL, albeit very manual. It's all Python code. So I guess what I want to ask Django experts/developers here is that: 1. Is there any reason this shouldn't be done? 2. Any technical challenge that prevent this method from being realized into a more automate tool? (I read somewhere that dumpdata doesn't always work?) 3. What do you think about having migration code be more part of the deployment tool, rather than couple into the source code ? 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django 1.1 to be in future Google App Engine release
Just for everyone information, I believe Guido just said that Django 1.1 will be in future Google App Engine release once it (Django 1.1) is out of beta. Looking forward to this Django 1.1 final! Link here: http://code.google.com/p/googleappengine/issues/detail?id=872=ID%20Type%20Status%20Priority%20Stars%20Owner%20Summary%20Log%20Component --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How would I do this ...
Hello! I have hit a small road block in designing a fairly simple CMS application: My url pattern is: url(r'^(?P[A-Za-z-_//]+)/$', page_handler, name='page_handler') I'm capturing whatever URL handing it off to a page handler view function that matches up a Page by slug and returns it .. this works great for textual content. View: def page_handler(request, url=None): #Default to page root when no url if url == None: page = get_object_or_404(Page, id=1) else: page = get_object_or_404(Page, slug__exact=url) if not page.template: template = 'cms/default.html' else: template = page.template return render_to_response(template, { 'page': page, 'request': request, }) I am trying to figure out if there is a way to pass additional context to a template from the view, say I have made a contact page but this page needs to access a form, currently I don't know how I would be able to do that, that is, to pass the form context to whatever template the Page specifies. Normally I'd just map a URL to a "contact" view function that handles the form and passes it off to a template. I am trying to be efficient about this without "hard-coding" that in ... if that makes sense. Any help is appreciated! Regards, Titus --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with startproject
On Tuesday 02 June 2009 10:46:03 am Technicalbard wrote: > OK - newb here (in more ways than one). I'm trying to get going on an > Ubuntu VM (inside VirtualBox) and I installed Django via synaptic. > > The problem comes when I try to start the tutorial: > > mor...@morgan-laptop:~/www$ django-admin startproject mysite > Error: [Errno 13] Permission denied: '/home/morgan/www/mysite' > > I made sure that I have ownership of the /www folder (as opposed to > root having ownership), but that didn't make a difference. What's the output from each of these commands: (all at the command prompt, one at a time) ls -dl /home/morgan/www ls -dl /home/morgan/www/mysite whoami touch /home/morgan/www/TESTFILE After the last one, does the file /home/morgan/www/TESTFILE exist? -- Aaron Maxwell http://redsymbol.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How would I do this ...
I have a small problem, fairly new to django: I currently am building a small CMS application, and its all handled by a Page model. The url for this is: --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django Registration templates not talking to my other pages. Sometimes.
This is a weird one. It's so weird, I'm positive I'm making a very dumb mistake somewhere. This is my MO. Anyway, I am trying to use django-registration to do some very basic login, logout stuff. I'm using RequestContext to make usernames available to all of my templates, like so: //views.py from django.template import RequestContext def detail(request): ... context = { 'employees': employees, 'entityinfo': entityinfo} return render_to_response('results/resultstable.html', context_instance=RequestContext(request, context)) // I'm doing some variation of the same in all of my views. The problem is my {{ user }} (which I'm using in base.html) isn't showing up in the majority of my pages. It shows up on all of the django-registration pages that start with "/accounts/." It also shows up on my index page, which is the redirect from the login page. Here's the curveball: When I log in to the admin site, and then go to my project, everything works smashingly. I can go to all of my pages, and it says, "Hi, Matt!" What is going on here? I assume I either am using registration incorrectly, or am using RequestContext incorrectly. Or both. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: HOW DO YOU ACCESS SESSION AND COOKIES DATA W/O USING THE REQUEST OBJECT ?
I know but, then again the set value for the language is only retrievable from a request obj. Thanks. On Jun 2, 1:03 pm, akaariaiwrote: > On 1 kesä, 22:38, Rami wrote: > > > I'm trying to access Session's (logged in) user id info from a py > > function that does not have 'request' object. > > You could write up something similar to get_language() in > utils.translation or use threadlocals. I don't know if this is > actually a good idea. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Do you use a skeleton for new django sites?
On Tuesday 02 June 2009 22:09:03 Aaron Maxwell wrote: > Over time, I'll discover something new I'll want to add to all my django > sites. So I just make that change to django-skel and forget about it. > > Does anyone else follow this technique? yes - I have only used the startproject startapp thingie twice. Once in 2005 and once when the structure changed dramatically after MR. -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Managers to aggregate child object values?
I'm pretty new to Django still and I know much is still escaping me. In particular I'm having trouble still with how to query subsets of related objects. In this case I have two Models. class Project(models.Model): title = models.CharField(max_length=141) ... class Release(models.Model): project_fk = models.ForeignKey(Project) point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, null=True, blank=True) velocity_points = models.IntegerField(choices=VELOCITY_CHOICES, null=True, blank=True) ... What I was looking to do is create a way sum the total number of velocity points in releases related to a Project. I also wanted to sum the total number of point_estimate points related to a Project. >From what I see a Custom Manager would seem necessary but I'm getting confused on related objects and aggregating items. This is for Django v 1.0 and would not include v1.1 aggregation features. Thanks in advance for any insight. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Test client DoesNotExists exception
Thanks a lot! That was it! Regards On 3 Cze, 00:21, Karen Traceywrote: > On Tue, Jun 2, 2009 at 4:30 PM, SlafS wrote: > > > Hi! > > > Im trying to test my app with django test Client. > > When I try to do 'get' to the '/accounts/' which in my urls.py is > > equiv to generic login view I get DoesNotExists exception and a > > traceback. check it herehttp://dpaste.com/50688/. > > Can You tell me what am I doing wrong ? > > You've apparently got 'django.contrib.sites' listed in your INSTALLED_APPS > and you have set SITE_ID in your settings file to a value that has no match > in your Sites table. As mentioned here: > > http://docs.djangoproject.com/en/dev/ref/contrib/sites/#how-django-us... > > the auth app's login view, which the url you are testing is mapped to, > attempts get the current site name (if the sites app is installed) and pass > it as the variable site_name to the template. It's not finding a match when > it attempt to retrieve the currents (i.e. SITE_ID) site. > > > PS. when Im 'get'ing 'accounts/' I Get the "TypeError: 'NoneType' > > object is not iterable" > > I believe that's ticket #10834: > > http://code.djangoproject.com/ticket/10834 > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Where to configure this view
Thanks Alex David On Jun 2, 3:00 pm, Alex Gaynorwrote: > On Tue, Jun 2, 2009 at 4:56 PM, David wrote: > > > Hello, > > > I added a "telephone_number = models.CharField(max_length=15)" in the > > "User" class in Django-1.0.2-final/django/contrib/auth/models.py. Now > > I need to add/update telephone numbers on admin page. Which file > > should I configure so that I can see this "telephone_number" on the > > admin page? > > > Can anybody give me a suggestion? Thanks a lot. > > This isn't really the right way to extend the django user > model:http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m > However, if you insist on doing it this way you would need to alter > the > admin.py file in the same directory. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: select template for adminform based on type of user
any hint on this issue? Thanks, Sergio On May 29, 12:51 am, "Sergio A."wrote: > Dear all, > > Is it possible to select the template to be applied to an admin form > based on the logged user? > In particular, I've two cases: > > - if super user, a certain template should be used > - if not a super user, but the owner of the data, then another > template should be used > - if not a super user, but the owner of the data, then a third option > template should be used > > I understood that probably the get_form is the right place where to > work, but not sure if this can be done. > > Thanks for your support, Sergio --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Test client DoesNotExists exception
On Tue, Jun 2, 2009 at 4:30 PM, SlafSwrote: > > Hi! > > Im trying to test my app with django test Client. > When I try to do 'get' to the '/accounts/' which in my urls.py is > equiv to generic login view I get DoesNotExists exception and a > traceback. check it here http://dpaste.com/50688/ . > Can You tell me what am I doing wrong ? > You've apparently got 'django.contrib.sites' listed in your INSTALLED_APPS and you have set SITE_ID in your settings file to a value that has no match in your Sites table. As mentioned here: http://docs.djangoproject.com/en/dev/ref/contrib/sites/#how-django-uses-the-sites-framework the auth app's login view, which the url you are testing is mapped to, attempts get the current site name (if the sites app is installed) and pass it as the variable site_name to the template. It's not finding a match when it attempt to retrieve the currents (i.e. SITE_ID) site. > PS. when Im 'get'ing 'accounts/' I Get the "TypeError: 'NoneType' > object is not iterable" > I believe that's ticket #10834: http://code.djangoproject.com/ticket/10834 Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Where to configure this view
On Tue, Jun 2, 2009 at 4:56 PM, Davidwrote: > > Hello, > > I added a "telephone_number = models.CharField(max_length=15)" in the > "User" class in Django-1.0.2-final/django/contrib/auth/models.py. Now > I need to add/update telephone numbers on admin page. Which file > should I configure so that I can see this "telephone_number" on the > admin page? > > Can anybody give me a suggestion? Thanks a lot. > > > This isn't really the right way to extend the django user model: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/. However, if you insist on doing it this way you would need to alter the admin.py file in the same directory. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Where to configure this view
Hello, I added a "telephone_number = models.CharField(max_length=15)" in the "User" class in Django-1.0.2-final/django/contrib/auth/models.py. Now I need to add/update telephone numbers on admin page. Which file should I configure so that I can see this "telephone_number" on the admin page? Can anybody give me a suggestion? Thanks a lot. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: learning django
2009/6/2 virgo: > > I am very new to this field..got a job as python programmer and was > asked to use django for web developmentHow do u think I should > start learning...I dont have much time left before they kick me > out!! You must follow the tutorial, and the django book, first. It is really easy. Do it yourself, not just reading or cut & paste. Familiarize yourself with Django's documentation, and look for available Django books. Look for Django code, and try to see how it works. Good luck!! -- Hernan Olivera --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Accesing cliente devices
On Tue, Jun 2, 2009 at 4:46 PM, educonstantinwrote: > > need to know the standard way that Django offers access to devices > such as printers and scanners on the client side > > > > Django doesn't. It's a server side web framework. It neither a) knows about the client side, nor b) handles printing on the server side because that's a task for some sort of printer/scanner library. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Test client DoesNotExists exception
Hi! Im trying to test my app with django test Client. When I try to do 'get' to the '/accounts/' which in my urls.py is equiv to generic login view I get DoesNotExists exception and a traceback. check it here http://dpaste.com/50688/ . Can You tell me what am I doing wrong ? PS. when Im 'get'ing 'accounts/' I Get the "TypeError: 'NoneType' object is not iterable" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
learning django
I am very new to this field..got a job as python programmer and was asked to use django for web developmentHow do u think I should start learning...I dont have much time left before they kick me out!! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-reversion with recent svn django
Fixed it. I was assigning a string to a date field. Django is ok with this, django- reversion isn't. Changed: lDate = '%s-%s-%s' % (lYear, lMonth, lDay) lContestEvent.date_of_event = lDate to: lContestEvent.date_of_event = date(int(lYear), int(lMonth), int(lDay)) and all appears fine. Tim. On Tuesday 02 June 2009 22:01:26 Tim Sawyer wrote: > Hi, > > I'm using django svn 10784, and I've just added django-reversion, latest > svn version from trunk (198). I'm using the middleware option for django- > reversion. > > It's not working, and I'm getting the following error. I've tried with the > same django version and the tagged 1.1.1 release of django-reversion, but I > get the same problem. > > The error occurs on a save and is: > > > Traceback (most recent call last): > > File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", > line 278, in run > self.result = application(self.environ, self.start_response) > > File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", > line 636, in __call__ > return self.application(environ, start_response) > > File "/home/mybandsite/django-trunk/django/core/handlers/wsgi.py", line > 245, in __call__ > response = middleware_method(request, response) > > File "/home/mybandsite/src/reversion/middleware.py", line 23, in > process_response > reversion.revision.end() > > File "/home/mybandsite/src/reversion/revisions.py", line 263, in end > serialized_data = serializers.serialize(registration_info.format, > [obj], fields=registration_info.fields) > > File "/home/mybandsite/django-trunk/django/core/serializers/__init__.py", > line 87, in serialize > s.serialize(queryset, **options) > > File "/home/mybandsite/django-trunk/django/core/serializers/base.py", > line 44, in serialize > self.handle_field(obj, field) > > File "/home/mybandsite/django- > trunk/django/core/serializers/xml_serializer.py", line 70, in handle_field > self.xml.characters(field.value_to_string(obj)) > > File "/home/mybandsite/django-trunk/django/db/models/fields/__init__.py", > line 518, in value_to_string > data = datetime_safe.new_date(val).strftime("%Y-%m-%d") > > File "/home/mybandsite/django-trunk/django/utils/datetime_safe.py", line > 30, in new_date > return date(d.year, d.month, d.day) > > AttributeError: 'unicode' object has no attribute 'year' > > I think this might be something to do with my MIDDLEWARE_CLASSES which is > set to: > > MIDDLEWARE_CLASSES = ( > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.middleware.transaction.TransactionMiddleware', > 'reversion.middleware.RevisionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.doc.XViewMiddleware', > ) > > which doesn't match the recommendation from the django-reversion site. I > had to put the AuthenticationMiddleware first so that request.user was > available for the RevisionMiddleware to use, and that dragged the > SessionMiddleware in too. > > Any clues anyone? > > Thanks, > > Tim. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django-reversion with recent svn django
Hi, I'm using django svn 10784, and I've just added django-reversion, latest svn version from trunk (198). I'm using the middleware option for django- reversion. It's not working, and I'm getting the following error. I've tried with the same django version and the tagged 1.1.1 release of django-reversion, but I get the same problem. The error occurs on a save and is: Traceback (most recent call last): File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", line 278, in run self.result = application(self.environ, self.start_response) File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", line 636, in __call__ return self.application(environ, start_response) File "/home/mybandsite/django-trunk/django/core/handlers/wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "/home/mybandsite/src/reversion/middleware.py", line 23, in process_response reversion.revision.end() File "/home/mybandsite/src/reversion/revisions.py", line 263, in end serialized_data = serializers.serialize(registration_info.format, [obj], fields=registration_info.fields) File "/home/mybandsite/django-trunk/django/core/serializers/__init__.py", line 87, in serialize s.serialize(queryset, **options) File "/home/mybandsite/django-trunk/django/core/serializers/base.py", line 44, in serialize self.handle_field(obj, field) File "/home/mybandsite/django- trunk/django/core/serializers/xml_serializer.py", line 70, in handle_field self.xml.characters(field.value_to_string(obj)) File "/home/mybandsite/django-trunk/django/db/models/fields/__init__.py", line 518, in value_to_string data = datetime_safe.new_date(val).strftime("%Y-%m-%d") File "/home/mybandsite/django-trunk/django/utils/datetime_safe.py", line 30, in new_date return date(d.year, d.month, d.day) AttributeError: 'unicode' object has no attribute 'year' I think this might be something to do with my MIDDLEWARE_CLASSES which is set to: MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.transaction.TransactionMiddleware', 'reversion.middleware.RevisionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.doc.XViewMiddleware', ) which doesn't match the recommendation from the django-reversion site. I had to put the AuthenticationMiddleware first so that request.user was available for the RevisionMiddleware to use, and that dragged the SessionMiddleware in too. Any clues anyone? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Search in one table, order by a field in another table
Yes, this exactly what I want. Thanks a lot! -Larry On Jun 2, 12:11 pm, Daniel Rosemanwrote: > On Jun 2, 3:04 pm, Larry wrote: > > > > > > > Hi, > > > Here is what I want to do: > > > I have one table A with two columns: user_id, msg_id (ManyTOMany) > > and other table B with two column: msg_id, msg_time > > > Now I want to search for msg_id's of a certain user_id in table A, and > > display the msgs > > ordered by the msg_time. > > > Could anyone tell me how to do this? > > > Many many thanks! > > > -Larry > > You might need to provide some actual model definitions. > > Generally, you can use the double-underscore format in order_by, so > you can do this: > ModelA.objects.filter(field=x).order_by('modelb__field') > > Is that what you want? > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Automatically creating auth.models.group for an application
2009/6/2 eric.frederich: > > In an application I'm writing I have a model that stores admins by > location in a model called LocationAdmin. So in this model I have a > foreign key to User and a foreign key to a Location object. > > I would like to override the save() method so that when an Admin is > created they are assigned to a special group (auth group). This group > would be called something like "Location Admins" and have various > permissions. > Couldn't you do this with the post-save signal? http://docs.djangoproject.com/en/dev/ref/models/instances/#what-happens-when-you-save Create a signal that listens for the save of a admin and have it place an admin into your group if they aren't already. That way you could could add your new admin user to your special group. HTH Dan > I have having a hard time finding a way let alone the correct way to > do this. > > I feel that the group should be created when running syncdb but by > using a fixture I'd have to hard code the permissions keys that the > group needs. > > Its almost like I need a fixture that runs some python script that > runs Permission.objects.get to go after the wanted permissions. > > Is there a mechanism to do something like? > > > -- Dan Hilton DanHilton.co.uk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: HOW DO YOU ACCESS SESSION AND COOKIES DATA W/O USING THE REQUEST OBJECT ?
On 1 kesä, 22:38, Ramiwrote: > I'm trying to access Session's (logged in) user id info from a py > function that does not have 'request' object. You could write up something similar to get_language() in utils.translation or use threadlocals. I don't know if this is actually a good idea. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with startproject
Technicalbard wrote: > OK - newb here (in more ways than one). I'm trying to get going on an > Ubuntu VM (inside VirtualBox) and I installed Django via synaptic. > > The problem comes when I try to start the tutorial: > > mor...@morgan-laptop:~/www$ django-admin startproject mysite > Error: [Errno 13] Permission denied: '/home/morgan/www/mysite' > > I made sure that I have ownership of the /www folder (as opposed to > root having ownership), but that didn't make a difference. This is not the /www directory, but the /home/morgan/www/ directory. You do not need ownership (although it is customary of directories under your home directory), but write permission. Execute sudo chown morgan ~/www sudo chmod 755 ~/www If there are any files in ~/www, such as an existing 'mysite' directory, delete them. HTH, -- Jochem Berndsen | joc...@functor.nl GPG: 0xE6FABFAB --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with startproject
django-admin is executable. The problem appears to be that django- admin doesn't have rights to the target directory... On Jun 2, 11:52 am, James Bennettwrote: > On Tue, Jun 2, 2009 at 12:46 PM, Technicalbard wrote: > > The problem comes when I try to start the tutorial: > > > mor...@morgan-laptop:~/www$ django-admin startproject mysite > > Error: [Errno 13] Permission denied: '/home/morgan/www/mysite' > > Quoting the tutorial: > > "you may see the message “permission denied” when you try to run > django-admin.py startproject. This is because, on Unix-based systems > like OS X, a file must be marked as “executable” before it can be run > as a program. To do this, open Terminal.app and navigate (using the cd > command) to the directory where django-admin.py is installed, then run > the command chmod +x django-admin.py." > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with startproject
On Tue, Jun 2, 2009 at 12:46 PM, Technicalbardwrote: > The problem comes when I try to start the tutorial: > > mor...@morgan-laptop:~/www$ django-admin startproject mysite > Error: [Errno 13] Permission denied: '/home/morgan/www/mysite' Quoting the tutorial: "you may see the message “permission denied” when you try to run django-admin.py startproject. This is because, on Unix-based systems like OS X, a file must be marked as “executable” before it can be run as a program. To do this, open Terminal.app and navigate (using the cd command) to the directory where django-admin.py is installed, then run the command chmod +x django-admin.py." -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with startproject
OK - newb here (in more ways than one). I'm trying to get going on an Ubuntu VM (inside VirtualBox) and I installed Django via synaptic. The problem comes when I try to start the tutorial: mor...@morgan-laptop:~/www$ django-admin startproject mysite Error: [Errno 13] Permission denied: '/home/morgan/www/mysite' I made sure that I have ownership of the /www folder (as opposed to root having ownership), but that didn't make a difference. Help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Automatically creating auth.models.group for an application
In an application I'm writing I have a model that stores admins by location in a model called LocationAdmin. So in this model I have a foreign key to User and a foreign key to a Location object. I would like to override the save() method so that when an Admin is created they are assigned to a special group (auth group). This group would be called something like "Location Admins" and have various permissions. I have having a hard time finding a way let alone the correct way to do this. I feel that the group should be created when running syncdb but by using a fixture I'd have to hard code the permissions keys that the group needs. Its almost like I need a fixture that runs some python script that runs Permission.objects.get to go after the wanted permissions. Is there a mechanism to do something like? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
overriding model field defaults in inherited model class with static methods
Hi. I'm trying to override the defaults of an text field in an subclass. I thought i could accomplish that by the following code, but models.TextField(default = default('flags')... wouldn't find default (). I cant reference it by self.__class__.default() as the is no self at the field initialization. Im kind of stuck ... Thank you for your help! class Compiler(Model): class Meta(Checker.Meta): abstract = True # default values for the model fields defaults = { 'flags' : "-Wall -static", 'output_flags' : "-o %s", 'libs' : "", 'file_pattern' : r"^[a-zA-Z0-9_]*$"# Regular expression describing all source files to be passed to the compiler. } def default(key): """ By making the model field defaults a callable instead of an value it will be called every time a new object is created wich will allow for altered defaults in subclasses. """ return defaults[key] _flags = models.TextField(default = default('flags'), help_text = _ ('Compiler flags')) _output_flags = models.TextField(default = default('output_flags'), help_text = _('Output flags')) _libs = models.TextField(default = default('libs'), help_text = _ ('Compiler libraries')) class CXXBuilder(compiler): """ A C++ compiler for construction. """ # override configuration _compiler = "c++" _language = "C++" # override default values for the model fields defaults['flags'] = "-Wall", defaults['output_flags']= "" defaults['file_pattern']= r"^[a-zA-Z0-9_]*\.(c|C|cc|CC|cxx|CXX|c\+\+| C\+\+|cpp|CPP)$" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Possible memory leak moving to Django 1.1 from 1.0.2 in mixed use test.
We've got an application that is running behind apache, mod_wsgi and front ending a postgres 8.3 db. We needed to upgrade our Satchmo to the latest version which requires Django 1.1. After the upgrade the system starts eventually running out of memory until it thrashes and locks up the machine under a fairly light load, just a few reqs per second. I can understand the system using more memory but it doesn't seem to release it when the load stops. This graph: http://www.flickr.com/photos/proteusguy/3589788760 shows the results of both systems which, besides the Django & Satchmo versions are identical. You can see that when the test completes on the old system the process returns a great amount of memory but the new one never releases the memory. In production this will eventually grow to consume all RAM. This particular test is of a set of 7 different requests simulating what a typical user might do. This graph: http://www.flickr.com/photos/proteusguy/3589788752 shows a similar test except it only contains a single request out of the seven from the prior test. We were hoping to identify that something in one of our requests was the cause of the problem but similar exclusive test runs with all 7 requests from the combined test from above show similar results - fairly stable memory usage. This leads me to believe that the issue is systemic to django, most likely in the db handling as most of the requests don't touch the Satchmo system. If this was a C++ app I'd be able to figure this out pretty quick but I'm not sure how to attack the problem in a dynamic language environment like python. So this leaves me with two questions: 1. Is anyone else seeing this kind of memory extra memory usage and an inability to return memory once requests end? 2. What suggestions does anyone have about how I can determine what aspect of the system is using this extra memory and holding onto it? thanx very much, -- Ben Scherrey --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: inline model's choices field empty in admin
Thank you sir. I got this from "Python Web Dev. w/ Django". An unforseen side effect. ryan On Jun 2, 12:05 pm, Daniel Rosemanwrote: > On Jun 2, 4:53 pm, ryan wrote: > > > This additional model, which uses the same choices is emptying the > > choices dropdown of both User with inline UserProfile and UserProfile > > itself. Add it prior to UserProfile in models.py of your test app: > > > class Person(models.Model): > > sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) > > user_class = models.IntegerField(choices=USER_CLASS_CHOICES) > > last_name = models.CharField(max_length=40) > > first_name = models.CharField(max_length=30) > > > This behavior is not mentioned as a caveat > > inhttp://docs.djangoproject.com/en/dev/ref/models/fields/#choices > > > ryan > > Because enumerate() is an iterator. So it is consumed the first time > it is run. > > You could call list() on it to flatten it: > SALES_TEAM_CHOICES = list(enumerate(('CLS','CCS','TPS'))) > > I've never heard of anyone doing this, which is presumably why it's > not mentioned in the documentation... > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Do you use a skeleton for new django sites?
Hi all, When creating a new django based website, my first step used to be to invoke "python manage.py startproject". The files created would be the first or second commit into version control for that project. I found, however, that I would always make a similar set of changes right after: certain configurations and changes to settings, creating an apps directory (module), 404 and 500 templates, etc. So what I do now is I have a separate project, which I call django-skel, that is just a new project file layout with the changes I already want to make for every project. For each new project, I just export from that, copy the files into the new project space, and commit. Over time, I'll discover something new I'll want to add to all my django sites. So I just make that change to django-skel and forget about it. Does anyone else follow this technique? Or do you have some different approach that solves this problem for you? Thanks, Aaron -- Aaron Maxwell http://redsymbol.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Search in one table, order by a field in another table
On Jun 2, 3:04 pm, Larrywrote: > Hi, > > Here is what I want to do: > > I have one table A with two columns: user_id, msg_id (ManyTOMany) > and other table B with two column: msg_id, msg_time > > Now I want to search for msg_id's of a certain user_id in table A, and > display the msgs > ordered by the msg_time. > > Could anyone tell me how to do this? > > Many many thanks! > > -Larry You might need to provide some actual model definitions. Generally, you can use the double-underscore format in order_by, so you can do this: ModelA.objects.filter(field=x).order_by('modelb__field') Is that what you want? -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: inline model's choices field empty in admin
On Jun 2, 4:53 pm, ryanwrote: > This additional model, which uses the same choices is emptying the > choices dropdown of both User with inline UserProfile and UserProfile > itself. Add it prior to UserProfile in models.py of your test app: > > class Person(models.Model): > sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) > user_class = models.IntegerField(choices=USER_CLASS_CHOICES) > last_name = models.CharField(max_length=40) > first_name = models.CharField(max_length=30) > > This behavior is not mentioned as a caveat > inhttp://docs.djangoproject.com/en/dev/ref/models/fields/#choices > > ryan Because enumerate() is an iterator. So it is consumed the first time it is run. You could call list() on it to flatten it: SALES_TEAM_CHOICES = list(enumerate(('CLS','CCS','TPS'))) I've never heard of anyone doing this, which is presumably why it's not mentioned in the documentation... -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: inline model's choices field empty in admin
This additional model, which uses the same choices is emptying the choices dropdown of both User with inline UserProfile and UserProfile itself. Add it prior to UserProfile in models.py of your test app: class Person(models.Model): sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) user_class = models.IntegerField(choices=USER_CLASS_CHOICES) last_name = models.CharField(max_length=40) first_name = models.CharField(max_length=30) This behavior is not mentioned as a caveat in http://docs.djangoproject.com/en/dev/ref/models/fields/#choices ryan On Jun 2, 11:22 am, Karen Traceywrote: > On Tue, Jun 2, 2009 at 10:59 AM, ryan wrote: > > > When I edit a User in the admin, the sales_team and user_class > > dropdowns are empty. > > > If anyone can point out my error or point me to the django core code > > that ignores the choices, I would greatly appreciate it. > > > [snip code] > > I cannot recreate this with either Django 1.0.2 or current trunk. When I > cut and paste the models/admin defs you show into a test app and then edit a > user in admin, the two profile dropdowns are populated with an empty choice > (all dashes) plus the choices you have specified. There must be something > beyond what you have shown here that is coming into play. > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Having trouble authenticating/validating
On Tue, Jun 2, 2009 at 9:42 AM, gsnyder2007wrote: > > Had the same issue and the info below allowed me to resolve the issue, > i.e. is_valid() is now returning True on a valid username/password > combination. Seemed to me that the key was setting the test cookie and > assigning the POST data into the 'data' variable. The former makes > sense to me. The latter does not. I wonder if anyone out there can > explain why. > AuthenticationForm adds a 'request' (keyword or first positional) parameter to the standard Form arguments: http://code.djangoproject.com/browser/django/tags/releases/1.0/django/contrib/auth/forms.py#L54 So if you are instantiating an AuthenticationForm without passing in 'request' you need to specify what's normally simply the first positional Form argument by keyword (which is 'data'), because if you pass it as simply first positional it will be assigned to 'request'. Not sure if that explains what does not make sense to you? (Both the details of AuthenticationForm and the fact that the first positional argument to the base Form class has the keyword 'data' could probably use a bit more explicit documentation, unless I'm missing where these things are currently covered...I couldn't find them in a brief search.) Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: inline model's choices field empty in admin
On Tue, Jun 2, 2009 at 10:59 AM, ryanwrote: > > When I edit a User in the admin, the sales_team and user_class > dropdowns are empty. > > If anyone can point out my error or point me to the django core code > that ignores the choices, I would greatly appreciate it. > > [snip code] I cannot recreate this with either Django 1.0.2 or current trunk. When I cut and paste the models/admin defs you show into a test app and then edit a user in admin, the two profile dropdowns are populated with an empty choice (all dashes) plus the choices you have specified. There must be something beyond what you have shown here that is coming into play. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Markdown Encoding Problem
Yes. I completely missed that ticket, but I had switched to importing markdown normally instead of through Django, and it solved my problems. But I noticed on Ubuntu that the repository version of python-markdown is still 1.6. So I will switch to a newer version of Markdown. Thank you both for your help. On Jun 2, 8:08 am, Waylan Limbergwrote: > On Jun 1, 7:11 pm, Karen Tracey wrote: > > > > > That comment, specifically, includes the same exception and traceback as you > > are showing. I read subsequent discussion in the ticket to be saying that > > the problem here is the markdown version, it's some pre-Unicode support > > level that you likely don't want to be using if you need proper Unicode > > support. Apparently some bits may work (that comment shows passing Unicode > > working whereas passing a utf-8 encoded bytestring of the same content > > fails), but the comments from a markdown core dev indicate any semblance of > > "working" here is likely accidental. Sounds like the easiest fix for you > > may be to upgrade your markdown to at least 1.7. > > Karen nailed it. If your are using anything prior to Markdown 1.7 > upgrade immediately (the 1.6 series was horribly buggy). Actually, > Markdown is currently at version 2.0.1 [1]. With 2.0 we've made a > number of improvements in a number of ways. However, one thing we are > dedicated to keeping the same is that since 1.7, Markdown will only > ever accept unicode text as input - nothing else. That has been a > tremendous help in eliminating these kinds of problems. > > [1]:http://pypi.python.org/pypi/Markdown > > Waylan Limberg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
inline model's choices field empty in admin
When I edit a User in the admin, the sales_team and user_class dropdowns are empty. If anyone can point out my error or point me to the django core code that ignores the choices, I would greatly appreciate it. #models.py SALES_TEAM_CHOICES = enumerate(('CLS','CCS','TPS')) USER_CLASS_CHOICES = enumerate(('DOM','DSK','DFA','DTM')) class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) sales_team = models.IntegerField(choices=SALES_TEAM_CHOICES) user_class = models.IntegerField(choices=USER_CLASS_CHOICES) #admin.py class UserProfileInline(admin.StackedInline): model = UserProfile max_num = 1 class CustomUserAdmin(UserAdmin): inlines = [UserProfileInline,] admin.site.unregister(User) admin.site.register(User, CustomUserAdmin) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Search in one table, order by a field in another table
Hi, Here is what I want to do: I have one table A with two columns: user_id, msg_id (ManyTOMany) and other table B with two column: msg_id, msg_time Now I want to search for msg_id's of a certain user_id in table A, and display the msgs ordered by the msg_time. Could anyone tell me how to do this? Many many thanks! -Larry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Having trouble authenticating/validating
Had the same issue and the info below allowed me to resolve the issue, i.e. is_valid() is now returning True on a valid username/password combination. Seemed to me that the key was setting the test cookie and assigning the POST data into the 'data' variable. The former makes sense to me. The latter does not. I wonder if anyone out there can explain why. On May 12, 1:28 pm, adrianwrote: > Figured it out by looking at how the admin view using > AuthenticationForm: > > In POST: > > loginForm = AuthenticationForm(data=request.POST) > > note the use of data= which I have not seen before > > in GET: > > loginForm = AuthenticationForm(request) > request.session.set_test_cookie() > > note the passing of request to the form which is also unusual --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Utilizing Admin Views but with custom subset
I have successfully created a little app and i would like to leverage the already existing admin interface rather than reinvent the wheel and create my own table listings I have managed to do this fine for simple models but in this case i have a custom queryset that i would like to use. Essentially I have a Report that is contains multiple ReportItems. A ReportItem is a subset/filter of the Log model. I want to display multiple subsets/filters of the log model all joined together in a table in the admin interface. I have managed to do this in the views.py but it looks basic and is missing all the funky kewl sorting and things that is present in the admin interface. So is there a way for me to feed my queryset querySets into the admin interface? -- models.py file -- class Feed(models.Model): name = models.CharField(max_length=200) feed_url = models.CharField(max_length=200) active = models.BooleanField() def __unicode__(self): return self.name class Log(models.Model): feed = models.ForeignKey(Feed) creator = models.CharField(max_length=200) pubdate = models.DateTimeField() title = models.CharField(max_length=200) changeset = models.IntegerField() changeset_url = models.CharField(max_length=200) description = models.CharField(max_length=200) category = models.CharField(max_length=200) qa_notes = models.CharField(max_length=200) status = models.IntegerField() def __unicode__(self): return self.title class Report(models.Model): name = models.CharField(max_length=200) def __unicode__(self): return self.name @models.permalink def get_absolute_url(self): return ('vtps2.logs.views.report_detail_table', (), {'report_id':self.id}) class ReportItem(models.Model): report = models.ForeignKey(Report) feed = models.ForeignKey(Feed) start = models.IntegerField() finish = models.IntegerField() -- Views.py file -- class LogTable(tables.ModelTable): class Meta: model = Log def report_detail_table(request, report_id): report = get_object_or_404(Report, pk=report_id) # retrieve set querySets = Log.objects.filter(feed=0) for ri in report.reportitem_set.all(): querySets = querySets | (Log.objects.filter(feed=ri.feed_id, changeset__range=(ri.start,ri.finish))) # load set into table table = LogTable( querySets, order_by=request.GET.get('sort', 'changeset')) return render_to_response('logs/table.html', {'table': 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
proxy table filtering
Hi, I have been a Django user for a long time now but only recently ran into a position where have needed to use Generic relationships, I need to be able to do something similar to filtering on a GenericForeignKey. Essentially I have a media management app that looks something similar to the following: class MediaProxy(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() class Media(models.Model): title = models.CharField(max_length=160) uploader = models.ForeignKey('auth.User') proxy = generic.GenericRelation(MediaProxy) class Meta: abstract = True class Image(Media): content = models.ImageField(upload_to='media/') The idea being that no matter how many different types of media I have (images, video, audio, etc..), I can still have them all grouped together via the MediaProxy model. Although there's a problem in that you can't filter on the GenericForeignKey attribute because it doesn't exist in the table. So I am wondering if anyone knows any way of filtering over multiple models that inherit from one parent model (and thus are similar) without specifically having to run a filter on each model individually as that would violate DRY and make it a large pain to add new media types. Any help would be hugely appreciated, thank you. gord. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Markdown Encoding Problem
On Jun 1, 7:11 pm, Karen Traceywrote: > > That comment, specifically, includes the same exception and traceback as you > are showing. I read subsequent discussion in the ticket to be saying that > the problem here is the markdown version, it's some pre-Unicode support > level that you likely don't want to be using if you need proper Unicode > support. Apparently some bits may work (that comment shows passing Unicode > working whereas passing a utf-8 encoded bytestring of the same content > fails), but the comments from a markdown core dev indicate any semblance of > "working" here is likely accidental. Sounds like the easiest fix for you > may be to upgrade your markdown to at least 1.7. Karen nailed it. If your are using anything prior to Markdown 1.7 upgrade immediately (the 1.6 series was horribly buggy). Actually, Markdown is currently at version 2.0.1 [1]. With 2.0 we've made a number of improvements in a number of ways. However, one thing we are dedicated to keeping the same is that since 1.7, Markdown will only ever accept unicode text as input - nothing else. That has been a tremendous help in eliminating these kinds of problems. [1]: http://pypi.python.org/pypi/Markdown Waylan Limberg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: request.session in template tag?
If you just need the request obj passed to all pages. I use this in my URLs: # Custom Direct to template - carrys the request object def direct_to_template(request, template): from django.shortcuts import render_to_response from django.template import RequestContext return render_to_response(template, {'request': request}, context_instance = RequestContext(request)) urlpatterns = patterns('', (r'^$', 'urls.direct_to_template', {'template': 'index.html'}), ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Tastiest show-off Django template filters
I'm doing a demo of some of our Django work soon. Partly, it'll be a showcase for Django. One thing I'd like to do is demonstrate Django's template filters, to show how powerful it is and how it can make a a contribution to the quality of web output. So far I have: * typogrify * humanize Are there any other must-have candidates for this list? Thanks, Daniele --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using Request Info in Generic Views
Hi, you can use this: http://docs.djangoproject.com/en/dev/topics/auth/#authentication-data-in-templates to add the user to the template context. Then you cold write template tags to actually get the data you need using the user template variable. http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags adi On 02.06.2009, at 13:33, Keyton Weissinger wrote: > > I know I'm in the minority, but I'm still having some trouble grokking > the details of generic views. I keep thinking I should be using them > but keep running into the same issue. > > Here's my problem: I am building a mgmt site for schools in which > schools sign up for a monthly service fee. Most of my models have a > "school" foreign key which is also part of the user's profile. > > So to see, for example, a list of teachers, I do something kind of > like this (assumes login has already occurred): > > def myview(request): > current_person = request.user.get_profile() > current_school = current_person.school > teacher_list = Teacher.objects.filter(school=current_school) > etc > > Almost everything I have has this school property. > > My question is this: How do I leverage generic views in this capacity? > Is there a way to use the request information (specifically > request.user.get_profile().school in my case) in my urls.py when > generating my querysets? > > Thank you! > > Keyton > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: request.session in template tag?
On Jun 1, 7:53 pm, "bax...@gretschpages.com"wrote: > I'm trying to write a template tag that accesses the user's > request.session. My problem is, I don't know how to get the request. > > Googling around, I saw references to including > TEMPLATE_CONTEXT_PROCESSORS in settings, but I'm still not seeing the > request. > > Help? Hi your best bet is to do the following - I used this for something else but you'll get the idea: from django.template import resolve_variable from django import template from django.template import Library, Node register = template.Library() class AlertNode(Node): def __init__(self, request): self.request = request def render(self, context): request = resolve_variable(self.request, context) # Do something with the session var = request.session.get('js_alert', None) if var: del request.session['js_alert'] return str('alert("%s");' % var) else: return '' @register.tag(name="get_js_alert") def get_js_alert(parser, token): try: tag_name, request = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents[0] return AlertNode(request) # Usage: {% load js_tag %}{% get_js_alert request %} You now have acces to POST, GET and SESSION ect in your templatetag. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django with ajax
Thanks Jorge, Dajax looks very useful. Ill do it with Json though until Dajax becomes mainstream. Thanks. On Jun 2, 10:47 am, Jorge Bastidawrote: > Hello Marc, > > You can render a template into an string. > > from django.template.loader import render_to_string > my_template = render_to_string('template.html',{'some':'data'}) > > If you want to send the list of objects to the browser you can use > serialization into > json:http://docs.djangoproject.com/en/dev/topics/serialization/#id2 > > In other hand, i'm currently developing Dajax > (http://code.google.com/p/dajaxproject/) it will help you using ajax in > django. For example, for sending serialized objects to the browser and use > it as you want in JS. > > Thanks > > 2009/6/2 Aldo > > > > > Hey, > > > I have some ajax running on my pages. > > > I want to have it pass back some objects. However, I am unsure if I > > can pass a list of objects back. So far I have only ever passed back > > raw xml or text. Can objects be passed and then iterated via the html > > template? > > > Thanks > > -- > neo2001[at]gmail.com > jorge[at]thecodefarm.com > neo[at]art-xtreme.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using Request Info in Generic Views
http://groups.google.com/group/django-users/browse_thread/thread/bde817d4620fdfec On Tue, Jun 2, 2009 at 7:33 AM, Keyton Weissingerwrote: > I know I'm in the minority, but I'm still having some trouble grokking > the details of generic views. I keep thinking I should be using them > but keep running into the same issue. > > Here's my problem: I am building a mgmt site for schools in which > schools sign up for a monthly service fee. Most of my models have a > "school" foreign key which is also part of the user's profile. > > So to see, for example, a list of teachers, I do something kind of > like this (assumes login has already occurred): > > def myview(request): > current_person = request.user.get_profile() > current_school = current_person.school > teacher_list = Teacher.objects.filter(school=current_school) > etc > > Almost everything I have has this school property. > > My question is this: How do I leverage generic views in this capacity? > Is there a way to use the request information (specifically > request.user.get_profile().school in my case) in my urls.py when > generating my querysets? > > Thank you! > > Keyton --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Using Request Info in Generic Views
I know I'm in the minority, but I'm still having some trouble grokking the details of generic views. I keep thinking I should be using them but keep running into the same issue. Here's my problem: I am building a mgmt site for schools in which schools sign up for a monthly service fee. Most of my models have a "school" foreign key which is also part of the user's profile. So to see, for example, a list of teachers, I do something kind of like this (assumes login has already occurred): def myview(request): current_person = request.user.get_profile() current_school = current_person.school teacher_list = Teacher.objects.filter(school=current_school) etc Almost everything I have has this school property. My question is this: How do I leverage generic views in this capacity? Is there a way to use the request information (specifically request.user.get_profile().school in my case) in my urls.py when generating my querysets? Thank you! Keyton --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Internationalization and Apache
On Jun 2, 6:03 pm, Damien MATHIEU <4...@dmathieu.com> wrote: > So that is what I have in os.environ with Apache : > LANG = en > TZ = France/Paris > DJANGO_SETTINGS_MODULE = setting.production > SHLVL = 1 > APACHE_RUN_USER = www-data > APACHE_PID_FILE = /var/run/apache2.pid > PWD = /home/git/pyki/public > APACHE_RUN_GROUP = www-data > TMPDIR = /tmp/passenger.31221/var > HOME = /var/www > PATH = /usr/local/bin:/usr/bin:/bin > _ = /usr/sbin/apache2 > > And with the development server : > LANG = en_GB > TERM = xterm > SHELL = /bin/bash > TZ = France/Paris > RUN_MAIN = true > SHLVL = 1 > SSH_TTY = /dev/pts/0 > OLDPWD = /home/git/pyki/content > PWD = /home/git/pyki > SSH_CLIENT = 193.251.16.192 2616 22 > DJANGO_SETTINGS_MODULE = pyki.settings > USER = dmathieu > PATH = /usr/local/bin:/usr/bin:/bin:/usr/games > MAIL = /var/mail/dmathieu > LOGNAME = dmathieu > SSH_CONNECTION = 193.251.16.192 2616 213.251.184.40 22 > HOME = /home/ > _ = /usr/bin/python In your user account, run: LANG=en export LANG and then run Django's own development server. Does the application when run under Django's development server then break also? If it does, that should indicate reasonably well what the problem likely is. Graham > On Jun 1, 10:58 pm, Damien MATHIEU <4...@dmathieu.com> wrote: > > > Thank you Karen for being more precise and writing something > > understandable. > > > On Jun 1, 5:15 pm, Karen Traceywrote: > > > > On Mon, Jun 1, 2009 at 8:39 AM, Damien MATHIEU <4...@dmathieu.com> wrote: > > > > > Based on the advices of a friend, I've tried with mod_wsgi instead of > > > > mod_python. > > > > However, it still doesn't work. > > > > > And the sys.path is similar to the one I have when I do a manage.py > > > > runserver (where I correctly have my language strings). > > > > > So it's not a path problem. > > > > You've included Graham's response below but you have apparently not acted > > > on > > > any of its advice. Graham doesn't mention a path problem, nor does he > > > suggest that switching to mod_wsgi would fix the issue: he mentions an > > > environment problem, specifically related to the locale environment > > > variables. Perhaps if you follow Graham's advice below about writing a > > > view > > > that displays os.environ variables and compare the values between > > > development server and Apache you will make more progress. > > > > Karen > > > > > On May 29, 1:51 am, Graham Dumpleton > > > > wrote: > > > > > On May 28, 11:56 pm, Damien MATHIEU <4...@dmathieu.com> wrote: > > > > > > > Hi, > > > > > > > Using the internal web server, I correctly load every language > > > > > > string > > > > > > located in application_path/locale/language/LC_MESSAGES/django.mo > > > > > > But whenever I use Apache, they don't appear to be loaded anymore. > > > > > > > However it appear the default ones are loaded. > > > > > > The languages names are appropriately translated (French to Français > > > > > > for example). > > > > > > > I have the following virtual host : > > > > > > > > > > > > DocumentRoot /home/git/refdoc > > > > > > ServerName doc.tmp.dev.refstats.net > > > > > > ServerAlias doc.tmp.dev.refstats.net > > > > > > SetEnv DJANGO_SETTINGS_MODULE setting.production > > > > > > > > > > > > > SetHandler python-program > > > > > > PythonHandler django.core.handlers.modpython > > > > > > PythonPath "['/home/git/refdoc'] + sys.path > > > > > > PythonDebug On > > > > > > > > > > > > > > > > > > > And I use localeurl :http://code.google.com/p/django-localeurl/ > > > > > > > Thanks by advance for any help you'll hopefully provide me. > > > > > > The development server is likely working because it is picking up > > > > > locale and language environment variables from your personal account. > > > > > When running Apache, which starts up as root before changing to non > > > > > privileged user, it will not be getting those environment variables > > > > > from your personal account. As such, it will use whatever is the > > > > > system default. > > > > > > Often it is not enough to just set the variables from inside Apache or > > > > > your code and you need to ensure they are set in the environment of > > > > > Apache when it runs. How this is done depends a bit on whether you are > > > > > using Apache compiled from source or some specific operating systems > > > > > distribution. > > > > > > I would start by writing a test URL which dumps out os.environ in each > > > > > way of running it, then compare settings for LC_* and LANG environment > > > > > variables. > > > > > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit
Re: ModelForm problems, Programming Error 1146
Well i only say the e.save() line causes social mayhem as when doing a line by line debug of that section, that's the command that causes all the trouble. I suspected there's a problem with my dispatch.cgi script, as if i were to manually add the table i get the same behavior (though adding the redirect middleware solved some issues, i'd only had the fallback middleware showing up). The url it directs to hits the same function just that it triggers a if request.POST statement, and with all my sloppy fixes in place my error_log looks like: http://dpaste.com/50434/ Now my only concern is any significant trunk differences between my installation and the model installation a peer has shown me (which i don't have open access to). With what i've seen i believe it to be either a version discrepancy issue (as i don't know much about the django redirect apps) or something wrong with my dispatch.cgi. I will double check my URLS to be sure, but do either of my suspected causes seem probable for this type of issue? And again, thanks for the input, i think this has been more than once from you;) On Jun 1, 4:39 pm, Karen Traceywrote: > On Mon, Jun 1, 2009 at 5:09 PM, Robocop wrote: > > > Hello, > > I'm trying to deploy another developer's blog code, and have run into > > some snags with their ModelForm for adding entries. > > > The segment of code that triggers the error in my views.py: > >http://dpaste.com/50238/ > > > The model and modelforms for both the blog, and for the entries: > >http://dpaste.com/50237/ > > > The Traceback: > >http://dpaste.com/50240/ > > > Now my templates seem to be working fine, and the form is validated > > properly on POST. I can get at all the attributes of the form, and > > they all look correct. It's only when i save the form data that i get > > the error. Any help would be greatly appreciated, i've been trying to > > sort this out all day and don't seem to be making much progress. > > Why do you say it is the e.save() in your first dpaste that causes the > error? The traceback: > > Traceback (most recent call last): > File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 558, in > run > File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 1116, in > handler > File > "/usr/local/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line > 243, in __call__ > response = middleware_method(request, response) > File > "/usr/local/lib/python2.4/site-packages/django/contrib/redirects/middleware.py", > line 11, in process_response > r = Redirect.objects.get(site__id__exact=settings.SITE_ID, > old_path=path) > File "/usr/local/lib/python2.4/site-packages/django/db/models/manager.py", > line 93, in get > return self.get_query_set().get(*args, **kwargs) > File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", > line 298, in get > num = len(clone) > File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", > line 154, in __len__ > self._result_cache = list(self.iterator()) > File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", > line 269, in iterator > for row in self.query.results_iter(): > File > "/usr/local/lib/python2.4/site-packages/django/db/models/sql/query.py", line > 206, in results_iter > for rows in self.execute_sql(MULTI): > File > "/usr/local/lib/python2.4/site-packages/django/db/models/sql/query.py", line > 1700, in execute_sql > cursor.execute(sql, params) > File "/usr/local/lib/python2.4/site-packages/django/db/backends/util.py", > line 19, in execute > return self.cursor.execute(sql, params) > File > "/usr/local/lib/python2.4/site-packages/django/db/backends/mysql/base.py", > line 83, in execute > return self.cursor.execute(query, args) > File > "/usr/local/lib/python2.4/site-packages/MySQL_python-1.2.2-py2.4-linux-i686.egg/MySQLdb/cursors.py", > line 166, in execute > File > "/usr/local/lib/python2.4/site-packages/MySQL_python-1.2.2-py2.4-linux-i686.egg/MySQLdb/connections.py", > line 35, in defaulterrorhandler > ProgrammingError: (1146, "Table 'usbroker_brokerage.django_redirect' doesn't > exist") > > doesn't support that statement. Not only is your e.save() nowhere to be > seen in that traceback, nothing from your code appears anywhere in that > traceback. Also, the error message that accompanies the generic '1146 > error' shows the problem is a table that does not exist. Specifically, a > table named django_redirect. Looking further back in the traceback you can > see the code that is issuing the query causing the exception is in > django/contrib/redirects/middleware.py. Doc for that middleware is here: > > http://docs.djangoproject.com/en/dev/ref/contrib/redirects/ > > and it states that this middleware only does something when a response code > of 404 is being returned. > > I'd guess somehow your form-save code path is resulting in a 404 > (redirecting to a
Re: Django with ajax
Hello Marc, You can render a template into an string. from django.template.loader import render_to_string my_template = render_to_string('template.html',{'some':'data'}) If you want to send the list of objects to the browser you can use serialization into json: http://docs.djangoproject.com/en/dev/topics/serialization/#id2 In other hand, i'm currently developing Dajax ( http://code.google.com/p/dajaxproject/) it will help you using ajax in django. For example, for sending serialized objects to the browser and use it as you want in JS. Thanks 2009/6/2 Aldo> > Hey, > > I have some ajax running on my pages. > > I want to have it pass back some objects. However, I am unsure if I > can pass a list of objects back. So far I have only ever passed back > raw xml or text. Can objects be passed and then iterated via the html > template? > > Thanks > > > -- neo2001[at]gmail.com jorge[at]thecodefarm.com neo[at]art-xtreme.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django with ajax
Hey, I have some ajax running on my pages. I want to have it pass back some objects. However, I am unsure if I can pass a list of objects back. So far I have only ever passed back raw xml or text. Can objects be passed and then iterated via the html template? 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: extending django-registration ( MixIn ModelForm and Form)
yes the problem using this method is that DRY principle is broken, because you redefine the fields that are already defined I was thinking of MixIn the 2 Forms to keep the whole thing reusable but nevermind, if this is the only way, I'll do it like this. thanks On Tue, Jun 2, 2009 at 05:57, Rishabh Manochawrote: > On Tue, Jun 2, 2009 at 9:10 AM, Marco Bazzani > wrote: >> >> On Mon, Jun 1, 2009 at 23:19, V wrote: >> > >> > On Jun 1, 6:50 pm, Marco Bazzani wrote: >> >> I'm trying to extends django-registration app with some more fields in >> >> the moment of registration >> >> those fields are saved in a subclass of User >> >> >> >> for reference here are the form >> >> classes:http://bitbucket.org/ubernostrum/django-registration/src/tip/registra... >> >> >> >> ok here is my code >> >> >> >> #models.py >> >> class Customer(User): >> >> company = >> >> models.CharField(_('Company'),max_length=200,blank=True) >> >> address = models.CharField(_('Address'),max_length=255) >> >> state_province = >> >> models.CharField(_('State/Province'),max_length=200) >> >> country = >> >> models.CharField(_('Country'),max_length=3,choices=COUNTRY_CHOICES) >> >> phone_number = models.CharField(_('Phone Number'), max_length=20) >> >> fax_number = models.CharField(_('Fax Number'), >> >> max_length=20,blank=True) >> >> other_contacts = models.TextField(_('Other Contacts'),blank=True) >> >> >> >> objects = UserManager() >> >> >> >> #forms.py >> >> from registration.forms import RegistrationForm >> >> from django import forms >> >> from customers.models import Customer >> >> from classmaker import classmaker >> >> >> >> class ProfileForm(forms.ModelForm): >> >> class Meta: >> >> model = Customer >> >> fields = ( >> >> 'state_province', >> >> 'country', >> >> 'phone_number', >> >> 'fax_number', >> >> 'other_contacts', >> >> ) >> >> >> >> class RegistrationFormProfile(RegistrationForm, ProfileForm): >> >> __metaclass__ = classmaker() >> >> >> >> the classmaker was necessary to solve the metaclass conflict problem >> >> as described herehttp://www.djangosnippets.org/snippets/703/ >> >> >> >> anyway everythings seams to be ok a part from the fact that only >> >> ProfileForm is displayed in the template >> >> even if I switch the order of the inheritance. >> >> >> >> I've also modified some django registration to use my Model instead of >> >> User ( but shouldn't be the origin of the problem) >> >> >> >> any clue ? >> >> >> >> cheers >> >> Marco >> > >> > I don't have any clues on your problem, except that I can't really >> > understand why do you extend the User model as you do, instead of >> > adding a profile model that has a OneToOneField to User >> > >> > this way you don't have to edit django-registration, and you can have >> > a fairly simple save method in your profile where you first create the >> > User, and then attach a profile to it. I would go this way. >> > >> > V >> > > >> > >> >> how do you collect additional user data during registration with your >> method ? >> >> > > You can define your own form class (which can inherit from one of the > existing form classes defined in the App) and define custom actions in it's > save method. See [1] for an example of a form I am using. You can then pass > the "register" view your own form using the "form_class" parameter as > explained in [2]. > > -- > > Best, > > R > > [1] - http://dpaste.com/50347/ > [2] - > http://bitbucket.org/ubernostrum/django-registration/src/tip/docs/views.txt > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Internationalization and Apache
So that is what I have in os.environ with Apache : LANG = en TZ = France/Paris DJANGO_SETTINGS_MODULE = setting.production SHLVL = 1 APACHE_RUN_USER = www-data APACHE_PID_FILE = /var/run/apache2.pid PWD = /home/git/pyki/public APACHE_RUN_GROUP = www-data TMPDIR = /tmp/passenger.31221/var HOME = /var/www PATH = /usr/local/bin:/usr/bin:/bin _ = /usr/sbin/apache2 And with the development server : LANG = en_GB TERM = xterm SHELL = /bin/bash TZ = France/Paris RUN_MAIN = true SHLVL = 1 SSH_TTY = /dev/pts/0 OLDPWD = /home/git/pyki/content PWD = /home/git/pyki SSH_CLIENT = 193.251.16.192 2616 22 DJANGO_SETTINGS_MODULE = pyki.settings USER = dmathieu PATH = /usr/local/bin:/usr/bin:/bin:/usr/games MAIL = /var/mail/dmathieu LOGNAME = dmathieu SSH_CONNECTION = 193.251.16.192 2616 213.251.184.40 22 HOME = /home/ _ = /usr/bin/python On Jun 1, 10:58 pm, Damien MATHIEU <4...@dmathieu.com> wrote: > Thank you Karen for being more precise and writing something > understandable. > > On Jun 1, 5:15 pm, Karen Traceywrote: > > > On Mon, Jun 1, 2009 at 8:39 AM, Damien MATHIEU <4...@dmathieu.com> wrote: > > > > Based on the advices of a friend, I've tried with mod_wsgi instead of > > > mod_python. > > > However, it still doesn't work. > > > > And the sys.path is similar to the one I have when I do a manage.py > > > runserver (where I correctly have my language strings). > > > > So it's not a path problem. > > > You've included Graham's response below but you have apparently not acted on > > any of its advice. Graham doesn't mention a path problem, nor does he > > suggest that switching to mod_wsgi would fix the issue: he mentions an > > environment problem, specifically related to the locale environment > > variables. Perhaps if you follow Graham's advice below about writing a view > > that displays os.environ variables and compare the values between > > development server and Apache you will make more progress. > > > Karen > > > > On May 29, 1:51 am, Graham Dumpleton > > > wrote: > > > > On May 28, 11:56 pm, Damien MATHIEU <4...@dmathieu.com> wrote: > > > > > > Hi, > > > > > > Using the internal web server, I correctly load every language string > > > > > located in application_path/locale/language/LC_MESSAGES/django.mo > > > > > But whenever I use Apache, they don't appear to be loaded anymore. > > > > > > However it appear the default ones are loaded. > > > > > The languages names are appropriately translated (French to Français > > > > > for example). > > > > > > I have the following virtual host : > > > > > > > > > > DocumentRoot /home/git/refdoc > > > > > ServerName doc.tmp.dev.refstats.net > > > > > ServerAlias doc.tmp.dev.refstats.net > > > > > SetEnv DJANGO_SETTINGS_MODULE setting.production > > > > > > > > > > > SetHandler python-program > > > > > PythonHandler django.core.handlers.modpython > > > > > PythonPath "['/home/git/refdoc'] + sys.path > > > > > PythonDebug On > > > > > > > > > > > > > > > > And I use localeurl :http://code.google.com/p/django-localeurl/ > > > > > > Thanks by advance for any help you'll hopefully provide me. > > > > > The development server is likely working because it is picking up > > > > locale and language environment variables from your personal account. > > > > When running Apache, which starts up as root before changing to non > > > > privileged user, it will not be getting those environment variables > > > > from your personal account. As such, it will use whatever is the > > > > system default. > > > > > Often it is not enough to just set the variables from inside Apache or > > > > your code and you need to ensure they are set in the environment of > > > > Apache when it runs. How this is done depends a bit on whether you are > > > > using Apache compiled from source or some specific operating systems > > > > distribution. > > > > > I would start by writing a test URL which dumps out os.environ in each > > > > way of running it, then compare settings for LC_* and LANG environment > > > > variables. > > > > > Graham > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: user.is_authenticated
Wiadomość napisana w dniu 2009-06-01, o godz. 18:50, przez Tim Sawyer: > > You need a RequestContext for the user object to be available in > templates > > http://lincolnloop.com/blog/2008/may/10/getting-requestcontext-your-templates/ > > I use a render_auth method instead of render_to_response, which > automatically > adds the RequestContext to all of my templates. > > Tim. > > On Monday 01 June 2009 17:40:53 K.Berkhout wrote: >> Hi, >> >> Is there a way I can access the "user.is_authenticated" method in >> every view, without having to manually pass the User model to every >> template? Basicly I want to show a login or logout link on every >> page, >> depending on wether the visitor is logged in or not. I've included >> the >> following if statement in my base template: >> >> {% if user.is_authenticated %} >> Welcome {{ user }} , showing logout link... >> {% else %} >> Showing login link... >> {% endif %} >> >> However, it only works with the standard "accounts/login" view, as >> that view has acces to the user.is_authenticated method. >> For completeness sake: RequestContext *and* django.core.context_processors.auth in TEMPLATE_CONTEXT_PROCESSORS (it's there by default unless one changes configuration). -- Artificial intelligence stands no chance against natural stupidity Jarek Zgoda, R, Redefine jarek.zg...@redefine.pl --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: filtering the join table in a many-to-many relationship
Sam, Thanks for the rapid response. I think I see what you mean, but I'm not sure it solves my problem. Looking at the example you sent, here's how my problem would look in that context: - Friendship has an extra column called "degree_of_friendship", which can be "meh", "good", or "great" - I want to find all of Bob's "great" friends. I can get Bob's great friendSHIPS by doing this: Friendship.objects.filter(first = bob, degree_of_friendship = "great") or I could get all of Bob's friends: bob.friends.all() but how do I get the Friend objects that are "great", but not others? In other words, how do I impose a constraint on the Friendship join- table when I do bob.friends? -Ben On Jun 1, 7:59 pm, Sam Chuparkoffwrote: > On Mon, 2009-06-01 at 16:01 -0700, Ben Adida wrote: > > I have a ManyToMany self relationship with a custom join table (I > > don't think the self-reference is important to the problem, but it > > might be, so I'm mentioning it): > > > class Documents > > related_docs = models.ManyToManyField("self", > > through='DocumentRels') > > > DocumentRels is a table that maps one document to another, with a > > relationship type. > > > If I want all documents related to doc_0, I can just do: > > > doc_0.related_docs > > > But what if I want all documents related to doc_0 where I specify an > > extra constraint on the join table, e.g. a value for > > DocumentRels.relationship? Is there a way to do that without custom > > SQL? > > You will not need custom sql, because DocumentRels is going to be a > Model. When you want to filter based on DocumentRels.relationship, you > will either use: > > DocumentRels.objects.filter() > > or go through the RelatedManagers that are added to your Document > model for the ForeignKeys in DocumentRels. The reference is here: > > http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > For code that exactly fits your case, see PersonSelfRefM2M in: > > http://code.djangoproject.com/browser/django/trunk/tests/modeltests/m... > > sdc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---