mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
28 lines
782 B
Python
28 lines
782 B
Python
from django.db.models import ForeignKey, ManyToManyField
|
|
|
|
|
|
class CategoryM2MField(ManyToManyField):
|
|
def __init__(self, **kwargs):
|
|
from .models import Category
|
|
|
|
if "to" in kwargs:
|
|
kwargs.pop("to")
|
|
super(CategoryM2MField, self).__init__(to=Category, **kwargs)
|
|
|
|
|
|
class CategoryFKField(ForeignKey):
|
|
def __init__(self, **kwargs):
|
|
from .models import Category
|
|
|
|
if "to" in kwargs:
|
|
kwargs.pop("to")
|
|
super(CategoryFKField, self).__init__(to=Category, **kwargs)
|
|
|
|
|
|
try:
|
|
from south.modelsinspector import add_introspection_rules
|
|
|
|
add_introspection_rules([], [r"^categories\.fields\.CategoryFKField"])
|
|
add_introspection_rules([], [r"^categories\.fields\.CategoryM2MField"])
|
|
except ImportError:
|
|
pass
|