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

  • Home
  • SEARCH
  • 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 8930177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:49:41+00:00 2026-06-15T08:49:41+00:00

class Task(models.Model): owner_set=set() for each in User.objects.all(): owner_set.add((each.username,each.username)) Owner = models.CharField(max_length=100,choices=owner_set) In the code,

  • 0
class Task(models.Model):

    owner_set=set()
    for each in User.objects.all():
         owner_set.add((each.username,each.username))

    Owner = models.CharField(max_length=100,choices=owner_set)

In the code, i create a field by the choices of User, but this leads a problem:
When i create a new user, the new username will not apprear in the filed of “Owner”;
i need to restart the server. So i want that the Owner filed should be dynamic, is there any way to do this?

I don’t want to use the Owner= models.ForeignKey(User,...) because may be i will use the names not only from the auth_user.

  • 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-15T08:49:42+00:00Added an answer on June 15, 2026 at 8:49 am

    Why would you store Owner as a CharField? If it’s a reference to a User object, it should be a ForeignKey.

    Edit after comment Your data model seems broken. Nevertheless, if you really want to keep it as a CharField, you should not try to set the choices in the model at all. Define a custom form and either use a ModelChoiceField or set the choices in the form’s __init__ method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model like this class Task(models.Model): name = models.CharField(max_length=100) ... class TaskForm(forms.ModelForm):
I have two models , Task and TaskComment : class Task(models.Model): title = models.CharField(max_length
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I'd like to do something like this: class Task(models.Model): ... created_by = models.ForeignKey( User,
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
class TaskManager(models.Manager): def get_query_set(self): return super(TaskManager, self).get_query_set().filter(Owner='jim') class Task(models.Model): Name = models.CharField('Title', max_length=200) Notes
I have a model for users to add time to a task. class Time(models.Model):
let me put it like this: model.py: class Task(models.Model): ... seq_file = models.FileField(upload_to='files/', blank=True,
I have a Task model where every task has deadline. class Tasks(models.Model): assigned_to =
I have the following model: class Task(Model): solvers = ManyToManyField(User, related_name='slvrs') Now I want

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.