django-views

How to implement filter API in Django rest framework

断了今生、忘了曾经 提交于 2019-12-23 05:48:24
问题 I am trying to implement filter api in django rest. Something like - localhost:8000/api/v1/users/?email=abc.xzy@gmail.com/ So it should search for user with the passed filter and return the result.But currently it is returning all user. URLS.py url(r'^api/v1/users/$', UserViews.UserList.as_view(), name='userlist_view'), url(r'^api/v1/users/(?P<email>.+)/$', UserViews.UserList.as_view(), name='userList_view'), url(r'^api/v1/users/(?P<pk>[0-9]+)/$', UserViews.UserDetail.as_view(), name=

Newbie Django urls, views, and templates - how can this incredibly simple django project possibly be failing?

我是研究僧i 提交于 2019-12-23 05:32:09
问题 When the user lands at http://127.0.0.1:8000/ I would like to display an html page that says "welcome." When the user goes http://127.0.0.1:8000/time/ I would like to display the current time. I have followed instructions to the t and dotted every i. My settings are below. Why do I continue to get a TemplateDoesNotExist error? views.py from django.template.loader import get_template from django.shortcuts import render import datetime def current_datetime(request): now = datetime.datetime.now(

How to send user notifications using django-channels 2.0?

你。 提交于 2019-12-23 05:29:38
问题 I am working on a chat app that has Rooms. Each room has two users. A user can be in multiple rooms i.e, a user has multiple rooms. And now he is chatting in one room. But he receives a message in another room. I would like to notify about the message from other room to the user. How should I implement this? Currently a websocket connection is established as: ws://localhost:8000/chat/int<room_id>/ And the group_name is named as "room"+room_id . and So far I have: async def connect(self): room

Django: saving the Form does not work (The ModelForm Filters the ForeignKey choices by request.user)

六月ゝ 毕业季﹏ 提交于 2019-12-23 05:22:57
问题 I Managed to Filter the ForeignKey choices "Context.name" by "request.user" with the Code Below. First, I defined the Models. models.py class Extension(models.Model): username = models.CharField(primary_key=True, max_length=200, help_text='') callerid = models.CharField(max_length=200, help_text='') extension = models.CharField(max_length=3, help_text='') firstname = models.CharField(max_length=200, help_text='') lastname = models.CharField(max_length=200, help_text='') password = models

How to make generic ListView only show user's listing?

隐身守侯 提交于 2019-12-23 05:18:03
问题 I'm new to Django and I'm utilizing class-based views for the first time. I want to use the generic ListView to show a list of "tables" owned by a user. And so far I've gotten it to display ALL the tables in the database. But I only want it to show tables for the logged in user. this is what my view looks like: from django.shortcuts import render from django.http import HttpResponse from django.views import generic from vtables.models import Vtable class TableListView(generic.ListView): model

Zipping files in Django view and serving them

会有一股神秘感。 提交于 2019-12-23 05:11:41
问题 First of all I want to say that I know its bad to serve files from django but my situation can only be handled by django so I chose it to serve zipped files.In my models.py I have a model class Documents(models.Model): filename = models.CharField(max_length=100) document = models.FileField(upload_to='docs') allowedGroup = models.ManyToManyField(Group) So when a normal user log-in it will be displayed the Documents which he has permission according to his/her group.I want user to be able to

Django pagination with bootstrap

大城市里の小女人 提交于 2019-12-23 04:34:09
问题 I am about to add a pagination to my list of contacts. I am sitting over it the whole day and have no idea what I mixed up. Important thing is that I do have a working filters - so I can narrow the list. But from my understanding pagination should work anyway. In my case I see nothing so my guess is first "if" fails. If you could point me in the right direction. Best regards. Views.py def ContactsList(request): contacts_list = Contact.objects.all() Contacts_filter = LFilter(request.GET,

Django: How can I use get_model in my use case to correctly import a class and avoid conflicts

蓝咒 提交于 2019-12-23 04:18:25
问题 I have a model with a get_form method. # models.py from model_utils.managers import InheritanceManager from breathingactivities.forms import ParentRecordForm, ChildRecordForm class ParentRecord(models.Model): .... objects = InheritanceManager() def get_fields(self, exclude=('user')): fields = self._meta.fields return [(f.verbose_name, f.value_to_string(self)) for f in fields if not exclude.__contains__(f.name)] @classmethod def get_form(self, *args, **kwargs): return ParentRecordForm class

Adding Foreign Key To Django Model

此生再无相见时 提交于 2019-12-23 03:46:11
问题 I was wondering what they best procedures in turning a column from an IntegerField to a Foreign Key. Here are my two models: class workout(models.Model): userid = models.IntegerField() datesubmitted = models.DateField() workoutdate = models.DateField(); bodyweight = models.FloatField(null=True); totalreps = models.IntegerField() totalweight = models.FloatField() numsets = models.IntegerField(); numexercises = models.IntegerField() workoutname = models.CharField(max_length=250) and the second

Django Using Slug Field for Detail URL

只谈情不闲聊 提交于 2019-12-23 03:26:48
问题 I'm attempting to setup my site so that the url for my job-detail will use a slug field instead of a pk. It's telling me that it cannot find my job with the given slug (which is an int, 147). Update: After looking at the DetailView description at https://ccbv.co.uk/projects/Django/1.11/django.views.generic.detail/DetailView/ I realized there is a slug_field attribute for DetailView . My new view looks like: class JobDetailView(CacheMixin, DetailView): model = Job slug_field = 'slug' Question: