django

How to manually render a Django template for an inlineformset_factory with can_delete = True / False

I have an inlineformset with a custom Modelform. So it looks something like this: MyInlineFormSet = inlineformset_factory(MyMainModel, MyInlineModel, form=MyCustomInlineModelForm) I am rendering this inlineformset manually in a template so that I have more control over widgets and javascript. So I go in a loop like {% for form in myfo...

Django admin - limiting access to objects based on the user logged in

Hi, I'm working on creating a simple website for an exhibition. It's intended to use django with django CMS as much as possible - so Django admin site will be used. Now I want to limit user's access to objects they can view/modify/delete. There's going to be an Admin user, who can do all that admin can in django. But there are going t...

Django model manager didn't work with related object when I do aggregated query

Hi, all. I'm having trouble doing an aggregation query on a many-to-many related field. Here are my models: class SortedTagManager(models.Manager): use_for_related_fields = True def get_query_set(self): orig_query_set = super(SortedTagManager, self).get_query_set() # FIXME `used` is wrongly counted ret...

django + xmppy: send a message to two recipients

I'm trying to use xmpppy for sending jabber-messages from a django-website. This works entirely fine. However, the message only gets sent to the -first- of the recipients in the list. This happens when I run the following function from django, and also if I run it from an interactive python-shell. The weird part though, is that if I ext...

Django query get recent record for each entry and display as combined list

I have two models device and log setup as such: class device(models.Model): name = models.CharField(max_length=20) code = models.CharField(max_length=10) description = models.TextField() class log(model.Model): device = models.ForeignKey(device) date = models.DateField() time = models.TimeField() data = models.C...

How to make Django work with unsupported MySQL drivers such as gevent-mysql or Concurrence's MySQL driver?

I'm interested in running Django on an async framework like Concurrence or gevent. Both frameworks come with its own async MySQL driver. Problem is Django only officially supports MySQLdb. What do I need to do to make Django work with the MySQL drivers that come with gevent or Concurrence? Is there a step-by-step guide somewhere that ...

Editting ForeignKey from "child" table

I'm programming on py with django. I have models: class Product(mymodels.Base): title = models.CharField() price = models.ForeignKey(Price) promoPrice = models.ForeignKey(Price, related_name="promo_price") class Price(mymodels.Base): value = models.DecimalField(max_digits=10, decimal_places=3) taxValue = models.Deci...

Django as S3 proxy

I extended a ModelAdmin with a custom field "Download file", which is a link to a URL in my Django project, like: http://www.myproject.com/downloads/1 There, I want to serve a file which is stored in a S3-bucket. The files in the bucket are not public readable, and the user may not have direct access to it. Now I want to avoid that ...

django + south + python: strange behavior when using a text string received as a parameter in a function

Hello, this is my first question. I'm trying to execute a SQL query in django (south migration): from django.db import connection # ... class Migration(SchemaMigration): # ... def transform_id_to_pk(self, table): try: db.delete_primary_key(table) except: pass finally: ...

django models: how to select only objects which aren't belong to the inherited class?

Hello! I have two models in my Django 1.1.1 application: class UserRequest(models.Model): # blah blah class JournalistRequest(UserRequest): # blah blah So, JournalistRequest is a special type of UserRequest, and all JournalistRequests are still common UserRequests with special fields. JournalistRequest.objects.all() returns a...

arbitrary typed data in django model

I have a model, say, Item. I want to store arbitrary amount of attributes on it, like title, description, release_date. And i want them to be not just strings but have python type, so string, boolean, datetime etc. What are my options here? EAV pattern with separate name-value table won't work because of the same DB type across all val...

Detecting permission errors in django tests

I'm writing detailed functional tests for my views to complement the unit tests on my models. It's a Django project and I'm using the built in Django test framework with unittest. Obviously, one of the important things to check in these functional tests is that the permissions are set up correctly. With that in mind, I'm attempting somet...

set maximum imagesize for django Photologue..

hi, just uploaded some photos via django photologue. And one image, an extreme panorama format will not show properly. its 2200px wide. Is there a limitation to the size of an image and can this limitation be changed? thx ...

django internationalization and translations problem

I have a problem with django translations. Problem 1 - i updated string in django.po file, but the change does not appear on the webpage. Problem 2 - i have created my own locale file with django-admin.py makemessages -l et, added the translation string into file, but they too do not appear on the page. I do not think this is settin...

Django: Read only field

How do I allow fields to be populated by the user at the time of object creation ("add" page) and then made read-only when accessed at "change" page? ...

IIS Not Linking to Django with PyISAPIe

Hello, I'm trying to run a site with Django on an IIS-based server. I followed all the instructions on the main site (http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer), and double checked it with a very good article (http://www.messwithsilverlight.com/2009/11/django-on-windows-server-2003-and-iis6/). I successfully...

Django/Python: Save an HTML table to Excel

I have an HTML table that I'd like to be able to export to an Excel file. I already have an option to export the table into an IQY file, but I'd prefer something that didn't allow the user to refresh the data via Excel. I just want a feature that takes a snapshot of the table at the time the user clicks the link/button. I'd prefer it if...

Populating Models from other Models in Django?

This is somewhat related to the question posed in this question but I'm trying to do this with an abstract base class. For the purposes of this example lets use these models: class Comic(models.Model): name = models.CharField(max_length=20) desc = models.CharField(max_length=100) volume = models.IntegerField() ... <50 o...

How can I conditionally only log something if it's a certain Class?

Something like this: if self.__class__ == "User": logging.debug("%s non_pks were found" % (str(len(non_pks))) ) In [2]: user = User.objects.get(pk=1) In [3]: user.__class__ Out[3]: <class 'django.contrib.auth.models.User'> In [4]: if user.__class__ == 'django.contrib.auth.models.User': print "yes" ...: In [5]: u...

Django Querysets -- need a less expensive way to do this..

Hi all, I have a problem with some code and I believe it is because of the expense of the queryset. I am looking for a much less expensive (in terms of time) way to to this.. log.info("Getting Users") employees = Employee.objects.filter(is_active = True) log.info("Have Users") if opt.supervisor: if opt.hierarchical: peopl...