working to fix tag widgets in admin
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from . import models
|
||||
from . import forms
|
||||
|
||||
# Register your models here.
|
||||
|
||||
class CagtegoryAdmin(admin.ModelAdmin):
|
||||
form = forms.CategoryTagForm
|
||||
|
||||
|
||||
|
||||
class CategoryInline(admin.TabularInline):
|
||||
model = models.CategoryTag
|
||||
form = forms.CategoryTagForm
|
||||
|
||||
|
||||
admin.site.register(models.Product)
|
||||
admin.site.register(models.TreeTag)
|
||||
admin.site.register(models.CategoryTag)
|
||||
admin.site.register(models.CategoryTag, CagtegoryAdmin)
|
||||
admin.site.register(models.AttributeTag)
|
||||
|
||||
14
products/forms.py
Normal file
14
products/forms.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from dal import autocomplete
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import CategoryTag
|
||||
|
||||
|
||||
class CategoryTagForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CategoryTag
|
||||
fields = ('__all__')
|
||||
widgets = {
|
||||
'category': autocomplete.ModelSelect2(url='cagtegory-autocomplete')
|
||||
}
|
||||
@@ -34,7 +34,6 @@ class AttributeTag(TagTreeModel):
|
||||
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
|
||||
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
|
||||
SYNCHRONIZED = 'SYNCHRONIZED'
|
||||
|
||||
@@ -16,10 +16,11 @@ from rest_framework.filters import OrderingFilter
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
import requests
|
||||
|
||||
from products.models import Product
|
||||
from products.models import Product, CategoryTag
|
||||
from products.serializers import ProductSerializer, TagFilterSerializer, SearchResultSerializer
|
||||
from companies.models import Company
|
||||
from history.models import HistorySync
|
||||
from dal import autocomplete
|
||||
|
||||
from back_latienda.permissions import IsCreator
|
||||
from .utils import extract_search_filters, find_related_products_v3, find_related_products_v6, product_loader
|
||||
@@ -214,3 +215,20 @@ def product_search(request):
|
||||
return Response(data={"filters": filters, "count": total_results, "products": result_list, 'prices': prices})
|
||||
except Exception as e:
|
||||
return Response({"errors": {"details": str(e)}}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
|
||||
class CategoryTagAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
# Get the tag model dynamically
|
||||
Tag = Product.category.tag_model
|
||||
|
||||
# Return nothing if not auth
|
||||
if not self.request.is_authenticated():
|
||||
return Tag.objects.none()
|
||||
|
||||
qs = Tag.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__istartswith=self.q)
|
||||
|
||||
return self.q
|
||||
|
||||
Reference in New Issue
Block a user