Ignoring fields in deserialization
Hello, I had some copies of a model with 10 fields serialized in a file. I deleted some of the fields (since I don't need them anymore) now I can't deserialize the model. error: raise FieldDoesNotExist, '%s has no field named %r' % (self.object_name, name) Any help, please. Luis -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Accessing foreign key related item
I have this structure: class Album(models.Model): caption = models.CharField(max_length=500) def get_album_type(self): if self.a_set.count() > 0: return 'a' if self.b_set.count() > 0: return 'b' def _get_a(self): return self.a_set.all()[0] def _get_b(self): return self.b_set.all()[0] a = property(_get_a) b = property(_get_b) class A(models.Model): album = models.ForeignKey('album.Album', null=True) class B(models.Model): album = models.ForeignKey('album.Album', null=True) I need to know what is the type of the album and access the related object, currently using the solution above. In a template with many albums I'm running a lot of queries, is there a better way of doing this (a least for the get_album_type function)? regards -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Model inheritance - filtering base model only
I guess this solution works but for +50 the performance should be terrible... Shouldn't django have some option for this? On 23 Nov, 04:53, Preston Holmes <pres...@ptone.com> wrote: > Perhaps there is a more efficient way, but in my quick test, one can't > filter() a queryset based on __class__ of the model, but seems one can > manually filter it afterwords: > > qs = Player.objects.all() > for i,obj in enumerate(qs): > if obj.__class__ != Player: > del(qs[i]) > > On Nov 22, 4:32 pm, lfrodrigues <lfrodrig...@gmail.com> wrote: > > > Hello, > > > I have these models: > > > class Player(models.Model): > > . > > > class PlayerM(Player): > > ... > > > If I do PlayerM.objects.all() e get all PlayerM objects and for > > Player.objects.all() I get all Player and PlayerM as expected. > > > How can get only the objects of type Player (only retrieve the objects > > that were created with Player() constructor)? > > > Regards, > > > Luis -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Model inheritance - filtering base model only
Hello, I have these models: class Player(models.Model): . class PlayerM(Player): ... If I do PlayerM.objects.all() e get all PlayerM objects and for Player.objects.all() I get all Player and PlayerM as expected. How can get only the objects of type Player (only retrieve the objects that were created with Player() constructor)? Regards, Luis -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Object Edition Moderation
Hello, I've been using admin to create/change some objects in my company. Now I have a new set of users that will be able to change objects but a moderator needs to approve the changes. Do you have any suggestion on how to implement this? Best regards, Luis -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Saving Oracle Connection across requests
Hello, I'm not sure this is possible but I would to save a oracle connection across several requests (like I do with a normal object) I would like to: if 'object' in request.session: do stuff else: import cx_Oracle conn = cx_Oracle.connect(constring) request.session['object'] = conn do stuff Since this doesn't work I thought about a global variable on settings.py but that only works on de dev server. Apache uses multiple processes so the global variable has different values depending of the process. Any ideas how to keep a persistent connection across requests? 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 deploy problem
Hi, I want to deploy 2 django sites in different subdirectories so I have: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE admin.settings PythonDebug On PythonOption django.root /admin SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE webservice.settings PythonDebug On PythonOption django.root /websvc When I go to http://host/admin/url/whatever sometimes sometimes it works ok, sometimes I get a "page no found" error from the other application " Using the URLconf defined in webservice.urls, ... " Any ideas why the applications are overlapping? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google 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 aggregates and having
Sorry I didn't explain my self properly. I want this query: SELECT (date_format(date, '%%U')) AS `d`, SUM (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory` GROUP BY date_format(date, '%%U') HAVING `d`= 2 How can I make it with ORM? The other one was the only similar query I managed to make using the ORM. On Aug 12, 3:44 am, Russell Keith-Magee <freakboy3...@gmail.com> wrote: > On Wed, Aug 12, 2009 at 5:50 AM, lfrodrigues<lfrodrig...@gmail.com> wrote: > > > Hi, > > > I'm having some problems with "having": > > > I want to group by date and restrict to a given week, in my tests I > > can do this: > > select_data = {"d": """date_format(date, '%%U')"""} > > ScoreHistory.objects.extra(select=select_data).values('d').annotate > > (l=Sum("points")).filter(l=2).query.as_sql() > > > sql: > > SELECT (date_format(date, '%%U')) AS `d`, SUM > > (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory` > > GROUP BY date_format(date, '%%U') HAVING SUM > > (`profile_scorehistory`.`points`) = 2 > > > Good but what I want to get is this: > > sql: > > SELECT (date_format(date, '%%U')) AS `d`, SUM > > (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory` > > GROUP BY date_format(date, '%%U') HAVING `d`= 2 > > I might be missing something here, but as far as I can make out, > you're getting exactly what you've asked for. Your query contains > filter(l=2) - that is, you're filtering on l, the SUM. > > > How can I force using having when I can't define the param in > > annotate? > > I'm afraid I don't see how this relates to your original question. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django aggregates and having
Hi, I'm having some problems with "having": I want to group by date and restrict to a given week, in my tests I can do this: select_data = {"d": """date_format(date, '%%U')"""} ScoreHistory.objects.extra(select=select_data).values('d').annotate (l=Sum("points")).filter(l=2).query.as_sql() sql: SELECT (date_format(date, '%%U')) AS `d`, SUM (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory` GROUP BY date_format(date, '%%U') HAVING SUM (`profile_scorehistory`.`points`) = 2 Good but what I want to get is this: sql: SELECT (date_format(date, '%%U')) AS `d`, SUM (`profile_scorehistory`.`points`) AS `l` FROM `profile_scorehistory` GROUP BY date_format(date, '%%U') HAVING `d`= 2 How can I force using having when I can't define the param in annotate? Thanks in advance, Luis --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google 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 django.root in mod_python
Hello, All my previous projects I've deployed them on the root of a web address. Now I have to deploy two in the same address eg: http://myserver.com/proj1 http://myserver.com/proj2 I'm using django.root to set the correct root (with works fine). I just have two questions: 1 - all the media are relative do /media/... is there a template variable with I can put there (I don't want to hardcode /proj1/ media/...) 2 - LOGIN_URL = '/auth/login' do I have to hardcode LOGIN_URL = '/ proj1/auth/login' or is there a solution? Regards, Luis --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google 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 -~--~~~~--~~--~--~---
Multiple Logins
Hi, I've developed a special Auth backend for a internal communication protocol. Everything was ok but now the requirements changed and I need to allow on the same browser (in diferent tabs) several logged users. How can I have (in the same browser process) several logged users at the same time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: UserProfile and select_related
Isn't there any way to cache profile data on User side? When are you planning on closing 7270? A lot of my code uses get_profile in templates and that is always a query. Isn't it possible to optimize this? On Aug 3, 3:45 pm, lfrodrigues <lfrodrig...@gmail.com> wrote: > Ok Thanks > > On Aug 3, 12:12 pm, Malcolm Tredinnick <malc...@pointy-stick.com> > wrote: > > > On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote: > > > Hello, > > > > I'm displaying lot of user profile picture with are on a user profile > > > (i'm using contrib.auth). So for each picture I have a query for the > > > user profile. > > > > I wanted to use User.objects.filter(stuff).select_related > > > ('userprofile') but this has no effect. Any ideas how to prevent the > > > +200 queries from happening? > > > The link between the two models runs from UserProfile -> User, not the > > other way around. The select_related() call only follows forwards links, > > so it will not traverse from User to UserProfile. It's not completely > > trivial to add backwards-link following, particularly because there can > > be multiple values for backwards links. > > > However, you can often turn this type of query around. Instead of > > filtering User objects, filter Userprofile objects, where you can use > > select_related(). Thus > > > User.objects.filter(username="fred") > > > becomes > > > UserProfile.objects.filter(user__username="fred").select_related() > > > The main trick here is that each condition needs the "user__" bit > > prepended, so a little munging of filters -- either automatically or by > > hand -- is required. You can still access the User instance attributes > > via > > > obj.user.username > > > where "obj" is now a UserProfile instance. > > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: UserProfile and select_related
Ok Thanks On Aug 3, 12:12 pm, Malcolm Tredinnickwrote: > On Mon, 2009-08-03 at 02:48 -0700, alant...@neei.uevora.pt wrote: > > Hello, > > > I'm displaying lot of user profile picture with are on a user profile > > (i'm using contrib.auth). So for each picture I have a query for the > > user profile. > > > I wanted to use User.objects.filter(stuff).select_related > > ('userprofile') but this has no effect. Any ideas how to prevent the > > +200 queries from happening? > > The link between the two models runs from UserProfile -> User, not the > other way around. The select_related() call only follows forwards links, > so it will not traverse from User to UserProfile. It's not completely > trivial to add backwards-link following, particularly because there can > be multiple values for backwards links. > > However, you can often turn this type of query around. Instead of > filtering User objects, filter Userprofile objects, where you can use > select_related(). Thus > > User.objects.filter(username="fred") > > becomes > > UserProfile.objects.filter(user__username="fred").select_related() > > The main trick here is that each condition needs the "user__" bit > prepended, so a little munging of filters -- either automatically or by > hand -- is required. You can still access the User instance attributes > via > > obj.user.username > > where "obj" is now a UserProfile instance. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---