django-categories/categories/fields.py

22 lines
631 B
Python
Raw Permalink Normal View History

"""Custom category fields for other models."""
from django.db.models import ForeignKey, ManyToManyField
2012-07-12 23:24:55 +00:00
class CategoryM2MField(ManyToManyField):
"""A many to many field to a Category model."""
def __init__(self, **kwargs):
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
class CategoryFKField(ForeignKey):
"""A foreign key to the Category model."""
def __init__(self, **kwargs):
if "to" in kwargs:
kwargs.pop("to")
2020-03-13 19:02:38 +00:00
super(CategoryFKField, self).__init__(to="categories.Category", **kwargs)