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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:46:22+00:00 2026-06-07T11:46:22+00:00

I have a Person model and I am using a django form to edit

  • 0

I have a Person model and I am using a django form to edit another object with a foreign key to Person. The person model has first_name and last_name fields. I want to run a method to filter results for the drop down box of the foreign reference.

I am trying to use values_list() to override the form field options (choices property) like so:

data.form.fields['person'].choices = GetPersons().values_list('id', 'first_name')

GetPersons() just filters the Person class like

return Person.objects.filter(id__gt=1000)`

for example, so I only get people I want to show up. How can I use values_list() to return the concatenation of first_name and last_name without having to return a dictionary and splitting everything manually?

  • 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-07T11:46:24+00:00Added an answer on June 7, 2026 at 11:46 am

    I have in mind 2 sugestions for you:

    • First one is to concatenate fields in database with extra . For me is a dirty solutions but can run.

    Sample:

    persons =  GetPersons().extra(select={'full_name': "concatenate( first, last) "} )
    choices = persons.values_list('id', 'full_name')
    

    and …

    • the second one use list comprehension:

    Sample:

    choices = [ ( p.id, '{0} {1}'.format( p.first, p.last ),) for p in GetPersons() ]
    

    Edited 2018

    Concat is now available as database function:

    >>> from django.db.models import CharField, Value as V
    >>> from django.db.models.functions import Concat
    >>> persons = GetPersons().annotate(
    ...     full_name=Concat(
    ...         'last', V(', '), 'first', V('.'),
    ...         output_field=CharField()
    ...     )
    ... )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Person model that has a foreign key relationship to Book ,
Say I have a model object 'Person' defined, which has a field called 'Name'.
I have attribute name of model Person. I want to use html-form with fields:
I'm using the Code First approach and have the following Model: public class Person
In my core data model I have a Person entity that has a to
I have a symmetrical many-to-many relationship in Django class Person(models.Model): id = models.CharField(max_length=32, primary_key=True)
I have a Person model that has a many-to-many relationship with an Email model
I have a model named Person. It has two properties - name and parent_person_id
I have a model called MessagePerson which has the fields of details which depict
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...

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.