django-views

Django reverse ordering with ListView

萝らか妹 提交于 2020-01-22 16:26:10
问题 I have implemented ordering in a generic ListView: class CarList(LoginRequiredMixin, ListView): model = Car paginate_by = 30 ordering = 'car_id_internal' def get_ordering(self): return self.request.GET.get('ordering', 'car_id_internal') def get_context_data(self, *args, **kwargs): context = super(CarList, self).get_context_data(*args, **kwargs) context['current_order'] = self.get_ordering() return context And in my template: <thead> <tr> <th><a href="{% url 'car_list' %}?ordering=car_id

Django reverse ordering with ListView

给你一囗甜甜゛ 提交于 2020-01-22 16:26:05
问题 I have implemented ordering in a generic ListView: class CarList(LoginRequiredMixin, ListView): model = Car paginate_by = 30 ordering = 'car_id_internal' def get_ordering(self): return self.request.GET.get('ordering', 'car_id_internal') def get_context_data(self, *args, **kwargs): context = super(CarList, self).get_context_data(*args, **kwargs) context['current_order'] = self.get_ordering() return context And in my template: <thead> <tr> <th><a href="{% url 'car_list' %}?ordering=car_id

Django - counting model instance views (for a “top entries” app)

核能气质少年 提交于 2020-01-21 10:26:20
问题 I'm new, and confused. I want to create a module that keeps track of the "top hit" instances of both an article and a blog model. I don't want to touch the code for the article or blog models. Is this a candidate for middleware? looking at the HttpRequest.path ? 回答1: Middleware looking at request.path is ugly, as it introduces a dependency on the details of the URL patterns you use to display articles and blog posts. If you don't mind this coupling, then you might as well just save the

Django - counting model instance views (for a “top entries” app)

不羁岁月 提交于 2020-01-21 10:26:09
问题 I'm new, and confused. I want to create a module that keeps track of the "top hit" instances of both an article and a blog model. I don't want to touch the code for the article or blog models. Is this a candidate for middleware? looking at the HttpRequest.path ? 回答1: Middleware looking at request.path is ugly, as it introduces a dependency on the details of the URL patterns you use to display articles and blog posts. If you don't mind this coupling, then you might as well just save the

Search through multiple fields in Django

社会主义新天地 提交于 2020-01-21 03:28:32
问题 I'm trying to build a search system, and I want to search by multiple fields name, state, city, in my django models. I wrote the below code, yet I've been unable to figure out how to go about it. Models: class Finhall(models.Model): user=models.ForeignKey(User) name=models.CharField(max_length=250, unique=True) address=models.CharField(max_length=200) city=models.CharField(max_length=200) state=models.CharField(max_length=200) def __unicode__(self): return u'%s' % (self.name) Views.py def hup

How to use filtering data while using distinct method in django?

只谈情不闲聊 提交于 2020-01-20 08:46:12
问题 please help me on my problem I hope my title is enough to understand what I mean, please help me on this problem guys. When I tried this: id_list = grade.objects.filter(Teacher=m.id).values_list('Students_Enrollment_Records_id',flat=True).distinct() I use distinct() to eliminates duplicate rows of Students Enrollment Record from the query results but I wonder why the result is like this: What should I do to show the Students name not that QuerySet in my html? This is my current views.py : id

django tutorial 3 indexpage missing

人走茶凉 提交于 2020-01-17 15:48:45
问题 i am learning django by using django 1.6 documents tutorial 1 - 6. this round is my 4th try and, previous 3 try was successful and i understand more on every try. i am in tutorial 3 now, to create views. according to the documents, after i created a view, i need to map it to a URL. so i follow the documents to add a urls.py in the polls directory. and then i follow the document to add include() to mysite/urls.py i am able to so called wired an index view into the polls view. now if i go back

Save date in django in desired format

泪湿孤枕 提交于 2020-01-17 07:53:11
问题 I want to save date in my django model into desired format. post_date = str(request.POST['date']) I am getting date from front end is 12/21/2016 i want to save this date in my django modal is like 21-Dec-2016 . How can i do it. it will be good if you can provide some sample code. Thanks in advance. 回答1: you want to store in DB string parameter? The easiest way convert input string to date and then convert from date to string. But of course it is more logical to store date format imho 来源:

How to retrieve data from RethinkDB via Django view?

余生长醉 提交于 2020-01-17 05:37:48
问题 Am trying to view data from RethinkDB in Django via custom middleware. Below is the middleware code am using to connect to RethinkDB @singleton class rDBMiddleware(object): connection = None def __init__(self): if self.connection == None: self.connection = r.connect(host=' 192.x.x.x ', port=28015, db=' re_test ').repl() views.py - from app.utils import rwrapper from app.utils import fields class MyTable(rwrapper): _db_table = 'test_table' name = fields.CharField(max_length=60) skill = fields

How to retrieve data from RethinkDB via Django view?

↘锁芯ラ 提交于 2020-01-17 05:37:07
问题 Am trying to view data from RethinkDB in Django via custom middleware. Below is the middleware code am using to connect to RethinkDB @singleton class rDBMiddleware(object): connection = None def __init__(self): if self.connection == None: self.connection = r.connect(host=' 192.x.x.x ', port=28015, db=' re_test ').repl() views.py - from app.utils import rwrapper from app.utils import fields class MyTable(rwrapper): _db_table = 'test_table' name = fields.CharField(max_length=60) skill = fields