num2words - help

34 views
Skip to first unread message

Ariel Matysiak

unread,
Jan 28, 2018, 11:32:54 AM1/28/18
to Django users
Hello :)

It's my first post in here.

I've made simple model and simple app.

I want to use num2words library and I want to see my "cash" i words.

I don't know how to do it/

Can you help me ???

Please edit code for me.


-------------------------------------------
models.py

class Payment(models.Model):
    name = models.CharField(max_length=20)
    cash = models.IntegerField()

    def __str__(self):
        return self.name
------------------------------------------------
views.py

class PaymentListView(ListView):
    model = Payment

---------------------------------------------
template.html

{% for payment in payment_list %}
            <p>{{ payment.name }}: {{ payment.cash }}</p>
{% endfor %}

-----------------------------------------------
forms.py

class PaymentForm(forms.ModelForm):

    class Meta:
        model = Payment
        fields = ('name','cash')


THANK YOU VERY MUCH
Ariel

Kasper Laudrup

unread,
Jan 28, 2018, 12:10:19 PM1/28/18
to django...@googlegroups.com
On 2018-01-28 17:30, Ariel Matysiak wrote:
> Hello :)
>

Howdy!

> It's my first post in here.
>
> I've made simple model and simple app.
>
> I want to use num2words library and I want to see my "cash" i words.
>
> I don't know how to do it/
>
> Can you help me ???
>

I'm not really sure I understand your question, but maybe you should
look into the humanize template filter:

https://docs.djangoproject.com/en/2.0/ref/contrib/humanize/

If you really need to use the num2words library, you should probably
write a custom filter for that. The documentation should have all the
information you need:

https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/

> Please edit code for me.
>

Don't expect people to solve the problem for you. Take your time to
explain the problem you're facing, what you have done to try and solve
it and then ask for help.

Kind regards,

Kasper

Akhil Lawrence

unread,
Jan 28, 2018, 12:12:17 PM1/28/18
to Django users
You need to write a template tag which will make use of the num2words library to convert the cash to words and apply it in your template.

Lets say your template tag name is num2word, You can apply it in your template like {{ payment.cash|num2word }}
Reply all
Reply to author
Forward
0 new messages