Re: How to read part of many-to-many field in the template

2014-06-15 Thread Elliot Bradbury
Hi Mohammad,

Check out slice
.

It's a builtin template filter that can be used like this:

{% for author in book.authors.all|slice:"3" %}
  {# HTML up in here #}
{% endfor %}

Good luck,
Elliot


On Sun, Jun 15, 2014 at 9:31 AM, alghafli  wrote:

>  Hello django users. I am working on my first django project and I faced a
> little problem.
> I have a library database with books. A book element may have several
> authors.
> In the view function I query the database for books. I want to show the *first
> three* authors. I was thinking to do something similar to the following
> python code but using the template language:
>
> authors_to_show = book.authors.get_queryset() [0:3]
> for author in authors_to_show:
> #html code here
>
> However, it appears that I cannot define variables in the template unless
> I extend the language a bit. Note that I have several books to process and
> I can do that using the for loop in the template language. But I want to
> ignore some authors in each book.
> Any idea of a proper way to do this.
>
> Thank you in advance,
> Mohammad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/539DA033.4060100%40gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAErR_z4JoZu0Xe7M7LiJq-3M4pR%2BYwTxaEnJk56AqZnX-nZHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating a Node in Django ORM

2013-07-09 Thread Elliot Bradbury
Check out django-mptt for creating parent/child (tree) relationships
between models. https://github.com/django-mptt/django-mptt


On Tue, Jul 9, 2013 at 9:07 AM, Nafiul Islam wrote:

> How would you create a node using Django's ORM. This is what I mean:
> https://dpaste.de/JG52c/
>
> Now, what I am basically trying to create is a liked list with nodes here.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problem with django 1.5.1

2013-05-09 Thread Elliot Bradbury
Hey kl4us,

I think the problem is that you need to specify the URL name as a string,
like: {% url 'post' slug=post.slug %}

https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns

Elliot


On Thu, May 9, 2013 at 10:29 AM, kl4us  wrote:

> I have this code http://pastebin.com/xTJTmZws
> with django 1.4.3 on OSX works fine, on ubuntu with django 1.5.1 i have
> error "coercing to Unicode: need string or buffer, Post found" at line
> "{% url post slug=post.slug %}" of template post_list.html.
>
> Why and how can i adjust this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: TDD with Django/Splinter/plupload queue

2013-03-20 Thread Elliot Bradbury
PhantomJS is a headless webkit browser that can be programmed to perform
automated webpage tasks (like maybe select a file for upload). The standard
API is Javscript but I believe there is a Python port. Maybe that could
help?

http://phantomjs.org/

On Wed, Mar 20, 2013 at 3:34 PM, Bill Freeman  wrote:

> You can always write a stand alone python tool that pretends that it is a
> browser, does the GET, confirms that the form looks right, gathers the
> cookies or other CSRF token souces, and does the POST, including attaching
> the uploaded data parts.  But since this requires dipping into HTTP and
> HTML further than most people go, it has the potential to be more
> complicated than what you are testing.  Perhaps someone has already done
> this and will comment.
>
> Of course this doesn't test any browser JavaScript that you are using.
>
> Another approach, probably even more complex, is to add to your favorite
> browser(s) the ability to script the filling of upload fields.
>
> There are engines that allow you to script clicking and typing on a
> desktop, but I have no experience with them, and that sounds fragile to me,
> since, for example, FireFox auto updates and where things are changes.
>
> Bill
>
>
> On Wed, Mar 20, 2013 at 2:19 PM, Daniel França wrote:
>
>> Hi all,
>> I'm trying to set up tests for a upload using the plupload queue widget:
>> http://www.plupload.com/
>> I'm using Splinter for in-browser test, but I couldn't find a way to make
>> it happen. Splinter has some methods to attach files, but only if it's a
>> simple file field.
>> Another way would be click the button to browse the files, and choose the
>> file... but I don't think it's possible using Splinter (or selenium), is it?
>> Or with drag-n-drop of the files.
>>
>> Anyone has any suggestion of the best way to automatize theses tests?
>>
>> --
>> Daniel França,
>> about.me/danielfranca
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Tutorial three '-pub_date'

2012-07-03 Thread Elliot Bradbury
'-' reverses the ordering of that field. So it will order the most recently
published Polls first.

On Tue, Jul 3, 2012 at 2:33 PM, Smaran Harihar wrote:

> Hey Djangoers,
>
> I am on the tutorial 
> 3,
> and found this code where we are modifying the view index()
>
> def index(request):
> latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
> output = ', '.join([p.question for p in latest_poll_list])
> return HttpResponse(output)
>
> What I did not understand, was why did we state,
>
> order_by('-pub_date'), what does that *'-'* mean before 'pub_date' ?
>
> --
> Thanks & Regards
> Smaran Harihar
>
>  --
> 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.
>

-- 
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: Google Drive with Django?

2012-05-10 Thread Elliot Bradbury
django-social-auth has some Google OAuth2 code. I'm not sure if it applies
to Drive but it might be worth looking at. I was able to create an OpenID
backend to a new service in about 2 minutes.

https://github.com/omab/django-social-auth/blob/master/social_auth/backends/google.py#L69

On Thu, May 10, 2012 at 12:16 AM, Jordon Wing  wrote:

> Hey guys,
> I'm trying to integrate Google Drive into my app, and I'm having some
> trouble using OAuth2. I'm not sure if any of you have played with the SDK,
> but if anyone has, what library (if any) did you use? Is there anything
> that simplifies the 200+ lines of code they have in the examples?
>
> Link to the SDK: https://developers.google.com/drive
>
> Thanks
>
> --
> 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/-/qwx3ZJG5MYgJ.
> 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.
>
>

-- 
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.