django-templates

Get count on several filtered subqueries in template

Deadly 提交于 2019-12-25 02:58:55
问题 I recently asked for how to get count on filetered subqueries in a template and got an answer here: Get count on filtered subqueries in template Now I realised that I need this extended as following (which I think is a lot mroe than my first question, therefor creating a new one here): Show articles that doesn't match the tag, but then with 0 as count. Extend to allow counting on different tags. With the following model: class Category(models.Model): ... class SubCategory(models.Model):

Serve external template in Django

亡梦爱人 提交于 2019-12-25 02:32:49
问题 I want to do something like return render_to_response("http://docs.google.com/View?id=bla", args) and serve an external page with django arguments. Django doesn't like this (it looks for templates in very particular places). What's the easiest way make this work? Right now I'm thinking to use urllib to save the page to somewhere locally on my server and then serve with the templates pointing to there. Note: I'm not looking for anything particularly scalable here, I realize my proposal above

TemplateDoesNotExist on python app-engine django 1.2 while template rendering absolute paths

安稳与你 提交于 2019-12-25 02:24:47
问题 Due to App Engine warning You are using the default Django version (0.96). The default Django version will change in an App Engine release in the near future. Please call use_library() to explicitly select a Django version. For more information see http://code.google.com/appengine/docs/python/tools/libraries.html#Django I have added two lines of code to top of main.py from google.appengine.dist import use_library use_library("django", "1.2") This code totally broke my app raising this error

Manager isn't accessible via “model” instances django

六月ゝ 毕业季﹏ 提交于 2019-12-25 02:16:17
问题 I am suffering an error with django and their custom Managers. I have this custom Manager: class CallManager(models.Manager): def get_queryset(self): return super(CallManager, self).get_queryset().filter(is_active=True) class Call(models.Model): ... # Data is_active = models.BooleanField(default=True) # Managers objects = models.Manager() # Default active = CallManager() # Active calls Ok, So now I am trying to retrive data from views.py (call/views.py) # Call list def call_list(request):

Django - Accessing _set from Admin change page

丶灬走出姿态 提交于 2019-12-25 02:14:53
问题 Lets take the standard example class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title = models.CharField(max_length=100) author = models.ForeignKey(Author) #... Many other fields ... From the admin change template of Author trying to access to the related books <ul> {% for book in original.book_set.all %} <li> <a href="{% url admin:myapp_manager_change book.id %}">Edit {{ book }}</a> </li> {% endfor %} </ul> I get Caught NoReverseMatch while

Loop over related model's children in Django template

自作多情 提交于 2019-12-25 01:37:59
问题 I have a model for a company. Then I have a base model for company posts. It contains common posts attributes. An attribute is the company that publishes the posts. It refers to the Company model with a ForeignKey. Finally I have a child model (based on the CompanyPost base model) for posts of type A: class Company(models.Model): name = models.CharField(...) ... class CompanyPost(models.Model): company = models.ForeignKey(Company,...) ... class PostA(CompanyPost): name = ... In a template I

Django Not null constraint failed while posting json data to models

孤街浪徒 提交于 2019-12-25 01:34:56
问题 hey i tried this code but still have an error that is Not Null constraint failed i know this is because of my cheque_no that is unique type but how could i remove this error i did not remove my cheque_no is unique because its required.now am getting this problem i want to save these entries in my model. views.py @csrf_exempt def jsdata(request): table_data = json.loads(request.POST.get('MyData')) # print(table_data) r_data = { 'success': True, } for data in table_data: # Since you are just

how to reload a segment of webpage in django?

ⅰ亾dé卋堺 提交于 2019-12-25 00:22:22
问题 In django, I am trying to make buttons that change one segment of the webpage by loading html file. The html file shows map and statistics and stuff so they have to be separate. My approach was to use ajax call and in the view, return the html file. <script type="text/javascript" > function mapcall (office, year){ console.log(office, year, "clicked") $.ajax ({ method : "GET", url: '/map/', // % url "map" % end point data: { office_called: office, year_called: year, }, success: function (map){

Dynamic content in django template

徘徊边缘 提交于 2019-12-24 23:25:07
问题 I have a Django application where using wkhtmltopdf I generate a pdf document. I have a section there, like the code below. I want to on each side was exactly 4 texts (objects). But everyone is different and the text comes out uneven arrangement. CSS does not help. How to do it? The problem occurs when sections of text are of different sizes, in the generated PDF document. Sometimes everything is ok, because the number of texts fit on the page, and the rest goes to the next. And sometimes the

Can't get key to display in Django template

回眸只為那壹抹淺笑 提交于 2019-12-24 23:24:29
问题 I have been trying for about a day and a half to get the ID of a related field in a model to display in my template. Nothing fancy, I just want the ID. Here is the model in question: class CompositeLesson(models.Model): lesson = models.ForeignKey(Lesson) student = models.ForeignKey(Student) actualDate = models.DateTimeField() Assume I have a list, lessonsList , of CompositeLesson and am able to successfully iterate through the list. Other fields (i.e. actualDate) display correctly. Snippet of