django

Automatic author in Django admin

Hi, all. I'm working on the admin for my django site, and I've run into an obstacle. I've got an Entry model and a Related model. The Related model has two foreign key fields: one to the Entry model (entry) and one to django's User model (author). The Related model is considered a "sub-model" of the Entry model, and each user can only h...

Highcharts SVG Export from Python Server Side Code

I am using reportlab in python to render a pdf server side. I really like the look of highcharts graphs. But I am building a pdf server side which needs to include some graphs. The server side graphing (reportlab and matplotlib) do not have nearly as much choices for formatting / design. Is there a way I can run a client side javas...

django/python imports perfomance

Hello, Can somebody please proof why it's a bad practice to use solution like this: In django views in 98% cases you need to use from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ anyway in my project my every view has these imports and e...

Is it "a-must" to trim all whitespaces in POST/GET vars?

IMHO, I heard about this few times lately. On some web portals I saw when whitespace in the beginning of the keywords, returns empty search result, without whitespaces it's working. Are there some cases when this can be harmful? Can somebody give an arguments for this kind of practice? ...

Django: Make all formset forms required?

Exactly like this question, except that one got closed and accepted without a real answer. It looks like I can use a custom formset and override the clean method, but that still doesn't answer how I check that they're all filled in. What properties am I supposed to be looking at? The formset is smart enough to ignore extra forms that...

Problem with Python relative imports

I am using Python 2.6 and have the Facebook API installed as a python package (under /usr/lib64/python2.6/site-packages/facebook/...) which means, it is available with a plain import facebook or from facebook import .... This works well, as long as there is no name clash. For example, in my project, I try to import the Facebook API in m...

Python Exception handling in Google App Engine

I have exception handling in my app engine app. The code work perfectly fine on the dev server. But when I upload the file on the app engine server, I get a syntax error. Here is the traceback: Exception in request: Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/core/h...

How should I model this out?

I am a bit stuck on how I should model this out. Here is what I have: I have a model called Location. In this model I have postal code, city, region, longitude, and latitude. This data is pre-populated with all of Canada's stuff. You can imagine this table is quite large. This is what I would like to achieve by stuck on how to model ...

Can't do an AJAX call with Python and Django

I am still learning to do javascript and django and yesterday I tried to do a simple hello world ajax exercise. Server logs show that python code is being called but somehow django/python does not return anything when I check the xmlhttp.responseText and responseXML in firebug. UPDATE: I removed the checking of the http status return...

Django - how to dynamically generate a menu based on use privs

Does anyone know a good way to solve this other problem I have. My site shows menus based on a users privs. I have a function that returns the privs as a dictionary as below: return {"manage_entries":True, "manage_members":False, "manage_something_else":True} I passed in each priv to my base template that includes the navigation b...

How to properly use and cancel subprocess in python using Django?

I have a view that gets data from a form and executes a subprocess: def sync_job(request, job_id, src, dest): form = SyncJobForm() check = SyncJob.objects.get(id=job_id) check.status = True check.save() pre_sync = SyncJobCMD.objects.get(id=1) p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE) syncoutput,s...

How to use Custom JS with Django inline

I have Django application with inline in place: class Account(models.Model): ContractNum = models.PositiveIntegerField(unique=True, blank=True, null=True) LastName = models.CharField(max_length=50,) FirstName = models.CharField(max_length=50, ) class Subscription(models.Model): Account = models.ForeignKey(Account, relat...

Django load test fixtures with django-nose

How do you load test fixtures using the django-nose test runner? ...

Prepopulating a Django FileField

Hey all I wanted to know how is it possible in django to bind an already uploaded file (stored in the file system of server) to a Model FileField. This way I want to have my edit page of that model to prepopulate the FileField with this file. Thanks ...

How can I add an option to a field inherited from a parent class?

Hi, How can I add in my custom class an option to a field existing in the parent model? More concretely: I'm writing a custom comment model inheriting from django.contrib.comments.models.Comment. I'd like to add the option editable = False to the IPAddressField. thank you ...

Set default value to UserProfile model field from User instance field

I use UserProfile model for keeping additional info about user and one of the fields is subdomain variable that is by default should be set to username. Here is UserProfile model: class UserProfile(models.Model): theme = models.ForeignKey(Theme, unique=True, null=True) user = models.ForeignKey(User, unique=True) subdomain = ...

django models foreignkey beetwen apps

Hello, I have problems with making my models to work. Here is my appname.misc.models file from django.db import models class user(models.Model): login=models.CharField(max_length=20) email=models.EmailField(max_length=50) banned=models.BooleanField() key=models.CharField(max_length=15) rights=models.CharField(max_le...

Class based default value for field in Django model inheritance hierarchy

How can one accomplish class-based default value in following scheme? I mean, I would like to inherited classes set default value for "number" differently: class OrderDocumentBase(PdfPrintable): number = models.PositiveIntegerField(default=self.create_number()) @classmethod def create_number(cls): raise NotImplement...

Use Django admin modules inside own forms

In the Django admin i have a customized changelist with added search and filters. I have been looking alot but cannot seem to find a way to use the whole "changelist module" outside of admin. So i can embed it in one of my own pages. I do not need any of the authentication or anything like that. I just want to show a table (for a conten...

Odd Django Problem

In my views I want to pass in an error condition. def something(request): name = request.GET.get('name') if name is None: return render_to_response('myapp.html', {'invalid': 'true'}) Then in my template I want to display different things depending on this. So I do: {% if invalid %} INVALID {% else %} ALL OK {% endi...