Re: question about template engine jinja

2011-08-13 Thread Phang Mulianto
Thanks Reinout for the response,

i read the doc , just in time compilation to Python bytecode is used in
jinja..

is django default template also do this ?

which i see the reason why jinja faster.

mulianto

On Sun, Aug 14, 2011 at 6:19 AM, Reinout van Rees wrote:

> On 13-08-11 14:41, Phang Mulianto wrote:
>
>> and i read about jinja template, why it can be faster than django
>> template engine ?
>>
>
> Jinja basically uses django's syntax, but (if my memory is correct) it
> allows you to do more things than django's templates allows you to.
>
> Is it faster? I thought there were people trying to bring jinja into django
> as it is good and fast. If it is faster, it would probably be because people
> are making a dedicated effort at making it fast. Multiple projects are using
> jinja, so there's a good chance that the combined effort *could* make it
> faster.
>
> I don't know from experience, though, *if* it is faster.
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
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: Connecting to the django app from outside the server

2011-08-13 Thread Landy Chapman
>The application runs  when I remote into the server and run
> the web pages with localhost on the 8000 port.
> How do I connect to this web page for demonstration purposes when I am
> not remoting into the virtual server.
>
> I tried just replacing localhost with the IP address with port 8000
> and that does not work.

What command do you use to start the server?  If your IP was
33.215.11.2 it would look like:
python manage.py runserver 33.215.11.2:8000

> Do I need to open up port 8000 ?
Yes  Or figure out what port is already open and use that... Also
check firewall status.

> Is it possibly a permissions issue.
Most likely not.

> I am presuming that I can continue to use the django light weight web
> server for demonstration purposes.
Yes

-- 
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: template newlines

2011-08-13 Thread Python_Junkie
I think that if you performed the logic to determine if there actually
is something in the interest for that row in the view and
then only pass those components from the view, and not in the template
then your problem goes away.



On Aug 13, 8:53 pm, CrabbyPete  wrote:
> I'm using the django template system for format a text email. I send
> it a dictionary and it formats the output. The problem is that it
> inserts lots of newlines
>
> Here is the template, and reports is a dictionary that contains an
> event and a dictionary of interests
>
> Weekly Contact List For {{date}}
> {% for event, interests in report.items %}
>     {% if interests|length > 0 %}
>         {{event}}
>         {% for interest, value in interests.items %}
>             {{ value }} {% if value == 1 %} lead {% else %} leads {%
> endif %} for {{ interest }}
>         {% endfor %}
>     {% endif %}
> {% endfor %}
>
> Is there a way for it just to print the lines without adding all the
> extra blank lines when interests = 0?

-- 
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.



Connecting to the django app from outside the server

2011-08-13 Thread Python_Junkie
I have placed my django application on the virtual server from go
daddy.  The application runs  when I remote into the server and run
the web pages with localhost on the 8000 port.

How do I connect to this web page for demonstration purposes when I am
not remoting into the virtual server.

I tried just replacing localhost with the IP address with port 8000
and that does not work.

Do I need to open up port 8000 ?

Is it possibly a permissions issue.

I am presuming that I can continue to use the django light weight web
server for demonstration purposes.

Any assistance would be appreciated.


Thanks in advance

-- 
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.



template newlines

2011-08-13 Thread CrabbyPete
I'm using the django template system for format a text email. I send
it a dictionary and it formats the output. The problem is that it
inserts lots of newlines

Here is the template, and reports is a dictionary that contains an
event and a dictionary of interests

Weekly Contact List For {{date}}
{% for event, interests in report.items %}
{% if interests|length > 0 %}
{{event}}
{% for interest, value in interests.items %}
{{ value }} {% if value == 1 %} lead {% else %} leads {%
endif %} for {{ interest }}
{% endfor %}
{% endif %}
{% endfor %}

Is there a way for it just to print the lines without adding all the
extra blank lines when interests = 0?

-- 
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: Ynt: Re: Could not parse the remainder: |slice

2011-08-13 Thread Chintan Tank
*can you paste the entire error stacktrace? use http://dpaste.de/ or
equivalent to share it.
*
On Sat, Aug 13, 2011 at 8:01 PM, electrocoder wrote:

> my syntax is   *{% autoescape off %} {{ myobje.mypage|slice:":150" }} {%
> endautoescape %}*
> *
> *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/UpRrFOATAeIJ.
> 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.
>



-- 
Thanks & Regards,

Chintan Tank
Software Developer
School of Library & Information Science
Indiana University, Bloomington.

http://www.cs.indiana.edu/~cdtank/

-- 
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.



Ynt: Re: Could not parse the remainder: |slice

2011-08-13 Thread electrocoder
my syntax is   *{% autoescape off %} {{ myobje.mypage|slice:":150" }} {% 
endautoescape %}*
*
*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/UpRrFOATAeIJ.
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: Could not parse the remainder: |slice

2011-08-13 Thread Chintan Tank
are you sure you used proper syntax?

{{ sliceable|slice:":2" }}


https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#slice

On Sat, Aug 13, 2011 at 7:28 PM, electrocoder wrote:

> Blog on my local PC with "Could not parse the remainder: | Slice" I get the
> error message. How can I fix.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/AeqglbCy8ZIJ.
> 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.
>



-- 
Thanks & Regards,

Chintan Tank
Software Developer
School of Library & Information Science
Indiana University, Bloomington.

http://www.cs.indiana.edu/~cdtank/

-- 
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.



Could not parse the remainder: |slice

2011-08-13 Thread electrocoder
Blog on my local PC with "Could not parse the remainder: | Slice" I get the 
error message. How can I fix.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/AeqglbCy8ZIJ.
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: question about template engine jinja

2011-08-13 Thread Reinout van Rees

On 13-08-11 14:41, Phang Mulianto wrote:

and i read about jinja template, why it can be faster than django
template engine ?


Jinja basically uses django's syntax, but (if my memory is correct) it 
allows you to do more things than django's templates allows you to.


Is it faster? I thought there were people trying to bring jinja into 
django as it is good and fast. If it is faster, it would probably be 
because people are making a dedicated effort at making it fast. Multiple 
projects are using jinja, so there's a good chance that the combined 
effort *could* make it faster.


I don't know from experience, though, *if* it is faster.


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ManyRelatedManager.add() acting funny?

2011-08-13 Thread Jeff Blaine
Nevermind.  I get it.  'tags' has another field, description, which is what 
the extra u'' is for.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jnvlX18nWtwJ.
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.



ManyRelatedManager.add() acting funny?

2011-08-13 Thread Jeff Blaine
What happened here?  Do I not understand .add()?  I would have expected to 
see
[(u'rcf_clients',)] not [(u'rcf_clients', u'')]

>>> print d.tags.values_list()
[]
>>> d.tags.add('rcf_clients')
>>> d.save()
>>> print d.tags.values_list()
[(u'rcf_clients', u'')]
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/UD_riTfXZXsJ.
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.



inherit adminSite and get 404 when click model

2011-08-13 Thread brian
I have multiple models.  I'm trying to create an admin site for all
models (using admin.site) and an admin site for each model (by
inheriting from AdminSite).

The admin.site is working as expected.  The AdminSite will load the
app as normal but when I click on the model, I get a 404 error.

I'm following very closely 'How to have 2 different admin sites in a
Django project'(http://stackoverflow.com/questions/3206856/how-to-
have-2-different-admin-sites-in-a-django-project).

Here is the pseudo code of what I'm doing:
model.py
---
class myBaseModel(models.Model):
first_name   = models.CharField( max_length=100)

class myModel1( myBaseModel ):
class Meta(myBaseModel .Meta):
verbose_name = 'my model 1 info'

class myModel2( myBaseModel ):
class Meta(myBaseModel .Meta):
verbose_name = 'my model 2 info'
---

admin.py
---
admin.site.register( myModel1)
admin.site.register(myModel2)
---

myModel1Admin.py
---
class myModel1Site(AdminSite):
pass

adminModel1 = myModel1Site()
adminModel1.register( myModel1 )
---

url.py
---
from django.contrib import admin
admin.autodiscover()

from .myModel1Admin import adminModel1

urlpatterns = patterns('',

url(r'^masterAdmin/', include(admin.site.urls)),
url(r'^model1Admin/$', include(adminModel1.urls)),
)
---

The url   is working as expected.  When I go to
 the page looks as I would expect but when I click on
'my model 1 info' I get a 404 error.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How do I apply a filter in a custom template tag?

2011-08-13 Thread Doug Ballance
I'd like to see you model structure, but based on what I think it is:

class Entry(model.Model):
categories=models.ManyToManyField(Category)

class Content(models.Model):
entry=models.ForeignKey(Entry)

You have a Content Instance
You want to see other entries belonging to one or more of the
categories for that Content instances Entry instance

You could do a custom template tag like yours:

{% get_related_entries content_instance.entry  as related_entries %}

That tag would do something like the following :

#fetching primary key only since we don't need the whole thing
category_ids=content_instance.entry.categories.values("pk")
context['related_entries']=Entry.objects.filter(pk__in=category_ids)

That would work, but my choice would probably be to add a method to
your Entry class.

class Entry(models.Model):
categories=models.ManyToManyField(Category)

def related_entries(self,**filters):
return
Entry.objects.filter(pk__in=self.categories.filter(**filters).values("pk"))

That way you don't need a tag at all.  Just do:

{% for related_entry in content.entry.related_entries %}
...
{% endfor %}

-- 
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: same form model with separate admins and data

2011-08-13 Thread brian
Hi  Landy,

I'm seeing separate database tables created.  The tables that are
created are _.  I've tested in the latest
Django, python 2.7 and on windows with a sqlite3 database.

Thank you for your help  You have given me a lot of great ideas.

Brian

-- 
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: Redisplay form with different field value?

2011-08-13 Thread Jonas H.

On 08/13/2011 05:00 PM, Karen Tracey wrote:

Plus, afaik, fields can not access form instances so this code would have
to live in the form subclass -- not practical in my use case.


Where I have done this (reluctantly) has been in the form (or perhaps it was
the field) clean method, where self is the form. I am not sure why in your
case you believe that to be not practical.


The field's clean method does not have access to the form; but the 
value-changing logic should go into the field code because I want to 
re-use the field on multiple forms.  Well, I guess that's just not 
possible with Django's form framework. I'll have to find some workarounds.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using South HOWTO create an instance of a model from a different app during DataMigration

2011-08-13 Thread Chintan Tank
*UPDATE:*
*
*
I was able to resolve the problem by looking up the contenttype manually so,

ct = orm['contenttypes.ContentType'].*objects.*get(app_label="blog",
model="Post")

Thanks Tom & Andrew (at south user listserv) for helping with this.


On Sat, Aug 13, 2011 at 1:14 PM, Chintan Tank  wrote:

> Tom,
> I tried looking up the content_type and then using it, but it still throws
> errors.
>
> *1. I tried*
>
> ct = ContentType.objects.get_for_model(Post)
> chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)
>
> *It gave error,*
>
> ValueError: Cannot assign "": "Chapter.content_type"
> must be a "ContentType" instance.
>
> *2. I tried*
>
> ct =
> orm['contenttypes.ContentType'].objects.get_for_model(orm['blog.Post'])
> chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)
>
> *It gave error,*
>
> AttributeError: 'Manager' object has no attribute 'get_for_model'
>
> *3. I tried*
>
> ct = orm['contenttypes.ContentType'].get(app_label="blog", model="Post")
>
> # I also tried setting model in the above get method to be lowercase.
>
> chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)
>
> *It gave error,*
>
> AttributeError: type object 'ContentType' has no attribute 'get'
>
> *BTW*, I am using *South 0.7.3.*
>
> Thanks again for helping.
>
> On Mon, Aug 8, 2011 at 10:25 AM, Tom Evans wrote:
>
>> On Mon, Aug 8, 2011 at 3:06 PM, Chintan Tank 
>> wrote:
>> > (sorry for duplicate I have already posted on stackoverflow.com >
>> > http://goo.gl/I7Jj6 )
>> >
>> > I need to perform a datamigration of a model Answer in app Question.
>> > In that script there is a dependency such that I need to create an
>> > instance of a model Chapter which is in the app Journal. So, I coded
>> > it as follows:
>> >
>> > def forwards(self, orm):
>> >for answer_object in orm.Answer.objects.all():
>> >
>> >#This Works.
>> >blog, is_created =
>> > orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:
>> > 100])
>> >blog.save()
>> >
>> >#This DOES NOT work
>> >chapter, is_created =
>> > orm['journal.Chapter'].objects.get_or_create(content_object=blog)
>> >chapter.save()
>> >#cleanup task, not relevant to this question below
>> >answer_object.chapter_ptr = chapter
>> >answer_object.save()
>> >
>> >
>> >
>> > But as expected this throws an error on "
>> > orm['journal.Chapter'].objects.get_or_create(content_object=blog)"
>> > saying that > django.core.exceptions.FieldError: Cannot resolve
>> > keyword 'content_object' into field.
>> >
>> > This is presumably due to content_object being a GenericForeignKey so
>> > some operations are not allowed. But I also tried other alternatives
>> > for creating the "chapter" object like,
>> >
>> > chapter = orm['journal.Chapter'](content_object=blog)
>> > ERROR > TypeError: 'content_object' is an invalid keyword argument for
>> > this function
>> >
>> > and
>> >
>> > chapter = orm.journal.Chapter(content_object=blog)
>> > ERROR > AttributeError: The model 'journal' from the app 'questions'
>> > is not available in this migration. (Did you use orm.ModelName, not
>> > orm['app.ModelName']?)
>> >
>> > So since my earlier approach was failing I tried a new tact. The model
>> > whose instantiation was failing in my code above i.e. Chapter in the
>> > Journal app, I decided to create a datamigration for that instead. I
>> > also made sure to --freeze the models I am referring to in the
>> > forwards definition. Now this should have been straight forward, I
>> > would think. I have my forward code as follows -
>> >
>> > def forwards(self, orm):
>> >
>> >for answer_object in orm['questions.Answer'].objects.all():
>> >
>> >#Works, AGAIN!
>> >blog, is_created =
>> > orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:
>> > 100])
>> >blog.save()
>> >
>> ># DOES NOT WORK, AGAIN!
>> >chapter = orm.Chapter(rank=1, content_object=blog)
>> >chapter.save()
>> >
>> >
>> > I would have thought that now since I am creating instance of a model
>> > (Chapter) which exists in the subject app (Journal) everything should
>> > have worked out. But i am getting the same error > TypeError:
>> > 'content_object' is an invalid keyword argument for this function.
>> >
>> > It fails at the same point, namely, "content_object". I will post
>> > below the model definition if that might help.
>> >
>> > class Chapter(models.Model):
>> >
>> >rank = models.IntegerField()
>> >
>> >content_type = models.ForeignKey(ContentType)
>> >object_id = models.PositiveIntegerField()
>> >content_object = generic.GenericForeignKey()
>> >
>> > Also all the models being touched in these forwards methods, namely -
>> > blog, chapter, questions; are fully defined in the 00n_*.py files
>> > created by South's schemamigration.
>> >
>>
>> content_object isn't a 'real' field, it is some magic applied to the
>> ORM and your model. The real fields are o

Re: Using South HOWTO create an instance of a model from a different app during DataMigration

2011-08-13 Thread Chintan Tank
Tom,
I tried looking up the content_type and then using it, but it still throws
errors.

*1. I tried*

ct = ContentType.objects.get_for_model(Post)
chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)

*It gave error,*

ValueError: Cannot assign "": "Chapter.content_type" must
be a "ContentType" instance.

*2. I tried*

ct = orm['contenttypes.ContentType'].objects.get_for_model(orm['blog.Post'])
chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)

*It gave error,*

AttributeError: 'Manager' object has no attribute 'get_for_model'

*3. I tried*

ct = orm['contenttypes.ContentType'].get(app_label="blog", model="Post")

# I also tried setting model in the above get method to be lowercase.

chapter = orm.Chapter(rank=1, content_type=ct, object_id=blog.id)

*It gave error,*

AttributeError: type object 'ContentType' has no attribute 'get'

*BTW*, I am using *South 0.7.3.*

Thanks again for helping.

On Mon, Aug 8, 2011 at 10:25 AM, Tom Evans  wrote:

> On Mon, Aug 8, 2011 at 3:06 PM, Chintan Tank 
> wrote:
> > (sorry for duplicate I have already posted on stackoverflow.com >
> > http://goo.gl/I7Jj6 )
> >
> > I need to perform a datamigration of a model Answer in app Question.
> > In that script there is a dependency such that I need to create an
> > instance of a model Chapter which is in the app Journal. So, I coded
> > it as follows:
> >
> > def forwards(self, orm):
> >for answer_object in orm.Answer.objects.all():
> >
> >#This Works.
> >blog, is_created =
> > orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:
> > 100])
> >blog.save()
> >
> >#This DOES NOT work
> >chapter, is_created =
> > orm['journal.Chapter'].objects.get_or_create(content_object=blog)
> >chapter.save()
> >#cleanup task, not relevant to this question below
> >answer_object.chapter_ptr = chapter
> >answer_object.save()
> >
> >
> >
> > But as expected this throws an error on "
> > orm['journal.Chapter'].objects.get_or_create(content_object=blog)"
> > saying that > django.core.exceptions.FieldError: Cannot resolve
> > keyword 'content_object' into field.
> >
> > This is presumably due to content_object being a GenericForeignKey so
> > some operations are not allowed. But I also tried other alternatives
> > for creating the "chapter" object like,
> >
> > chapter = orm['journal.Chapter'](content_object=blog)
> > ERROR > TypeError: 'content_object' is an invalid keyword argument for
> > this function
> >
> > and
> >
> > chapter = orm.journal.Chapter(content_object=blog)
> > ERROR > AttributeError: The model 'journal' from the app 'questions'
> > is not available in this migration. (Did you use orm.ModelName, not
> > orm['app.ModelName']?)
> >
> > So since my earlier approach was failing I tried a new tact. The model
> > whose instantiation was failing in my code above i.e. Chapter in the
> > Journal app, I decided to create a datamigration for that instead. I
> > also made sure to --freeze the models I am referring to in the
> > forwards definition. Now this should have been straight forward, I
> > would think. I have my forward code as follows -
> >
> > def forwards(self, orm):
> >
> >for answer_object in orm['questions.Answer'].objects.all():
> >
> >#Works, AGAIN!
> >blog, is_created =
> > orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:
> > 100])
> >blog.save()
> >
> ># DOES NOT WORK, AGAIN!
> >chapter = orm.Chapter(rank=1, content_object=blog)
> >chapter.save()
> >
> >
> > I would have thought that now since I am creating instance of a model
> > (Chapter) which exists in the subject app (Journal) everything should
> > have worked out. But i am getting the same error > TypeError:
> > 'content_object' is an invalid keyword argument for this function.
> >
> > It fails at the same point, namely, "content_object". I will post
> > below the model definition if that might help.
> >
> > class Chapter(models.Model):
> >
> >rank = models.IntegerField()
> >
> >content_type = models.ForeignKey(ContentType)
> >object_id = models.PositiveIntegerField()
> >content_object = generic.GenericForeignKey()
> >
> > Also all the models being touched in these forwards methods, namely -
> > blog, chapter, questions; are fully defined in the 00n_*.py files
> > created by South's schemamigration.
> >
>
> content_object isn't a 'real' field, it is some magic applied to the
> ORM and your model. The real fields are object_id and content type, so
> use them directly.
>
> Use ContentType.objects.get_for_model() [1] to get the content type.
>
> [1]
> https://docs.djangoproject.com/en/1.3/ref/contrib/contenttypes/#django.contrib.contenttypes.models.ContentTypeManager.get_for_model
>
> Cheers
>
> Tom
>
> --
> 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

How do I apply a filter in a custom template tag?

2011-08-13 Thread Josh
I'm trying to retrieve a m2m relation from a blog entry. It should give a 
list of entries with the same categories. Below works when I work in the 
shell.

from content.models import Entry
qs = Entry.objects.all()
obj = qs[0]
related = Entry.objects.filter(categories=obj.categories.all())


The obj simulates a single Entry in a template for use in the shell.

I'm trying to put this in a custom template tag, so a list of related 
entries can be shown with a blog entry. I cooked up the following:

{% load content_tags %}
{% get_related_entries content.entry from*object.categories.all
* as related_entries %}
{% for item in related_entries %}
{{ 
item.title }}
{% endfor %}

This isn't working though. I'm not sure how to do this, even after 
(re)reading Django-books and documentation. When I don't apply a filter and 
the following in the Node render() works:

context[self.varname] = self.model.objects.all()

Obviously I get a list of all entries, without any filter. I'm pretty sure 
it has to do with the object.categories.all (which is a list of all 
categories) in my template tag and the use of it in the parser/Node. How can 
I achieve this? 

PS:
I didn't include any of my (now many) variants of code I tried on purpose. I 
suspect I'm following an entirely wrong approach and don't want to focus 
attention at wrong code. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/4Jzt29ZtGywJ.
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: Displaying form from app in other view.

2011-08-13 Thread Karen Tracey
On Sat, Aug 13, 2011 at 8:18 AM, Petey  wrote:

> I have a login/logout application - it works within its defined view
> (login/views.py) and templates (templates/login/index.html).
>
> I want to port this app so it will be displayed in base.html. The main
> problem is that I don't really know how to import this app correctly to
> base.html.
>
>
FYI the terminology of "importing" an app into a template is a bit
confused/confusing, we don't, in Django, import apps into templates. There
is no concept in Django that quite matches those words, although loading
custom template tags from an application comes close.

If I use code pasted below it does only display correctly on localhost/login
> page instead of localhost. On pages containing other forms it will display
> other form instead of my login form.
>
> How can I import login form to global template (base.html) and how I can
> differentiate forms from different apps?
>

Your template code fragment uses a context variable named "form". That
template code works for your login/logout pages presumably because your
login.views.index and login.views.logout_view supply the correct "form"
variable in the context used to render the template.

Including that fragment in your base.html file means that you are expecting
every view that renders a template which ultimately extends from base.html
to provide a context variable named "form" that is the login/logout form.
That's not working because apparently you've got some other views that also
use this name "form" for some other kind of form, and that other form is
what you see rendered in this template fragment instead. If you have views
that provide no variable named "form" in the context, then this bit of
template code will show no form at all.

Essentially by including this HTML fragment in your base template you have
put the template-side of your login/logout app into all your templates, but
that does not accomplish the necessary piece of also incorporating the
Python code side of populating the template context with the correct
variables for the template side.

What you probably want to be doing is creating a custom template tag (to be
specific, probably an inclusion tag) in your login/logout app. You can then
use that template tag in your base template to render the login/logout form.
See the docs here:
https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/

Karen
-- 
http://tracey.org/kmt/

-- 
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: Redisplay form with different field value?

2011-08-13 Thread Karen Tracey
On Sat, Aug 13, 2011 at 4:41 AM, Jonas H.  wrote:

> On 08/13/2011 06:33 AM, Karen Tracey wrote:
>
>> On Thu, Aug 11, 2011 at 7:03 AM, Jonas H.  wrote:
>>
>>  On 08/09/2011 12:45 AM, Jonas H. wrote:
>>>
>>>  Hello list!

 Is there any way to use a different value for a field when re-displaying
 a form? I.e. if a user enters '42' into an IntegerField but made the
 other fields not validate, how could that IntegerField be re-displayed
 with '43'?


  Change the value in the form's data dictionary.
>>
>> Thanks Karen but that's not easily possible because that's an immutable
> QueryDict.


Because you've past request.POST directly to the form as the data dict. You
can instead pass a copy when instantiating the form, then you will be able
to modify the copy.


> Plus, afaik, fields can not access form instances so this code would have
> to live in the form subclass -- not practical in my use case.
>
>
Where I have done this (reluctantly) has been in the form (or perhaps it was
the field) clean method, where self is the form. I am not sure why in your
case you believe that to be not practical.

If you want to change the value displayed for a field in the form, you'll
either need to change the value in the data dictionary or change the guts of
how the form displays itself. The former is the easier choice, imo.

Karen
-- 
http://tracey.org/kmt/

-- 
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: Showing per-user information in admin

2011-08-13 Thread Isaac XxX
Thanks a lot derek! It's just all I was looking for :)

On Fri, Aug 12, 2011 at 4:03 PM, Derek  wrote:

> On Aug 12, 1:29 pm, Isaac  wrote:
> > Hi dudes,
> >
> > I'm having trouble at finding a solution for my problem. All I want to
> > do is tune django admin to show, for a given user an a given model, only
> > instance related to that user.
> >
> > my pseudocode
> >
> > class User
> >  ...
> > class A
> >  foreign_key User
> >
> > A1 related to User1
> > A2 related to User1
> > A3 related to User2
> >
> > then, I want that User1 was only be able to see A1 and A2, and User2 was
> > only be able to see A3.
> > I know that I can create filters to allow user to filter instances, but
> > all I want is not to allow user to make that decision, it will be only
> > able to see what its related.
> >
> > Any clue about how to use admin in this way?
> >
> > Thanks in advance
>
> See:
>
> http://lincolnloop.com/static/slides/2010-djangocon/customizing-the-admin.html#slide45
> for an example of this. Note how the default queryset is now filtered
> per user.
>
> --
> 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.
>
>

-- 
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.



question about template engine jinja

2011-08-13 Thread Phang Mulianto
Hi all,

i need sugestion about templating.

if i use many include in django template, is it a good practice and effect
the load performance of the application ?

and i read about jinja template, why it can be faster than django template
engine ?

how many of you prefer jinja, and why ?

thanks all.

-- 
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.



Displaying form from app in other view.

2011-08-13 Thread Petey
I have a login/logout application - it works within its defined view 
(login/views.py) and templates (templates/login/index.html).

I want to port this app so it will be displayed in base.html. The main 
problem is that I don't really know how to import this app correctly to 
base.html.

If I use code pasted below it does only display correctly on localhost/login 
page instead of localhost. On pages containing other forms it will display 
other form instead of my login form.

How can I import login form to global template (base.html) and how I can 
differentiate forms from different apps?

{% csrf_token %}
{{ form.as_p }}



urls:
(r'^login/$', 'login.views.index'),
(r'^logout/$', 'login.views.logout_view'),

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uP90OcnzfFQJ.
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: Redisplay form with different field value?

2011-08-13 Thread Jonas H.

On 08/13/2011 06:33 AM, Karen Tracey wrote:

On Thu, Aug 11, 2011 at 7:03 AM, Jonas H.  wrote:


On 08/09/2011 12:45 AM, Jonas H. wrote:


Hello list!

Is there any way to use a different value for a field when re-displaying
a form? I.e. if a user enters '42' into an IntegerField but made the
other fields not validate, how could that IntegerField be re-displayed
with '43'?



Change the value in the form's data dictionary.

Karen


Thanks Karen but that's not easily possible because that's an immutable 
QueryDict. Plus, afaik, fields can not access form instances so this 
code would have to live in the form subclass -- not practical in my use 
case.


--
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.