Changing table name in response to a QuerySet

2015-03-16 Thread Peter of the Norse
We have two tables that — for legal reasons — are not allowed to be combined. 
The data is so similar that we are using PostgreSQL table inheritance 
, but we can’t 
return the information in the same page. Originally, we only had one table with 
a column specifying which data set to use, but or lawyers put an end to that.

So we have two tables tables with the exact same columns: product_foo and 
product_bar. We also have two models that use model inheritance so that they 
have the exact same fields: ProductFoo and ProductBar. The decision to choose 
which table to use is handled based on user settings.

We would like to go back to just having the one Product model, and have its 
table name switch as necessary. Is there a way to do that?

Peter of the Norse
rahmc...@radio1190.org



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0A706025-5A66-47E3-B524-222E1780ADA4%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django multiple application with common users

2015-03-16 Thread Luis Zárate
You maybe need to take a look documentation of using routes.
https://docs.djangoproject.com/en/1.7/topics/db/multi-db/#using-routers



2015-03-16 8:47 GMT-06:00 Domagoj Kovač :

> Hi Raphael,
>
> I also though this are may options, although first option is the easiest i
> would like to do something a bit more complex. I would also like to access
> my applications from different domains and this means options a and b cant
> satisfied my needs. If i use multiple databases this only means i will
> separate my applications on database level but not on the application
> level. I want them to be separate completely.
>
> I am thinking the best solution for now would be to use a combination of
> multiple databases and separate application. Lets say i have my application
> called "cost management" there i will be using two database connection:
> default one for the cost management and user-connection to connect to user
> database. Although the idea with external authentification provider is
> better, the best thing to do would be to create some kind of user API that
> i can use to authenticate any type of application mobile/web and use this
> api trough some kind of custom authentification provider - i know this is
> bit more complicated to do just for home apps but it could be fun :).
>
> Best,
> Domagoj
>
>
> On Monday, March 16, 2015 at 11:50:02 AM UTC+1, Raphael Michel wrote:
>>
>> Hi,
>>
>> Am Mon, 16 Mar 2015 01:23:22 -0700 (PDT)
>> schrieb Domagoj Kovač :
>> > I would like to have separate databases for every application
>> > including user management.
>>
>> I can think of:
>>
>> (a) You put all the application in the same database and share a user
>> model (look up 'reusable django apps')
>>
>> (b) You let all applications have their own database but share one
>> common user database (look up 'django multiple databases')
>>
>> (c) You set up the apps completely separated and use an external,
>> independent authentication provider (look up 'django ldap', 'django
>> openid', …)
>>
>> For 'small home apps', I'd absolutely go for (a).
>>
>> Best regards,
>> Raphael
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3ea8828d-0f31-4654-bfdc-3753738080e5%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyMXXRyuBRWK7LHzb8ZSSs9mbUyo2c%3DesgEwjGMu17i-xg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing Migrations (django 1.7)?

2015-03-16 Thread Sean Briceland
Hi all,
Previous to Django 1.7, I had a nifty solution for testing south Migrations.

I'd basically get a list of migrations for an app via:
migrations = Migrations('some_app')

Then to get the ORM at a given point in migrations:
orm_at_migration = migrations['000X_name_of_migration'].orm()

I could then use call_command to perform a migration and assert using the 
state-based orm's.

In Django 1.7, I haven't found a way to get the ORM at a given point in 
migrations. If anyone has any ideas or experience in this area, I would 
greatly appreciate a nudge in the right direction.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/af578fb2-f36b-4ff2-b4e5-03ce190b0cec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need your advices to optimize when annotate foreign key

2015-03-16 Thread Simon Charette
Hi Sardor,

I think you've hit a long standing bug: #19259 Annotations generating 
inefficient SQL on PostgreSQL 

Simon

Le lundi 16 mars 2015 11:56:19 UTC-4, Sardor Muminov a écrit :
>
>
> Hi Simon.
>
> Yes I am. I forgot to mention it. I am using PostgreSQL 9.3.6
>
> Now I am implementing Chenxiong Qi's suggestion.
>
> Do you have any idea?
>
>
> On Tuesday, March 17, 2015 at 12:25:00 AM UTC+9, Simon Charette wrote:
>>
>> Hi Sardor,
>>
>> Are you using PostgreSQL?
>>
>> Simon
>>
>> Le lundi 16 mars 2015 05:19:38 UTC-4, Sardor Muminov a écrit :
>>>
>>>
>>>
>>> Hello there,
>>>
>>>
>>> I am trying to perform aggregation from all objects which have one 
>>> foreign key.
>>>
>>>
>>> These are my models:
>>>
>>> ...
>>>
>>> class Post(models.Model):
>>> id = models.CharField(max_length=255, primary_key=True) 
>>> 
>>> 
>>> message = models.TextField()
>>> created_time = models.DateTimeField(db_index=True)
>>> updated_time = models.DateTimeField()
>>> creator = models.ForeignKey(Member, db_index=True)
>>> likes = models.IntegerField(db_index=True)
>>>
>>>
>>> class Comment(models.Model):
>>> id = models.CharField(max_length=255, primary_key=True, 
>>> db_index=True)
>>> message = models.TextField()
>>> created_time = models.DateTimeField(db_index=True)
>>> creator = models.ForeignKey(Member, db_index=True)
>>> post = models.ForeignKey(Post, db_index=True)
>>> likes = models.IntegerField(db_index=True)
>>>
>>> ...
>>>
>>>
>>> And this is my query:
>>>
>>> top_commented_posts = Post.objects.annotate(
>>> num_comments=Count('comment')).order_by('-num_comments')[:10]
>>>
>>> In my template, I iterate over top_commented_posts:
>>>
>>> ...
>>>
>>> {% for post in top_commented_posts %}
>>>  
>>> {{ forloop.counter }}.
>>> {{ post.message | slice:"25"}}...
>>> {{ post.num_comments }}
>>> https://www.mydomain.com/{{ post.id }}/" target="_blank">>> class="icon-link">
>>> 
>>> {% endfor %}
>>>
>>> ...
>>>
>>>
>>> This operations is one of the 27 ones from one page.
>>>
>>> Django debug toolbar result:
>>> 5335.56 ms (27 queries)
>>>
>>> 26 each queries taking between 1.44ms (min) and 227ms (max).
>>>
>>>
>>> Please, share your experience and advices on how can I optimize this 
>>> query.
>>> I have also attached Django debug toolbar screenshot.
>>>
>>>
>>> Thanks in advance,
>>> Sardor
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/17f2b2dc-b9b6-49a8-8e35-97cc2131e19a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need your advices to optimize when annotate foreign key

2015-03-16 Thread Sardor Muminov

Hi Simon.

Yes I am. I forgot to mention it. I am using PostgreSQL 9.3.6

Now I am implementing Chenxiong Qi's suggestion.

Do you have any idea?


On Tuesday, March 17, 2015 at 12:25:00 AM UTC+9, Simon Charette wrote:
>
> Hi Sardor,
>
> Are you using PostgreSQL?
>
> Simon
>
> Le lundi 16 mars 2015 05:19:38 UTC-4, Sardor Muminov a écrit :
>>
>>
>>
>> Hello there,
>>
>>
>> I am trying to perform aggregation from all objects which have one 
>> foreign key.
>>
>>
>> These are my models:
>>
>> ...
>>
>> class Post(models.Model):
>> id = models.CharField(max_length=255, primary_key=True)   
>> 
>>   
>> message = models.TextField()
>> created_time = models.DateTimeField(db_index=True)
>> updated_time = models.DateTimeField()
>> creator = models.ForeignKey(Member, db_index=True)
>> likes = models.IntegerField(db_index=True)
>>
>>
>> class Comment(models.Model):
>> id = models.CharField(max_length=255, primary_key=True, db_index=True)
>> message = models.TextField()
>> created_time = models.DateTimeField(db_index=True)
>> creator = models.ForeignKey(Member, db_index=True)
>> post = models.ForeignKey(Post, db_index=True)
>> likes = models.IntegerField(db_index=True)
>>
>> ...
>>
>>
>> And this is my query:
>>
>> top_commented_posts = Post.objects.annotate(
>> num_comments=Count('comment')).order_by('-num_comments')[:10]
>>
>> In my template, I iterate over top_commented_posts:
>>
>> ...
>>
>> {% for post in top_commented_posts %}
>>  
>> {{ forloop.counter }}.
>> {{ post.message | slice:"25"}}...
>> {{ post.num_comments }}
>> https://www.mydomain.com/{{ post.id }}/" target="_blank">> class="icon-link">
>> 
>> {% endfor %}
>>
>> ...
>>
>>
>> This operations is one of the 27 ones from one page.
>>
>> Django debug toolbar result:
>> 5335.56 ms (27 queries)
>>
>> 26 each queries taking between 1.44ms (min) and 227ms (max).
>>
>>
>> Please, share your experience and advices on how can I optimize this 
>> query.
>> I have also attached Django debug toolbar screenshot.
>>
>>
>> Thanks in advance,
>> Sardor
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7dea739d-b2c5-43f3-8bd6-30ae22fe63f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need your advices to optimize when annotate foreign key

2015-03-16 Thread Simon Charette
Hi Sardor,

Are you using PostgreSQL?

Simon

Le lundi 16 mars 2015 05:19:38 UTC-4, Sardor Muminov a écrit :
>
>
>
> Hello there,
>
>
> I am trying to perform aggregation from all objects which have one foreign 
> key.
>
>
> These are my models:
>
> ...
>
> class Post(models.Model):
> id = models.CharField(max_length=255, primary_key=True)   
> 
>   
> message = models.TextField()
> created_time = models.DateTimeField(db_index=True)
> updated_time = models.DateTimeField()
> creator = models.ForeignKey(Member, db_index=True)
> likes = models.IntegerField(db_index=True)
>
>
> class Comment(models.Model):
> id = models.CharField(max_length=255, primary_key=True, db_index=True)
> message = models.TextField()
> created_time = models.DateTimeField(db_index=True)
> creator = models.ForeignKey(Member, db_index=True)
> post = models.ForeignKey(Post, db_index=True)
> likes = models.IntegerField(db_index=True)
>
> ...
>
>
> And this is my query:
>
> top_commented_posts = Post.objects.annotate(
> num_comments=Count('comment')).order_by('-num_comments')[:10]
>
> In my template, I iterate over top_commented_posts:
>
> ...
>
> {% for post in top_commented_posts %}
>  
> {{ forloop.counter }}.
> {{ post.message | slice:"25"}}...
> {{ post.num_comments }}
> https://www.mydomain.com/{{ post.id }}/" target="_blank"> class="icon-link">
> 
> {% endfor %}
>
> ...
>
>
> This operations is one of the 27 ones from one page.
>
> Django debug toolbar result:
> 5335.56 ms (27 queries)
>
> 26 each queries taking between 1.44ms (min) and 227ms (max).
>
>
> Please, share your experience and advices on how can I optimize this query.
> I have also attached Django debug toolbar screenshot.
>
>
> Thanks in advance,
> Sardor
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a6c163eb-c782-4ecf-9d56-c0039469bab7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django multiple application with common users

2015-03-16 Thread Domagoj Kovač
Hi Raphael,

I also though this are may options, although first option is the easiest i 
would like to do something a bit more complex. I would also like to access 
my applications from different domains and this means options a and b cant 
satisfied my needs. If i use multiple databases this only means i will 
separate my applications on database level but not on the application 
level. I want them to be separate completely.

I am thinking the best solution for now would be to use a combination of 
multiple databases and separate application. Lets say i have my application 
called "cost management" there i will be using two database connection: 
default one for the cost management and user-connection to connect to user 
database. Although the idea with external authentification provider is 
better, the best thing to do would be to create some kind of user API that 
i can use to authenticate any type of application mobile/web and use this 
api trough some kind of custom authentification provider - i know this is 
bit more complicated to do just for home apps but it could be fun :).

Best,
Domagoj


On Monday, March 16, 2015 at 11:50:02 AM UTC+1, Raphael Michel wrote:
>
> Hi, 
>
> Am Mon, 16 Mar 2015 01:23:22 -0700 (PDT) 
> schrieb Domagoj Kovač >: 
> > I would like to have separate databases for every application 
> > including user management. 
>
> I can think of: 
>
> (a) You put all the application in the same database and share a user 
> model (look up 'reusable django apps') 
>
> (b) You let all applications have their own database but share one 
> common user database (look up 'django multiple databases') 
>
> (c) You set up the apps completely separated and use an external, 
> independent authentication provider (look up 'django ldap', 'django 
> openid', …) 
>
> For 'small home apps', I'd absolutely go for (a). 
>
> Best regards, 
> Raphael 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ea8828d-0f31-4654-bfdc-3753738080e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
Well, that preaty much closes the case Bill..

already created a function that loads the file independently, and returns a
HttpResponse with its contents...

But thanks a lot for everyones help!

Em seg, 16 de mar de 2015 às 11:44, Bill Freeman 
escreveu:

> But that's what the template loader does.  It loads *DJANGO* templates.
> If it does the loading, the template will receive Django processing.
>
> I see two choices:
>
> 1. Quote everything in the template that looks like a Django template
> special syntax so that the rendering process instead just renders it as
> what you wanted orriginally.
>
> 2. Load the file yourself.  Yes, you have to know the path or search
> suitable sub-directories of installed apps yourself.  But those directories
> probably shouldn't be called "templates", because those are for Django
> templates.  Perhaps "angular_templates"?
>
> On Mon, Mar 16, 2015 at 10:24 AM, Guilherme Leal 
> wrote:
>
>> Just to clarify the things a little bit more to Avraham.. i DO want the
>> request to pass through django
>>
>> what i dont want is that django treat this particular html as a template.
>>
>> Em seg, 16 de mar de 2015 às 11:15, Guilherme Leal 
>> escreveu:
>>
>>> Can you give me an exemple?
>>>
>>> Em seg, 16 de mar de 2015 às 11:05, Avraham Serour 
>>> escreveu:
>>>
>>> if you don't want django to render your angularjs template file then
 don't.

 You could treat it as a static file, same way as a .png, the request
 woudn't even get to django

 you can not use render to return on the view, instead return the file
 without loading it in the template renderer

 On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal 
 wrote:

> and the {% ssi %} was the winner :)
>
> the only thing that i didnt liked is that i have to strictly type the
> file path. But that would happend either way, working with the file
> directly or not.
>
> anyway, worked with the {% ssi %}.
>
> Thanks A LOT!
>
> Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
> fschietteca...@gmail.com> escreveu:
>
> I am not sure what you mean.
>>
>> I have this is urls.py
>>
>> # Root view, goes to 'app.home.views.page'
>> (r'^$', 'app.home.views.page'),
>>
>> and the code below in page() in views.py, django routes ‘/‘ to that
>> view and it renders the home page.
>>
>> Or you could use {% ssi %} to include the angular stuff.
>>
>> François
>>
>>
>> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
>> wrote:
>> >
>> > This solution crossed my mind, and the only down side that i see on
>> it, is that i cant use the "template.loader" logic for finding the right
>> template.
>> >
>> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
>> fschietteca...@gmail.com> escreveu:
>> > You can just read the file content and return it with an
>> HttpResponse(), like this:
>> >
>> >
>> > # File handle
>> > fileHandle = None
>> >
>> > # Open the file, return a 404 if failed
>> > try:
>> > fileHandle = open(filePath, 'r')
>> > except IOError:
>> > raise Http404()
>> >
>> ># Return the file
>> > return HttpResponse(content=fileHandle.read(),
>> content_type=’text/html')
>> >
>> > François
>> >
>> >
>> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
>> wrote:
>> > >
>> > > Hello!
>> > >
>> > > Anyone knows a way to load a template file WITHOUT
>> parsing/rendering it?
>> > >
>> > > To ilustrate a bit more:
>> > >
>> > > I have a django app serving a restfull api, and everithing is
>> just fine with it. The front end that consumes this api, is an Angular.js
>> single page app. To centralize the routing logic, what i want to do is to
>> let django to serve the "index.html" of this app. The only problem is, 
>> when
>> i load the html of the front end (through "django.template.loader.get_
>> template"), the template engine tries to parse it, and throws an
>> exception because this "template" has the angularjs template tags on it.
>> > >
>> > > What i need is:
>> > > - Load the template without parsing/rendering it
>> > > OR
>> > > - Serve this html document as static in production (the static
>> serving view only works when debug is activated)
>> > >
>> > > Thanx in advance!
>> > >
>> > > --
>> > > You received this message because you are subscribed to the
>> Google Groups "Django users" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com.
>> > > To post to this group, send email to
>> django-users@googlegroups.com.
>> > > Visit this group at http://groups.google.com/group/django-users.
>>

Re: Load Template without rendering/parsing

2015-03-16 Thread Avraham Serour
return HttpResponse(content, content_type='text/html')

On Mon, Mar 16, 2015 at 4:43 PM, Bill Freeman  wrote:

> But that's what the template loader does.  It loads *DJANGO* templates.
> If it does the loading, the template will receive Django processing.
>
> I see two choices:
>
> 1. Quote everything in the template that looks like a Django template
> special syntax so that the rendering process instead just renders it as
> what you wanted orriginally.
>
> 2. Load the file yourself.  Yes, you have to know the path or search
> suitable sub-directories of installed apps yourself.  But those directories
> probably shouldn't be called "templates", because those are for Django
> templates.  Perhaps "angular_templates"?
>
> On Mon, Mar 16, 2015 at 10:24 AM, Guilherme Leal 
> wrote:
>
>> Just to clarify the things a little bit more to Avraham.. i DO want the
>> request to pass through django
>>
>> what i dont want is that django treat this particular html as a template.
>>
>> Em seg, 16 de mar de 2015 às 11:15, Guilherme Leal 
>> escreveu:
>>
>>> Can you give me an exemple?
>>>
>>> Em seg, 16 de mar de 2015 às 11:05, Avraham Serour 
>>> escreveu:
>>>
>>> if you don't want django to render your angularjs template file then
 don't.

 You could treat it as a static file, same way as a .png, the request
 woudn't even get to django

 you can not use render to return on the view, instead return the file
 without loading it in the template renderer

 On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal 
 wrote:

> and the {% ssi %} was the winner :)
>
> the only thing that i didnt liked is that i have to strictly type the
> file path. But that would happend either way, working with the file
> directly or not.
>
> anyway, worked with the {% ssi %}.
>
> Thanks A LOT!
>
> Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
> fschietteca...@gmail.com> escreveu:
>
> I am not sure what you mean.
>>
>> I have this is urls.py
>>
>> # Root view, goes to 'app.home.views.page'
>> (r'^$', 'app.home.views.page'),
>>
>> and the code below in page() in views.py, django routes ‘/‘ to that
>> view and it renders the home page.
>>
>> Or you could use {% ssi %} to include the angular stuff.
>>
>> François
>>
>>
>> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
>> wrote:
>> >
>> > This solution crossed my mind, and the only down side that i see on
>> it, is that i cant use the "template.loader" logic for finding the right
>> template.
>> >
>> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
>> fschietteca...@gmail.com> escreveu:
>> > You can just read the file content and return it with an
>> HttpResponse(), like this:
>> >
>> >
>> > # File handle
>> > fileHandle = None
>> >
>> > # Open the file, return a 404 if failed
>> > try:
>> > fileHandle = open(filePath, 'r')
>> > except IOError:
>> > raise Http404()
>> >
>> ># Return the file
>> > return HttpResponse(content=fileHandle.read(),
>> content_type=’text/html')
>> >
>> > François
>> >
>> >
>> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
>> wrote:
>> > >
>> > > Hello!
>> > >
>> > > Anyone knows a way to load a template file WITHOUT
>> parsing/rendering it?
>> > >
>> > > To ilustrate a bit more:
>> > >
>> > > I have a django app serving a restfull api, and everithing is
>> just fine with it. The front end that consumes this api, is an Angular.js
>> single page app. To centralize the routing logic, what i want to do is to
>> let django to serve the "index.html" of this app. The only problem is, 
>> when
>> i load the html of the front end (through "django.template.loader.get_
>> template"), the template engine tries to parse it, and throws an
>> exception because this "template" has the angularjs template tags on it.
>> > >
>> > > What i need is:
>> > > - Load the template without parsing/rendering it
>> > > OR
>> > > - Serve this html document as static in production (the static
>> serving view only works when debug is activated)
>> > >
>> > > Thanx in advance!
>> > >
>> > > --
>> > > You received this message because you are subscribed to the
>> Google Groups "Django users" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com.
>> > > To post to this group, send email to
>> django-users@googlegroups.com.
>> > > Visit this group at http://groups.google.com/group/django-users.
>> > > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqX
>> DSfNNcH10gUvAZB-3UazG

Re: Load Template without rendering/parsing

2015-03-16 Thread Bill Freeman
But that's what the template loader does.  It loads *DJANGO* templates.  If
it does the loading, the template will receive Django processing.

I see two choices:

1. Quote everything in the template that looks like a Django template
special syntax so that the rendering process instead just renders it as
what you wanted orriginally.

2. Load the file yourself.  Yes, you have to know the path or search
suitable sub-directories of installed apps yourself.  But those directories
probably shouldn't be called "templates", because those are for Django
templates.  Perhaps "angular_templates"?

On Mon, Mar 16, 2015 at 10:24 AM, Guilherme Leal 
wrote:

> Just to clarify the things a little bit more to Avraham.. i DO want the
> request to pass through django
>
> what i dont want is that django treat this particular html as a template.
>
> Em seg, 16 de mar de 2015 às 11:15, Guilherme Leal 
> escreveu:
>
>> Can you give me an exemple?
>>
>> Em seg, 16 de mar de 2015 às 11:05, Avraham Serour 
>> escreveu:
>>
>> if you don't want django to render your angularjs template file then
>>> don't.
>>>
>>> You could treat it as a static file, same way as a .png, the request
>>> woudn't even get to django
>>>
>>> you can not use render to return on the view, instead return the file
>>> without loading it in the template renderer
>>>
>>> On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal 
>>> wrote:
>>>
 and the {% ssi %} was the winner :)

 the only thing that i didnt liked is that i have to strictly type the
 file path. But that would happend either way, working with the file
 directly or not.

 anyway, worked with the {% ssi %}.

 Thanks A LOT!

 Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
 fschietteca...@gmail.com> escreveu:

 I am not sure what you mean.
>
> I have this is urls.py
>
> # Root view, goes to 'app.home.views.page'
> (r'^$', 'app.home.views.page'),
>
> and the code below in page() in views.py, django routes ‘/‘ to that
> view and it renders the home page.
>
> Or you could use {% ssi %} to include the angular stuff.
>
> François
>
>
> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
> wrote:
> >
> > This solution crossed my mind, and the only down side that i see on
> it, is that i cant use the "template.loader" logic for finding the right
> template.
> >
> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
> fschietteca...@gmail.com> escreveu:
> > You can just read the file content and return it with an
> HttpResponse(), like this:
> >
> >
> > # File handle
> > fileHandle = None
> >
> > # Open the file, return a 404 if failed
> > try:
> > fileHandle = open(filePath, 'r')
> > except IOError:
> > raise Http404()
> >
> ># Return the file
> > return HttpResponse(content=fileHandle.read(),
> content_type=’text/html')
> >
> > François
> >
> >
> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
> wrote:
> > >
> > > Hello!
> > >
> > > Anyone knows a way to load a template file WITHOUT
> parsing/rendering it?
> > >
> > > To ilustrate a bit more:
> > >
> > > I have a django app serving a restfull api, and everithing is just
> fine with it. The front end that consumes this api, is an Angular.js 
> single
> page app. To centralize the routing logic, what i want to do is to let
> django to serve the "index.html" of this app. The only problem is, when i
> load the html of the front end (through 
> "django.template.loader.get_template"),
> the template engine tries to parse it, and throws an exception because 
> this
> "template" has the angularjs template tags on it.
> > >
> > > What i need is:
> > > - Load the template without parsing/rendering it
> > > OR
> > > - Serve this html document as static in production (the static
> serving view only works when debug is activated)
> > >
> > > Thanx in advance!
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > > To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscr...@googlegroups.com.
> > > To post to this group, send email to django-users@googlegroups.com
> .
> > > Visit this group at http://groups.google.com/group/django-users.
> > > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqX
> DSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To

Re: Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
Just to clarify the things a little bit more to Avraham.. i DO want the
request to pass through django

what i dont want is that django treat this particular html as a template.

Em seg, 16 de mar de 2015 às 11:15, Guilherme Leal 
escreveu:

> Can you give me an exemple?
>
> Em seg, 16 de mar de 2015 às 11:05, Avraham Serour 
> escreveu:
>
> if you don't want django to render your angularjs template file then don't.
>>
>> You could treat it as a static file, same way as a .png, the request
>> woudn't even get to django
>>
>> you can not use render to return on the view, instead return the file
>> without loading it in the template renderer
>>
>> On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal 
>> wrote:
>>
>>> and the {% ssi %} was the winner :)
>>>
>>> the only thing that i didnt liked is that i have to strictly type the
>>> file path. But that would happend either way, working with the file
>>> directly or not.
>>>
>>> anyway, worked with the {% ssi %}.
>>>
>>> Thanks A LOT!
>>>
>>> Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
>>> fschietteca...@gmail.com> escreveu:
>>>
>>> I am not sure what you mean.

 I have this is urls.py

 # Root view, goes to 'app.home.views.page'
 (r'^$', 'app.home.views.page'),

 and the code below in page() in views.py, django routes ‘/‘ to that
 view and it renders the home page.

 Or you could use {% ssi %} to include the angular stuff.

 François


 > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
 wrote:
 >
 > This solution crossed my mind, and the only down side that i see on
 it, is that i cant use the "template.loader" logic for finding the right
 template.
 >
 > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
 fschietteca...@gmail.com> escreveu:
 > You can just read the file content and return it with an
 HttpResponse(), like this:
 >
 >
 > # File handle
 > fileHandle = None
 >
 > # Open the file, return a 404 if failed
 > try:
 > fileHandle = open(filePath, 'r')
 > except IOError:
 > raise Http404()
 >
 ># Return the file
 > return HttpResponse(content=fileHandle.read(),
 content_type=’text/html')
 >
 > François
 >
 >
 > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
 wrote:
 > >
 > > Hello!
 > >
 > > Anyone knows a way to load a template file WITHOUT
 parsing/rendering it?
 > >
 > > To ilustrate a bit more:
 > >
 > > I have a django app serving a restfull api, and everithing is just
 fine with it. The front end that consumes this api, is an Angular.js single
 page app. To centralize the routing logic, what i want to do is to let
 django to serve the "index.html" of this app. The only problem is, when i
 load the html of the front end (through 
 "django.template.loader.get_template"),
 the template engine tries to parse it, and throws an exception because this
 "template" has the angularjs template tags on it.
 > >
 > > What i need is:
 > > - Load the template without parsing/rendering it
 > > OR
 > > - Serve this html document as static in production (the static
 serving view only works when debug is activated)
 > >
 > > Thanx in advance!
 > >
 > > --
 > > You received this message because you are subscribed to the Google
 Groups "Django users" group.
 > > To unsubscribe from this group and stop receiving emails from it,
 send an email to django-users+unsubscr...@googlegroups.com.
 > > To post to this group, send email to django-users@googlegroups.com.
 > > Visit this group at http://groups.google.com/group/django-users.
 > > To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqX
 DSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
 > > For more options, visit https://groups.google.com/d/optout.
 >
 > --
 > You received this message because you are subscribed to the Google
 Groups "Django users" group.
 > To unsubscribe from this group and stop receiving emails from it,
 send an email to django-users+unsubscr...@googlegroups.com.
 > To post to this group, send email to django-users@googlegroups.com.
 > Visit this group at http://groups.google.com/group/django-users.
 > To view this discussion on the web visit https://groups.google.com/d/
 msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
 > For more options, visit https://groups.google.com/d/optout.
 >
 > --
 > You received this message because you are subscribed to the Google
 Groups "Django users" group.
 > To unsubscribe from this group and stop receiving emails from it,
 send an email to django-users+unsubscr...@googlegroups.com.
 > To post to this group, send email to djan

Re: Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
Can you give me an exemple?

Em seg, 16 de mar de 2015 às 11:05, Avraham Serour 
escreveu:

> if you don't want django to render your angularjs template file then don't.
>
> You could treat it as a static file, same way as a .png, the request
> woudn't even get to django
>
> you can not use render to return on the view, instead return the file
> without loading it in the template renderer
>
> On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal 
> wrote:
>
>> and the {% ssi %} was the winner :)
>>
>> the only thing that i didnt liked is that i have to strictly type the
>> file path. But that would happend either way, working with the file
>> directly or not.
>>
>> anyway, worked with the {% ssi %}.
>>
>> Thanks A LOT!
>>
>> Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
>> fschietteca...@gmail.com> escreveu:
>>
>> I am not sure what you mean.
>>>
>>> I have this is urls.py
>>>
>>> # Root view, goes to 'app.home.views.page'
>>> (r'^$', 'app.home.views.page'),
>>>
>>> and the code below in page() in views.py, django routes ‘/‘ to that view
>>> and it renders the home page.
>>>
>>> Or you could use {% ssi %} to include the angular stuff.
>>>
>>> François
>>>
>>>
>>> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
>>> wrote:
>>> >
>>> > This solution crossed my mind, and the only down side that i see on
>>> it, is that i cant use the "template.loader" logic for finding the right
>>> template.
>>> >
>>> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
>>> fschietteca...@gmail.com> escreveu:
>>> > You can just read the file content and return it with an
>>> HttpResponse(), like this:
>>> >
>>> >
>>> > # File handle
>>> > fileHandle = None
>>> >
>>> > # Open the file, return a 404 if failed
>>> > try:
>>> > fileHandle = open(filePath, 'r')
>>> > except IOError:
>>> > raise Http404()
>>> >
>>> ># Return the file
>>> > return HttpResponse(content=fileHandle.read(),
>>> content_type=’text/html')
>>> >
>>> > François
>>> >
>>> >
>>> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
>>> wrote:
>>> > >
>>> > > Hello!
>>> > >
>>> > > Anyone knows a way to load a template file WITHOUT parsing/rendering
>>> it?
>>> > >
>>> > > To ilustrate a bit more:
>>> > >
>>> > > I have a django app serving a restfull api, and everithing is just
>>> fine with it. The front end that consumes this api, is an Angular.js single
>>> page app. To centralize the routing logic, what i want to do is to let
>>> django to serve the "index.html" of this app. The only problem is, when i
>>> load the html of the front end (through 
>>> "django.template.loader.get_template"),
>>> the template engine tries to parse it, and throws an exception because this
>>> "template" has the angularjs template tags on it.
>>> > >
>>> > > What i need is:
>>> > > - Load the template without parsing/rendering it
>>> > > OR
>>> > > - Serve this html document as static in production (the static
>>> serving view only works when debug is activated)
>>> > >
>>> > > Thanx in advance!
>>> > >
>>> > > --
>>> > > You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> > > To unsubscribe from this group and stop receiving emails from it,
>>> send an email to django-users+unsubscr...@googlegroups.com.
>>> > > To post to this group, send email to django-users@googlegroups.com.
>>> > > Visit this group at http://groups.google.com/group/django-users.
>>> > > To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/
>>> CAOs3Lp43aDqXDSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
>>> > > For more options, visit https://groups.google.com/d/optout.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> > To post to this group, send email to django-users@googlegroups.com.
>>> > Visit this group at http://groups.google.com/group/django-users.
>>> > To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> > To post to this group, send email to django-users@googlegroups.com.
>>> > Visit this group at http://groups.google.com/group/django-users.
>>> > To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/CAOs3Lp7DtTtDdmaYHp%3DnKAxD%
>>> 2B-_SU7JtBqbyNMpPDRdqpnjTNw%40mail.gmail.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this me

Re: Need your advices to optimize when annotate foreign key

2015-03-16 Thread tkdchen


On Monday, March 16, 2015 at 5:19:38 PM UTC+8, Sardor Muminov wrote:
>
>
>
> Hello there,
>
>
> I am trying to perform aggregation from all objects which have one foreign 
> key.
>
>
> These are my models:
>
> ...
>
> class Post(models.Model):
> id = models.CharField(max_length=255, primary_key=True)   
> 
>   
> message = models.TextField()
> created_time = models.DateTimeField(db_index=True)
> updated_time = models.DateTimeField()
> creator = models.ForeignKey(Member, db_index=True)
> likes = models.IntegerField(db_index=True)
>
>
> class Comment(models.Model):
> id = models.CharField(max_length=255, primary_key=True, db_index=True)
> message = models.TextField()
> created_time = models.DateTimeField(db_index=True)
> creator = models.ForeignKey(Member, db_index=True)
> post = models.ForeignKey(Post, db_index=True)
> likes = models.IntegerField(db_index=True)
>
> ...
>
>
> And this is my query:
>
> top_commented_posts = Post.objects.annotate(
> num_comments=Count('comment')).order_by('-num_comments')[:10]
>
>
top_commented_posts = 
Comment.objects.values('post').annotrate(post_count=Count('pk')).order_by('-post_count')

The rest is to construct above result with Posts to display in template.

Regards,
Chenxiong Qi
 

> In my template, I iterate over top_commented_posts:
>
> ...
>
> {% for post in top_commented_posts %}
>  
> {{ forloop.counter }}.
> {{ post.message | slice:"25"}}...
> {{ post.num_comments }}
> https://www.mydomain.com/{{ post.id }}/" target="_blank"> class="icon-link">
> 
> {% endfor %}
>
> ...
>
>
> This operations is one of the 27 ones from one page.
>
> Django debug toolbar result:
> 5335.56 ms (27 queries)
>
> 26 each queries taking between 1.44ms (min) and 227ms (max).
>
>
> Please, share your experience and advices on how can I optimize this query.
> I have also attached Django debug toolbar screenshot.
>
>
> Thanks in advance,
> Sardor
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/250c65e2-01e0-4591-bee4-7f8eca2e3855%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load Template without rendering/parsing

2015-03-16 Thread Avraham Serour
if you don't want django to render your angularjs template file then don't.

You could treat it as a static file, same way as a .png, the request
woudn't even get to django

you can not use render to return on the view, instead return the file
without loading it in the template renderer

On Mon, Mar 16, 2015 at 3:55 PM, Guilherme Leal  wrote:

> and the {% ssi %} was the winner :)
>
> the only thing that i didnt liked is that i have to strictly type the file
> path. But that would happend either way, working with the file directly or
> not.
>
> anyway, worked with the {% ssi %}.
>
> Thanks A LOT!
>
> Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
> fschietteca...@gmail.com> escreveu:
>
> I am not sure what you mean.
>>
>> I have this is urls.py
>>
>> # Root view, goes to 'app.home.views.page'
>> (r'^$', 'app.home.views.page'),
>>
>> and the code below in page() in views.py, django routes ‘/‘ to that view
>> and it renders the home page.
>>
>> Or you could use {% ssi %} to include the angular stuff.
>>
>> François
>>
>>
>> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal 
>> wrote:
>> >
>> > This solution crossed my mind, and the only down side that i see on it,
>> is that i cant use the "template.loader" logic for finding the right
>> template.
>> >
>> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
>> fschietteca...@gmail.com> escreveu:
>> > You can just read the file content and return it with an
>> HttpResponse(), like this:
>> >
>> >
>> > # File handle
>> > fileHandle = None
>> >
>> > # Open the file, return a 404 if failed
>> > try:
>> > fileHandle = open(filePath, 'r')
>> > except IOError:
>> > raise Http404()
>> >
>> ># Return the file
>> > return HttpResponse(content=fileHandle.read(),
>> content_type=’text/html')
>> >
>> > François
>> >
>> >
>> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
>> wrote:
>> > >
>> > > Hello!
>> > >
>> > > Anyone knows a way to load a template file WITHOUT parsing/rendering
>> it?
>> > >
>> > > To ilustrate a bit more:
>> > >
>> > > I have a django app serving a restfull api, and everithing is just
>> fine with it. The front end that consumes this api, is an Angular.js single
>> page app. To centralize the routing logic, what i want to do is to let
>> django to serve the "index.html" of this app. The only problem is, when i
>> load the html of the front end (through 
>> "django.template.loader.get_template"),
>> the template engine tries to parse it, and throws an exception because this
>> "template" has the angularjs template tags on it.
>> > >
>> > > What i need is:
>> > > - Load the template without parsing/rendering it
>> > > OR
>> > > - Serve this html document as static in production (the static
>> serving view only works when debug is activated)
>> > >
>> > > Thanx in advance!
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com.
>> > > To post to this group, send email to django-users@googlegroups.com.
>> > > Visit this group at http://groups.google.com/group/django-users.
>> > > To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-
>> 3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
>> > > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to django-users+unsubscr...@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
>> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to django-users+unsubscr...@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAOs3Lp7DtTtDdmaYHp%3DnKAxD%
>> 2B-_SU7JtBqbyNMpPDRdqpnjTNw%40mail.gmail.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this 

Re: Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
and the {% ssi %} was the winner :)

the only thing that i didnt liked is that i have to strictly type the file
path. But that would happend either way, working with the file directly or
not.

anyway, worked with the {% ssi %}.

Thanks A LOT!

Em seg, 16 de mar de 2015 às 10:32, François Schiettecatte <
fschietteca...@gmail.com> escreveu:

> I am not sure what you mean.
>
> I have this is urls.py
>
> # Root view, goes to 'app.home.views.page'
> (r'^$', 'app.home.views.page'),
>
> and the code below in page() in views.py, django routes ‘/‘ to that view
> and it renders the home page.
>
> Or you could use {% ssi %} to include the angular stuff.
>
> François
>
>
> > On Mar 16, 2015, at 9:01 AM, Guilherme Leal  wrote:
> >
> > This solution crossed my mind, and the only down side that i see on it,
> is that i cant use the "template.loader" logic for finding the right
> template.
> >
> > Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
> fschietteca...@gmail.com> escreveu:
> > You can just read the file content and return it with an HttpResponse(),
> like this:
> >
> >
> > # File handle
> > fileHandle = None
> >
> > # Open the file, return a 404 if failed
> > try:
> > fileHandle = open(filePath, 'r')
> > except IOError:
> > raise Http404()
> >
> ># Return the file
> > return HttpResponse(content=fileHandle.read(),
> content_type=’text/html')
> >
> > François
> >
> >
> > > On Mar 16, 2015, at 8:49 AM, Guilherme Leal 
> wrote:
> > >
> > > Hello!
> > >
> > > Anyone knows a way to load a template file WITHOUT parsing/rendering
> it?
> > >
> > > To ilustrate a bit more:
> > >
> > > I have a django app serving a restfull api, and everithing is just
> fine with it. The front end that consumes this api, is an Angular.js single
> page app. To centralize the routing logic, what i want to do is to let
> django to serve the "index.html" of this app. The only problem is, when i
> load the html of the front end (through 
> "django.template.loader.get_template"),
> the template engine tries to parse it, and throws an exception because this
> "template" has the angularjs template tags on it.
> > >
> > > What i need is:
> > > - Load the template without parsing/rendering it
> > > OR
> > > - Serve this html document as static in production (the static serving
> view only works when debug is activated)
> > >
> > > Thanx in advance!
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > Visit this group at http://groups.google.com/group/django-users.
> > > To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-
> 3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAOs3Lp7DtTtDdmaYHp%3DnKAxD%
> 2B-_SU7JtBqbyNMpPDRdqpnjTNw%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/63341965-80C9-457B-B6C8-766C094869EA%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving em

Re: Load Template without rendering/parsing

2015-03-16 Thread François Schiettecatte
I am not sure what you mean.

I have this is urls.py

# Root view, goes to 'app.home.views.page'
(r'^$', 'app.home.views.page'),

and the code below in page() in views.py, django routes ‘/‘ to that view and it 
renders the home page.

Or you could use {% ssi %} to include the angular stuff.

François


> On Mar 16, 2015, at 9:01 AM, Guilherme Leal  wrote:
> 
> This solution crossed my mind, and the only down side that i see on it, is 
> that i cant use the "template.loader" logic for finding the right template.
> 
> Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte 
>  escreveu:
> You can just read the file content and return it with an HttpResponse(), like 
> this:
> 
> 
> # File handle
> fileHandle = None
> 
> # Open the file, return a 404 if failed
> try:
> fileHandle = open(filePath, 'r')
> except IOError:
> raise Http404()
> 
># Return the file
> return HttpResponse(content=fileHandle.read(), content_type=’text/html')
> 
> François
> 
> 
> > On Mar 16, 2015, at 8:49 AM, Guilherme Leal  wrote:
> >
> > Hello!
> >
> > Anyone knows a way to load a template file WITHOUT parsing/rendering it?
> >
> > To ilustrate a bit more:
> >
> > I have a django app serving a restfull api, and everithing is just fine 
> > with it. The front end that consumes this api, is an Angular.js single page 
> > app. To centralize the routing logic, what i want to do is to let django to 
> > serve the "index.html" of this app. The only problem is, when i load the 
> > html of the front end (through "django.template.loader.get_template"), the 
> > template engine tries to parse it, and throws an exception because this 
> > "template" has the angularjs template tags on it.
> >
> > What i need is:
> > - Load the template without parsing/rendering it
> > OR
> > - Serve this html document as static in production (the static serving view 
> > only works when debug is activated)
> >
> > Thanx in advance!
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAOs3Lp7DtTtDdmaYHp%3DnKAxD%2B-_SU7JtBqbyNMpPDRdqpnjTNw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/63341965-80C9-457B-B6C8-766C094869EA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
This solution crossed my mind, and the only down side that i see on it, is
that i cant use the "template.loader" logic for finding the right template.

Em seg, 16 de mar de 2015 às 09:59, François Schiettecatte <
fschietteca...@gmail.com> escreveu:

> You can just read the file content and return it with an HttpResponse(),
> like this:
>
>
> # File handle
> fileHandle = None
>
> # Open the file, return a 404 if failed
> try:
> fileHandle = open(filePath, 'r')
> except IOError:
> raise Http404()
>
># Return the file
> return HttpResponse(content=fileHandle.read(),
> content_type=’text/html')
>
> François
>
>
> > On Mar 16, 2015, at 8:49 AM, Guilherme Leal  wrote:
> >
> > Hello!
> >
> > Anyone knows a way to load a template file WITHOUT parsing/rendering it?
> >
> > To ilustrate a bit more:
> >
> > I have a django app serving a restfull api, and everithing is just fine
> with it. The front end that consumes this api, is an Angular.js single page
> app. To centralize the routing logic, what i want to do is to let django to
> serve the "index.html" of this app. The only problem is, when i load the
> html of the front end (through "django.template.loader.get_template"),
> the template engine tries to parse it, and throws an exception because this
> "template" has the angularjs template tags on it.
> >
> > What i need is:
> > - Load the template without parsing/rendering it
> > OR
> > - Serve this html document as static in production (the static serving
> view only works when debug is activated)
> >
> > Thanx in advance!
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-
> 3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs3Lp7DtTtDdmaYHp%3DnKAxD%2B-_SU7JtBqbyNMpPDRdqpnjTNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load Template without rendering/parsing

2015-03-16 Thread François Schiettecatte
You can just read the file content and return it with an HttpResponse(), like 
this:


# File handle
fileHandle = None

# Open the file, return a 404 if failed
try:
fileHandle = open(filePath, 'r')
except IOError:
raise Http404()

   # Return the file
return HttpResponse(content=fileHandle.read(), content_type=’text/html')

François


> On Mar 16, 2015, at 8:49 AM, Guilherme Leal  wrote:
> 
> Hello!
> 
> Anyone knows a way to load a template file WITHOUT parsing/rendering it?
> 
> To ilustrate a bit more: 
> 
> I have a django app serving a restfull api, and everithing is just fine with 
> it. The front end that consumes this api, is an Angular.js single page app. 
> To centralize the routing logic, what i want to do is to let django to serve 
> the "index.html" of this app. The only problem is, when i load the html of 
> the front end (through "django.template.loader.get_template"), the template 
> engine tries to parse it, and throws an exception because this "template" has 
> the angularjs template tags on it.
> 
> What i need is:
> - Load the template without parsing/rendering it
> OR
> - Serve this html document as static in production (the static serving view 
> only works when debug is activated)
> 
> Thanx in advance!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/FFC3A2C1-51A0-4A2D-9D94-EEF0C511C5A6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Load Template without rendering/parsing

2015-03-16 Thread Guilherme Leal
Hello!

Anyone knows a way to load a template file WITHOUT parsing/rendering it?

To ilustrate a bit more:

I have a django app serving a restfull api, and everithing is just fine
with it. The front end that consumes this api, is an Angular.js single page
app. To centralize the routing logic, what i want to do is to let django to
serve the "index.html" of this app. The only problem is, when i load the
html of the front end (through "django.template.loader.get_template"), the
template engine tries to parse it, and throws an exception because this
"template" has the angularjs template tags on it.

What i need is:
- Load the template without parsing/rendering it
OR
- Serve this html document as static in production (the static serving view
only works when debug is activated)

Thanx in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs3Lp43aDqXDSfNNcH10gUvAZB-3UazGEL45bW59t-6Hyay9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django multiple application with common users

2015-03-16 Thread Raphael Michel
Hi,

Am Mon, 16 Mar 2015 01:23:22 -0700 (PDT)
schrieb Domagoj Kovač :
> I would like to have separate databases for every application
> including user management.

I can think of:

(a) You put all the application in the same database and share a user
model (look up 'reusable django apps')

(b) You let all applications have their own database but share one
common user database (look up 'django multiple databases')

(c) You set up the apps completely separated and use an external,
independent authentication provider (look up 'django ldap', 'django
openid', …)

For 'small home apps', I'd absolutely go for (a).

Best regards,
Raphael

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150316114913.47790ae7%40kvothe.
For more options, visit https://groups.google.com/d/optout.


pgp1WzAsUUHuj.pgp
Description: Digitale Signatur von OpenPGP


Re: Django 1.7 issue

2015-03-16 Thread James Schneider
Can you please paste in a copy of your urls.py file that is referenced in
the error?

-James
On Mar 16, 2015 1:21 AM, "Piyush Sharma" 
wrote:

> i was following the django 1.7 documentation and having issue in creating
> an app part 3
> please help
>
> TypeError at /polls/34/results/
>
> 'function' object has no attribute '__getitem__'
>
> Request Method:GETRequest URL:http://127.0.0.1:8000/polls/34/results/Django
> Version:1.9Exception Type:TypeErrorException Value:
>
> 'function' object has no attribute '__getitem__'
>
> Exception Location:C:\Python27\Scripts\news\news\urls.py in ,
> line 8Python Executable:C:\Python27\python.exePython Version:2.7.9
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/342e437d-0eb4-41c3-baec-7e1d2787d887%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWH%3DgDfZ4EEFhjF5U0BfzBHyAthGWy3pm9CrEMSCkeqwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Message from David about views

2015-03-16 Thread Daniele Procida
Yesterday I accidentally rejected a message from a new user called David about 
views.

Unfortunately Google Groups gives us no logs of any kind, so I have no way of 
correcting the error or contacting David.

So David: if you're reading this, please try sending your message again, and 
sorry for the mistake.

Daniele

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150316082335.8822958%40mail.wservices.ch.
For more options, visit https://groups.google.com/d/optout.


Django multiple application with common users

2015-03-16 Thread Domagoj Kovač
Hi everybody,

I have a question. I am working on a series of small home apps for me and 
my family. 
I have application like:

   - cost management - application where i track all my income and costs
   - market research - application that i use for market researc
   - food management - application where i plan my meals

List will probably continue.

I want to have users shared between this applications, what would be the 
best approach to this?

I would like to have separate databases for every application including 
user management.

Best,
Domagoj

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3f7487f-2089-4560-8100-b82d0b7989f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.7 issue

2015-03-16 Thread Piyush Sharma
i was following the django 1.7 documentation and having issue in creating 
an app part 3
please help

TypeError at /polls/34/results/

'function' object has no attribute '__getitem__'

Request Method:GETRequest URL:http://127.0.0.1:8000/polls/34/results/Django 
Version:1.9Exception Type:TypeErrorException Value:

'function' object has no attribute '__getitem__'

Exception Location:C:\Python27\Scripts\news\news\urls.py in , line 
8Python 
Executable:C:\Python27\python.exePython Version:2.7.9

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/342e437d-0eb4-41c3-baec-7e1d2787d887%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.