def handle(self, *args, **options): user = \ get_user_model().objects.get_or_create(email='*****@*****.**', username='******', password='******')[0] pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0] category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0] category.save() basetag = Tag() basetag.name = "标签" basetag.save() for i in range(1, 20): article = Article.objects.get_or_create(category=category, title='nice title ' + str(i), body='nice content ' + str(i), author=user )[0] tag = Tag() tag.name = "标签" + str(i) tag.save() article.tags.add(tag) article.tags.add(basetag) article.save() from website.utils import cache cache.clear() self.stdout.write(self.style.SUCCESS('created test datas \n'))
def refresh_memcache(request): try: if request.user.is_superuser: from website.utils import cache if cache and cache is not None: cache.clear() return HttpResponse("ok") else: from django.http import HttpResponseForbidden return HttpResponseForbidden() except Exception as e: return HttpResponse(e)
def form_valid(self, form): form = AuthenticationForm(data=self.request.POST, request=self.request) if form.is_valid(): from website.utils import cache if cache and cache is not None: cache.clear() logger.info(self.redirect_field_name) auth.login(self.request, form.get_user()) return super(LoginView, self).form_valid(form) # return HttpResponseRedirect('/') else: return self.render_to_response({'form': form})
def save_model(self, request, obj, form, change): super(ArticlelAdmin, self).save_model(request, obj, form, change) from website.utils import cache cache.clear()
def save(self, *args, **kwargs): super().save(*args, **kwargs) from website.utils import cache cache.clear()
def get(self, request, *args, **kwargs): from website.utils import cache cache.clear() logout(request) return super(LogoutView, self).get(request, *args, **kwargs)
def handle(self, *args, **options): cache.clear() self.stdout.write(self.style.SUCCESS('Cleared cache\n'))