views

django ListView specifying variable available for all methods inside the class

扶醉桌前 提交于 2019-12-22 09:47:28
问题 My url has a keyword "shop_name" variable. There's also the Shop model with "name" field. In my ListView class I need to make repeating queries to Shop model to get a unicode variable from Shop.get_type() method. Depending on the result, a proper template directory is selected or queryset (Using subclassed django models). Here's the code. class OfferList(ListView): def get_template_names(self): shop = Shop.objects.get(name=self.kwargs['shop_name']) return ["shop/%s/offer_list" % shop.get_type

Read DataAnnotations from a collection of models in an MCV2 view

纵饮孤独 提交于 2019-12-22 06:56:57
问题 In my MVC2 AdminArea I'd like to create an overview table for each of my domain models. I am using DataAnnotations like the following for the properties of those domain model objects: [DisplayName("MyPropertyName")] public string Name { get; set; } Now my question is: How can I access the DisplayName Attribute if my view receives a collection of my domain models? I need this to build the table headers which are defined outside of the usual <% foreach (var item in Model) { %> loop. Inside this

Codeigniter- cache view into a view

落花浮王杯 提交于 2019-12-22 06:47:39
问题 i'm wondering if it's possible to cache a view which is loaded inside another view. I do: view.php: <div> <?php echo $this->load->view('modules/new_view'); ?> </div> so view.php requires a new view inside himself, can i cache the views/modules/new_view.php content? 回答1: Codeigniter has Web Page Caching CodeIgniter lets you cache your pages in order to achieve maximum performance. Although CodeIgniter is quite fast, the amount of dynamic information you display in your pages will correlate

Django show render_to_response in template

邮差的信 提交于 2019-12-22 05:54:40
问题 Hello and thank you in advance. I know this is total noob question, and I have searched in the various forum and read and re-read the documentation, so please be gentle. I have a view: #views.py from django.shortcuts import render_to_response from django.shortcuts import render from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from acme.acmetest.models import Player from acme.acmetest.models import PickForm def playerAdd(request, id=None): form = PickForm(request.POST or

Why would “Where 1 <> 1” in a query return all rows?

霸气de小男生 提交于 2019-12-22 05:39:05
问题 I've come across a query in an application that I've inherited that looks like this: Select * From foo where 1 <> 1 As I parse that, it should return nothing ( 1 <> 1 should evaluate to false, right). However (at least on my Oracle box) it comes back with a full listing of everything in foo . When I try the same thing in MSAccess/Jet and MSSQL I get the behaviour I expect. Why is it different for Oracle (and why would the original developer want to do this)? Note: I've seen some superstition

Neat way to conditionally test whether to add a class in HAML template [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-22 05:17:15
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Append class if condition is true in Haml (with Rails) I'm using a template that allows you to mark a list item as current (using class=current ), highlighting it in a nav bar. In HAML, this looks like: %li.current Menu item A %li Menu item B %li Menu item C I have this code in a Sinatra view and want to programmatically add the class=current , depending on a parameter to the view. How do I do this in the

MySQL Query to group by date range?

眉间皱痕 提交于 2019-12-22 03:52:35
问题 I've got a table in MySQL that shows me number of hours logged on a daily basis. I'm trying to build a view that will allow me to quickly group my data by blocks/range of days. The simplest case would be on a monthly basis which wouldn't be difficult. I could just select the date as "%y-%m" and then group by that column. Ex: select time_logged, date_format(start_date, '%Y-%m') AS `month_logged` from work_log group by month_logged That works fine if I am just grouping by month. But my issue is

Views vs. inline subqueries SQL Server 2005/2008

烂漫一生 提交于 2019-12-22 00:25:30
问题 In certain areas in my application I need data from several tables in the database (I have an application, the application has many attributes, each attribute has several definitions, and each definition has a value). I need the data from all these tables for an application. Should I use a view (one that would be rather large) or subqueries for selecting the records? In the case of subqueries is the optimizer able to work efficiently? I'm also interested if caching will work for subqueries.

Error: A “url” property or function must be specified, except url is specified

六眼飞鱼酱① 提交于 2019-12-22 00:10:04
问题 I have a Conversation model and a view that displays this model. This model is fetched from the server without any problem (the url property works fine then), and the view is rendered. However, when I attempt to destroy the model in a function of the view, I get the error 'A "url" property or function must be specified', even though when I display said url right before the destroy call, it is exactly the url it should be. Here is the code for the model: MessageManager.models.Conversation =

Drupal Views display newest content per taxonomy limit to one node

巧了我就是萌 提交于 2019-12-21 22:29:50
问题 I want to create a view where all 5 of my taxonomy terms are displayed and it then displays the latest node published but this is limited by 1. For Example: Tax Term 1 Latest node published Tax Term 2 Latest node published etc etc Currently I'm grouping by taxonomy term so it's displaying all nodes published then sorted by published date desc. I can't quite figure out how to limit the nodes to only show one item per taxonomy term. Any help would be greatly appreciated. 回答1: This is possible