Re: Building correct queryset

2017-05-19 Thread Andrew Beales
brand = Brand.objects.get(title='mybrand') products = Product.objects.filter(brand=brand).order_by('-score')[:4] ...gets you the top 4 products in order for the brand On Friday, May 19, 2017 at 10:32:49 AM UTC+1, Горобец Дмитрий wrote: > > Hello. I have these two models. I have to show 4 or less

Re: list? queryet? joining together

2017-01-12 Thread Andrew Beales
Hi, just a couple of follow-up questions as having trouble following precisely. Can you re-state the exact queries you’re looking for? - Are you looking to check if there are tools of a given type available at a given time? - And whether a tool of a given type can be booked in a given time

Re: How to display user's photo that i follow in post's list in Django

2016-12-27 Thread Andrew Beales
If I'm following correctly and you want to access author profile photos from querysets of Post objects: if you add related_name=‘profile’ to the user field in the Profile model then you can add a method to the Post model: def author_profile_photo(self): return self.author.profile.photo and

Re: Dynamic querysets?

2016-12-23 Thread Andrew Beales
typo: # urls.py url(r'^(?P[A-Z]{2})', views.state_home, name="state_home"), On Saturday, December 24, 2016 at 7:35:12 AM UTC, Andrew Beales wrote: > > You can pass strings from URLs as arguments into your Django view > functions. > > Assuming your Jurisdiction model a

Re: Dynamic querysets?

2016-12-23 Thread Andrew Beales
You can pass strings from URLs as arguments into your Django view functions. Assuming your Jurisdiction model already has a "name" field, make sure it also has a "postal_code" field (consider renaming the model State?) Your urls and views can be something like: # urls.py url(r'^(?P[A-Z]{2})',

Re: New to Django

2016-08-20 Thread Andrew Beales
This works for me: {% for server, images in child_list.items %} {{ server }} {% for image in images %} {% for key,val in image.items %} {{ key }}: {{ val }} {% endfor %} {% endfor %} {% endfor %} In your template, 'image' is a list of dicts, so you need to loop

Re: New to Django

2016-08-17 Thread Andrew Beales
All this talk about "child images on servers" has probably set off an alarm somewhere. On Wednesday, August 17, 2016 at 7:00:09 AM UTC+1, Andrew Beales wrote: > > Hi, you can use aggregation queries to count the child images connected to > each server: > > > # views.

Re: New to Django

2016-08-17 Thread Andrew Beales
Hi, you can use aggregation queries to count the child images connected to each server: # views.py from django.db.models import Count def servers(request): servers = Server.objects.all() for server in servers: server.child_images = server.images.aggregate(total=Count('base'))

Re: Help with django form an ajax, error 500

2016-08-10 Thread Andrew Beales
Guessing this is old news, but there are 2 problems with views: ProductoConcepto.objects.create(producto=producto, orden=orden, cantidad=cantidad) - producto and orden need to be Python objects and cantidad is a float, but the request.POST values will be string representations. Also the ajax