Re: Cannot resolve keyword into field
On Apr 22, 3:13 am, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I using a script to fetch some database records. However, when it > encounters a ManyToManyField it gives the following error- > > TypeError: Cannot resolve keyword 'book' into field > > My models.py looks like this- > > from django.db import models > > # Create your models here. > class Author(models.Model): > name = models.CharField(maxlength=100) > > class Book(models.Model): > title = models.CharField(maxlength=100) > authors = models.ManyToManyField(Author) > > and my test script to retrieve records contains (the app name is > test)- > > import os > if not os.environ.has_key('DJANGO_SETTINGS_MODULE'): > os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' > > import settings > from test.models import * > > b = Book.objects.get(id=1) > for a in b.authors.all(): print a > > I am using django with sqlite2 on Fedora Core 6 with python-2.4.3 and > have tried version 0.95, 0.96 and svn trunk. All throw the same error- > TypeError: Cannot resolve keyword 'book' into field > When I try the same through "python manage.py shell" interactive > shell, i.e. by entering the two lines above, it works fine. Probably, > I'm missing some setting option. But the same script works for models > that don't contain an M2M field, so that seems unlikely. > > Any clues? Sorry, a typo in my earlier post. Its sqlite3 not sqlite2. Ram --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Another take on auto-history
Looks like the download link is broken. On Apr 21, 4:24 am, Oliver Charles <[EMAIL PROTECTED]> wrote: > Morning all > > I've been meaning to post this to the list for a while, and I think my > code is now ready to be shown. I've been working on a small bug tracker > type project for myself - as I have 3 Django projects on the go at the > moment. Anyway, I wanted a way to track changes made to bugs/tickets so > I made this automatic history decorator. It works by logging revisions > of fields on a model, so you can specific which fields should have a > history, etc. > > I haven't included rollback support yet, but if people are interested, I > will happily look into offering it (shouldn't be hard!) Without furthor > ado, here is the website, with a mini example application too: > > http://acid2.user.openhosting.com/history/ > > The way that my auto history module works is through decorating the > save() method of a model. Everytime you save a model, it looks up the > model in the database first. Then, each field is compared and log > entries are made. You can then retrieve a list of these changes through > the models provided (see the example in the zip). > > This was mainly an experiment to learn introspection and metaprogramming > type stuff in Python, but if anyone has any ideas on what could improve > this, I'd love to hear them. > > Thanks, hope someone finds it useful! > > -- > Oliver Charles --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: [database-api] Using .select_related() with a multi-table query (bug?)
On Wed, 2007-04-18 at 19:57 -0300, Luiz Carlos Geron wrote: > Hi, > I have three models, listed at [1], that I want to get data from with > only one query, because of performance issues with my app. The way > that worked so far is: > > league_ids = [12, 21] > bets = > models.Bet.objects.filter(game__league__id__in=league_ids).order_by('bet__game__league.id', > 'game_part', 'bet__game.venuedate') > > The problem with this is that for each bet I iterate, the database > will be hit one or more times because I need to use > bet.game.league.name and so on. So I tried adding .select_related() to > the query and now it returns no results, while without > select_related() I get 172 results. So that looks like a bug somewhere. Using select_related() is intended to have no effect whatsoever on the contents of the result set, from the point of view of using the results. If you could reduce this to a simple test case (how many relations can you remove before it stops giving different results?), it would be good if you could file a ticket, including the models that cause the problem, and we could examine it in detail. > Looking at the sql generated by > the query with and without select_related() I noticed that with it, > the sql was very strange, when the orm could have just added fields > from the other tables to the select list. Not quite sure what you mean here. What "other tables"? Without seeing your models, it looks like all the relevant columns are being selected in the second query. Are some of your relations nullable? If so, that might explain the difference in the SQL results -- there should be some left outer joins in there for those cases, rather than all inner joins. > Please look at the original > generated sql at [2] and the one with select_related() at [3]. This > looks like a bug to me, at least on the documentation, if I am not > supposed to use select_related() with queries like this. > > BTW, is there are any better way to do what I want (get columns from > the three models in only one query) with the django orm? I tried to > use .values() in the query but it turns out that I cannot specify > columns from other tables in it. For now I'll be using the sqlalchemy > model I already have for this database, but I'd really appreciate to > do everything with the django parts, since they seem to fit very good > together and this is the first really bad problem I found while > developing with django. If you want to select basically arbitrary columns from arbitrary tables, you will need to write a method containing custom SQL. That's not too hard to do and is the recommended way. The difficulty with trying to do this automatically in the Django ORM without resorting to SQL is that there's no natural way to map the results back to models: they aren't related to a model's columns any longer, after all. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to connect Django to objects served over xml-rpc?
Hi Brandon, On Fri, Apr 20, 2007 at 01:58:48PM -0400, [EMAIL PROTECTED] wrote: > I want to try out Django for a small project, hoping to discover that > it will be the web framework of my dreams, but I need some advice. > > My project group has written an xml-rpc API in front of our database > and password stores. This means that when we want to, say, create a > campus guest account, we call xml-rpc functions like create_guest(), > set_guest_info(), and set_account_password(), and those functions do > all of the database operations (and sometimes operations on other > systems) needed to perform each operation consistently (creating a > guest requires at least six tables to be updated, for example). I think you'll find that Django meets your needs quite well, however, I wouldn't recommend at all that you try to make Django's database layer wrap your XML-RPC services. Django's database layer is an ORM, so, unless your XML-RPC services constitute a thin wrapper around your database, or provide a very database-like interface, it probably doesn't meet your requirements at a basic, conceptual model. One thing you could do is provide a set of read-only thin wrappers to your database that can live alongside your current XML-RPC implementation. Then, you could use Django's ORM as an interface to that, and be able to take advantage of things like generic views and the automatic admin interface. Since the interface would be read-only, you'd have to make direct XML-RPC calls to actually make changes to the database, but it sounds like your XML-RPC functions probably provide some enforcement of data integrity, so that's probably not very avoidable. Of course, ultimately, you are getting into a new framework with significant work to do before you can even get your first app put togther (since you'll need to implement a custom database layer). That may not be the best way to introduce yourself to Django :) If your clever, you may be able to implement a read-only DB layer with only a little code, but get some advice from some Django experts first (I am not included in that group). -Forest signature.asc Description: Digital signature
Re: Error - 'int' object is unsubscriptable
Jay, Thanks for all your help. I found this ticket (http:// code.djangoproject.com/ticket/3708) and switched from python 2.5 back to 2.4 and now everythings working fine. Since it's a known issue, I'll just leave it alone and continue on with 2.4. As for the indents, I think it's just the formating here, everythings at 4 in scribes. Thanks again, mateo On Apr 21, 4:09 pm, "Jay Parlar" <[EMAIL PROTECTED]> wrote: > On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > > > > > I've found that if I add the 'admin' subclass to the 'choices' class > > and remove 'edit_inline=models.TABULAR, num_in_admin=3' from > > the Foreign Key I can save new entries just fine. The error only pops > > up when I have the 'choices' edited inline with the 'polls'. > > Well that's certainly less than desirable. If you have the time (and > know-how with Python), maybe download the 0.96 release, and try with > that, just to make sure that something didn't get screwed up recently > in SVN. I'd try myself, but I've run out of time for the evening. > > Also, in the code you posted, the indents seem to be quite strange. > Maybe it's just the way Gmail formats it, but it looks like you're > using indent levels of 5 and 3 in different places. Try to stay > consistent and just use 4. > > Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: reverse relationships with ForeignKey?
Thats' because by default Django will name the field "model_set" on the reverse relationship. So if you want to access it that way, you should do entry.updates_set.all(). A nicer, more readable way, is to set related_name on the ForeignKey. E.g: entry = models.ForeignKey(Entry, related_name="updates") (This is a field in your Updates model) Hope this helps! -- Ollie > I have an app that I'm building and I've run into a problem. I have 2 > models "Entries" and "Updates" which points to "Entries" with a > ForeignKey. The idea is that an entry can be updated at multiple times > and I track the date and other meta information of the update within > the update model. > > When I try and create the detail template I can't seem to find a way > to list the updates for an entry. Here is the code I am trying to use: > > {% for update in entry.updates.all %} > {{update.body}} > {% endfor %} > > sadly this has no effect.. Any help would be much appriciated :) > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > > I've found that if I add the 'admin' subclass to the 'choices' class > and remove 'edit_inline=models.TABULAR, num_in_admin=3' from > the Foreign Key I can save new entries just fine. The error only pops > up when I have the 'choices' edited inline with the 'polls'. > Well that's certainly less than desirable. If you have the time (and know-how with Python), maybe download the 0.96 release, and try with that, just to make sure that something didn't get screwed up recently in SVN. I'd try myself, but I've run out of time for the evening. Also, in the code you posted, the indents seem to be quite strange. Maybe it's just the way Gmail formats it, but it looks like you're using indent levels of 5 and 3 in different places. Try to stay consistent and just use 4. Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
reverse relationships with ForeignKey?
I have an app that I'm building and I've run into a problem. I have 2 models "Entries" and "Updates" which points to "Entries" with a ForeignKey. The idea is that an entry can be updated at multiple times and I track the date and other meta information of the update within the update model. When I try and create the detail template I can't seem to find a way to list the updates for an entry. Here is the code I am trying to use: {% for update in entry.updates.all %} {{update.body}} {% endfor %} sadly this has no effect.. Any help would be much appriciated :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
I've found that if I add the 'admin' subclass to the 'choices' class and remove 'edit_inline=models.TABULAR, num_in_admin=3' from the Foreign Key I can save new entries just fine. The error only pops up when I have the 'choices' edited inline with the 'polls'. On Apr 21, 3:02 pm, mateo <[EMAIL PROTECTED]> wrote: > I've been following the code step by step and checking along the way, > but I didn't try to save anything up until the end of that section. > The admin console itself works fine, it isn't until I hit 'save' (or > one of it's variations) that I get the error. I will rollback the > models.py tutorial code a bit and see if I get the same error. > > On Apr 21, 2:46 pm, "Jay Parlar" <[EMAIL PROTECTED]> wrote: > > > On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > > > > I am on part 2, 'Custominze the Admin Change List'. (http:// > > >www.djangoproject.com/documentation/tutorial02/#customize-the-admin-c...) > > > Sorry, I meant, what stage exactly did it break? ie., did you go > > through tutorial 2 step by step, checking that the Admin looks like it > > does in the tutorial, after each change, or did you just put in all > > the code and try it? It'd be helpful to know what the last part was > > that still worked, and what change caused it to break. > > > Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Cannot resolve keyword into field
Hi, I using a script to fetch some database records. However, when it encounters a ManyToManyField it gives the following error- TypeError: Cannot resolve keyword 'book' into field My models.py looks like this- from django.db import models # Create your models here. class Author(models.Model): name = models.CharField(maxlength=100) class Book(models.Model): title = models.CharField(maxlength=100) authors = models.ManyToManyField(Author) and my test script to retrieve records contains (the app name is test)- import os if not os.environ.has_key('DJANGO_SETTINGS_MODULE'): os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import settings from test.models import * b = Book.objects.get(id=1) for a in b.authors.all(): print a I am using django with sqlite2 on Fedora Core 6 with python-2.4.3 and have tried version 0.95, 0.96 and svn trunk. All throw the same error- TypeError: Cannot resolve keyword 'book' into field When I try the same through "python manage.py shell" interactive shell, i.e. by entering the two lines above, it works fine. Probably, I'm missing some setting option. But the same script works for models that don't contain an M2M field, so that seems unlikely. Any clues? Thanks, Ram --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
I've been following the code step by step and checking along the way, but I didn't try to save anything up until the end of that section. The admin console itself works fine, it isn't until I hit 'save' (or one of it's variations) that I get the error. I will rollback the models.py tutorial code a bit and see if I get the same error. On Apr 21, 2:46 pm, "Jay Parlar" <[EMAIL PROTECTED]> wrote: > On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > > > I am on part 2, 'Custominze the Admin Change List'. (http:// > >www.djangoproject.com/documentation/tutorial02/#customize-the-admin-c...) > > Sorry, I meant, what stage exactly did it break? ie., did you go > through tutorial 2 step by step, checking that the Admin looks like it > does in the tutorial, after each change, or did you just put in all > the code and try it? It'd be helpful to know what the last part was > that still worked, and what change caused it to break. > > Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > I am on part 2, 'Custominze the Admin Change List'. (http:// > www.djangoproject.com/documentation/tutorial02/#customize-the-admin-change-list) Sorry, I meant, what stage exactly did it break? ie., did you go through tutorial 2 step by step, checking that the Admin looks like it does in the tutorial, after each change, or did you just put in all the code and try it? It'd be helpful to know what the last part was that still worked, and what change caused it to break. Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
> What stage of the tutorial, exactly, did this error occur at? Could > you also please copy and paste the contents of your models.py file > with your response? > > Jay P. I am on part 2, 'Custominze the Admin Change List'. (http:// www.djangoproject.com/documentation/tutorial02/#customize-the-admin-change-list) Here is my copy of models. thanks, mateo from django.db import models import datetime class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() was_published_today.short_description = 'Published today?' class Admin: list_display = ('question', 'pub_date', 'was_published_today') list_filter = ['pub_date'] search_fields = ['question'] date_hierarchy = 'pub_date' fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}), ) class Choice(models.Model): poll = models.ForeignKey(Poll, edit_inline=models.TABULAR, num_in_admin=3) choice = models.CharField(maxlength=200, core=True) votes = models.IntegerField(core=True) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
SQL Debug middleware
Hey all, I made this the other day to help me track all the sql statements my pages were doing. I wanted something unobtrusive (i.e. middleware) and simple. Hope you like: from django.db import connection import re, pprint body_end = re.compile('', re.IGNORECASE) class DebugMiddleware(object): def process_response(self, request, response): if body_end.search(response.content) is not None: db_info = pprint.pformat(connection.queries) total = 0.0 for con in connection.queries: total += float(con['time']) response.content = body_end.sub('%s\nTotal: %f' % (db_info,total), response.content) return response --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
newforms.BooleanField needs a required=False?
Hi, I'm making my first 0.96 application, a Faroe Islands tax calculator (it's at gladsheinur.webfactional.com/skattur/, check it out, it's a work in progress). I'm trying to use a BooleanField, but GET requests send nothing back to the server if the checkbox is unchecked. That makes the form return a "This field is required', although it IS being used (it's only set to 'off'). To make things work, I have to hack around using class MyForm(forms.Form): bool = forms.BooleanField(label="boolean", required=False) which isn't good. Anyone else have this problem with newforms? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
It is actually more than photosharing
I d like to show you http://www.morecute.com It has been awesome runs on Fedora I wanted to share it early on so there is litte load on the server and the early adopter crowd can try it out thanks Jerry It is actually more than photosharing http://morecute.com/vote/400562/1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
A simple photosharing application written in django
I d like to show you http://www.morecute.com It has been awesome runs on Fedora I wanted to share it early on so there is litte load on the server and the early adopter crowd can try it out thanks Jerry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Error - 'int' object is unsubscriptable
On 4/21/07, mateo <[EMAIL PROTECTED]> wrote: > > List, > > When following the tutorial I get the below error when attempting a > save from the admin console. I'm new to Django and certainly not a > guru of any sort so I thought I would ask about it here first before > posting a bug report. I am using the latest SVN release as of 4/21. > Any ideas what might be going on? > > Traceback (most recent call last): > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" > in get_response > 77. response = callback(request, *callback_args, **callback_kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/views/ > decorators.py" in _checklogin > 55. return view_func(request, *args, **kwargs) > File "/usr/lib/python2.5/site-packages/django/views/decorators/ > cache.py" in _wrapped_view_func > 39. response = view_func(request, *args, **kwargs) > File "/usr/lib/python2.5/site-packages/django/contrib/admin/views/ > main.py" in change_stage > 329. new_object = manipulator.save(new_data) > File "/usr/lib/python2.5/site-packages/django/db/models/ > manipulators.py" in save > 191. param = f.get_manipulator_new_data(rel_new_data, rel=True) > File "/usr/lib/python2.5/site-packages/django/db/models/fields/ > __init__.py" in get_manipulator_new_data > 289. return new_data.get(self.name, [self.get_default()])[0] > > TypeError at /admin/polls/poll/1/ > 'int' object is unsubscriptable > > What stage of the tutorial, exactly, did this error occur at? Could you also please copy and paste the contents of your models.py file with your response? Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Error - 'int' object is unsubscriptable
List, When following the tutorial I get the below error when attempting a save from the admin console. I'm new to Django and certainly not a guru of any sort so I thought I would ask about it here first before posting a bug report. I am using the latest SVN release as of 4/21. Any ideas what might be going on? Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response 77. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/views/ decorators.py" in _checklogin 55. return view_func(request, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/views/decorators/ cache.py" in _wrapped_view_func 39. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/views/ main.py" in change_stage 329. new_object = manipulator.save(new_data) File "/usr/lib/python2.5/site-packages/django/db/models/ manipulators.py" in save 191. param = f.get_manipulator_new_data(rel_new_data, rel=True) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ __init__.py" in get_manipulator_new_data 289. return new_data.get(self.name, [self.get_default()])[0] TypeError at /admin/polls/poll/1/ 'int' object is unsubscriptable --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: [database-api] Using .select_related() with a multi-table query (bug?)
Any ideas on how I can do this with one query? On 4/18/07, Luiz Carlos Geron <[EMAIL PROTECTED]> wrote: > Hi, > I have three models, listed at [1], that I want to get data from with > only one query, because of performance issues with my app. The way > that worked so far is: > > league_ids = [12, 21] > bets = > models.Bet.objects.filter(game__league__id__in=league_ids).order_by('bet__game__league.id', > 'game_part', 'bet__game.venuedate') > > The problem with this is that for each bet I iterate, the database > will be hit one or more times because I need to use > bet.game.league.name and so on. So I tried adding .select_related() to > the query and now it returns no results, while without > select_related() I get 172 results. Looking at the sql generated by > the query with and without select_related() I noticed that with it, > the sql was very strange, when the orm could have just added fields > from the other tables to the select list. Please look at the original > generated sql at [2] and the one with select_related() at [3]. This > looks like a bug to me, at least on the documentation, if I am not > supposed to use select_related() with queries like this. > > BTW, is there are any better way to do what I want (get columns from > the three models in only one query) with the django orm? I tried to > use .values() in the query but it turns out that I cannot specify > columns from other tables in it. For now I'll be using the sqlalchemy > model I already have for this database, but I'd really appreciate to > do everything with the django parts, since they seem to fit very good > together and this is the first really bad problem I found while > developing with django. > > > [1] http://dpaste.com/8743/ > [2] http://dpaste.com/8581/ > [3] http://dpaste.com/8582/ > > -- > []'s, > Luiz Carlos Geron > -- []'s, Luiz Carlos Geron --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Subclasses or OneToOne relationship
OK thanks very much for the reply Malcolm. On Apr 21, 3:47 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Fri, 2007-04-20 at 20:00 +, Jamie Pittock wrote: > > Hi all, > > > I'm currently planning my first Django application and after a quick > > search of groups I need a model structure very similar to that mention > > in this thread: > > >http://groups.google.com/group/django-users/browse_thread/thread/4835... > > > Basically I need models for Restaurant, Bar, Hotel etc but it would be > > useful to have a parent model Place that could contain the fields > > general to all the models, plus it would be useful so that a > > restuarant and bar wouldn't have the same ID, or at least they'd have > > a unique Place ID. > > > Has Model Inheritance moved on at all since that previous thread? > > Not yet. > > > Is > > a OnetoOneField the best option, > > Yes. > > > or ,given that (after another quick > > search) it seems Model Inheritance may well be back in the not too > > distant future, > > Correct. > > > is there another option that would make an easy > > transition once it is supported? > > Use one-to-one now and change it to MI later. The changes won't be that > significant. A few quick search-and-replace operations in your templates > and views should do it. > > Cheers, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: audit trail support
> I will be working on this project as part of my Real Job(tm), > so devoting time to it should not be a problem. However, > before I begin coding, I want the community's input on a few > issues. > > What is the right way, at DB level, to implement the audit > trail? I had two ideas: Todd Schraml authored a good article in Dr. Dobb's Journal (http://www.ddj.com/dept/database/184406340) titled _Table Patterns & Changing Data_ where he discusses five patterns for keeping historical data, and the requirements that would lead to choosing one pattern over another. While it's written in the context of SarbOx, auditing can be needed even where SarbOx isn't a concern. While I know I had thought of each of these patterns independently, I hadn't gathered such patterns into one place at the same time to weigh benefits vs. costs. I don't know the answer to your "What is the right way, at the DB level, to implement the audit trail" question, but my thought would be it depends on the scenario. I don't know if seeing the various common ways of keeping an audit trail would help guide design decisions, but ya'll may find the link helpful. -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Another take on auto-history
Morning all I've been meaning to post this to the list for a while, and I think my code is now ready to be shown. I've been working on a small bug tracker type project for myself - as I have 3 Django projects on the go at the moment. Anyway, I wanted a way to track changes made to bugs/tickets so I made this automatic history decorator. It works by logging revisions of fields on a model, so you can specific which fields should have a history, etc. I haven't included rollback support yet, but if people are interested, I will happily look into offering it (shouldn't be hard!) Without furthor ado, here is the website, with a mini example application too: http://acid2.user.openhosting.com/history/ The way that my auto history module works is through decorating the save() method of a model. Everytime you save a model, it looks up the model in the database first. Then, each field is compared and log entries are made. You can then retrieve a list of these changes through the models provided (see the example in the zip). This was mainly an experiment to learn introspection and metaprogramming type stuff in Python, but if anyone has any ideas on what could improve this, I'd love to hear them. Thanks, hope someone finds it useful! -- Oliver Charles --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: error separating apps from projects
that's a nice idea thanks Michael On 4/21/07, Michael Trier <[EMAIL PROTECTED]> wrote: > > > I recently did something similar but what I ended up doing was > creating a symbolic link to a path that was already in my sys.path > location. For me since I have site-packages/django I just created a > site-packages/djangoapps subdirectory and then reference each > application with djangoapps.registration for instance. > > Michael > > On 4/20/07, tejas <[EMAIL PROTECTED]> wrote: > > > > Gah! > > > > I'm so sorry > > > > I forgot to change one of the urls when moving the app out of my > > project directory > > > > on a related note - I'm using ubuntu and I tried setting the > > PYTHONPATH variable to my APPS directory, but then django could not > > see the apps (so I used the python import statement). Am I trying to > > set the right variable? > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Accessing named URL patterns from views
On Sat, 2007-04-21 at 01:47 -0700, Michael wrote: > I'm not sure if this is obvious, but the documentation at: > > http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns > > doesn't mention how you can use your named URL patters to redirect > from one view to another. It only shows how you can get the url for a > view from within a template. > > Anyways, turns out to be pretty simple (found it in the source > django_src/django/template/defaulttags.py): > > from django.core.urlresolvers import reverse > return HttpResponseRedirect( reverse( 'your-url-name' ) ) > > Have I missed something and this was documented else where? Otherwise > I'll raise a ticket to update the above documentation for named url > patterns... We haven't documented reverse() anywhere, as far as I know. So worth filing a ticket. Thanks, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Accessing named URL patterns from views
I'm not sure if this is obvious, but the documentation at: http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns doesn't mention how you can use your named URL patters to redirect from one view to another. It only shows how you can get the url for a view from within a template. Anyways, turns out to be pretty simple (found it in the source django_src/django/template/defaulttags.py): from django.core.urlresolvers import reverse return HttpResponseRedirect( reverse( 'your-url-name' ) ) Have I missed something and this was documented else where? Otherwise I'll raise a ticket to update the above documentation for named url patterns... Cheers, Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Earn $1 for every person that joins your downline!
All you have to do is sign up and then get others to sign up under you, $1 for every single person. http://genbucks.com/?jassey --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to connect Django to objects served over xml-rpc?
Hey, seeing as you haven't had any relies yet, I will through my idea down. What I think you're gonna have to do for the most graceful version is to create your own database wrapper, that calls xml-rpc, instead of an actual database. Then Django *should* be free to use. The problem may occur that Django really does expect to see database like data, so you may have to reformat your data. My only other idea is to extend the model base class, and replacement the save function, etc. This will get messy though, because QuerySet's also use the db api, so it would require rewriting them too. I think that option 1 is your best bet, and looking at the SQLite wrapper should make stuff easier. Hope this helps -- Ollie > I want to try out Django for a small project, hoping to discover that > it will be the web framework of my dreams, but I need some advice. > > My project group has written an xml-rpc API in front of our database > and password stores. This means that when we want to, say, create a > campus guest account, we call xml-rpc functions like create_guest(), > set_guest_info(), and set_account_password(), and those functions do > all of the database operations (and sometimes operations on other > systems) needed to perform each operation consistently (creating a > guest requires at least six tables to be updated, for example). > > This is great in two ways. First, our business logic is all in one > place, where complex operations get written once, correctly. Second, > we wrote it in simple, plain Python that we could all agree upon, so > that now each front-end and client can be written in the favorite > language and framework of the group deploying it (so long as it talks > xml-rpc), avoiding the need for a religious war and everyone being > forced to use One True Platform. > > The problem is that Django seems to really, really want to talk to the > database by itself. :-) > > At what level, then, would I subvert Django if, say, a Guest were not > a row in a database table, but an entity that I get information about > from an xml-rpc call, and for which some other xml-rpc calls let me > set information? Thanks for any guidance! > > I'll be happy to write up my solution for the Django documentation > page, which already discusses connecting to a legacy database - but > not a ... what would one call it? A "legacy non-database." > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Ready For dating
Send free email to dating members http://www.datingseasons.com Find your dream partner online free http://www.datingseasons.com Search and make your online partners http://www.datingseasons.com Find more details about your dream partner http://www.datingseasons.com Search your soulmate http://www.datingseasons.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: selecting a framework ,
I have build a simple billing module for an ad agency which is functional using Django. It is very easy to use it Ramdas On 4/20/07, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > > > On 20-Apr-07, at 8:53 AM, Jeremy Dunck wrote: > > >> > >> check out satchmo - it is an erp with django > > > > If you mean this satchmo: > > http://www.satchmoproject.com/ > > then I think we're not agreeing on what ERP is: > > http://en.wikipedia.org/wiki/Enterprise_resource_planning > > :) > > i stand corrected - but i'm fairly sure it started out as an erp thing > > -- > > regards > kg > http://lawgon.livejournal.com > http://nrcfosshelpline.in/web/ > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---