On 5/7/2009 11:16 AM, Eric Chamberlain wrote: > > On May 7, 2009, at 10:36 AM, George Song wrote: > >> On 5/7/2009 8:56 AM, Eric Chamberlain wrote: >>> Our view is taking too long to render, can anyone offer suggestions >>> to >>> improve its speed? >>> >>> There are 5830 profiles. >>> >>> /Total query count:/ 23809 >>> /Total duplicate query count:/ 493 >>> /Total SQL execution time:/ 66.003 >>> /Total Request execution time:/ 142.931 >>> >>> class Profile(Model): >>> id = UUIDField(primary_key=True) >>> user = ForeignKey(User, verbose_name=_('user'), unique=True, >>> null=True) >>> partner = ForeignKey('Partner') >>> call_records = ManyToManyField('CallRecord', verbose_name=_('call >>> record'), null=True, blank=True, help_text='Calls made by the user') >>> >>> class Partner(Model): >>> id = UUIDField(primary_key=True) >>> name = CharField(max_length=255, help_text='The name for the >>> partner') >>> users = ManyToManyField(User, related_name='partner_users', >>> null=True, blank=True, help_text='Users signed up specifically >>> through >>> this partner') >>> providers = ManyToManyField('Provider', >>> related_name='provider_partners', blank=True, null=True, >>> help_text="Calling services owned by this provider.") >>> calls = ManyToManyField('CallRecord', >>> related_name='call_partners', >>> blank=True, null=True, help_text='Calls made through this calling >>> service.') >>> >>> class CallRecord(Model): >>> id = UUIDField(primary_key=True) >>> provider_account = ForeignKey('ProviderAccount', null=True, >>> blank=True, help_text='The calling service, if any, the call was made >>> through') >>> provider = ForeignKey('Provider', blank=True, null=True, >>> help_text='The calling service the call was made through') >>> >>> class Provider(Model): >>> id = UUIDField(primary_key=True) >>> name = CharField(max_length=255) >>> >>> class ProviderAccount(Model): >>> provider = ForeignKey('Provider', help_text='The calling service >>> this account works with') >>> username = TextField() >>> encrypted_password = TextField(db_column='password') >>> user = ForeignKey(User, help_text='The user this calling service >>> account belongs to') >>> >>> >>> profiles = >>> Profile >>> .objects >>> .filter(partner=request.partner,user__is_active=True).order_by('- >>> user__date_joined') >>> for p in profiles: >>> p.provider_list = list( >>> account.provider for account in >>> ProviderAccount >>> .objects >>> .filter(user=p.user,provider__provider_partners=request.partner)) >>> p.call_count = p.call_records.filter().count() >>> return PartnerResponse(request, {'profiles': profiles}) >>> >>> PartnerResponse returns the view to the user, the template uses a for >>> loop to iterate through the profiles. >> Well, it seems like what you're really after is the ProviderAccount, >> right? >> >> So you can just pass this to your template: >> {{{ >> accounts = >> ProviderAccount >> .objects >> .filter(provider__provider_partners=request.partner).order_by('- >> user__date_joined') >> }}} >> >> In your template you can regroup accounts by user and you should be >> good >> to go, right? >> > > We are after user information and a user can have 0 or more > ProviderAccounts. > > The template looks like: > > {% for profile in profiles %} > <tr> > <td><a href="{% url partner-edit-user user_id=profile.id > %}">{{profile.user.email}}</a></td> > <td>{{profile.user.first_name}} {{profile.user.last_name}}</td> > <td>{{profile.user.date_joined|date:"Y M d H:i" }}</td> > <td> > {% for calling_service in profile.provider_list %} > <a href="{% url partner-calling-service-edit > calling_service_id=calling_service.id %}">{{calling_service.name}}</ > a>{% if not forloop.last %}<br />{% endif %} > {% endfor %} > </td> > <td> > {% for sim in profile.sims.all %} > {{sim.caller_id}}{% if not forloop.last %}<br />{% endif %} > {% endfor %} > </td> > <td>{{profile.call_count}}</td> > <td><a href="{% url partner-delete-user user_id=profile.id > %}"><img src="{{ MEDIA_URL }}/images/delete.png" alt="Delete user > account" title="Delete user account"/></a></td> > </tr> > {% endfor %}
I'll have to look at this some more when I have time. But you can eliminate call_count right off the bat, right? Since that can be accessed directly via `profile.call_records.count` directly on the template. -- George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---