On 31-7-2012 14:36, Joris wrote:
>
>> Hmm, I guess I'm missing the "real world use case" for this. Most
>> importantly, I'm missing how this slow model relates to the fast model
>> and what kind of query it is executing. I'm especially curious about the
>> "as this statement is executed as an instance of the model" bit.
>
> Ok, I'll try to explain this better. The fast model is coupled directly to
> a table. The Slow model is not, it is activated by a specific sql query
> that depends on a specific condition.
I thought about an alternative, since it seems your only reason to split
the models is performance and you prefer to have one model.
The prerequisite is that you know when you want to have access to the
slow data and make it available to the view.
The idea is borrowed from django.contrib.gis.db and it's GeoManager and
consists of implementing the raw sql as a method of the ModelManager and
adding the result of the query as attributes of the model.
For reference you can look at for example GeoQueryset.area()[1].
This will give you the ability to specify the queryset on a generic
class-based view to either be model.objects.all() for the fast version
or model.objects.calculate_slow_stuff() for the slow version.
[1]
https://docs.djangoproject.com/en/1.4/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.GeoQuerySet.area
--
Melvyn Sopacua
--
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
Re: union of two QuerySets
On Monday, December 11, 2006 4:37:25 AM UTC+1, Rares Vernica wrote:
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.
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.
Checkbox checking
Hi,
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.
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.
Re: Error in Brand New Django 1.4.1 released Yesterday
On Tue, Jul 31, 2012 at 3:15 AM, JJ Zolper <codingatmt@gmail.com> wrote:
> Hello all,
>
> I didn't realize a new release was put out until something weird happened.
>
> I'm installing DJ on my production server now and when I was downloading a
> copy from https://www.djangoproject.com/download/
On that same page (option number 2) are a couple of links for the
"Latest Development Version". The zip file is named:
django-django-1.4-616-g8d3e501.zip
but indeed the version in the zip file is:
VERSION = (1, 5, 0, 'alpha', 0)
-Doug
> and installed it and went into python:
>
>>>> import django
>>>> print django.get_version()
>
> I didn't see 1.4.1 I saw 1.5
>
> Sure it's probably a minor configuration fix to change it to 1.4.1 but I was
> really worried that I did something wrong.
>
> Maybe someone else can repeat this and see if I made a mistake or that
> indeed something is wrong with the brand new release?
>
> Cheers to all!
>
> JJ
>
> --
> 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/-/sN647bh67AAJ.
> 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.
> Hello all,
>
> I didn't realize a new release was put out until something weird happened.
>
> I'm installing DJ on my production server now and when I was downloading a
> copy from https://www.djangoproject.com/download/
On that same page (option number 2) are a couple of links for the
"Latest Development Version". The zip file is named:
django-django-1.4-616-g8d3e501.zip
but indeed the version in the zip file is:
VERSION = (1, 5, 0, 'alpha', 0)
-Doug
> and installed it and went into python:
>
>>>> import django
>>>> print django.get_version()
>
> I didn't see 1.4.1 I saw 1.5
>
> Sure it's probably a minor configuration fix to change it to 1.4.1 but I was
> really worried that I did something wrong.
>
> Maybe someone else can repeat this and see if I made a mistake or that
> indeed something is wrong with the brand new release?
>
> Cheers to all!
>
> JJ
>
> --
> 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/-/sN647bh67AAJ.
> 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: Error in Brand New Django 1.4.1 released Yesterday
Just now I also did
pip install --upgrade django
>>> import django
>>> django.get_version()
'1.4.1'
>>>
On 8/1/12, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> Yesterday I did ...
>
> pip install --upgrade django
>
> ... and it happily upgraded mine to 1.4.1
>
> Mike
>
> On 1/08/2012 9:46am, Dennis Lee Bieber wrote:
>> On Tue, 31 Jul 2012 16:06:20 -0700 (PDT), JJ Zolper
>> <codingatmt@gmail.com> declaimed the following in
>> gmane.comp.python.django.user:
>>
>>> Nope. Not Python 1.4. Django 1.4.
>>>
>>> http://pypi.python.org/pypi/Django/1.4#downloads
>>>
>> Intriguing... When I did my search python.org routed me to the
>> Django server itself...
>>
>
> --
> 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.
>
>
--
Sent from my mobile device
--
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.
pip install --upgrade django
>>> import django
>>> django.get_version()
'1.4.1'
>>>
On 8/1/12, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> Yesterday I did ...
>
> pip install --upgrade django
>
> ... and it happily upgraded mine to 1.4.1
>
> Mike
>
> On 1/08/2012 9:46am, Dennis Lee Bieber wrote:
>> On Tue, 31 Jul 2012 16:06:20 -0700 (PDT), JJ Zolper
>> <codingatmt@gmail.com> declaimed the following in
>> gmane.comp.python.django.user:
>>
>>> Nope. Not Python 1.4. Django 1.4.
>>>
>>> http://pypi.python.org/pypi/Django/1.4#downloads
>>>
>> Intriguing... When I did my search python.org routed me to the
>> Django server itself...
>>
>
> --
> 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.
>
>
--
Sent from my mobile device
--
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: Dynamic forms
On Tue, Jul 31, 2012 at 11:59 AM, Satinder Goraya
<satinder.goraya91@gmail.com> wrote:
> Lets say that you need a form with a drop-down list that have dynamic
> values. With Django this can be done simple and fast.
<snip>
> my_choice_field). With this code get_my_choices is called on every
> form load and you will get your dynamic drop-down.
This code is useful for bringing the drop down options from the database.
But I want to have the dynamically filtered options from the last
selected options without refreshing the page.
I have used the following code but it is not working according to my
requirement.
Please check and point out where I am making mistake.
<views.py >
from django import template
register = template.Library()
@register.inclusion_tag("field_test_select.html")
def field_test_select(request):
field_list = Field.objects.all()
return render_to_response('field_test_select.html', {'field_list'
: field_list}, context_instance=RequestContext(request))
def all_json_tests(request, field):
current_field = Field.objects.get(id=field)
test = Test.objects.all().filter(field=current_field)
json_test = serializers.serialize("json", test)
return HttpResponse(json_test, mimetype="application/javascript")
<urls.py>
(r'^add_job/$', 'field_test_select'),
(r'^field/(?P<field>[-\w]+)/all_json_tests/$', 'all_json_tests'),
<field_test_select.html>
<!-- field_test_select.html -->
<html>
<body>
<form action="" method="get" accept-charset="utf-8">
<select name="field" id="field">
<option value="Z">Select a field</option>
{% for field in field_list %}
<option value="{{ field.id}}">{{ field.name }}</option>
{% endfor %}
</select>
<select name="test" id="test" disabled="true">
<option>Select a test</option>
</select>
</form>
<script>
$(document).ready(
function() {
$("select#field").change(function() {
if ($(this).val() == 'Z') {
$("select#test").html("<option>Select
a test</option>");
$("select#test").attr('disabled', true);
}
else {
var url = "/field/" + $(this).val() +
"/all_json_tests";
var field = $(this).val();
$.getJSON(url, function(tests) {
var options = '<option
value="Z">Select a test</option>';
for (var i = 0; i < tests.length; i++) {
options += '<option value="' +
tests[i].pk + '">' + tests[i].fields['name'] + '</option>';
}
$("select#test").html(options);
$("select#test
option:first").attr('selected', 'selected');
$("select#test").attr('disabled', false);
});
//}
});
$("select#test").change(function(vent) {
if ($(this).val() == -1) {
return;
}
myAwesomeFunctionToCallWhenAtestIsSelected();
});
});
}
</script>
</body>
</html>
--
Sandeep Kaur
E-Mail: mkaurkhalsa@gmail.com
Blog: sandymadaan.wordpress.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.
<satinder.goraya91@gmail.com> wrote:
> Lets say that you need a form with a drop-down list that have dynamic
> values. With Django this can be done simple and fast.
<snip>
> my_choice_field). With this code get_my_choices is called on every
> form load and you will get your dynamic drop-down.
This code is useful for bringing the drop down options from the database.
But I want to have the dynamically filtered options from the last
selected options without refreshing the page.
I have used the following code but it is not working according to my
requirement.
Please check and point out where I am making mistake.
<views.py >
from django import template
register = template.Library()
@register.inclusion_tag("field_test_select.html")
def field_test_select(request):
field_list = Field.objects.all()
return render_to_response('field_test_select.html', {'field_list'
: field_list}, context_instance=RequestContext(request))
def all_json_tests(request, field):
current_field = Field.objects.get(id=field)
test = Test.objects.all().filter(field=current_field)
json_test = serializers.serialize("json", test)
return HttpResponse(json_test, mimetype="application/javascript")
<urls.py>
(r'^add_job/$', 'field_test_select'),
(r'^field/(?P<field>[-\w]+)/all_json_tests/$', 'all_json_tests'),
<field_test_select.html>
<!-- field_test_select.html -->
<html>
<body>
<form action="" method="get" accept-charset="utf-8">
<select name="field" id="field">
<option value="Z">Select a field</option>
{% for field in field_list %}
<option value="{{ field.id}}">{{ field.name }}</option>
{% endfor %}
</select>
<select name="test" id="test" disabled="true">
<option>Select a test</option>
</select>
</form>
<script>
$(document).ready(
function() {
$("select#field").change(function() {
if ($(this).val() == 'Z') {
$("select#test").html("<option>Select
a test</option>");
$("select#test").attr('disabled', true);
}
else {
var url = "/field/" + $(this).val() +
"/all_json_tests";
var field = $(this).val();
$.getJSON(url, function(tests) {
var options = '<option
value="Z">Select a test</option>';
for (var i = 0; i < tests.length; i++) {
options += '<option value="' +
tests[i].pk + '">' + tests[i].fields['name'] + '</option>';
}
$("select#test").html(options);
$("select#test
option:first").attr('selected', 'selected');
$("select#test").attr('disabled', false);
});
//}
});
$("select#test").change(function(vent) {
if ($(this).val() == -1) {
return;
}
myAwesomeFunctionToCallWhenAtestIsSelected();
});
});
}
</script>
</body>
</html>
--
Sandeep Kaur
E-Mail: mkaurkhalsa@gmail.com
Blog: sandymadaan.wordpress.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: combobox prepopulated to only related objects to "self"
you can try something like that:
choices = [(product.pk, product.name) for product in group.product_set.all()]
form.fields["myfield"].choices = choices
--
-- On Wed, Aug 1, 2012 at 1:17 AM, Ignacio Soto <isoto@ingehost.cl> wrote:
Hi everyone
i have this model
GROUP and Product
product has a group field thath is foreignkey to GROUP.
and Group has foreignKey to Product to select primary product.
so i want to have a group with many products and one is the "primary product".
so...i could do this by select inline products with "trough" and search an intermediary Model (boolean field).
but it let me select more than one promary,
the solution is the model this way:.
product has a group field thath is foreignkey to GROUP.
and Group has foreignKey to Product to select primary product.
so i want to have a group with many products and one is the "primary product".
but the primaryproduct field in group will be prepopulated with only the related products to this group.
how i prepopulate the select(combobox) with the reverse query ?
--
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/-/d3UpfhONEWwJ.
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.
Regards,
Anton Baklanov
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.
Subscribe to:
Posts (Atom)