Re: Manager is not accessible via model instances

2009-09-18 Thread Tiago Serafim
Try this:

def get_active_members(self):
return return self.get_query_set().filter(is_active=True)

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Design question: User vs. UserProfile

2009-09-18 Thread Tiago Serafim
I`d go with the first. It`s easier to get the current logged in user and all
other pluggable apps use User, so it's a common thing to do and you can
integrate things easily .

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Embedding A List in urlpatterns

2009-09-17 Thread Tiago Serafim
Hi Thomas,

When you define the urls patterns, you don't have to specify each
possibility. What you do is create a pattern that can match all the values
that might be there and, then, on your view, you check to see if they exist
on the DB.

One possible way is like this:
urlpatterns = patterns('',
   (r'^$', index),
   (r'^list_jobs/', list_jobs),
   (r'^job/(?P[\_\w]+)/$', list_job_details),
)

Then, you define you list_job_details like this:

def list_job_details(request, job_name):
   j = Job.objects..(job_name=job_name)


Check the docs for URLs to see why I used the named group (?) in the
url definition.

HTH,

On Thu, Sep 17, 2009 at 12:10 PM, Thomas <thomas.e.rectenw...@gmail.com>wrote:

>
> Hello,
>
> I'm learning Django and have some questions regarding passing data to
> urlpatterns.  Right now, I have something like this in my urls.py:
>
> urlpatterns = patterns('',
>(r'^$', index),
>(r'^list_jobs/', list_jobs),
> )
>
> This works fine.  I.e., any URL that matches ^list_jobs/ is handled by
> the list_jobs method in my views.py.  That calls a template which
> displays the list of jobs in an HTML table.
>
> So, now I have a list of jobs displayed in HTML, i.e. something like:
>
> Job | Severity | Message
>
> morning_job | INFO | Testing 123
> evening_job | ERROR | Testing 456
>
> My next step, I figured would be to have a user click on 'job1' or
> 'job2' in the table and call up information on that job in a new
> window.  So, I imagine that the correct way to do this within Django
> would be to have the HREF point to a the job in the URL.  I.e.:
>
> http://myserver:8000/morning_job
> http://myserver:8000/evening_job
>
> My next though was... grr, how do I do this?  So, I figured I can get
> the job names in the urls.py by first creating a method:
>
> from myapp.models import *
> def get_job_names():
>job_names = []
>for j in TransJob.objects.all():
>job_names.append(j.job)
>return job_names
> job_names = get_job_names()
>
> So, now I have a list (job_names) that would contain:
>
> ['morning_job', 'evening_job']
>
> I think I'm getting close.  Final step is to somehow take that list
> and put it within urlpatterns.  So, I tried something like:
>
> urlpatterns = patterns('',
>(r'^$', index),
>(r'^list_jobs/', list_jobs),
>(job_names, list_job_details),
> )
>
> Here is where I get lost.  I think I'm going down the wrong path
> here.  The above comes back with a TypeError saying "unhashable type:
> 'list'" ... I'm guessing that you can't put a list in place of the raw
> string that the patterns method expects.  So, my question is... how do
> I get patterns to match all results for the list.
>
> I hope this makes some sense.  I tried to be verbose as I'm new to the
> framework.  Thanks for any assistance.
>
> Regards,
> Thomas
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to get cms like features in Django

2009-09-15 Thread Tiago Serafim
If it's simple enough, check FlatPages. Comes bundled with django, so you
have it running within minutes.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting fields in a user profile

2009-09-15 Thread Tiago Serafim
Notice that the return is within []. Which means that it has returned a
list.

Try this:

>>> g1[0].get_modify_dt

On Tue, Sep 15, 2009 at 8:23 PM, PlanetUnknown <nikhil.kodil...@gmail.com>wrote:

>
> I could get the user profile object like below, but when I try to view
> any of its properties I just get "has no attribute xxx" -
> I can see that the genericUserProfile has data in it.
>
> # Continued from earlier entries in django python shell
> >>> g1 = GenericUserProfile.objects.filter(user=c1)
> >>> g1
> []
> >>> g1.modify_dt
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'QuerySet' object has no attribute 'modify_dt'
>
>
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting fields in a user profile

2009-09-15 Thread Tiago Serafim
Hi,

filter returns a list, with zero or more elements. To fix what you showed,
you should call "get" instead of "filter". "get" either return a object or
throws an Exception. Check the docs for more info.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: path depth problem

2009-09-15 Thread Tiago Serafim
Hi,

The right way(TM) to do this is using named urls:

http://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups

Then you can use reverse to get the right url, avoiding duplications and
problems like the one you have now:

http://docs.djangoproject.com/en/dev/topics/http/urls/#django.core.urlresolvers.reverse

HTH,


On Tue, Sep 15, 2009 at 4:42 PM, dijxtra <nsko...@gmail.com> wrote:

>
> Hello everybody,
>
> Django keeps surprising me with neat solutions for common web
> programming problems (I must say I haven't felt this "where has it
> been all of my life" since the time I was exploring lisp), so I hope
> django has a trick up his sleeve for this one too.
>
> So, I made a calendar "widget" (view snippet:
> http://pastebin.com/m765f778c,
> template snippet: http://pastebin.com/m16dcf115) and I have a problem
> with relative links in it. If I include this code in page with URL url/
> prefix//mm/dd (which represents one day), then my links point to
> right places, but if I'm in url/prefix//mm (which represents the
> whole month) then links point to the wrong place because they are
> relative links, and they were made to work with //mm/dd, not //
> mm.
>
> I tried to fix it with my {{calendar_data.path}} variable, but that's
> one ugly solution. I suppose this is a common problem... so, I suppose
> there is a common solution?
>
> BTW, if you give me constructive advice about my coding style, you get
> bonus points for heaven and I love you till the end of my life. :-D
>
> Thanks in advance,
> nick
>
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: When did Paul join the Beatles?

2009-09-14 Thread Tiago Serafim
Yes, it's inefficient. Yes, there's a way to do what you want:

memberships = Membership.objects.all().select_related('group', 'person')

;-)

On Mon, Sep 14, 2009 at 5:27 PM, W.P. McNeill <bill...@gmail.com> wrote:

>
> Is this inefficient?  Is there a way to do this with a single database
> call?
>
>

-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: When did Paul join the Beatles?

2009-09-14 Thread Tiago Serafim
You should query Membership like you do with any other model.

paul = Person.objects.get(...)
beatles = Group.objects.get(...)

membership = Membership.objects.get(person=paul, group=beatles)
print membership.join_date

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Development and deployment wit Git

2009-09-14 Thread Tiago Serafim
I recommend http://repositoryhosting.com/ . I needed the support a couple of
times and they were *very* responsive. The service is great and the price is
very fair.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: render a table

2009-09-14 Thread Tiago Serafim
Hi,

What you want is usually done using cycle:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle



On Mon, Sep 14, 2009 at 9:57 AM, luca72 <lucabe...@libero.it> wrote:

>
> hello i need to render a table where i need to separate a odd colum to
> even column
>
> my wrong idea
> 
>
>  
> File Name
> Size 
>  
>
>  {% for m in tutti %}
>{% if {{m.id}} even %}
>
>{% else %}
>
>{% endif %}
>  {{m.nome_fil}}
>  {{m.lungh}}
>
>  {% endfor %}
>  
>
> can you help me to write it
>
> Thanks Luca
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newbie: How to use object related to dropdown selection in django/javascript spaguetti code?

2009-09-13 Thread Tiago Serafim
Hi,

First you should have an attribute "name" on your select. It's needed to
pass the value when the form is submitted.

If your select's name is "foos_combo", then your code you'll look like this:

def foo_relatory(request):

if request.method == 'POST':
foos_combo = request.POST['foos_combo']
return HttpResponse(foos_combo)

else:
return render_to_response('foo_relatory.html',
 {'title'   : title,
  'show_filter_foos': True,
 },
 context_instance=RequestContext(request))


HTH,

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: redirect after post caches anchor?

2009-09-12 Thread Tiago Serafim
Hi Margie,

I misunderstood you first post. What I said is valid, but it doesn't relate
to your problem.

Now that I get it: FF scrolls back to the same position after a reload.

I don't know how to work around this issue unless you return a anchor
"#top"(like you did with the another one) and add an attribute id="top" on
your "body" tag.

HTH,

On Sun, Sep 13, 2009 at 1:55 AM, Margie <margierogin...@yahoo.com> wrote:

>
> Hi Tiago,
>
> Thanks very much for your response.  So is there a way I can tell the
> client that I don't want to retain the same anchor?  IE, tell the
> client to act as it would act if the client had initiated a new GET?
>
> Where would I find documentation on this?  Or not necessarily doc but
> just something that discusses this problem.  My googling didn't turn
> up much of anything but it seems like it would be a problem that
> others have as well.
>
> Margie
>
>

-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: docstring format documentation for the admin doc contrib?

2009-09-12 Thread Tiago Serafim
Hi,

These docs are in ReST (ReStructured Text) format, and each text file
> corresponds to a Web page on the official Django site.
>

source:
http://docs.djangoproject.com/en/dev/faq/general/#how-can-i-download-the-django-documentation-to-read-it-offline


On Sun, Sep 13, 2009 at 12:21 AM, Andrew R <andrew.rw.robin...@gmail.com>wrote:

>
> The built in templates and filters have formatted docstrings (``,
> ===, etc.). I don't see anywhere where this syntax is documented.
> Where can I find information on this.
>
> Example docstring:
> def yesno(value, arg=None):
>"""
>Given a string mapping values for true, false and (optionally)
> None,
>returns one of those strings accoding to the value:
>
>==  ==
> ==
>Value   ArgumentOutputs
>==  ==
> ==
>``True````"yeah,no,maybe"`` ``yeah``
>``False``   ``"yeah,no,maybe"`` ``no``
>``None````"yeah,no,maybe"`` ``maybe``
>``None````"yeah,no"``   ``"no"`` (converts None to
> False
>if no mapping for None is
> given.
>==  ==
> ======
>"""
>
> I would like to document my own filters and would like to understand
> the available syntax. Thanks.
>
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: redirect after post caches anchor?

2009-09-12 Thread Tiago Serafim
Hi,

This is the expected, as HTTP clients doesn't pass the #anchors to the
server.


On Sat, Sep 12, 2009 at 10:20 PM, Margie Roginski
<margierogin...@yahoo.com>wrote:

>
> I'm seeing some strange behavior related to anchors that I can't
> really explain.  I'm going to give an example of what I'm seeing and
> I'm hoping that someone can point me in the right direction.
>
> Let's say I do a post and my  views.py code that services the post
> returns like this:
>
>  return HttpResponseRedirect('/taskmanager/edit_task/12/
> #comment_101')
>
> (I am of course not hardcoding the redirect address - but have shown
> it explictly here for clarity)
>
> This correctly displays my /taskmanager/edit_task/12 page, taking me
> part way down the page due to the #comment_101 anchor.
>
> From this url I do a second post.  The views.py code associated with
> this second post returns like this:
>
>return HttpResponseRedirect('/taskmanager/edit_task/12')  # note
> no comment_101 anchor
>
> I thought this should take me to the top of my /taskmanager/edit_task/
> 12 page, but instead it takes me to /taskmanager/edit_task/12/
> #comment_101.  It's like the #comment_101 anchor is cached in some
> way.
>
> My runserver printouts from the second post and the get associated
> with its redirect show this:
>
> [12/Sep/2009 18:16:51] "POST /taskmanager/edit_task/12/ HTTP/1.1" 302
> 0
> [12/Sep/2009 18:16:52] "GET /taskmanager/edit_task/12/ HTTP/1.1" 200
> 50904
>
> So the #comment_101 is not there, yet it still appears in my firefox
> browser.   Anyone know why this is?
>
> Thanks,
> Margie
>
>
>
>
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Return something specific on 404's on a particular path

2009-09-11 Thread Tiago Serafim
Hi,

You can take a look on how the contrib.redirect handles 404 and then create
a custom Middleware for your specific need.

http://code.djangoproject.com/browser/django/trunk/django/contrib/redirects/middleware.py

HTH,
Tiago

On Fri, Sep 11, 2009 at 11:26 PM, Jordon Wii <jordon...@gmail.com> wrote:

> Hi,I want set up something where users upload an article, and an
> associated image.  If they do not provide an image, then, when someone reads
> the article, I'd like return a specific image.  I've looked at custom
> storage backends, but those are too complex.
>
> How can return a specific image when there is a 404 error for an image on a
> path?
> I can also resort to showing nothing, but that could make styling harder.
>  If there's is a way to do this, I'd like to.
>
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Couple of basic Django questions

2009-09-11 Thread Tiago Serafim
Hi,

On Fri, Sep 11, 2009 at 10:04 PM, Dan06 <dan.king...@yahoo.com> wrote:

>
> 1. Is there supposed to be only one 'view' (controller) file per
> application, with all the 'action' functions? Or can there be multiple
> different 'view' (controller) files for the same application? If the
> latter, how?
>
>
No, you can have multiple view modules per app. To do so, one can create a
'views' folder with a empty __init__.py file. Then,
you can have multiple views: views/foo.py , views/bar.py.
Although this is a possibility, I haven't seen this approach been used on
open source apps.



> 2. Does Django have dynamic loading of stylesheet and javascript files
> (as rails)?
>
>
You have to load yourself. You can use the MEDIA_URL context variable to
help you to not hardcode paths. Like this:


HTH.

-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Javascript working on development, not apache

2009-09-11 Thread Tiago Serafim
Open the Firefox console and try to see what's going on.

On Fri, Sep 11, 2009 at 12:44 PM, geraldcor <gregco...@gmail.com> wrote:

>
> Hello all,
>
> I have a site that has quite a bit of javascript/jquery going on. All
> of this works fine on my development server, but basically no
> javascript works when I deploy on Apache. This previously worked on
> this same site before some changes (suspiscious, I know) and other
> sites work fine on the same webserver.
>
> I suspect it is bad code that is making the whole thing come to a
> screeching halt, but why would it work in the development server and
> not Apache?
>
> Most of my js is linked. Oh, maybe I should make it local and see what
> that does. I will try that and if it works, I will respond to my own
> problem, if not, I will leave this open.
>
> Thanks for any help.
>
> Greg
> >
>


-- 
Tiago Serafim

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---