[Django]-Djongo redefine the structure of ArrayModelField

2πŸ‘

βœ…

As of latest version in Djongo, this structure is still not possible if you want to have automatic support for Admin Panel. Having said that, you can always use ListField and write custom view for the admin panel which is a valid solution for now. Also don’t see any timeline in which that will be fixed by the developer.

πŸ‘€hello world

1πŸ‘

Use ListField:

options = models.ListField()

πŸ‘€Cob

0πŸ‘

For your use case, where the database connected is a MongoDB, you can do this:

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


class Option(models.Model):
.
.
.

class Quiz(models.Model):
    _id = models.ObjectIdField()
    question = models.TextField(null=True, blank=True)
    options = models.ArrayField(models.CharField(max_length=1024, blank=True),size=8)

this will show your options in a comma-separated manner i.e. A,B,C
attaching a screenshot for example

πŸ‘€Mayank Arya

Leave a comment