Re: How to get topics user replied?

2011-10-06 Thread David.D
It work: Topic.objects.filter(pk__in=[comment.content_object.pk for comment in Comment.objects.filter(user__exact = request.user)]) On Oct 6, 9:13 pm, "David.D" <dengyuanzh...@gmail.com> wrote: > class Topic(models.Model): >     title = models.CharField(max_

How to get topics user replied?

2011-10-06 Thread David.D
class Topic(models.Model): title = models.CharField(max_length=100) body = models.TextField(_('body'), max_length=TEXT_MAX_LENGTH) user = models.ForeignKey(User, related_name='topic_user', editable=False) ... I use 'django.contrib.comments' to reply a topic. How to get topics

[django-ratings]Problem if my id key is not an integer.

2011-04-04 Thread David.D
My models all extend my custom model class which id is a CharField not a PositiveIntegerField like the Django's default django.db.models.Model . So, when I try to add a vote, I got a ValueError: invalid literal for int() with base 10: 'my-char-id' Because the object_id field is defined like this

[Template Filter] How to get rid of the extra 0 after the decimal point?

2011-04-04 Thread David.D
I hope to get this result: 34.000 --> 34 34.100 --> 34.1 34.120 --> 34.12 34.123 --> 34.123 But the output of floatformat filter is like this: 34.000|floatformat:"-3" --> 34 34.100|floatformat:"-3" --> 34.100 34.120|floatformat:"-3" --> 34.120 34.123|floatformat:"-3" --> 34.123 Thank

Re: Is it possible for template to use context variable as list index?

2010-09-14 Thread David.D
desthuilliers <bruno.desthuilli...@gmail.com> wrote: > On 13 sep, 18:20, "David.D" <dengyuanzh...@gmail.com> wrote: > > > In my template: > > > This is ok: > > {{ my_list.2 }} > > > But it doesn't work: > > {{ my_list.index }} > > &

Is it possible for template to use context variable as list index?

2010-09-13 Thread David.D
In my template: This is ok: {{ my_list.2 }} But it doesn't work: {{ my_list.index }} index is a context variable (index=2) Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: How to get the model name of an object in template?

2010-08-05 Thread David.D
; along the way. > > - Paulo > > On Thu, Aug 5, 2010 at 8:52 AM, Daniel Roseman <dan...@roseman.org.uk>wrote: > > > > > On Aug 4, 7:27 pm, "David.D" <dengyuanzh...@gmail.com> wrote: > > > I just wonder if there's some way requires

Re: How to get the model name of an object in template?

2010-08-04 Thread David.D
> @register.filter > def class_name(value): >     return value.__class__.__name__ > > On Aug 4, 11:13 am, "David.D" <dengyuanzh...@gmail.com> wrote: > > > > > There's no django's built-in way? > > > On Aug 4, 10:37 pm, Scott Gould <zi

Re: How to get the model name of an object in template?

2010-08-04 Thread David.D
There's no django's built-in way? On Aug 4, 10:37 pm, Scott Gould <zinck...@gmail.com> wrote: > How about writing a simple template tag that takes an object and > returns object.__class__.__name__? > > On Aug 4, 10:20 am, "David.D" <dengyuanzh...@gmail.com> wr

How to get the model name of an object in template?

2010-08-04 Thread David.D
I did it by adding this to my models: def get_model_name(self): return self.__class__.__name__ And it works But I don't want to define the 'get_model_name' method in my model. Is there a built-in way? Thanks. -- You received this message because you are

Re: How to get a model instance's field var while field's name is a string in template?

2010-07-04 Thread David.D
It work! Thank you. On Jul 4, 9:30 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Jul 4, 12:01 pm, "David.D" <dengyuanzh...@gmail.com> wrote: > > > i mean > > i have a model instance m, and m has a field fd. > > so i can wrote like this in te

How to get a model instance's field var while field's name is a string in template?

2010-07-04 Thread David.D
i mean i have a model instance m, and m has a field fd. so i can wrote like this in template {{ m.fd }} but, when i got a string s = "fd" how could i do the same as above? thanks for any help... -- You received this message because you are subscribed to the Google Groups "Django users"

Re: How to get comment_count in view?

2008-11-12 Thread David.D
) > > #get comment for instance > Comment.objects.for_model(Post.objects.get(id=1)).count() > > 2008/11/2 David.D <[EMAIL PROTECTED]> > > > > > I can get comment_count in templates: > > > {% get_comment_count for object as comment_count %} > > > But how to get it in my

How to get comment_count in view?

2008-11-02 Thread David.D
I can get comment_count in templates: {% get_comment_count for object as comment_count %} But how to get it in my view? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group,

Re: How to execute function dynamically?

2008-06-09 Thread David.D
I made a mistake! I use 'extra_context=locals()' in my generic view. Now no problem. Thanks very much. On Jun 9, 12:34 pm, "David.D" <[EMAIL PROTECTED]> wrote: > If there are no parameters, it works fine in django. > For example: > > def functionA(): # no para

Re: How to execute function dynamically?

2008-06-08 Thread David.D
(indata) func() # no parameter This will be fine. But it's not enough for my needs. Thank you. On Jun 8, 2:00 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > 2008/6/8 David.D <[EMAIL PROTECTED]>: > > > > > > > > > view.py > >

How to execute function dynamically?

2008-06-07 Thread David.D
view.py = def functionA(request): ... return ... def functionB(request): return ... callDict = {'functionA': functionA, 'functionB':functionB,...} def myview(request, indata): func = callDict.get(indata) func(request) indata is a

Re: How to import ModelForm Dynamically?

2008-06-02 Thread David.D
I worked! Thank you very much. On Jun 3, 1:15 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On Mon, Jun 2, 2008 at 9:06 AM, David.D <[EMAIL PROTECTED]> wrote: > > views.py > > == > > def model_form(request, model_name): > >    form_class

Re: How to import ModelForm Dynamically?

2008-06-02 Thread David.D
Thanks. But I got TypeError at /products/ModelA/ 'module' object is not callable On Jun 3, 1:12 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Mon, Jun 2, 2008 at 10:06 AM, David.D <[EMAIL PROTECTED]> wrote: > > > In my "products" app: >

How to import ModelForm Dynamically?

2008-06-02 Thread David.D
In my "products" app: models.py class ModelA(models.Model): ... class ModelB(models.Model): ... class ModelC(models.Model): ... ... class ModelAForm(ModelForm): class Meta: model = ModelA class ModelBForm(ModelForm): class Meta: model = ModelB

Re: How to get child model' name from parent obj in Multi-table inheritance

2008-05-30 Thread David.D
If there are lots of child model, use hasattr() or capture exception will not be good? "add a type field to Person() and overide the save fields on Man and Woman to set the type field correctly. " will be better? On May 30, 10:38 pm, David Zhou <[EMAIL PROTECTED]> wrote: > On May 30, 2008, at