django

Stand alone Django app for OS X

For school, I have made a CMS in django for my major assessment task for Software. My teacher has asked to get the source code and, if applicable, the program compiled. Now, because i dont want my teacher to install django (Something might go wrong, he may get a different version, missing dependences), how can i package up my django app...

How dynamic add custom field to model

How add custom field dynamicly? I'm trying that, but the field won't insert into database when I sync db: #It use as register(MyModel) def register(model, attr="my_attr"): if model in registry: raise AlreadyRegistered( _('The model %s has already been registered.') % model.__name__) registry.append(model) ...

How to simulate a HTTP Post request from a django view without a template

I am writing views, not so keen to write templates right away. But I need to test my program by submitting post requests. How do i simulate HTTP Post from within a django view I am aware that urllib2 and httplib modules of python allow a lot of options, but I am looking for something that elegantly integrates into the django views. ...

Django - uploaded images can not be retrieved

Hello! I am exploring file/images uploads in Django. I have a model with Photo class which has thumb ImageField. I uploaded thumb with admin panel and I made template which just gives <img src='{{photo.thumb.url}}' />. Unfortunately I don't get any images and when I try to get direct link it says "page not found". It seems that django e...

How can I protect my web-based game against cheaters?

I just wrote one of my first web applications (Linux, Apache, MySQL, Django), and would like to launch it publicly. It's a webform-based task disguised as a game; I intend to eventually put it on Amazon Mechanical Turk and give small bonuses to people who achieve certain scores. Even though this app does not have a tremendously high sec...

Getting Django admin url for an object

Before Django 1.0 there was an easy way to get the admin url of an object, and I had written a small filter that I'd use like this: <a href="{{ object|admin_url }}" .... > ... </a> Basically I was using the url reverse function with the view name being 'django.contrib.admin.views.main.change_stage' reverse( 'django.contrib.admin.views....

Can a django template know whether the view it is invoked from has the @login_required decorator?

Let's say that I have a system that has some pages that are public (both non-authenticated users and logged-in users can view) and others which only logged-in users can view. I want the template to show slightly different content for each of these two classes of pages. The @login_required view decorator is always used on views which on...

Google Data API authentication

I am trying to get my Django app (NOT using Google app engine) retrieve data from Google Contacts using Google Contacts Data API. Going through authentication documentation as well as Data API Python client docs First step (AuthSubRequest) which is getting the single-use token works fine. The next step(AuthSubSessionToken), which is upg...

Separating Django App Views

If the app/views.py file gets very large, should I separate it? If so, what is the best way to do this? ...

How do I get the filepath for a class in Python?

Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C. The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a class that uses a Django template...

Is there any advantage to Django versus ASP.NET MVC other than platform?

Is there any advantage to using Django instead of ASP.NET MVC other than I might not want to use Windows and IIS? I don't mean this as a religious type debate. I honestly don't know of any reasons other than personal preference but want to confirm this. For example, I might have only Microsoft products and be well versed in asp.net an...

How to send a session message to an anonymous user in a Django site?

I often show messages about user actions to logged in users in my Django app views using: request.user.message_set.create("message to user") How could I do the same for anonymous (not logged in) users? There is no request.user for anonymous users, but the Django documentation says that using the "session" middleware you can do the sa...

What is the simplest way to lock an object in Django

I want to raise error when a user tries to delete an object when some other users are active in update_object view. I feel some sort of mutex-like locking mechanism is needed for that. Do you have any suggestions? ...

Python/Django: Creating a simpler list from values_list()

Consider: >>>jr.operators.values_list('id') [(1,), (2,), (3,)] How does one simplify further to: ['1', '2', '3'] The purpose: class ActivityForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ActivityForm, self).__init__(*args, **kwargs) if self.initial['job_record']: jr = JobRecord.ob...

Python: Testing for unicode, and converting to time()

Sometimes self.start is unicode: eg. >>>self.start u'07:30:00' Which makes datetime.combine complain start = datetime.combine(self.job_record.date, self.start) How does one: Test for unicode? Convert from u'07:30:00' to datetime.time? ...

What is the best way of sliding section of html using javascript?

Guys, I have a hidden section in my Html template (Am using Django templates), the hidden section is a login form, i want when a user clicks some login text(link), the html text hidding the form should slide downwards revealing the form. I have a feeling this can be done in Javascript! Am using django, please give step by step details...

Control access to WebDav/Apache using Python

I want to give users access to WebDav using Apache, but I want to autenticate them first and give each user access to a specific folder. All authentication must be done against a Django-based database. I can get the Django-authentication working myself, but I need help with the part where I authenticate each user and provide them with a ...

Django Model.object.get pre_save Function Weirdness

Hello! I have made a function that connects to a models 'pre_save' signal. Inside the function I am trying to check if the model instance's pk already exists in the table with: sender.objects.get(pk=instance._get_pk_val()) The first instance of the model raises an error. I catch the error and generate a slug field from the title. In a...

Django vs other Python web frameworks?

I've pretty much tried every Python web framework that exists, and it took me a long time to realize there wasn't a silver bullet framework, each had its own advantages and disadvantages. I started out with Snakelets and heartily enjoyed being able to control almost everything at a lower level without much fuss, but then I discovered Tur...

Autocomplete and Django With ForeignKey fun!

Got an interesting dilemna here as I've tried to create an autocomplete widget for my Django app. The basic structure of the model is that I have 1 .. * Orders that each belong to a single Vendor. Since we have many Vendors I decided to make it an autocomplete widget instead of a big selectbox dropdown. With that in mind, I came up wit...