I am new to using django
and would appreciate your input to the following problem.
Two models are present, namely A
and B
. Instances of A
must belong to at least one instance of B
, while a B
could contain any number of instances of A
s from 0 to infinite.
class A(models.Model):
name = models.CharField(max_length = 128)
created_date = models.DateTimeField(auto_now_add = True)
modified_date = models.DateTimeField(auto_now = True)
class B(models.Model):
name = models.CharField(max_length = 128)
created_date = models.DateTimeField(auto_now_add = True)
modified_date = models.DateTimeField(auto_now = True)
A_list = models.ManyToManyField(A)
Okay. I think, based on the description I have given, ManyToManyField
should be used for the two models. The thing is, from what I have read, blank = false
must be used to prevent a null
assignment for A
(since an A
must be assigned to at least one B
) but a B
may not have an assigned A
(and thus should not have the blank = false
statement. Could anyone asymmetric ManyToMany
relation can be implemented in django
Model
?