Answer the question
In order to leave comments, you need to log in
How to make unique ForeignKey field values in Django based on records in the database?
It is interesting to make restrictions either at the model level or in the admin panel (I work with models from there).
There are such models:
class ModelA(models.Model):
name = models.CharField('имя модели А', max_length=200)
class ModelB(models.Model):
name = models.CharField('имя модели B', max_length=200)
class ModelC(models.Model):
name = models.CharField('имя модели C', max_length=200)
model_a = models.ForeignKey(ModelA, on_delete=models.SET_NULL, verbose_name='Модель А', null=True)
model_b = models.ForeignKey(ModelB, on_delete=models.SET_NULL, verbose_name='Модель A', null=True)
A1 (id=1, name="One"), A2 (id=2, name="Two")
B1 (id=1, name="One"), B2 (id=2, name="Two")
C1 (id=1, name="имя модели", model_a_id=1, model_b_id=1)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question