django

Python: Load module by its name

I'm working on a django project that serves multiple sites; depending on the site I want to import different functionality from a different module; how do I import a module in Python if I have the name of its package and the module name itself as a string? ...

Django equivalent to "rake rails:freeze:gems" and "rake gems:unpack"

Is there and equivalent in Django to Rails' freezing and unpacking mechanism to a vendor directory so that an application becomes self-contained? ...

Django: Deleting user selected entries from a database

I have a Django app that displays a list of rows in a table to the user. Each row maps to an entry in a database. I want to let the user select the rows they would like deleting by adding a checkbox to the end of each row and a delete button ( similar to how gmail lets you delete multiple mail messages). I can't quite figure out how to w...

Django Have to ForeignKey to share a constraint

Hi, I have the following model: class Program(models.Model): name = models.CharField(max_length = 128) def __unicode__(self): return self.name class Cheat(models.Model): program = models.ForeignKey(Program) shortcut = models.CharField(max_length = 64) description = models.CharField(max_length = 512) def ...

Django File Uploads and Model FileField

I'm sooo close... but I don't quite see the connection from the upload view to the model. When I use the callback in the model's FileField the upload works, but I'm not sure where the actual file copy is taking place. The goal is to make sure that chunking is happening, but the file copy action seems to be hidden somewhere? Here's what ...

Most succinct way of prepopulating the author in django 1.2 admin?

A previous answer points to http://code.djangoproject.com/wiki/CookBookNewformsAdminAndUser I'm wondering if it's really necessary to define both save_model and save_formset methods in Django 1.2 in order to prepopulate the author? ...

Aggregation and extra values with Django

Hi, I have a model which looks like this: class MyModel(models.Model) value = models.DecimalField() date = models.DatetimeField() I'm doing this request: MyModel.objects.aggregate(Min("value")) and I'm getting the expected result: {"mymodel__min": the_actual_minimum_value} However, I can't figure out a way to get at the ...

What is your (simple) continuous integration solution for Django projects?

Hi, In one of my Django projects I have a suite of unit tests that are based on TransactionalTestCase class (it takes much longer than TestCase). It is impossible to run tests after each change in code because it takes more than 0.5 hour to run all tests. We looked some time ago for some easy contiuous integration tool that could allow ...

Simple form not validating

I have found here on stackoverflow a method to extend django's built-in authentication using signals. My base User is defined by 'email' and passwords (so no username there). So I'm trying to modify it to my needs, but I'm geting a validation error for my form. Strange thing is that error is connected to the User.email field and I'm gett...

Where do things go when I ‘print’ them from my Django app?

I have a Django app on a Linux server. In one of the views, some form of print command is executed, and some string gets printed. How can I find out what the printed string was? Is there some log in which these things are kept? ...

getting/embedding user id in url/templates

hi i am fairly new to django and i want to update some of my contents in the django DB for this i have written a little view function. which looks like this def status_change(request,id): instance = get_object_or_404(register,id=id) if request.method == 'POST': rform = registerForm(instance=instance, data=request.POST)...

Logging in django gives server error

In my settings.py file I've added the following lines to enable logging. But unexpectedly now my project throws "500 Internal Server Error". Any ideas why ? import logging logging.basicConfig( level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename=os.path.join(rootdir, 'django.log'), filemode='a+')...

PyAMF (0.6) doesn't seem to include Django (1.2) ForeignKey related-objects on auth.models.User

I am trying to return a django.contrib.auth.models.User object, and it fetches all the data properly, but the related fields are nowhere to be found, even utilizing "select_related()" as suggested in documentation. class UserProfile(models.Model): user = models.ForeignKey( User, unique=True ) In pyamf gateway: def login_user( http_...

How to initialize model with calculated value

I have a Django model Reminder related to Event model. class Reminder(models.Model): email = models.EmailField("e-mail") event = models.ForeignKey(Event, unique=True, related_name='event',) date = models.DateTimeField(_(u"Remind date"), auto_now_add=False,) class Event(models.Model): date = models.DateTimeField(_(u"Even...

How to check why form is not valid

I have some troublesome form in my django app. Problem is that it doesn't validate. How can I check what is causing the problem ? I've tried the following : form.data = {dictionary_with_data} form.is_valid() False form._errors {} form.errors {} Form.non_field_errors() [] ...

In django, __init__ function on Model, causes attribute error, cannot save to database

Hi everyone, I am using django and a model definition such as class Question(models.Model): title = models.CharField(max_length=100) description = models.TextField() order = models.IntegerField() def __init__(self, *args, **kwargs): self.title = kwargs.get('title','Default Title') self.description = kw...

Foreign key to User table in django

I'm using django's built-in contrib.auth module and have setup a foreign key relationship to a User for when a 'post' is added: class Post(models.Model): owner = models.ForeignKey('User') # ... etc. Now when it comes to actually adding the Post, I'm not sure what to supply in the owner field before calling save(). I expected ...

problem with displaying data asynchronously

Hi, I have to execute commands such as iostat 3 > temp.txt & on server side Then, further send ajax request at each interval to get updated output on the client side When I execute this command using python subprocess module unless I kill the process file data is not read. in views.py the code for servicing ajax request is as fo...

libjpeg PIL django image display

I installed PIL. I can import PIL (with no error message) Then I ran the code mentioned here: http://stackoverflow.com/questions/3166221/python-images-display And I get this error message: IOError: decoder jpeg not available I understand this is Library called libjpeg and (?) it should be installed already. Or is it part of PIL? Whe...

Does reversion work for django-cms when page template is changed?

Hi, I use django-cms. I've just changed template for my page which ended with clearing my page (as expected). When I tried to restore old version (by using django reversion app that is suggested to use with django-cms) I realized this is impossible. I mean I have history of changes for my page but it looks like all reversion versions ar...