Y
Y
Yura Khlyan2019-11-06 18:43:34
Django
Yura Khlyan, 2019-11-06 18:43:34

How to create such models?

I have the following structure:

class Profile(models.Model):
    name = models.CharField(max_length=128)


class Characteristic(models.Model):
    name = models.CharField(max_length=128)


class ProfileCharacteristic(models.Model):
    profile = models.ForeignKey('profiles.Profile', on_delete=models.CASCADE, related_name='profile_characteristics')
    characteristic = models.ForeignKey('characteristic.Characteristic', on_delete=models.CASCADE, related_name='profile_characteristics')
    # следующие поля я б хотел упростить/изменить
    value_text = models.TextField(null=True)
    value_number = models.FloatField(null=True)
    value_range = ArrayField(models.FloatField(), size=2, null=True)
    value_list = ArrayField(models.CharField(max_length=128), null=true)

In other words, there is a profile that is formed by a combination of characteristics and their valid values ​​(number, range, list). Then that profile is assigned to some product.
For example, for paper.
Characteristics:
  • White
  • Brightness

Profile:
Class A :
  • Brightness: 98-112
  • Whiteness: 164-169

Class B :
  • Brightness: 94-95
  • Whiteness: 160-163

Hope the point is clear. Now to the question. How can I simplify (make better) relationships in models?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-11-06
@dimonchik2013

you do as you can, and after profiling, you will change at the
same time and you will master walking on migrations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question