django-views

New chat message notification Django Channels

女生的网名这么多〃 提交于 2019-12-12 07:49:43
问题 I've got Django Channels 2.1.2 set up in my Django app by following a tutorial and now need to set up a notification system for new messages. I want to do this in the simplest way possible. I can do it via browser push notifications, but I don't want to do it like that. I want it to be like Stack Overflow, where there is a red number representing the instance of a new message. One answer on here said For notifications you only need two models: User and Notification . On connect set the scope

How To Show User Profile To Everyone By Link! in Django

怎甘沉沦 提交于 2019-12-12 06:59:38
问题 How To Show User Profile To Everyone By Link! in Django I Want To Show User Profile To Everyone for-example if someone type this in browser domain.com/profile/1 Then Our First User Profile Want To Show But it's showing blank It's showing when user login but we need to show to everyone Here is my detail.html {% extends 'base.html' %} {% block body_block %} <h1 class="posttitle">{{user.username}}</h1> {% endblock %} Here is my Views.py def profile_detail(request,pk): model = get_object_or_404

Double filter on detail view

余生颓废 提交于 2019-12-12 06:51:29
问题 I'm trying to create a detail view using function based view. This view must make visible only the already published posts and the non draft posts. def singlePost(request, slug_post, slug_category): post_category = get_object_or_404(BlogCategory, slug_category=slug_category) if post_filter == BlogPost.objects.filter(draft=True): raise PermissionDenied if post_filter == BlogPost.objects.filter(publishing_date__gt=datetime.datetime.now()): raise PermissionDenied else: post_filter == BlogPost

Django redirect URL to latest created blog post

只谈情不闲聊 提交于 2019-12-12 06:38:07
问题 I want to have a redirect in my urls.py so that the latest Post entry in my Blog application is automatically loaded when people visit the Blog application index domain. A Blog.Post detail is supplied via the blog.views.post_detail(request, slug) method and a blog post will end up with the URL: www.example.com/blog/this-is-the-slug/ When someone loads the www.example.com/blog domain I want them to be automagically redirected to the latest blog post individual entry. I'm very new to the urls

Django beginner: How to query in django ORM to calculate fields based on dates

依然范特西╮ 提交于 2019-12-12 06:11:18
问题 Task: Querying a model in Django ORM so that I can calculate fields based on dates. Specifically, extract months from a model.datefield and calculate values based on these months. Example model: class PersonProjectHours(models.Model): project = models.ForeignKey('projects.Project') person = models.ForeignKey('projects.Person') rate = models.ForeignKey('PersonIncome') work_date = models.DateField(help_text=_('Enter date')) hours = models.IntegerField(help_text=_('Enter hours worked on this day

URL rendered as home_page after internationalization

Deadly 提交于 2019-12-12 05:29:10
问题 I have a Django Website that I am trying to internationalize. Until now it looked like this: Homepage: www.myhomepage.com Another page: www.myhomepage.com/content/cities Now I am trying to make it like this: Homepage: www.myhomepage.com/en www.myhomepage.com/de Another page: www.myhomepage.com/en/content/cities www.myhomepage.com/de/content/cities Following this and this, I managed to make the homepage work, so with www.myhomepage.com/en I see the homepage in English and with www.myhomepage

Display full names in Form ChoiceField but saving ID's

给你一囗甜甜゛ 提交于 2019-12-12 05:05:11
问题 I have model Person - from another database I copied all person_id to custom_id . models.py class Employee(models.Model): custom_id = models.CharField(max_length=20, unique=True) @property def person(self): return Person.objects.get(person_id='%s' % self.custom_id) def __str__(self): return '%s' % self.custom_id class Task(models.Model): employee = models.ManyToManyField(Employee, blank=True, null=True) task = models.CharField(max_length=100) comment = models.CharField(max_length=200) def _

django admin custom template page not found error

馋奶兔 提交于 2019-12-12 04:56:21
问题 I am trying to modify the django admin interface and I cannot see the custom templates. In the admin.py file I added this model admin class FTPAdmin(admin.ModelAdmin): def get_urls(self): urls = super(FTPAdmin,self).get_urls() my_urls = patterns('', (r'^ftp/$',self.admin_site.admin_view(self.FTPView))) return my_urls + urls def FTPView(self, request): form = FTPForm() if request.method == 'POST': if form.is_valid(): return HttpResponseRedirect('/admin/') return render_to_response(request,

How to access url part in python django?

懵懂的女人 提交于 2019-12-12 04:48:35
问题 I am working on APIs using django. I want to access my resources in following way: {base_url}/employee/{emp_id} . Here emp_id is not a GET parameter. How can I access this parameter in my view? Is there any standard way to access it without manually parsing URL? 回答1: Depending on whether you are using class based views or whether you are using standard view functions the method is different. For class based views, depending on which action you are willing to perform (ListView, DetailView, ...

set variable into queryset of forms.py from my generic view or url

大城市里の小女人 提交于 2019-12-12 04:36:51
问题 I want to set a dynamic variable into queryset of forms.py , I used __init__ to pass the dynamic variable , I think the code in forms.py is correct, the problem is how to pass the variable in views? forms.py : class ContainerForm(forms.ModelForm): vehicle=forms.ModelChoiceField(required=False,queryset=Vehicle.objects.all(),widget=forms.Select(attrs={'class':'form-control'})) def __init__(self, *args, **kwargs): vehicle_id = kwargs.pop('vehicle_id',None) super(ContainerForm, self).__init__(