How to compare two different types in templates using ifequal

2009-03-02 Thread eli

Hi,

I have a problem:

Python:
week = [1, 2, 3, 4, 5, 6, 7]
# There are only two records in objects_list with date_start field =
01.01.2000 and 02.01.2000
objects_list = SomeModel.objects.all()

Template:

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j" day %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output: none. So, trying to set the same types:

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|floatformat day|floatformat %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output:
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...

It should be only two times: I'm in...

Another way:

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|floatformat day %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output: none, and the last one

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|stringformat:"s" day|
stringformat:"s" %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output:
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...

I have no idea where is the bug...

Thanks for help.

regards.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



How to compare two different types in templates using ifequal

2009-03-02 Thread eli

Hi,

I have a problem (Django 1.1. alpha SVN):

Python:
week = [1, 2, 3, 4, 5, 6, 7]
# There are only two records in objects_list with date_start field =
01.01.2000 and 02.01.2000
objects_list = SomeModel.objects.all()

Template:

{% for day in week %}
  {% for e in objects_list %}
{#  date:"j" - return day of the month without leading zeros. #}
{% ifequal e.date_start|date:"j" day %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}


Output: none. So, trying to set the same types:

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|floatformat day|floatformat %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output:
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...

It should be only two times: I'm in...

Another way:

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|floatformat day %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output: none, and the last one

{% for day in week %}
  {% for e in objects_list %}
{% ifequal e.date_start|date:"j"|stringformat:"s" day|
stringformat:"s" %}
   I'm in...
{% endifequal %}
  {% endfor %}
{% endfor %}

Output:
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...
I'm in...

I have no idea where is the bug...

Thanks for help.

regards.

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



Django annotate with Count() problem

2009-03-20 Thread eli

Hi,

I have a problem with Django Orm annotate method..

My models (application: app):

class File(models.Model):
  name = models.CharField(max_length=255)
  file = MyFileField(upload_to=...)

class Visit(models.Model):
  file = models.ForeignKey(File)

class Comment(models.Model):
  file = models.ForeignKey(File)

#-

>> e = 
>> File.objects.annotate(comment_cnt=Count('comment')).order_by('comment_cnt')
>> print e[0].comment_cnt
>> 3 # ok

>> e = File.objects.annotate(visit_cnt=Count('visit')).order_by('visit_cnt')
>> print e[0].visit_cnt
>> 9 # ok

>> e = File.objects.annotate(comment_cnt=Count('comment'), 
>> visit_cnt=Count('visit')).order_by('comment_cnt')
>> print e[0].visit_cnt
>> 27 #  <- ?? (3*9?) WRONG!
>> print e[0].comment_cnt
>> 27 #  <- ?? (3*9?) WRONG!

SQL Query dump:

(...), COUNT("app_visit"."id") AS "visit_cnt", COUNT
("app_comment"."id") AS "comment_cnt" FROM "app_file" LEFT OUTER JOIN
"app_visit" ON ("app_file"."id" = "app_visit"."file_id") LEFT OUTER
JOIN "app_comment" ON ("app_file"."id" = "app_comment"."file_id")
GROUP BY (...)

What is wrong? Why, when I'm using more than one Count() function in
annotate, I've got multiply results?

Thanks for help..

regards.

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



Re: Django annotate with Count() problem

2009-03-20 Thread eli

I'm using latest SVN version of Django (10105 revision)

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



Re: Django annotate with Count() problem

2009-03-20 Thread eli

> Seems like you're seeing this:http://code.djangoproject.com/ticket/10060
Yes, It's a big bug.

> Try to add distinct() to query set.
It's work.. Thanks Alex... distinct is not very fast but it's last way
to fix the problem...

Proper query:
e = File.objects.annotate(comment_cnt=Count('comment', distinct=True),
visit_cnt=Count('visit', distinct=True)).order_by('comment_cnt')

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Problem with Sum() function

2009-03-23 Thread eli

How to pass to the Sum() function (ORM) more than one field?

My problem:

class Model1(models.Model):
name = models.CharField(u'Name', max_length=255)

class Model2(models.Model):
fk1 = models.ForeignKey(Model1, related_name='fk_1')
fk2 = models.ForeignKey(Model1, related_name='fk_2')

I want to sort data by sum of fk1 and fk2 field.

Model1.objects.annotate(myfk1=Count('fk1', distinct=True), myfk2=Count
('fk2', distinct=True)).annotate(my_sum=Sum('myfk1+myfk2')).order_by('-
my_sum')

Thanks for help.

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Problem with Sum() function

2009-03-23 Thread eli

anybody?

On 23 Mar, 16:17, eli  wrote:
> How to pass to the Sum() function (ORM) more than one field?
>
> My problem:
>
> class Model1(models.Model):
>     name = models.CharField(u'Name', max_length=255)
>
> class Model2(models.Model):
>     fk1 = models.ForeignKey(Model1, related_name='fk_1')
>     fk2 = models.ForeignKey(Model1, related_name='fk_2')
>
> I want to sort data by sum of fk1 and fk2 field.
>
> Model1.objects.annotate(myfk1=Count('fk1', distinct=True), myfk2=Count
> ('fk2', distinct=True)).annotate(my_sum=Sum('myfk1+myfk2')).order_by('-
> my_sum')
>
> Thanks for help.
>
> regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django remove value from field with attrs disabled="disabled"

2009-09-05 Thread eli

Hi,

I have problem with Django Forms and field with set attrs to
disabled="disabled"

# forms.py

class EditForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super(EditForm, self).__init__(*args, **kwargs)
self.fields['title'].widget.attrs.update({'readonly':
'readonly', 'disabled': 'disabled'})

class Meta:
model = MyModel
fields = ('title', 'tagline')

# views.py

form = EditForm(request.POST, instance=my_instance)
if form.is_valid():
form.save()

# models.py

class MyModel(models.Model):
title = models.CharField(max_length=120, db_index=True)
tagline = models.TextField(, max_length=500, db_index=True)

And now, Django remove values form field with attrs 'disabled':
'disabled' ("readonly" without "disabled" works fine, but I need
disabled option in my html output). Why Django do that?

Thanks for help.

regards.

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



Re: Django remove value from field with attrs disabled="disabled"

2009-09-06 Thread eli

Thanks for help.

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Custom url in django Django sitemap

2009-09-09 Thread eli

Hi,

How to add custom static url (they are not in database) to Django
Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Custom url in django Django sitemap

2009-09-09 Thread eli

Hi,

Thanks for replay, but I was talking about the django sitemap
framework http://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/ ,
and problem: how to add my custom page (serving by server) to output
(XML) of the django sitemap framework?

regards.

On 9 Wrz, 18:47, Peter Coles  wrote:
> Hi eli,
>
> If you want serve a "static file" (that never changes and doesn't take
> advantage of django's template system) then you shouldn't be serving
> it with django.  You can use django if you really 
> want:http://docs.djangoproject.com/en/dev/howto/static-files/but you're
> better off having your server (like apache) handle it 
> directly:http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1
>
> However, you may want your about-me page to inherit a header and
> footer or other stuff from a base template (if you don't know what I'm
> talking about read 
> this:http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
> ) -- if that's the case, you can use the direct_to_template generic
> view as described here:
>
> http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...
>
> -Peter
>
> On Sep 9, 11:41 am, eli  wrote:
>
> > Hi,
>
> > How to add custom static url (they are not in database) to Django
> > Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html
>
> > regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django-logging in production mode

2009-09-09 Thread eli

Hi,

It's a good idea to logging errors, notices etc using python module
logging in app under production mode (Nginx)?

I know about for ex: sending error:500 emails to admins etc, but
sometimes I want to log errors and lets app go on.

(I'm talking about logging errors to the file, and later sending it
via email using cron)

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: custom tag - render() isn't called

2009-09-11 Thread eli

I have problem when tag is called from for loop in template. It's
called only once (sic!). Why?
--~--~-~--~~~---~--~~
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: Problem with Sum() function

2009-03-27 Thread eli

Thank You.

regards.

On 23 Mar, 23:58, Russell Keith-Magee  wrote:
> On Tue, Mar 24, 2009 at 12:17 AM, eli  wrote:
>
> > How to pass to the Sum() function (ORM) more than one field?
>
> > My problem:
>
> > class Model1(models.Model):
> >    name = models.CharField(u'Name', max_length=255)
>
> > class Model2(models.Model):
> >    fk1 = models.ForeignKey(Model1, related_name='fk_1')
> >    fk2 = models.ForeignKey(Model1, related_name='fk_2')
>
> > I want to sort data by sum of fk1 and fk2 field.
>
> > Model1.objects.annotate(myfk1=Count('fk1', distinct=True), myfk2=Count
> > ('fk2', distinct=True)).annotate(my_sum=Sum('myfk1+myfk2')).order_by('-
> > my_sum')
>
> The first two parts - the annotation of myfk1 and myfk2 is fine - but
> at present, annotation is a purely aggregate activity - you can't
> (currently) annotate an expression that is formed from two fields on
> the same model instance. This is a feature I would like to add at some
> point, but it won't be happening any time soon.
>
> You could do this using an 'extra' clause; i.e., replace the final
> annotate() with:
>
> .extra(select={'my_sum':'myfk1+myfk2'})
>
> The extra clause is used to insert raw SQL into a Django query, so you
> are responsible for choosing column names, etc However, aggregate
> column names are fairly predictable, so you shouldn't hit too many
> problems. Regardless, I strongly advise reading the documentation on
> the extra clause so that you are aware of the issues you may hit.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Form wizard - previous step

2009-04-04 Thread eli

Hi,

What is the best way to add button "previous step" to multi-steps
form ?

Thank You.

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Form wizard - previous step

2009-04-05 Thread eli

anybody ? :-)

regards.

On 4 Kwi, 11:17, eli  wrote:
> Hi,
>
> What is the best way to add button "previous step" to multi-steps
> form ?
>
> Thank You.
>
> regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Form wizard - previous step

2009-04-05 Thread eli

No, I have one view.. My example is similar to that one from Django
tutorial: 
http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/?from=olddocs

regards.

On 5 Kwi, 21:52, codecowboy  wrote:
> Do you have one view for each form or do you use one view with a large
> amount of conditional logic (e.g. if stepone then show this form
> elseif steptwo show this form)?
>
> On Apr 5, 1:14 pm, eli  wrote:
>
> > anybody ? :-)
>
> > regards.
>
> > On 4 Kwi, 11:17, eli  wrote:
> > I have no problem reading existing docs if you know that this is already 
> > answered elsewhere
> > > Hi,
>
> > > What is the best way to add button "previous step" to multi-steps
> > > form ?
>
> > > Thank You.
>
> > > regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Form wizard - previous step

2009-04-05 Thread eli

No, how to add  functionality to back to the previous step without
deleting current step's data.

regards.

On 5 Kwi, 22:39, codecowboy  wrote:
> Are you asking how to modify the html in the multi-step-form app to
> add a button?
>
> On Apr 5, 4:33 pm, eli  wrote:
>
> > No, I have one view.. My example is similar to that one from Django
> > tutorial:http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizar...
>
> > regards.
>
> > On 5 Kwi, 21:52, codecowboy  wrote:
>
> > > Do you have one view for each form or do you use one view with a large
> > > amount of conditional logic (e.g. if stepone then show this form
> > > elseif steptwo show this form)?
>
> > > On Apr 5, 1:14 pm, eli  wrote:
>
> > > > anybody ? :-)
>
> > > > regards.
>
> > > > On 4 Kwi, 11:17, eli  wrote:
> > > > I have no problem reading existing docs if you know that this is 
> > > > already answered elsewhere
> > > > > Hi,
>
> > > > > What is the best way to add button "previous step" to multi-steps
> > > > > form ?
>
> > > > > Thank You.
>
> > > > > regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Form wizard - previous step

2009-04-06 Thread eli

Thank You Elliott.

regards.

On 6 Kwi, 11:52, Elliott  wrote:
> On Apr 5, 4:24 pm, eli  wrote:
>
> > No, how to add  functionality to back to the previous step without
> > deleting current step's data.
>
> > regards.
>
> That can't be done with the current form wizard. A session-based
> formwizard that would have allowed this was on the list for django
> 1.1, but nobody really put the work into it. The ticket for it is
> here:http://code.djangoproject.com/ticket/9200
--~--~-~--~~~---~--~~
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: Form validation in Admin Panel

2009-04-13 Thread eli

On 13 Kwi, 21:10, Alex Gaynor  wrote:
> Provide a custom form to the ModelAdmin using the form 
> option:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form
>
> Alex
>

Oh, it's so simple.. :-)

Thank You Alex

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Form validation in Admin Panel

2009-04-13 Thread eli

Hi,

How can I to validate data from form in Django Admin Panel? (like:
clena_fieldname in form.ModelForm) ?

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Problem with GenericRelation

2009-04-22 Thread eli

Hi,

I have a problem with GenericRelation ...

My code:

class Comment(models.Model):
text = models.TextField()
content_type = models.ForeignKey(ContentType, blank=True,
null=True)
object_id = models.PositiveIntegerField(blank=True, null=True)
content_object = generic.GenericForeignKey('content_type',
'object_id')

class Model1(models.Model):
name = models.CharField(max_length=255)
comments = generic.GenericRelation(Comment)

class Model2(models.Model):
name = models.CharField(max_length=255)
comments = generic.GenericRelation(Comment)

class Model3(models.Model):
name = models.CharField(max_length=255)
comments = generic.GenericRelation(Comment)

In my db ( Comment table):

id|text   |   content_type_id   |   object_id|
---
1 | lorem.. |12 |1   |
2 | lorem.. |13 |1   |
3 | lorem.. |14 |1   |


> a = Model1.objects.annotate(comment_cnt=Count('comments'))
> print a.comments
> 3

> b = Model2.objects.annotate(comment_cnt=Count('comments'))
> print b.comments
> 3

> c = Model3.objects.annotate(comment_cnt=Count('comments'))
> print c.comments
> 3

It's bug.. It should by only 1 comment for each models. I tried with
distinct=True and related_name, but it does not work correctly..

Thanks for help.

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Problem with GenericRelation

2009-04-22 Thread eli

Thank You Alex. This patch will be available in Django 1.1 ?

On 22 Kwi, 16:56, Alex Gaynor  wrote:
> On Wed, Apr 22, 2009 at 10:49 AM, eli  wrote:
>
> > Hi,
>
> > I have a problem with GenericRelation ...
>
> > My code:
>
> > class Comment(models.Model):
> >    text = models.TextField()
> >    content_type = models.ForeignKey(ContentType, blank=True,
> > null=True)
> >    object_id = models.PositiveIntegerField(blank=True, null=True)
> >    content_object = generic.GenericForeignKey('content_type',
> > 'object_id')
>
> > class Model1(models.Model):
> >    name = models.CharField(max_length=255)
> >    comments = generic.GenericRelation(Comment)
>
> > class Model2(models.Model):
> >    name = models.CharField(max_length=255)
> >    comments = generic.GenericRelation(Comment)
>
> > class Model3(models.Model):
> >    name = models.CharField(max_length=255)
> >    comments = generic.GenericRelation(Comment)
>
> > In my db ( Comment table):
>
> > id    |    text       |   content_type_id   |   object_id    |
> > ---
> > 1     | lorem..     |    12                     |    1               |
> > 2     | lorem..     |    13                     |    1               |
> > 3     | lorem..     |    14                     |    1               |
>
> > > a = Model1.objects.annotate(comment_cnt=Count('comments'))
> > > print a.comments
> > > 3
>
> > > b = Model2.objects.annotate(comment_cnt=Count('comments'))
> > > print b.comments
> > > 3
>
> > > c = Model3.objects.annotate(comment_cnt=Count('comments'))
> > > print c.comments
> > > 3
>
> > It's bug.. It should by only 1 comment for each models. I tried with
> > distinct=True and related_name, but it does not work correctly..
>
> > Thanks for help.
>
> > regards.
>
> > This a bug in Django right now, and there's a ticket for it:
>
> http://code.djangoproject.com/ticket/10870
>
> There's a patch here, but it doesn't completely work.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Getting data post from input with multiple name

2009-04-26 Thread eli

Hi,

I have problem:
In my template, I have some inputs with multiple name like:


How to get this data from request.POST in view method?

I tried:
 - request.POST.get('values', None)
 - request.POST.get('values[]', None)

but didn't wokr..

Thank You.

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Getting data post from input with multiple name

2009-04-27 Thread eli

Ok, I'm going to use string (like: items_{{ data.id }})

Thanks.

regards.

On 26 Kwi, 21:31, Malcolm Tredinnick  wrote:
> On Sun, 2009-04-26 at 10:20 -0700, eli wrote:
> > Hi,
>
> > I have problem:
> > In my template, I have some inputs with multiple name like:
> >  > value="{{ data.name }}" />
>
> > How to get this data from request.POST in view method?
>
> > I tried:
> >  - request.POST.get('values', None)
> >  - request.POST.get('values[]', None)
>
> > but didn't wokr..
>
> The name attribute in the HTML form will have a string value for the
> name. You have to use that string value, whatever it might be. If you
> are creating the string value at template rendering time, then you have
> to also compute exactly the same string value when processing the form.
> That is, repeat the logic in your view when accessing request.POST.
>
> There's nothing Django does or can do here. You are specifying the name
> attribute's value, so only you know what it is when it comes time to
> access it in the view.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



save_formset() in admin.TabularInline doesn't work.

2009-05-01 Thread eli

Hi,

I have problem with save_form, save_model, save_formset methods in
Admin class admin.TabularInline.

class AAdmin(admin.TabularInline):
model = A1
extra = 3

def save_form(self, request, form, change):
print "form"
return form.save(commit=False)

def save_model(self, request, obj, form, change):
print "model"
obj.save()

def save_formset(self, request, form, formset, change):
print "formset"
formset.save()


class BAdmin(admin.ModelAdmin):
inlines = [AAdmin]

def save_model(self, request, obj, form, change):
super(BAdmin, self).save_model(request, obj, form, change)

When I save BAdmin in Admin Panel the method in AAdmin aren't called.

Where is the problem?

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: save_formset() in admin.TabularInline doesn't work.

2009-05-01 Thread eli

Ok, I overloaded save_formset in BAdmin and everything works fine.

Thank You.

On 1 Maj, 16:46, George Song  wrote:
> On 5/1/2009 4:29 AM, eli wrote:
>
>
>
> > Hi,
>
> > I have problem with save_form, save_model, save_formset methods in
> > Admin class admin.TabularInline.
>
> > class AAdmin(admin.TabularInline):
> >     model = A1
> >     extra = 3
>
> >     def save_form(self, request, form, change):
> >         print "form"
> >         return form.save(commit=False)
>
> >     def save_model(self, request, obj, form, change):
> >         print "model"
> >         obj.save()
>
> >     def save_formset(self, request, form, formset, change):
> >         print "formset"
> >         formset.save()
>
> > class BAdmin(admin.ModelAdmin):
> >     inlines = [AAdmin]
>
> >     def save_model(self, request, obj, form, change):
> >         super(BAdmin, self).save_model(request, obj, form, change)
>
> > When I save BAdmin in Admin Panel the method in AAdmin aren't called.
>
> > Where is the problem?
>
> The problem is you're not telling us what it is you're trying to achieve.
>
> It's hard to debug code without knowing what you're tying to do, other
> than to say what you already know -- this doesn't work. The fact that
> you are trying to override `save_formset()` in `AAdmin` tells me you're
> stabbing in the dark a little bit.
>
> --
> George
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Create a view form capable of saving data into models through FK

2015-09-24 Thread eli
Hi Guys, 
A noob here,

I have two models, 

class Students(CommonInfo):
first_name = models.CharField(max_length=75)
surname = models.CharField(max_length=75)
class_score = models.ForeignKey(Course, related_name='course')
exam_score = models.ForeignKey('House')
...

def __unicode__(self):

return u'%s %s' % (
self.first_name, self.surname)

class Scores(models.Model):
class_score = models.PositiveIntegerField()
exam_score =  models.PositiveIntegerField()
...

I need to create view that would eventually produce a form with first_name, 
surname intact but the two foreign fields i.e class and exam scores as 
editable fields to allow users key in data and save(for named students) 
into the various models. I dont seem to find any concise way of doing this.
More efficient suggestions are welcome.
Thanks 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/b1dd4578-ee90-4fff-9623-65c633d2a591%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Redirect from get_queryset() in a class view?

2011-12-10 Thread Eli Criffield

So in a class based view inheriting generic.ListView I want to redirect on 
a condition, The logical place to do it is get_queryset, but you can't go 
returning a HttpResponseRedirect from a method that should return a query 
set. The django.shortcuts.redirect() just kinda does that for you so that 
doesn't work either. I can raise a  Http404 from inside get_queryset, but 
not something like raise Redirect('url/').

I saw one answer to the problem where you put the condition 
in render_to_response but that'll gets called after get_queryset. I guess 
the other option is to put the condition in get and check there and return 
redirect. But that seems hacky.

I'm just wonder whats the best way to do this.

Eli Criffield

-- 
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/-/pyY9hQ7iCPAJ.
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: Redirect from get_queryset() in a class view?

2011-12-12 Thread Eli Criffield
I like the raise exception idea, but where do i catch it? 
In a decorator?
Overwrite get() ?

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