Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Making complex model without database Django

On django 3

When I need data without real database(like mysql), I can use m.IntegerChoices

This CallType never changes so IntegerChoices is suitable.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from django.db import models as m
class CallType(m.IntegerChoices):
    PULL = 1 
    PUSH = 2

class BaseCall(models.Model):
    class Meta:
        db_table = 't_BaseCall'

    call_type = m.PositiveSmallIntegerField(
        choices=CallType.choices, default=CallType.PULL)

Now I want to expand CallType more complex.

class CallType(m.IntegerChoices):
    PULL = {"number":1,"name":"pulling"}
    PUSH = {"number":2,"name":"pushing"}

What practice should I use?

I am afraid IntegerChoices is not suitable for this case.

>Solution :

To add labels to Django enumeration types, pass tuples to each member where the first element is the value and second element is the custom label

class CallType(m.IntegerChoices):
    PULL = 1, "pulling"
    PUSH = 2, "pushing"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading