Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:07:33+00:00 2026-06-13T07:07:33+00:00

what does django do, when i do something like that in template {{ object.parameter

  • 0

what does django do, when i do something like that in template

{{ object.parameter }}

I ask this because in case of arrayfields (postgresql array fields) it will print out either

{'value', 'value', 'value'}

(because thats how postgresql stores arrays in arrayfields)

or

['value','value','value']

if i use fields post_init method to convert postgresql array to python list.

Desired output would of course be value, value, value. I would rather not use some kind of filters for that, because then i would have to resort using IFs in templates or use some kind of template tag filter for every value i print out and that does not feel like a smart thing to do.

By the way, i know i can do something like that in template :

{% for choice in field.choices %}
    {{ choice }}
    {% if forloop.last %}
    {% else %}, 
    {% endif%}
{% endfor %}

and that gives me exactly what i want, but i thought there would be some other way doing it – with some modelfield method or something.

Alan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:07:34+00:00Added an answer on June 13, 2026 at 7:07 am

    what does django do, when i do something like that in template

    {{ object.parameter }}

    See variables and lookups.

    Desired output would of course be value, value, value. I would rather not use some kind of filters for that, because then i would have to resort using IFs in templates or use some kind of template tag filter for every value i print out and that does not feel like a smart thing to do.

    You can make a really trivial filter:

    @register.filter
    def comma_join(values):
        return u', '.join(values)
    

    So simple:

    {{ object.parameter|comma_join }}
    

    Why would you want to avoid such a simple solution ?

    and that gives me exactly what i want, but i thought there would be some other way doing it – with some modelfield method or something.

    Of course you could also add such a method:

    class YourModel(models.Model):
        # ....
        def comma_join_parameter(self):
            return u', '.join(self.parameter)
    

    And use it in your template as such:

    {{ object.comma_join_parameter }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like I am writing something that should already exist. Does Django have
I have a Python program (with Django - does this matter?) that I want
I've got a module I want to log in Django that looks something like
Does the Django ORM support the SQL IN operator? Something like: SELECT * FROM
So I can create Django model like this: from django.db import models class Something(models.Model):
I would like to use ORDER BY FIELD() (MySQL) in Django. Does Django support
It looks like Django does not update last_login field in auth_user model when a
How does one alternate row colors in a table in django that's generated using
I have a list of python dictionaries that look like this: sandwiches = [
This seems like the kind of thing Django makes simple, wondering if anyone has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.