Change foreign key to many to many to allow more flexibility

This commit is contained in:
Zach Taylor 2020-10-21 16:03:20 -05:00
parent aaaa813b9b
commit 5d8ba99361
2 changed files with 6 additions and 12 deletions

View file

@ -27,7 +27,7 @@ class Migration(migrations.Migration):
('modified', models.DateTimeField(auto_now=True, verbose_name='Modified')),
('required', models.BooleanField(default=False, verbose_name='Required')),
('display_order', models.PositiveIntegerField(default=1, verbose_name='Display order')),
('entity_ct', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='attribute_entities', to='contenttypes.ContentType')),
('entity_ct', models.ManyToManyField(to='contenttypes.ContentType', blank=True)),
],
options={
'ordering': ['name'],

View file

@ -184,18 +184,12 @@ class Attribute(models.Model):
"""
required = models.BooleanField(verbose_name = _('Required'), default = False)
entity_ct = models.ForeignKey(
ContentType,
null = True,
blank = True,
on_delete = models.PROTECT,
related_name = 'attribute_entities'
)
entity_ct = models.ManyToManyField(ContentType, blank=True)
"""
This field allows you to specify a foreign key to a content type.
This would be useful, for example, if you wanted an attribute to apply only to one entity.
In that case, you could filter by content type in the :meth:`~eav.registry.EavConfig.get_attributes`
method of that entity's config.
This field allows you to specify a relationship with any number of content types.
This would be useful, for example, if you wanted an attribute to apply only to
a subset of entities. In that case, you could filter by content type in the
:meth:`~eav.registry.EavConfig.get_attributes` method of that entity's config.
"""
enum_group = models.ForeignKey(