django

Django admin does not show all entities

Hello! I've inherited an app created with Django. There is a problem with it: in admin interface, the page lists not all entities (videos), but some (16 of 25). I have no idea, what is this. Then I run python manage.py shell, and there Video.objects.all(), there are all 25 objects (counted them using len and by iterating them with for ...

Django Admin site TemplateSyntaxError at /admin/: name not defined

I have an issue where, when I log in to the Django admin site, I get a template syntax error in /Library/Python/2.6/site-packages/django/template/debug.py in render_node, line 81. I can't find out how to solve this as it is part of Django, I didn't write the code and I have no idea how it works. This did work fine up until a few days a...

django: dynamically inserting comment form using jquery

I'm building a Q&A site where one can comment on questions and their answers.Its a threaded commenting system with ajax. this is the javascript part: function bindPostCommentHandler() { $('.commentFormWrapper form').submit(function() { var current = $(this); $.ajax({ type: "POST", data: current....

Django - relation with class model instances

Hello I made some model classes with pets types: Parrot, Rabbit, Cat, Dog and i need make model Shop, where one field will be related for few of this models. This field will show what sells in shop. Can i make relation beetween one model object to few model classes? If i can't, how i need change my scheme? ex: 1 Shop1 [Parrot, Rabbit]...

Hidden field in Django Model

A while back I made a Model class. I made several ModelForms for it and it worked beautifully. I recently had to add another optional (blank=True, null=True) field to it so we can store some relationship data between Users. It's essentially a referral system. The problem is adding this new field has meant the referral field shows up wh...

Caching non-view returns

I have a dozen or so permission lookups on views that make sure users have the right permissions to do something on the system (ie make sure they're in the right group, if they can edit their profile, if they're group administrators, etc). A check might look like this: from django.contrib.auth.decorators import user_passes_test test_c...

Django: extra variables on a custom 404 template

Hi all, I want to be able to use extra variables on a custom 404 template. #404.html {{ extra_var }} I have already tried: #urls.py from myproject.myapp import views handler404 = views.handler404 #views.py from django.template import RequestContext, loader from django import http def handler404(request): extra_var = 'my_extra_v...

How do you divide your project into applications in Django?

I am not really sure how to divide my Django projects into applications. What things should I consider when laying out a Django project? ...

django get_current_user() middleware - strange error message which goes away if source code is "changed" , which leads to an automatic server restart

Hi, I'm using a middleware to get the currently logged in user in my views and models. This helps me to for example return only the objects created or assigned to the logged-in user. Please follow this link to see which middleware that I use. I call this middleware with: get_current_user() This worked fine till now. But now I experi...

How to aggregate over a single queryset in Django?

Short description: given a queryset myQueryset, how do I select max("myfield") without actually retrieving all rows and doing max in python? The best I can think of is max([r["myfield"] for r in myQueryset.values("myfield")]), which isn't very good if there are millions of rows. Long description: Say I have two models in my Django app,...

Django object creation and Postgres Sequences

I have an import script which runs a series of commands to get things from one Postgres DB to another, both running the same Django codebase. For the most part, it uses ./manage.py loaddata to copy over, but some objects require additional processing and I use Django's objects.create() method in a custom script to copy the data. When doi...

Django image upload ends up with wrong filename.

I don't know if this is expected behavior or not, but if I create a project with a single model with an ImageField field and upload a photo with the filename "árvórés", the uploaded file is saved with an incomprehensible filename(ascii, I presume). As a direct result, that photo becomes impossible to retrieve from the site. Is this norm...

Django + decorators: Adding context to the template based on a criteria.

Hi there, I'm not sure if decorators are the best way to do this, but I've removed the idea of using context processors and I'm not sure if a middleware is what I'd like. My situation is as follows: We process sales and other data daily. Every month, we close the month off just like any other business. We do this on paper, but I would ...

Django: Why is __unicode__ not run during print(some_model_instance)?

This is my class: class Account(models.Model): name = models.CharField(max_length=255) def __unicode__(self): return '{0}'.format(self.name) class Painting(models.Model): account = models.ForeignKey(Account) color = models.CharField(max_length=255) def __unicode__(self): return 'Account: {0} - Co...

django + ExtJs - list of example implementations with source code

Hi, I want to learn ExtJs http://www.extjs.com/ in combination with Django (I know Django already .. a bit ;-) and I'm on the search of examples I can learn from. I found already this post. Would be great if you post your links to examples here. Maybe we get a nice list of examplary implementations that help users to start with django ...

Getting translation strings for jinja2 templates integrated with django 1.x?

I can use jinj2 templates with django via render_to_response defined as below from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse from django.template import TemplateDoesNotExist, Context from django.utils import translation from itertools import chain from jinja...

Finding the Difference in DateTimeFields

I'm trying to find if two DateTimeFields are greater than 2 days difference in a template. Is this possible to do in a template? ...

Django Generic Relations with Django Admin

heya, I have a Django project, that has a "Address" model. This is used in several places - by a "User Profile" model, by a "Hospital" model, by an "Insitution" model etc. I'm using Django's generic relations to allow each of these objects to create a foreign-key to Address. However, this seems to cause some weirdness in the Django Ad...

Run a C++ Program from Django Framework

I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ? ...

Regular expresion for urlpattern

I need a regexp for a URL like: /slug/#slug/slug/ I know it should be something like: r'^(?P<slug1>[-\w]+)/#(?P<slug2>[-\w]+)/(?P<slug3>[-\w]+)/$' But I am having problems with the character # ...