2021-12-22 18:03:21 +00:00
|
|
|
"""Custom category fields for other models."""
|
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):
|
2015-05-13 20:08:35 +00:00
|
|
|
from .models import Category
|
2021-12-05 14:34:46 +00:00
|
|
|
|
|
|
|
|
if "to" in kwargs:
|
|
|
|
|
kwargs.pop("to")
|
2010-01-27 15:48:09 +00:00
|
|
|
super(CategoryM2MField, self).__init__(to=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):
|
2015-05-13 20:08:35 +00:00
|
|
|
from .models import Category
|
2021-12-05 14:34:46 +00:00
|
|
|
|
|
|
|
|
if "to" in kwargs:
|
|
|
|
|
kwargs.pop("to")
|
2011-03-17 10:20:53 +00:00
|
|
|
super(CategoryFKField, self).__init__(to=Category, **kwargs)
|