2

I am running Django together with Cassandra DB. The cassandra.cqlengine.columns.UUID variable is translated by the url tag in Django template to the form of UUID('uuid_identifier').

The expression {% url 'myapp' uuid %} results in url like .../UUID('uuid_identifier') . This causes problem if you are awaiting url in form of .../uuid_identifier.

What is the recommended or correct use of cassandra.cqlengine.columns.UUID variables in Django templates?

Do I need to write own filter?

Community
  • 1
  • 1
karelok
  • 301
  • 2
  • 9
  • What version of the Cassandra driver are you using? – peytoncas Feb 06 '17 at 14:45
  • @peytoncas: cassandra-driver 1.5.6 – karelok Feb 07 '17 at 18:41
  • Have you tried casting your uuid to a str before sending it to your Django template? str(uuid) – peytoncas Feb 07 '17 at 23:10
  • @peytoncas I am using DjangoCassandraModel from django_cassandra_engine.models. My intention is to use fields with UUID type. Maybe there is some possibility to implement a getter for this type of fields. What do you think? – karelok Feb 08 '17 at 09:01

1 Answers1

0

Surprisingly you don't have to convert a UUID to pass it in the URL template tag. As long as the url regex matches for the UUID, you're good to go. The debug output makes it seem like passing the UUID as an object is not acceptable, however it is.

Example of when the private key is a UUID4:

[urls.py]
url(r'^your_page/(?P<pk>[a-f0-9-]+)/$', views.your_page, name='your_page')

[templates/your_page.html]
<a href="{% url 'your_page' your_model.pk %}">Go to your page</a>