B
B
bituke2022-02-17 18:53:22
Django
bituke, 2022-02-17 18:53:22

How to select multiple statuses at once in django?

model:

class EbayProduct(models.Model):
    class Status(models.IntegerChoices):
        EBAY_PRODUCT = 0, 'Ebay product'
        READY_TO_LIST = 1, 'Ready to list'
        LISTINGS_TO_REMOVE = 2, 'Listings to remove'
        PRICE_UPDATE_NEEDED = 3, 'Price Update Needed'
        NO_WEIGHT = 4, 'No weight or weight = 0'
        NO_IMAGES = 5, 'No images'
        UPC_EAN_GTIN_NOT_ASSIGNED = 6, 'UPC/EAN/GTIN not assigned'
        NO_EBAY_CATEGORIES = 7, 'No ebay categories'
        PRODUCT_SWITCHED = 8, 'Products Switched off for this selling site'
        UPDATE_BLOCKED = 9, 'Update Blocked'

    ''' fields '''
    product = models.OneToOneField(Product, on_delete=models.CASCADE, related_name='for_ebay')
    status = models.SmallIntegerField(choices=Status.choices, default=Status.EBAY_PRODUCT, verbose_name='status')

The problem is that there can be several statuses at the same time. Writing a separate model for statuses and adding them to the database every time is not an option for me. How can I select several statuses at once in one field?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2022-02-17
@bacon

for example, replace SmallIntegerField with JSONField, but you will have to manually fill it

V
Vladimir Kuts, 2022-02-17
@fox_12

You can remember what bits are, And just set / check the corresponding bits in the number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question