from django.contrib import admin
from blog.models import Category, Article
from parler.admin import TranslatableAdmin
from .forms import ArticleForm
from django.core.exceptions import PermissionDenied
class CategoryAdmin(TranslatableAdmin):
pass
class ArticleAdmin(TranslatableAdmin):
form = ArticleForm
list_display = ('title', 'author', 'category')
class Media:
css = {
'all': ('css/admin/blog.css',)
}
admin.site.register(Category, CategoryAdmin)
admin.site.register(Article, ArticleAdmin)
class Wish(models.Model):
customer = models.ForeignKey(User)
item = models.ForeignKey(Product)
class Meta:
unique_together = ['customer', 'item']
class WishCreate(CreateView):
model = Wish
fields = ['item']
def form_valid(self, form):
obj = form.save(commit=False)
obj.customer = self.request.user
obj.save()
return http.HttpResponseRedirect(self.get_success_url())
class WishDelete(DeleteView):
model = Wish
success_url = reverse_lazy('wish-list')
class WishList(ListView):
model = Wish
def get_queryset(self):
return Wish.objects.filter(customer=self.request.user)
def send_mail(subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None, auth_password=None,
connection=None, html_message=None):
context = {
'order': order,
}
send_mail(
'Thanks for order',
'blablabla',
email_from,
[order.email],
fail_silently=True,
html_message=get_template('emails/confirmation.html').render(context)
)
# app.renderers.py
from rest_framework.renderers import JSONRenderer
class UTF8CharsetJSONRenderer(JSONRenderer):
charset = 'utf-8'
# settings.py
REST_FRAMEWORK = {
# ...
'DEFAULT_RENDERER_CLASSES': (
'app.renderers.UTF8CharsetJSONRenderer',
),
# ...
}