2021-12-22 18:03:21 +00:00
|
|
|
"""Custom category fields for other models."""
|
2024-04-15 17:43:22 +00:00
|
|
|
|
2010-01-27 15:48:09 +00:00
|
|
|
from django.db.models import ForeignKey, ManyToManyField
|
|
|
|
|
|
2012-07-12 23:24:55 +00:00
|
|
|
|
2010-01-27 15:48:09 +00:00
|
|
|
class CategoryM2MField(ManyToManyField):
|
2021-12-22 18:03:21 +00:00
|
|
|
"""A many to many field to a Category model."""
|
|
|
|
|
|
2010-01-27 15:48:09 +00:00
|
|
|
def __init__(self, **kwargs):
|
2021-12-05 14:34:46 +00:00
|
|
|
if "to" in kwargs:
|
|
|
|
|
kwargs.pop("to")
|
2020-03-13 19:02:38 +00:00
|
|
|
super(CategoryM2MField, self).__init__(to="categories.Category", **kwargs)
|
2010-02-12 17:09:58 +00:00
|
|
|
|
|
|
|
|
|
2010-01-27 15:48:09 +00:00
|
|
|
class CategoryFKField(ForeignKey):
|
2021-12-22 18:03:21 +00:00
|
|
|
"""A foreign key to the Category model."""
|
|
|
|
|
|
2010-01-27 15:48:09 +00:00
|
|
|
def __init__(self, **kwargs):
|
2021-12-05 14:34:46 +00:00
|
|
|
if "to" in kwargs:
|
|
|
|
|
kwargs.pop("to")
|
2020-03-13 19:02:38 +00:00
|
|
|
super(CategoryFKField, self).__init__(to="categories.Category", **kwargs)
|