On 08/01/12 10:28, Àlex Pérez wrote:
> Hi,
>
> it's better Person.objects.filter(models.Q(first_**name__startswith='mic'),
> models.Q(first_**name__startswith='joh'))
> (only one query...)
I'm pretty sure this will get you the intersection (it uses AND)
rather than the union (which would be using OR). So I think you want
from django.db.models import Q
Person.objects.filter(
Q(first_name__startswith="mic") |
Q(first_name__startswith="joh")
)
using the "|" (OR) operator to join the two Q objects.
-tkc
For reference, you can read at
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.filter
https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects
--
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.
Wednesday, August 1, 2012
How to print a graph
The information comes from a database, which I got it with a problem. However, I need to show a graph as well.
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.
Please let me know any suggestions...
thanks and have great day.
-- 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.
Re: Checkbox checking
I'm going to assume that we're talking about a single checkbox (an "I
agree to the terms" checkbox).
First, remember that unchecked is not the same as "blank", it is
"false", so "blank=False" is subject to interpretation.
There are two places where you might insist that the box be checked:
in the browser; and in the form processing. You *must* provide at
least the latter, since the first depends on JavaScript (since, as
you've discovered, the required attribute of a checkbox input doesn't
always work across browsers), which is disable-able and otherwise
circumventable.
The js approach is to disable the submit button on load (stays enabled
if js is disabled or the page is otherwise broken) and attach an on
change handler to the checkbox that enables or disables the submit
button based on whether the checkbox is now checked or not.
But the mandatory part is to add a validator to the field (see
https://docs.djangoproject.com/en/1.4/ref/forms/validation/ ) that
fails with a suitable error message if the checkbox field value is
False.
On Wed, Aug 1, 2012 at 7:37 AM, Jon Underwood <underwoodjon@gmail.com> wrote:
> Hi,
>
> My checkboxes are giving me grief.
>
> I want to make it required for the user to check a checkbox before being
> allowed to submit a forms.
>
> I'm using model forms so the checkbox is defined as a models.BooleanField in
> my models.py. I have included blank=False, though this should be the
> default.
>
> In the admin the checkboxes aren't required to be checked. When displaying
> the form in a template I can set required="True" as follows: <input
> type="checkbox" required="True" check_test="True" name="involved"
> id="id_involved"/>
>
> This works in most browsers, though not Safari for some reason.
>
> Is there a better method? I've messed around with this for ages!
>
> Thank you in advance.
>
> Jon
>
> --
> 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/-/4bBr_gr_Z44J.
> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
agree to the terms" checkbox).
First, remember that unchecked is not the same as "blank", it is
"false", so "blank=False" is subject to interpretation.
There are two places where you might insist that the box be checked:
in the browser; and in the form processing. You *must* provide at
least the latter, since the first depends on JavaScript (since, as
you've discovered, the required attribute of a checkbox input doesn't
always work across browsers), which is disable-able and otherwise
circumventable.
The js approach is to disable the submit button on load (stays enabled
if js is disabled or the page is otherwise broken) and attach an on
change handler to the checkbox that enables or disables the submit
button based on whether the checkbox is now checked or not.
But the mandatory part is to add a validator to the field (see
https://docs.djangoproject.com/en/1.4/ref/forms/validation/ ) that
fails with a suitable error message if the checkbox field value is
False.
On Wed, Aug 1, 2012 at 7:37 AM, Jon Underwood <underwoodjon@gmail.com> wrote:
> Hi,
>
> My checkboxes are giving me grief.
>
> I want to make it required for the user to check a checkbox before being
> allowed to submit a forms.
>
> I'm using model forms so the checkbox is defined as a models.BooleanField in
> my models.py. I have included blank=False, though this should be the
> default.
>
> In the admin the checkboxes aren't required to be checked. When displaying
> the form in a template I can set required="True" as follows: <input
> type="checkbox" required="True" check_test="True" name="involved"
> id="id_involved"/>
>
> This works in most browsers, though not Safari for some reason.
>
> Is there a better method? I've messed around with this for ages!
>
> Thank you in advance.
>
> Jon
>
> --
> 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/-/4bBr_gr_Z44J.
> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Checkbox checking
It seems in this particular case you don't need the boolean field in the model. As the behaviour you want has to do only with the form, you just have to add an additional required checkbox in this model form.
class MyModelForm(forms.ModelForm):
involved = forms.BooleanField(required=True)
class Meta:
model = MyModel
cheers
On Wednesday, 1 August 2012 13:37:12 UTC+2, Jon Underwood wrote:
Hi,My checkboxes are giving me grief.I want to make it required for the user to check a checkbox before being allowed to submit a forms.I'm using model forms so the checkbox is defined as a models.BooleanField in my models.py. I have included blank=False, though this should be the default.In the admin the checkboxes aren't required to be checked. When displaying the form in a template I can set required="True" as follows: <input type="checkbox" required="True" check_test="True" name="involved" id="id_involved"/>This works in most browsers, though not Safari for some reason.Is there a better method? I've messed around with this for ages!Thank you in advance.Jon
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/-/K2iX2zo_vUMJ.
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.
Re: union of two QuerySets
Hi,
--
Alex Perez
alex.perez@bebabum.com
bebabum be successful
c/ Còrsega 301-303, Àtic 2
08008 Barcelona
http://www.bebabum.com
http://www.facebook.com/bebabum
http://twitter.com/bebabum
This message is intended exclusively for its addressee and may contain
information that is confidential and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly prohibited by law.
Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si no es vd. el destinatario indicado,
queda notificado que la utilización, divulgación y/o copia sin autorización
está prohibida en virtud de la legislación vigente.
Le informamos que los datos personales que facilite/ha facilitado pasarán a
formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene
por finalidad gestionar las relaciones con usted.
Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección de e-mail lopd@bebabum.com
--
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.
it's better Person.objects.filter(models.Q(first_name__startswith='mic'), models.Q(first_name__startswith='joh'))
(only one query...)
2012/8/1 Robin Pedersen <robinpeder@gmail.com>
On Monday, December 11, 2006 4:37:25 AM UTC+1, Rares Vernica wrote:Hi,What is a way to get the union of two QuerySets?
Something like:
In [6]: a = Person.objects.filter(first_name__startswith='mic')
In [7]: b = Person.objects.filter(first_name__startswith='joh')
In [8]: a + b
Thanks a lot,
Ray--
Try:
a | b
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/-/ie69j4ewJNUJ.
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.
Alex Perez
alex.perez@bebabum.com
c/ Còrsega 301-303, Àtic 2
08008 Barcelona
http://www.bebabum.com
http://www.facebook.com/bebabum
http://twitter.com/bebabum
This message is intended exclusively for its addressee and may contain
information that is confidential and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly prohibited by law.
Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si no es vd. el destinatario indicado,
queda notificado que la utilización, divulgación y/o copia sin autorización
está prohibida en virtud de la legislación vigente.
Le informamos que los datos personales que facilite/ha facilitado pasarán a
formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene
por finalidad gestionar las relaciones con usted.
Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección de e-mail lopd@bebabum.com
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.
ContentType and multiple database
Hello,
--
Alex Perez
alex.perez@bebabum.com
bebabum be successful
c/ Còrsega 301-303, Àtic 2
08008 Barcelona
http://www.bebabum.com
http://www.facebook.com/bebabum
http://twitter.com/bebabum
This message is intended exclusively for its addressee and may contain
information that is confidential and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly prohibited by law.
Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si no es vd. el destinatario indicado,
queda notificado que la utilización, divulgación y/o copia sin autorización
está prohibida en virtud de la legislación vigente.
Le informamos que los datos personales que facilite/ha facilitado pasarán a
formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene
por finalidad gestionar las relaciones con usted.
Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección de e-mail lopd@bebabum.com
--
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.
I want to take objects of another project that i don't have installed.
I can have the contenttype of the external object but I can't take the object I understand that, take the object remotly of a model thah you dosen't have have the class is not possible (I think...) but if i want only a value i think that could be reasonable...
I want to tho something like that:
c = ContentType.objects.using("site").get(pk=self.ext_content_id)
obj = c.get_object_for_this_type(pk=self.ext_object_id).values("nombre")
but obiously doesn't work.
Please guys help me!!
Thanks
Alex Perez
alex.perez@bebabum.com
c/ Còrsega 301-303, Àtic 2
08008 Barcelona
http://www.bebabum.com
http://www.facebook.com/bebabum
http://twitter.com/bebabum
This message is intended exclusively for its addressee and may contain
information that is confidential and protected by professional privilege.
If you are not the intended recipient you are hereby notified that any
dissemination, copy or disclosure of this communication is strictly prohibited by law.
Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si no es vd. el destinatario indicado,
queda notificado que la utilización, divulgación y/o copia sin autorización
está prohibida en virtud de la legislación vigente.
Le informamos que los datos personales que facilite/ha facilitado pasarán a
formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene
por finalidad gestionar las relaciones con usted.
Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección de e-mail lopd@bebabum.com
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.
Re: form.errors is not a dictionary?
Read the above reply.
On Wednesday, August 1, 2012 1:56:28 AM UTC-4, vivek soundrapandi wrote: --
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/-/Ui_ValHbXG0J.
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.
When you print form.error --> prints out a custom __unicode__ for you to use in your templates.
However, you can iterate over form.errors and it will act as a normal dict.
On Wednesday, August 1, 2012 1:56:28 AM UTC-4, vivek soundrapandi wrote:
I too have the same problem. How did you fix it?
On Wednesday, April 6, 2011 2:13:48 AM UTC+5:30, Roy Smith wrote:I'm using django-1.3 . I have a view with the following code:
def item_create(request):
if request.method == 'POST':
form = ItemForm(request.POST)
if form.is_valid():
url = form.cleaned_data['url']
item.save()
return HttpResponseRedirect('/')
else:
print form.errors
when I submit the form, I expected that form.errors would print out as
a dict, as documented in http://docs.djangoproject.com/en/1.3/ref/forms/api/#using- .forms-to-validate-data
Instead, I'm getting a hunk of HTML:
Django version 1.3, using settings 'soco-site.settings'
Development server is running at http://0.0.0.0:7626/
Quit the server with CONTROL-C.
<ul class="errorlist"><li>date_added<ul class="errorlist"><li>This
field is required.</li></ul></li><li>user_id<ul
class="errorlist"><li>This field is required.</li></ul></li></ul>
[05/Apr/2011 16:36:32] "POST /item/create/ HTTP/1.1" 200 718
Is my understanding wrong, or is this a bug?
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/-/Ui_ValHbXG0J.
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.
Subscribe to:
Posts (Atom)