django

IOError: request data read error

I seem to be getting an IOError: request data read error quite a lot when i'm doing an Ajax upload. For example out of every 5 file uploads it errors out on atleast 3. Other people seem to have had the same issue. Eg. http://stackoverflow.com/questions/2641665/django-upload-failing-on-request-data-read-error http://stackoverflow.com...

Multiple versions of django admin page for the same model

In my django admin section, I'd like to show different versions of the admin page depending on what kind of user is currently logged in. I can think of a couple ways this might work, but haven't figured out how to do any of them. Perhaps I could put logic into the admin.ModelAdmin to look at the current user and change the 'exclude' fi...

How can I use annotate() to count a subset of related models in Django?

I'm trying to use Django's annotate feature to add the count of a related model to a queryset. However, I don't want a full count of related objects, I only want to count the active ones (i.e., "is_active=True"). I can't figure out how to filter down the count. The (simplified) relevant models: class Post(models.Model): user = mode...

Can you access a Django Model "property" from it's ModelForm?

I have a Django model class with a non-model-field property, ex: def _get(self): return "something" description = property(_get) I'm using the model class with in a ModelForm / ModelFormset. Is there any way to access the property from the form / formset? If not, what's best practice for including extra "display" data in a djang...

How to set a default value on a form when it's excluded?

I've tried 3 different approaches, and nothing seems to work. Here's my view: def my_view(request): if request.method == 'POST': form = DealershipForm(request.POST) if form.is_valid(): dealership = form.save(commit=False) dealership.entered_by = User(id=2) dealership.save() ...

Django json dumps help

Hello, I have the following code that I need help encoding to JSON and appending the data to a file, foo.json Here is my code: user = request.user print 'USER ID ', user.id // 83 sour = json.dumps({"toast" : [{"uid" : user.id }]}) print 'Sour Toast: ', sour.toast # I'm getting this error: AttributeError: 'str' object has no attribute ...

What steps do I take to integrate an (outdated) but working django application into my project?

I would like to integrate an existing application someone has on github into my site. What steps do I need to take to integrate it? Would most people just download this entire thing and throw it inside of the project root, add it to the INSTALLED_APPS and modify urls.py? I would imagine there are some extra steps I'd have to take to get...

Google app engine, multiple languages

Hi, i'm working on on a project with DJango but i'm also thinking about going the Jython route. By doing so...since i'll be using the java instance instead of cpython wouldn't I be able to use java, scala, ruby and other other languages that run on top of the jvm if need be? ...

Pythons M2Crypto raises exception in ssl_ctx_load_verify_locations when loading certificates

M2Crypto raises a TypeError when loading SSL CA certificates. I'm getting the path of an SSL certificate from an instance of a Django model. My code worked perfectly because I was pulling the path of the certificate from a Django model My code: from M2Crypto import SSL from django.db import models class MyModel(models.Model): ...

Django RegexField Letters and Numbers only

I need a regexfield in a django form to only accept letters and numbers, and nothing else. I've tried this, but it didn't work: myfield = forms.RegexField(label=("My Label"), max_length=31, regex=r'[a-zA-Z0-9]', error_message = ("This value must contain only letters and numbers."), I am not very good at using regular expressi...

Importing between two applications in a django project.

I've got two applications (app1 and app2) in my django project. I'm curious if there is a way to import things between applications. baseProject --app1 ----models.py ----etc.. --app2 ----models.py ----etc.. I'd like to be able, while in app2, to import something from the models section of app1. Is there an intended method to do ...

django-celery without an ampq server (rabbitmq)

I am using celery for distributed task processing. I wanted to deploy my work on a web-host, just to show the working of my project. So how can i get djcelery to use a database (sqlalchemy) as backend with django instead of rabbitmq or other ampq servers. ...

openid with django

I found a lot of options but this one https://launchpad.net/django-openid-auth looks good. sadly I can't find examples/HOWTO about this?Does anyone point/redirect me to correct urls? ...

Setting model level permissions in code for Django admin panel

Hi All, Is there a way to implement the permissions for models through the code? I have a large set of models and I want some of the models to be just viewable by the admin and not the ability to add them. Please suggest. ...

Is there a better way to write out my django-treemenu template?

Hi there, I'm using django-treemenus I'm curious to see if there is a better way to write out my menu.html which is my menu template. For each level that I add to my menu I have to manually add a level to my menu template. Here is my menu.html (menu template). It works, but could it be written more efficiently? {% load tree_menu_tags...

Django-Python: Generate XML file from model data

I need to write model data (CharFields only) to an XML file to contain the data for a flash file. I am new to this, and the process is a little unclear to me for doing this in django. I am creating an xml file, and then writing the text data to the file (as is done with the csv module, but to xml). A very simplified xml file should re...

How to read pcks#7 personal digital certificates with python?

Hi everyone, is it possible to read personal digital certificates with extension Pcks#7 ( http://en.wikipedia.org/wiki/X.509#Certificate_filename_extensions ) with python? I have to develop an application using Django that authenticate its users by reading their certificate. In an initial step we are going to use an external services t...

Can I access attributes of the first object in a list in Django templates?

I’ve got a Django template that’s receiving a list of objects in the context variable browsers. I want to select the first object in the list, and access one of its attributes, like this: <a class="{{ browsers|first.classified_name }}" href="">{{ browsers|first }}</a> However, I get a syntax error related to the attribute selection ....

Best way to change the value of "settings" from within a Python test case?

I'm writing unit tests in Python for the first time, for a Django app. I've struck a problem. In order to test a particular piece of functionality, I need to change the value of one of the app's settings. Here's my first attempt: def test_in_list(self): mango.settings.META_LISTS = ('tags',) tags = Document(filepath).meta['tags']...

Python, using os.system - Is there a way for Python script to move past this without waiting for call to finish?

I am trying to use Python (through Django framework) to make a Linux command line call and have tried both os.system and os.open but for both of these it seems that the Python script hangs after making the command line call as the call is for instantiating a server (so it never "finishes" as its meant to be long-running). I know for doin...