class CategoriesServicesInline(admin.TabularInline):
model = cm.CategoriesServices
extra = 1
fields = ('name', 'description', 'price', 'explanation', 'group')
# form = CategoryForm
@admin.register(cm.CategoriesGroups)
class CategoriesGroupsAdmin(admin.ModelAdmin):
inlines = [
CategoriesServicesInline,
]
@admin.register(cm.Services)
class ServicesAdmin(admin.ModelAdmin):
inlines = [
CategoriesServicesInline,
]
from django import forms
from core import models as cm
class CategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CategoryForm, self).__init__(*args, **kwargs)
if self.fields.get('group', None) is not None:
self.fields['group'].queryset = self.fields['group']\
.queryset.filter(service_id=self.instance.service_id)
class Meta:
model = cm.CategoriesServices
fields = '__all__'