Django versions 1.8 and later:

You should use get_fields():

[f.name for f in MyModel._meta.get_fields()]

The get_all_field_names() method is deprecated starting from Django 1.8 and will be removed in 1.10.

The documentation page linked above provides a fully backwards-compatible implementation of get_all_field_names(), but for most purposes the previous example should work just fine.


Django versions before 1.8:

model._meta.get_all_field_names()

That should do the trick.

That requires an actual model instance. If all you have is a subclass of django.db.models.Model, then you should call myproject.myapp.models.MyModel._meta.get_all_field_names()

Answer from rossipedia on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › django-model-data-types-and-fields-list
Django Model Data Types and Fields List - GeeksforGeeks
ForeignKey establishes a relationship between two models (Album- Musician). After creating and applying migrations, the above two tables are now created in the database. To view the tables and their structure, use Django’s database shell. Open the DB shell by running: ... Note: NullBooleanField (a boolean field that allowed True, False, or NULL) is deprecated.
Published   November 14, 2025
🌐
Django
docs.djangoproject.com › en › 6.0 › ref › models › fields
Model field reference | Django documentation | Django
If present, Django will create the underlying model table with a composite primary key. The *field_names argument is a list of positional field names that compose the primary key.
Discussions

django - List field in model? - Stack Overflow
Note that you will have to create ...ef/contrib/postgres/fields/#indexing-arrayfield). (Edit: updated links to newest Django LTS, this feature exists at least since 1.8.) ... I think it will help you. from django.db import models import ast class ListField(models.TextField): ... More on stackoverflow.com
🌐 stackoverflow.com
How do you put a ListField attribute in a Django model?
The approach may depend on the complexity you are looking for. If you have a large roster of students that can each have several tutors, then you would do a thorough data model (later) If a tutor is going to simply track the students who contact them (and there isn't a need for a central master list of students), there would be a second model Tutorship with a foreign key to TutorProfile (with a related_name='students') and a field for the student name and contact information. From a TutorProfile entry, Django will then provide a students accessor that will get you to details or you could do students.count(). For more thorough roster of students you would have another model for Student. Assuming a student could have more than one tutor (one for Math, one for Science), you would have another model Tutorship that contains a foreign key to TutorProfile (related_name='students') and a foreign key to Student (related_name=;tutors'), along with fields to track the start date, and end date. As before, the accessors would be available from either a TutorProfile or from the Student. With either approach, it might be desirable to track the sessions, so you might even have a TrainingSession model, with a foreign key to Tutorship that tracks each session's date (or datetime) and duration, and maybe a note field for what was done in that session. This seems like a lot of models, but it organizes the data into the relationships and allows you to track attributes of those relationships. From a Tutorship model, you can summarize all of the training sessions. It is also possible on the Tutorship to have an agreed hourly_rate (rather than the default hourly rate on the TutorProfile) in situations where the student needs more in-depth help or perhaps only a light review of progress. A good data model supports the business and how the business works, not the nifty shortcuts the programmer devises. I learned this once and it stuck with me and made the application incredibly extendable over the years as there were new attributes (fields) to track on each model but the relationships between the models did not change. More on reddit.com
🌐 r/django
13
11
October 18, 2021
Django lists with models
Implement another model- gym visit model or something. Give it a time stamp and a foreign key to the customer. Then, depending on your implementation, customer.gym_visit_set() could yield the ‘list’. More on reddit.com
🌐 r/django
7
8
January 14, 2023
How to use the ArrayField in Django to store a list of strings
Did you read this? https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/#arrayfield foo = ArrayField(models.CharField()) What are you confused about? More on reddit.com
🌐 r/djangolearning
3
1
April 13, 2019
Top answer
1 of 16
391

Django versions 1.8 and later:

You should use get_fields():

[f.name for f in MyModel._meta.get_fields()]

The get_all_field_names() method is deprecated starting from Django 1.8 and will be removed in 1.10.

The documentation page linked above provides a fully backwards-compatible implementation of get_all_field_names(), but for most purposes the previous example should work just fine.


Django versions before 1.8:

model._meta.get_all_field_names()

That should do the trick.

That requires an actual model instance. If all you have is a subclass of django.db.models.Model, then you should call myproject.myapp.models.MyModel._meta.get_all_field_names()

2 of 16
124

As most of answers are outdated I'll try to update you on Django 2.2 Here posts- your app (posts, blog, shop, etc.)

1) From model link: https://docs.djangoproject.com/en/stable/ref/models/meta/

from posts.model import BlogPost

all_fields = BlogPost._meta.fields
#or
all_fields = BlogPost._meta.get_fields()

Note that:

all_fields=BlogPost._meta.get_fields()

Will also get some relationships, which, for ex: you can not display in a view.
As in my case:

Organisation._meta.fields
(<django.db.models.fields.AutoField: id>, <django.db.models.fields.DateField: created>...

and

Organisation._meta.get_fields()
(<ManyToOneRel: crm.activity>, <django.db.models.fields.AutoField: id>, <django.db.models.fields.DateField: created>...

2) From instance

from posts.model import BlogPost

bp = BlogPost()
all_fields = bp._meta.fields

3) From parent model

Let's suppose that we have Post as the parent model and you want to see all the fields in a list, and have the parent fields to be read-only in Edit mode.

from django.contrib import admin
from posts.model import BlogPost 

@admin.register(BlogPost)
class BlogPost(admin.ModelAdmin):
    all_fields = [f.name for f in Organisation._meta.fields]
    parent_fields = BlogPost.get_deferred_fields(BlogPost)

    list_display = all_fields
    read_only = parent_fields
🌐
Readthedocs
django-mysql.readthedocs.io › en › latest › model_fields › list_fields.html
List Fields - django-mysql 4.19.0 documentation
When performing the list-to-string ... ListCharField performs some validation, and will raise ValueError if there is a problem, to avoid saving bad data. The following are invalid: Any member containing a comma in its string representation · Any member whose string representation is the empty string · The default form field is SimpleListField. class django_mysql.models.ListTextF...
🌐
Django
docs.djangoproject.com › en › 6.0 › topics › db › models
Models | Django documentation | Django
The most important part of a model – and the only required part of a model – is the list of database fields it defines. Fields are specified by class attributes. Be careful not to choose field names that conflict with the models API like clean, save, or delete. ... from django.db import models class Musician(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) instrument = models.CharField(max_length=100) class Album(models.Model): artist = models.ForeignKey(Musician, on_delete=models.CASCADE) name = models.CharField(max_length=100) release_date = models.DateField() num_stars = models.IntegerField()
Top answer
1 of 9
143

You can convert it into string by using JSON and store it as string.

For example,

In [3]: json.dumps([[1, 3, 4], [4, 2, 6], [8, 12, 3], [3, 3, 9]])

Out[3]: '[[1, 3, 4], [4, 2, 6], [8, 12, 3], [3, 3, 9]]'

You can add a method into your class to convert it automatically for you.

import json


class Foobar(models.Model):
    foo = models.CharField(max_length=200)

    def set_foo(self, x):
        self.foo = json.dumps(x)

    def get_foo(self):
        return json.loads(self.foo)

If you're using Django 1.9 or above, and you use postgresql, there is a new class called JSONField, you should use it instead. Here is a link to it

There is a good talk about PostgreSQL JSONs and Arrays on youtube. Watch it, it has very good information.

2 of 9
57

If you're on Django 1.10 or newer AND Postgres as your database, you can use ArrayField. It's better to use than django-taggit or other alternatives, as it's native to the Django framework. https://docs.djangoproject.com/en/3.1/ref/contrib/postgres/fields/#arrayfield

from django.db import models
from django.contrib.postgres.fields import ArrayField

class ChessBoard(models.Model):
    board = ArrayField(
        ArrayField(
            models.CharField(max_length=10, blank=True),
            size=8,
        ),
        size=8,
    )

If you're on Django 3.1 or newer they've added support for JSONField with most database backends (MariaDB 10.2.7+, MySQL 5.7.8+, Oracle, PostgreSQL, and SQLite 3.9.0+). You can use this to store your Array!

https://docs.djangoproject.com/en/3.1/ref/models/fields/#jsonfield

from django.db import models

class ChessBoard(models.Model):
    list_of_pieces = models.JSONField()
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-a-list-of-the-fields-in-a-django-model
How to Get a List of the Fields in a Django Model - GeeksforGeeks
July 23, 2025 - The '_meta' attribute has a method called 'get_fields()', which returns all the fields defined in the model, including related fields like foreign keys. This method allows us to work with the model’s structure dynamically without hardcoding ...
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › common-django-model-fields-and-their-use-cases
Django Model Fields – Common Use Cases and How They Work
November 23, 2023 - This field stores dates in your model and has two optional parameters (auto_now and auto_now_add). The auto_now parameter sets the date every time you change or update data, while the auto_now_add sets the field's date only when you create the data. The following is an example of how you can use the date field: from django.db import models class Product(models.Model): date_created = models.DateField(auto_now_add=True) date_updated = models.DateField(auto_now=True)
🌐
Django
django.how › models › data-types-and-fields-list
Data Types and Fields List Django.How
UUIDField A field for storing universally unique identifiers. Uses Python’s UUID class. When used on PostgreSQL, this stores in a uuid datatype, otherwise in a char(32). ForeignKey A many-to-one relationship. Requires two positional arguments: the class to which the model is related and the on_delete option.
🌐
Webforefront
webforefront.com › django › modeldatatypesandvalidation.html
Django model data types
Listing 7-7 illustrates a modified version of the Store model from listing 7-6 with a series of date field variations. The first two additional fields date and datetime use a DateField with a default value using Python's standard datetime library and a DateTimeField with a default value using Django's django.utils.timezone module, respectively -- the sidebar contains more details on why use the django.utils.timezone module to create a date time value.
🌐
GitHub
gist.github.com › 1200165
Howto use ListFields in Django's admin · GitHub
For more about custom form fields, refer to the Django documentation and your favourite search engine using the terms "Django custom form field". First, we need to subclass ListField to override the formfield method: from .forms import StringListField class CategoryField(ListField): def formfield(self, **kwargs): return models.Field.formfield(self, StringListField, **kwargs) class Post(models.Model): title = models.CharField(max_length=100) categories = CategoryField()
🌐
Django Documentation
docs.djangoproject.com › en › 5.2 › howto › custom-model-fields
How to create custom model fields | Django documentation | Django
serialize: If False, the field will not be serialized when the model is passed to Django’s serializers. Defaults to True. ... db_tablespace: Only for index creation, if the backend supports tablespaces. You can usually ignore this option. auto_created: True if the field was automatically created, as for the OneToOneField used by model inheritance. For advanced use only. All of the options without an explanation in the above list have the same meaning they do for normal Django fields.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › django tutorial › django model fields
Django Model Fields | Complete Guide on Django Model Fields
May 22, 2023 - This is a guide to Django Model Fields. Here we discuss the introduction, django model fields methods, types & list, and examples.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Medium
dextrop.medium.com › mastering-django-models-a-guide-to-field-types-and-relationships-e085b5fa9b59
Mastering Django Models: A Guide to Field Types and Relationships | by Saurabh Pandey | Medium
May 2, 2023 - In addition to these field types, ... for a field to a fixed set of values. For example, a ChoiceField might be used to provide a dropdown list of options for the user to choose from when creating or editing a blog post status. ... In this code example, we have defined three Django models: Profile, ...
🌐
Django Documentation
docs.djangoproject.com › en › 5.1 › ref › contrib › postgres › fields
PostgreSQL specific model fields | Django documentation | Django
Transformation of values between the database and the model, validation of data and configuration, and serialization are all delegated to the underlying base field. ... This is an optional argument. If passed, the array will have a maximum size as specified. This will be passed to the database, although PostgreSQL at present does not enforce the restriction. ... When nesting ArrayField, whether you use the size parameter or not, PostgreSQL requires that the arrays are rectangular: from django.contrib.postgres.fields import ArrayField from django.db import models class Board(models.Model): pieces = ArrayField(ArrayField(models.IntegerField())) # Valid Board( pieces=[ [2, 3], [2, 1], ] ) # Not valid Board( pieces=[ [2, 3], [2], ] )
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn › Server-side › Django › Models
Django Tutorial Part 3: Using models - Learn web development | MDN
October 24, 2024 - In the discussion below, we'll refer to a Book model with title and genre fields, where genre is also a model with a single field name. We can get all records for a model as a QuerySet, using objects.all(). The QuerySet is an iterable object, meaning that it contains a number of objects that we can iterate/loop through. ... Django's filter() method allows us to filter the returned QuerySet to match a specified text or numeric field against particular criteria.
🌐
Reddit
reddit.com › r/django › how do you put a listfield attribute in a django model?
r/django on Reddit: How do you put a ListField attribute in a Django model?
October 18, 2021 -

I have a model TutorProfile and I wanted it to have an attribute like a list for storing the names of students, so that I will know who are the students that has successfully booked a lesson to a certain tutor. Can someone guide me with this?

this my model

class TutorProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='tutor_profile')
    profile_headline = models.CharField(max_length=200, null=True)
    bio = models.TextField(max_length=500, blank=True, null=True)
    is_validated = models.BooleanField(default=False)
    hourly_rate = models.DecimalField(max_digits=8, decimal_places=2, default=0)
    students = models.ListField()
Top answer
1 of 2
7
The approach may depend on the complexity you are looking for. If you have a large roster of students that can each have several tutors, then you would do a thorough data model (later) If a tutor is going to simply track the students who contact them (and there isn't a need for a central master list of students), there would be a second model Tutorship with a foreign key to TutorProfile (with a related_name='students') and a field for the student name and contact information. From a TutorProfile entry, Django will then provide a students accessor that will get you to details or you could do students.count(). For more thorough roster of students you would have another model for Student. Assuming a student could have more than one tutor (one for Math, one for Science), you would have another model Tutorship that contains a foreign key to TutorProfile (related_name='students') and a foreign key to Student (related_name=;tutors'), along with fields to track the start date, and end date. As before, the accessors would be available from either a TutorProfile or from the Student. With either approach, it might be desirable to track the sessions, so you might even have a TrainingSession model, with a foreign key to Tutorship that tracks each session's date (or datetime) and duration, and maybe a note field for what was done in that session. This seems like a lot of models, but it organizes the data into the relationships and allows you to track attributes of those relationships. From a Tutorship model, you can summarize all of the training sessions. It is also possible on the Tutorship to have an agreed hourly_rate (rather than the default hourly rate on the TutorProfile) in situations where the student needs more in-depth help or perhaps only a light review of progress. A good data model supports the business and how the business works, not the nifty shortcuts the programmer devises. I learned this once and it stuck with me and made the application incredibly extendable over the years as there were new attributes (fields) to track on each model but the relationships between the models did not change.
2 of 2
3
If you are never going to need more data on the students and it's really just a list of names you want to have access to or query on, then `from django.contrib.postgres.fields import ArrayField` is a great choice. It's important not to use these too much, for sake of complicating matters down the road if you wind up wanting more metadata on students. Also, you need to be using Postgres.
🌐
Medium
medium.com › django-unleashed › django-model-tutorial-fields-attributes-and-meta-options-example-ba657101d1ce
Django model tutorial fields attributes and meta options example | by Mehedi Khan | Django Unleashed | Medium
February 15, 2025 - indexes: Specifies one or more indexes to create for the model. unique_together: Lists the set of fields that must be unique together. Let’s create a Django model for a simple blogging application.
🌐
Horilla
horilla.com › blogs › what-are-the-different-field-types-in-django
What are the Different Field Types in Django? | Blogs | Free HRMS | Horilla
February 3, 2024 - This blog post provided an overview ... including CharField, TextField, IntegerField, FloatField, BooleanField, DateField, DateTimeField, EmailField, and the relationship field types ForeignKey and ManyToManyField....