How to filter out posts from friends?

2009-07-01 Thread coan
I have a friendship model for users and want to retrieve all the posts my friends made. class Friendship(models.Model): from_friend = models.ForeignKey( User, related_name='friend_set' ) to_friend = models.ForeignKey( User, related_name='to_friend_set' ) class Post(models.Model): text = mode

Negative value in forms.Integerfield throws TypeError

2009-02-16 Thread coan
I'm validating a form, and use forms.IntegerField(min_value=0,). If I submit a -1 value in that field, it throws a TypeError: not all arguments converted during string formatting. How come it doesn't raise a forms.ValidationError, and how should I catch a negative value in this field? --~--~-

Re: Distinct users ordered by remote field

2009-01-06 Thread coan
On Jan 6, 12:22 am, Malcolm Tredinnick wrote: > Right now, with trunk or Django 1.0, it's not particularly easy without > using custom SQL or extra(). Ok! Thanks for clearing that up for me, I'll filter it manually. --~--~-~--~~~---~--~~ You received this messa

Distinct users ordered by remote field

2009-01-05 Thread coan
I have a model that looks something like this: class Collection(models.Model): user = models.ForeignKey(User) item = models.ForeignKey(Items) date = models.DateTimeField() I'm trying to retrieve a list of unique users ordered by the last time they added something to their collection. I would

Re: Ordering bookeditions by their rating

2008-11-29 Thread coan
On Nov 30, 1:48 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > The set of associated rating for an entry 'e' are accessible via > e.rating_set. So {{e.rating_set.rating}} will do what you're after. Thank you! {{ e.rating_set.all.count }} gives me the number of votes, and {{e.rating_set.a

Re: Ordering bookeditions by their rating

2008-11-29 Thread coan
On Nov 29, 2:45 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: >         user.edition_set.order_by('rating__rating') > > will do what you want. > Yes! It does! What an amazing timesaver that small line was :-) Is it possible to actually access the rating directly from the template? In the

Re: Ordering bookeditions by their rating

2008-11-28 Thread coan
On Nov 28, 1:50 pm, Peter Bengtsson <[EMAIL PROTECTED]> wrote: > The trick is to use .query.group_by. > Here's an example that will work:: Thank you for taking the time to putting this example together! You are hereby granted the title "django query ninja"! What I was trying to do was perhaps

Re: Ordering bookeditions by their rating

2008-11-28 Thread coan
On Nov 28, 12:56 pm, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 28 nov, 11:07, coan <[EMAIL PROTECTED]> wrote: > What's the point of having two distinct models for Bookcollection and > Rating ??? Looks like mostly redundant to me. Good point, I have consider

Ordering bookeditions by their rating

2008-11-28 Thread coan
I have book editions in my database. Users can rate editions. If they want, they can also add them to their book collection. Here is a simplified overview of the models: class Edition(models.Model): title = models.models.CharField(max_length=255) binding= models.models.CharField(max_l

post data and @login_required

2008-11-06 Thread coan
I tried to use the @login_required decorator on a view that takes post data. Why isn't there an option to have the request object passed to the login form? Then it would be possible to have the loginform pass the post data to the view that depends on it. Does anyone have any clever workarounds f

Re: order_by clause to preserve order in list?

2008-09-23 Thread coan
On Sep 24, 5:10 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Tue, 2008-09-23 at 07:01 -0700, coan wrote: > > > I want to fetch a list of items in my database, and I have their id > > ready: > > my_ids_to_get = [ 1, 3, 2, ] > > > In mysql I would

order_by clause to preserve order in list?

2008-09-23 Thread coan
I want to fetch a list of items in my database, and I have their id ready: my_ids_to_get = [ 1, 3, 2, ] In mysql I would fetch them like this: SELECT * FROM table WHERE id IN (1, 3, 2) ORDER BY FIELD( id, 1, 3, 2 ) This would preserve their order. Can I build this query with the native django

Re: How do I befriend a user in the User class?

2008-09-10 Thread coan
On Sep 9, 5:39 pm, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 9 sep, 14:56, coan <[EMAIL PROTECTED]> wrote: > > > I want to add a recursive relationship to the built-in User model - to > > store relationships between users. Are there any (non-hairy) ways

How do I befriend a user in the User class?

2008-09-09 Thread coan
I want to add a recursive relationship to the built-in User model - to store relationships between users. Are there any (non-hairy) ways to do this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" grou

Re: Field type for 13 digit positive integer?

2008-09-02 Thread coan
I think lookups go faster in a bigintfield. On Sep 2, 9:50 pm, tchendrix <[EMAIL PROTECTED]> wrote: > the reason i'm asking is that digits 14 and 15 will be alphanumeric so > add another field or two for that data (char?) and use bigint to hold > the numerical data > > c

Re: Field type for 13 digit positive integer?

2008-09-02 Thread coan
On Sep 2, 9:36 pm, tchendrix <[EMAIL PROTECTED]> wrote: > that looks like it's for an EAN code... how are you planning on EAN14 > and EAN 15? I will take them on one digit at a time :-) First I have to solve my 13 digit problem. --~--~-~--~~~---~--~~ You received

Field type for 13 digit positive integer?

2008-09-02 Thread coan
If I want to store a positive integer like 9781590599969 and use mysql - what field type can I choose in my model - if any? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group,

Re: HTML in ValidationError?

2008-08-24 Thread coan
On Aug 24, 1:18 am, "Tim Kersten" <[EMAIL PROTECTED]> wrote: > Seehttp://www.djangoproject.com/documentation/templates/#automatic-html-... > > Tim ^,^ It doesn't look as the form object is subject to this automatic html escaping, because you can pass html into the form object like this: forms.C

Re: HTML in ValidationError?

2008-08-24 Thread coan
On Aug 24, 2:13 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On Sun, Aug 24, 2008 at 7:07 AM, coan <[EMAIL PROTECTED]> wrote: > > I wonder why custom error messages are considered more dangerous than > > the help_text in the same form? &

Re: HTML in ValidationError?

2008-08-24 Thread coan
On Aug 24, 12:25 pm, "Tim Kersten" <[EMAIL PROTECTED]> wrote: > Ah, I see what you mean. A quick glance > athttp://code.djangoproject.com/changeset/4544 > tell's me this is not possible to do so inside the error message, for > good reasons. To style your message take a look at > > http://www.djan

HTML in ValidationError?

2008-08-23 Thread coan
I try to do a raise forms.ValidationError('oh no'), but the HTML tags are escaped when I render my form as {{ form }}. Tried to do raise forms.ValidationError(mark_safe('oh no')), but the HTML-tags are still escaped. Any way to get around this? --~--~-~--~~~---~--~--