pip freeze > requirements.txt
Django==1.10
django-cors-middleware==1.3.0
djangorestframework==3.4.5
djangorestframework-jsonapi==2.1.0
inflection==0.3.1
...
def handle_post_slug(sender, instance, *args, **kwargs):
from pyutils import translit
slug = translit(instance.title)
if Post.objects.filter(slug=slug).exclude(id=instance.id).exists():
slug = "-".join([slug, str(instance.id)])
instance.slug = slug
pre_save.connect(handle_post_slug, sender=Post)
class BookSerializer(serializers.ModelSerilaizer):
class Meta:
model = Book
fields = ('id', 'title', 'url')
class AuthorSerializer(serializers.ModelSerializer):
name = serializers.CharField(source='get_name', read_only=True)
url = serializers.CharField(source='get_absolute_url', read_only=True)
book_count = serializers.CharField(source='get_book_count', read_only=True)
books_url = serializers.CharField(source='get_books_url', read_only=True)
books = BookSerializer(many=True, read_only=True)
class Meta:
model = AuthorModel
exclude = ('first_name', 'last_name')
obj.parent.user == request.user
class Article(models.Model):
...
case = models.ForeignKey(Case, related_name='articles')
...
class CaseSerializer(serializers.ModelSerializer):
class Meta:
model = Case
fields = (..., ..., 'articles')
class ProductViewSet(viewsets.ReadOnlyModelViewSet):
# queryset = Product.objects.filter(is_active=True)
def get_queryset(self):
queryset = Product.objects.filter(is_active=True)
attributes = self.request.query_params.get('attributes', None)
# if attributes is not None:
# custom logic of search
# list_of_ids = [...]
# queryset.filter(id__in=list_of_ids)
return queryset