Question on a resembling function on truncatewords

2014-04-12 Thread Kimitaka
Hi, I started learning Django(also new to Python) and I would like to use 
it in Japanese. 

Since truncatewords doesn't seem working in non-English language, I tried 
to create a resembling function. 

I wrote the function in my Product class in my models.py:
class Product(models.Model):
title = models.CharField(max_length=220)
description = models.CharField(max_length=3000, null=True, blank=True)
price = models.DecimalField(max_digits=1000, decimal_places=2, null=True, 
blank=True)
slug = models.SlugField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=True, auto_now=False)
active = models.BooleanField(default=True)

def __unicode__(self):
return self.title
class Meta:
ordering = ['title',]

*def shorten_words(self):*
* if len(self.description) > 20:*
* print self.desciption[0:20]*
* else:*
* print self.desciption*


and I added a code in my products.html page:
{{ product.description*.shorten_words()* }}

And it's not working.. 
Could you give me some advices?
Thank you!

-- 
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/0f18a1dd-27de-4f7b-a4ac-d59bb77550a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Question on a resembling function on truncatewords

2014-04-12 Thread C. Kirby
Don't use the parenthasesbin the template. Just call 
{{product.description.shorten_words}}

Kirby

-- 
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/fbb90227-e6ba-485a-9a8f-7ff1cc2aaea9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on a resembling function on truncatewords

2014-04-12 Thread Camilo Torres
On Saturday, April 12, 2014 1:10:34 AM UTC-4:30, Kimitaka wrote:
>
> I wrote the function in my Product class in my models.py:
> class Product(models.Model):
> title = models.CharField(max_length=220)
> description = models.CharField(max_length=3000, null=True, blank=True)
> price = models.DecimalField(max_digits=1000, decimal_places=2, null=True, 
> blank=True)
> slug = models.SlugField()
> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
> updated = models.DateTimeField(auto_now_add=True, auto_now=False)
> active = models.BooleanField(default=True)
>
> def __unicode__(self):
> return self.title
> class Meta:
> ordering = ['title',]
>
> *def shorten_words(self):*
> * if len(self.description) > 20:*
> * print self.desciption[0:20]*
> * else:*
> * print self.desciption*
>
>
> and I added a code in my products.html page:
> {{ product.description*.shorten_words()* }}
>
Hello,

Should it be?:
{{ product.shorten_words }} 

Regards,
Camilo

-- 
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/070e50c3-73bb-4f99-a425-8ed2125fc005%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on a resembling function on truncatewords

2014-04-12 Thread Sanjay Bhangar
On Sat, Apr 12, 2014 at 7:50 PM, Camilo Torres  wrote:
> On Saturday, April 12, 2014 1:10:34 AM UTC-4:30, Kimitaka wrote:
>>
>> I wrote the function in my Product class in my models.py:
>> class Product(models.Model):
>> title = models.CharField(max_length=220)
>> description = models.CharField(max_length=3000, null=True, blank=True)
>> price = models.DecimalField(max_digits=1000, decimal_places=2, null=True,
>> blank=True)
>> slug = models.SlugField()
>> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
>> updated = models.DateTimeField(auto_now_add=True, auto_now=False)
>> active = models.BooleanField(default=True)
>>
>> def __unicode__(self):
>> return self.title
>> class Meta:
>> ordering = ['title',]
>>
>> def shorten_words(self):
>> if len(self.description) > 20:
>> print self.desciption[0:20]
>> else:
>> print self.desciption
>>
>>
>> and I added a code in my products.html page:
>> {{ product.description.shorten_words() }}
>
> Hello,
>
> Should it be?:
> {{ product.shorten_words }}
>

This. And in the desciption() method, you want to do "return
self.description[0:20] and not print..." - print will just print the
output in the console at that point - you need to "return" the value
from the method.

So:

def shorten_words(self):
if len(self.description) > 20:
return self.desciption[0:20]
else:
return self.desciption

That, and {{ product.shorten_words }} in your template should do the trick.

All the best,
Sanjay

-- 
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/CAG3W7ZFEoBh8fzusWjAdbSdGQj9hmJSHKS8YUTZVJE1obPZmnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Dynamic Formsets

2014-04-12 Thread Venkatraman S
Can you try with this : https://gist.github.com/venkasub/10544716
It works for me. Let me know if you have trouble.

-V


On Wed, Apr 9, 2014 at 4:58 PM, Leandro Alves  wrote:

> Hi again,
>
> So I followed the documentation and created a formset as we have there.
> https://docs.djangoproject.com/en/1.6/topics/forms/formsets/
>
> Then I followed the documentation and included the django-formset-js:
> https://pypi.python.org/pypi/django-formset-js/
>
> But I can't get the buttons "Add another" neither "Delete" working.
> And I'm sure I'm missing something that I don't know yet.
>
> This is what I have so far:
>
>
> *forms.py*
>
> from django import forms
> from django.forms.formsets import formset_factory
>
> class ArticleForm(forms.Form):
> title = forms.CharField()
> pub_date = forms.DateField()
>
>
> *views.py*
>
> from django.forms.formsets import formset_factory
> from django.shortcuts import render_to_response
> from formsets.djdocs.forms import ArticleForm
>
> def manage_articles(request):
> ArticleFormSet = formset_factory(ArticleForm, can_delete=True, extra=2)
> if request.method == 'POST':
> formset = ArticleFormSet(request.POST, request.FILES)
> if formset.is_valid():
> # do something with the formset.cleaned_data
> for form in formset:
> print(form.as_table())
> pass
> else:
> formset = ArticleFormSet()
>
> return render_to_response('djdocs/manage_articles.html', {'formset':
> formset})
>
>
> *urls.py*
>
> from django.conf.urls import patterns, include, url
> from formsets.djdocs.views import manage_articles
>
> urlpatterns = patterns('djdocs.views',
> url(r'^$', manage_articles),
> )
>
>
> *template manage_articles.html*
>
> {% extends "index.html" %}
> {% block content %}
>
> {% load formset_tags %}
> 
> {{ formset.management_form }}
>
> 
> 
> {% for form in formset %}
> 
> {{ form }}
> {{ form.DELETE }}
> Delete
> form
> 
> {% endfor %}
> 
>
> 
> 
> {% escapescript %}
> 
> {{ formset.empty_form }} > >
> {% endescapescript %} > > > > > > jQuery(function($) { > $("#formset").formset({ > animateForms: true > }); > }); > > > > {% endblock %} > > In the index.html file I'm loading the .js like: > > {% load staticfiles %} > > > > > Any advice? :) > > Best regards, > > Leandro > > > > On Wednesday, April 9, 2014 7:19:11 AM UTC+2, Venkatraman.S. wrote: > >> Actually, there is nothing more to it. Include the js and create the >> formset_factory and start using it in the template by iterating over it. In >> the view, post-POST, again iterate over the formsets. Bulk of the work is >> done by the js and you dont have to do much in django. There is a minor bug >> in the js which lets even one row in the UI to get deleted, but its not a >> show-stopper :) >> >> Let me know if its still trouble and I shall write something up. >> >> On Tue, Apr 8, 2014 at 10:16 PM, Leandro Alves wrote: >> >>> Hello Venkatraman, >>> >>> Yes.. I saw this one was well... and I want to try it.. but I'm still >>> learning about Formsets... >>> Would you have any basic simple foo example to share? :) >>> >>> Best, >>> >>> Leandro >>> >>> >>> >>> On Tuesday, April 8, 2014 2:48:15 AM UTC+2, Venkatraman.S. wrote: >>> Have you tried the jquery formset - works like a breeze for me. On Mon, Apr 7, 2014 at 10:43 PM, Leandro Alves wrote: > Hi, > > I wonder if anyone knows of any example of django-dynamic-formsets [1] > that works with Django 1.6? > > So far all I found on the internet are over 3 years old and they don't > work with Django version 1.6. > > I am willing to pay for any example that works if necessary. :) > > Thanks in advance, > > Leandro > > > [1] - https://code.google.com/p/django-dynamic-formset/ > > -- > 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...@googlegroups.com. > To post to this group, send email to django...@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/95dc89cb-cdd7-43c5-adca-da0a1aaf9573%40goog > legroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- >>> You received this message b

validate answers from a detail view

2014-04-12 Thread Brad Rice
I'm using a Class based Generic Detail View to show end users their answers 
to previous mulit-page forms. How can I use that final detail view to 
validate the answers? Should I not be using a Detail view or can I somehow 
do a conditional get to the next view based upon those answers? Right now I 
just have a link to the next page where they can submit all their answers 
from the forms. If they haven't filled out a field, I want to take them 
back to the form they need to go to to fix that. All it does on that final 
page after the datail is set a true value in the db that they are done 
updating their application form.

-- 
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/1dbd99b0-f12f-4eff-aa10-754da6828184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.