N
N
Neyury2016-11-28 02:22:31
Django
Neyury, 2016-11-28 02:22:31

How to change field display or create custom widget in django admin?

Implementing an online clothing catalog in Django.
To store information about clothing sizes, I decided to use a numeric field, the value of which will be determined through the sum of numbers corresponding to certain sizes.
Example
S = 00001 (1)
M = 00010 (2)
L = 00100 (4)
XL = 01000 (8)
XXL = 10000 (16) etc
S, M, XXL = 1 + 2 + 16 = 19 (10011 )
How can this be turned into a convenient option for moderators? (Group of checkboxes, or something else) What are the options?
A temporary option is a dropdown box with predefined options.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stepan Krapivin, 2016-11-30
@Neyury

The easiest option is to create a field for each size on the model, and combine these fields into one line in the admin class.
like this

# models.py
class Clothes(models.Model):
    s_size = models.BooleanField()
    m_size = models.BooleanField()
    l_size = models.BooleanField()

# admin.py
class ClothesAdmin(admin.ModelAdmin):
    fields = (
        ('s_size', 'm_size', 'l_size'),
        ...другие поля,
    )

V
Vayladion Gognazdiak, 2016-11-28
@etspring

Many to one via ForeignKey

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question