Re: Problem with models

2011-01-04 Thread Quetzacotl
I have added related_name to text1 and text2, so at least syncdb
worked, but how can I now make this query.

In manager:

self.compare_set.filter(~Q(Q(compare__user=request.user)&Q(Q(compare__text1__id=id)|
Q(compare__text2__id=id.all()

this doesn't work

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

2011-01-04 Thread Quetzacotl
I have model of text, like that:

class Text(models.Model):
 text = models.CharField()
 user = models.ForeignKey(User) #author

And i need to compare two of texts, so i need table like this:

class Compare(models.Model):
 text1 = models.ForeignKey(Text)
 text2 = models.ForeignKey(Text)
 user = models.ForeignKey(User) #who compared

Now i want to get from Text table two random texts and at least one of
them cant be compared yet by given user, how can i do this?

if I try reverse relation compares_set, it doesnt work cause' i have
two foreignkey of same model.
I cant give manaytomanyfield in Text through Compare because i cant
make symmetrical reference with intermediate table.

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



Returning value directly to another function

2010-12-09 Thread Quetzacotl
Hello, this is rather python problem, but maybe You can help. What i
want to do is to return value in another function calling from other
function.

It doesnt mean i want this:

def Func():
 return 1

def Func2():
 return Func()

I want function Func to return 1 directly in Func2 as it is Func2
returning it.

I have this problem because view function has to return response
object and my function that adds element to database (comments)
returns HttpResponseRedirect or context dict with form that has
errors.
If it returns redirect then i want view function to return it, if it
return context then i dont want to return it but rather give it to
render_to_response.

It comes to this:

def Add():
 #form valid, add to db
 return { 'redirect': HttpResponseRedirect('url'), }

 #form not valid
 return { 'form': form, 'redirect': 0, }

def View(request):
 add = Add()
 if add['redirect']!=0:
  return add['redirect']

 return render_to_response(template,add)

Thing i dont want here is if statement checking if there is redirect,
so i want within function Add return HttpResponseRedirect as it is
View function.

I dont know if this is possible.





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

2010-12-06 Thread Quetzacotl
Hello, i want to make function that wraps all things related to
comments, so there should be part that gets comments from database and
part that checks if comment was added. Then i can simply write just
one line of code in view where i want comments. Problem is that after
successful comment post, view should make redirect, and as we know to
redirect you need to return response instance. That one thing doesnt
let me make wrap function for my comments, because i cant return
response after post. thought I can make IF statement that checks if
return value is response instance or not. But this is 4 lines of code
instead of one, is there any other way?

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