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 8900759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:10:34+00:00 2026-06-15T01:10:34+00:00

I have a users click a series of checkboxes to identify which areas a

  • 0

I have a users click a series of checkboxes to identify which areas a certain place is related to (i.e, entertainment, sports etc) , which I then retrieve with:

    areas_related=request.POST.getlist('areas_related')

When I am displaying those values in a different view of what areas different places are related to I am using:

                    {% for service in services %}
                    {{service.areas_related}}
                    {% endfor %}

… But it is displayed as:

[u'Education', u'Food'] 

.. If I try to make a for loop to go through the list, each individual character gets displayed, one line at a time. I.e.,
[
u
‘
E
etc.Is there a filter I can use to not display [u’, etc.?

Any help would be appreciated.

  • 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-15T01:10:35+00:00Added an answer on June 15, 2026 at 1:10 am

    What is probably going on here is that you are storing the areas_related as a string.

    So you probably have a model like:

    class Service(models.Model):
        ...
        areas_related = models.CharField(max_length=<length_here>)
    

    and then in the view you do this:

    def foo_view(request, ...):
        ...
        service = <retrieve Service here>
        areas_related = request.POST.getlist('areas_related')
        service.areas_related = areas_related
        service.save()
        ...
    

    So what is going on here is that request.POST.getlist('areas_related') returns a Python list. However then you store that value into a string field of your model. As a result, Django tries to convert the given list to a string, which it then stores in the db; and when you convert Python list to a string, the result is a string representation of the list:

    >>> a = [u'foo', u'foo2']
    >>> unicode(a)
    u"[u'foo', u'foo2']"
    

    To solve this, you can do one of these things:

    Foreign Key

    Instead of storing all the areas_related as a single field within your model, store those as foreign keys. This I think is a better way because then you can do SQL aggregation and is just considered more flexible compared to the next method.

    # models.py
    class AreaRelated(models.Model):
         service = models.ForeignKey('Service', related_name='areas_related')
         areas_related = models.CharField(max_length=<length_here>)
    
    class Service(models.Model):
        ...
    
    # views.py
    def foo_view(request, ...):
        ...
        service = <retrieve Service here>
        areas_related = request.POST.getlist('areas_related')
        for a in areas_related:
             service.areas_related.create(areas_related=a)
        ...
    
    # template
    {% for service in services %}
        {% for area_related in service.areas_related.all() %}
            {{ area_related }}
        {% endfor %}
    {% endfor %}
    

    Encoded string

    Store the list in the areas_related model field as a string by encoding it somehow, and then on retrieval decode to get the list. This method is nice because everything gets stored in db in one column, however then you can’t really do any queries on the areas_related because it will store an encoded string of multiple values instead of just one.

    # models.py
    import json
    class Service(models.Model):
        ...
        areas_related = models.CharField(max_length=<length_here>)
    
        def get_areas_related(self):
             return json.loads(self.areas_related)
    
    # views.py
    import json
    def foo_view(request, ...):
        ...
        service = < retrieve Service here>
        areas_related = request.POST.getlist('areas_related')
        service.areas_related = json.dumps(areas_related)
        service.save()
        ...
    
    # template
    {% for service in services %}
        {% for area_related in service.get_areas_related %}
            {{ area_related }}
        {% endfor %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feature of my application which depends on alternate-click. Windows users don't
I have a jqGrid on a page and users can click a button to
I have problem while loading data into html select when users press or click
I have done like if user click on the Button then the Sound is
I have a link with a series of checkboxes, due to the legacy code,
I'm making a flash quiz which will have a series of questions. Each question
I have a business requirement that when the user clicks a series of checkboxes
I have a form with a series of checkboxes. I want to warn the
I have a ListBox which I bind to an ObservableCollection<Series> in the view model.
I have a series of buttons and foreach button I have a seperate .click(function()

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.