A
A
Andrey Kirdyashkin2020-12-03 11:38:47
Django
Andrey Kirdyashkin, 2020-12-03 11:38:47

Is it possible to combine two CharField fields in models?

Is it possible to combine two fields through a slash and check for unique on it?

Let's say

class Factory(models.Model):
    city = models.CharField('Город', max_length=30)
    name = models.CharField('Наименование организации', max_length=50)
    uniquetincity = city + '/' + tin(verbose_name='Город/ИНН', unique=True)


Or how to implement it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-12-03
@ANDYNEI

class Meta:
        unique_together = ('city', 'tin')

Two fields - one model must be

D
Dr. Bacon, 2020-12-03
@bacon

https://qna.habr.com/answer?answer_id=1808781#answ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question