mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
21 lines
631 B
Python
21 lines
631 B
Python
"""Custom category fields for other models."""
|
|
|
|
from django.db.models import ForeignKey, ManyToManyField
|
|
|
|
|
|
class CategoryM2MField(ManyToManyField):
|
|
"""A many to many field to a Category model."""
|
|
|
|
def __init__(self, **kwargs):
|
|
if "to" in kwargs:
|
|
kwargs.pop("to")
|
|
super(CategoryM2MField, self).__init__(to="categories.Category", **kwargs)
|
|
|
|
|
|
class CategoryFKField(ForeignKey):
|
|
"""A foreign key to the Category model."""
|
|
|
|
def __init__(self, **kwargs):
|
|
if "to" in kwargs:
|
|
kwargs.pop("to")
|
|
super(CategoryFKField, self).__init__(to="categories.Category", **kwargs)
|