django

How to disable autoescape in django feeds?

Hi! I use django feed framework to organize rss feeds for my website. I need to put some hyperlinks to feed items, but al of them are autoescaped ( "<" is replaced with "&lt;" and so on). Is it possible to keep tags in my feed (as I understand, I can't use {% autoescape off %} tag in feed templates)? Thanks. ...

How to get all related/parent instances from set of child instances without looping through latter set

Hi! Please regard the following Django models: ParentModel(models.Model): ... ChildModel(models.Model): parent = models.ForeignKey(ParentModel, related_name='children') Let's assume there is certain subset of all children in the database available as a queryset (call it the 1st set). Now, I'd like to gain access to the sub...

Permissions for a site only

Hello, I have a multilingual Django project. Every language is a different subdomain. So we've decided to use the "sites" application and to create one different site for every language. On that project, I also have a "pages" application, which is quite similar to a CMS. The user can create pages with content and they'll be displayed i...

Making Django admin display the Primary Key rather than each object's Object type.

Hi all, In Django 1.1 admin, when I go to add or change an object, my objects are displayed as: Select host to change * Add host Host object Host object Host object Host object Host object This happens for all models in my site, not just Hosts. Rather than display the same name for each object, I would like ...

Problem with local dumpdata (on django app-engine-patch)

I'm using django with app-engine-patch and I'm having this wierd problem running manage.py dumpdata from local store (works fine when I use the --remote option) I'm running a local development server that has some test data on it. I can see that data on the admin site. However running manage.py dumpdata all I get is this: [{"pk": "agZm...

How do you model this in django?

Considering the class model as follows: How do you do this in models.py? class House(models.Model): foo = models.CharField(max_length=123) class Caravan(models.Model): foo = models.CharField(max_length=123) class Door(models.Model): bar = models.CharField(max_length=123) house = models.ForeignKey(House) caravan ...

Django forms: making a disabled field persist between validations

At some point I need to display a "disabled" (greyed out by disabled="disabled" attribute) input of type "select". As specified in the standard (xhtml and html4), inputs of type "select" can not have the "readonly" attribute. Note that this is for presentation purposes only, the actual value must end up in the POST. So here is what I do ...

django urls without a trailing slash do not redirect

I've got two applications located on two seperate computers on one in the urls.py file I have a line like the following: (r'^cast/$', 'mySite.simulate.views.cast') And that url will work for both mySite.com/cast/ and MySite.com/cast. But on the other server I have a similar url written out like: (r'^login/$', 'mySite.myUser.views.lo...

Pull data from production to dev for debugging (Django)

This is what I want: [Production MySQL Data] -> [Development MySQL Data] For debugging or improvement, I occasionally need to have a copy of the data running on the production site to be present in my development environment. Obviously I don't want to actually use the production database and manually entering the data is out of the qu...

How do you convert a Word Document into very simple html in Python?

Every now and then I receive a Word Document that I have to display as a web page. I'm currently using Django's flatpages to achieve this by grabbing the html content generated by MS Word. The generated html is quite messy. Is there a better way that can generate very simple html to solve this issue using Python? ...

EmailMultiAlternatives adding a 3D when sending mail with image in django

Hi, I'm using the EmailMultiAlternatives class to send text and html mails with django. While testing with some dummy code, I wanted to add an image with some text. msg = EmailMultiAlternatives('My subject','some text here', '[email protected]', ['to@my_domain.com']) msg.attach_alternative('<p>here is what I was talking about</p> <img src...

Specific use case for Django admin

I have a couple special use cases for Django admin, and I'm curious about other peoples' opinions: I'd like to use a customized version the admin to allow users to edit certain objects on the site (customized to look more like the rest of the site). At this point users can only edit objects they own, but I'll eventually open this up to...

Elegant setup of Python logging in Django

I have yet to find a way of setting up Python logging with Django that I'm happy with. My requirements are fairly simple: Different log handlers for different events - that is, I want to be able to log to different files Easy access to loggers in my modules. The module should be able to find its logger with little effort. Should be eas...

Atomic increment of a counter in django

I'm trying to atomically increment a simple counter in Django. My code looks like this: from models import Counter from django.db import transaction @transaction.commit_on_success def increment_counter(name): counter = Counter.objects.get_or_create(name = name)[0] counter.count += 1 counter.save() If I understand Django c...

Python (Django) Shopify API Client -- For a Beginner

Hello, I have a requirement to build a client for Shopify's API, building it in Python & Django. I've never done it before and so I'm wondering if someone might advise on a good starting point for the kinds of patterns and techniques needed to get a job like this done. Here's a link to the Shopify API reference Thanks. ...

Using south to refactor a Django model with inheritence

I was wondering if the following migration is possible with Django south and still retain data. Before: I currently have two apps, one called tv, one called movies, each with a VideoFile model (simplified here): tv/models.py: class VideoFile(models.Model): show = models.ForeignKey(Show, blank=True, null=True) name = models.Ch...

How could I block all non-US IP addresses from access to my website?

I want to block all non-US users from accessing my website. I'm using nginx on the front end and have a django powered website. 1) How can I determine what are US IP addresses? 2) Should I be blocking them in my webserver or in my application layer? ...

Django custom command and cron

I want my custom made Django command to be executed every minute. However it seems like python /path/to/project/myapp/manage.py mycommand doesn't seem to work while at the directory python manage.py mycommand works perfectly. How can I achieve this ? I use /etc/crontab with: ****** root python /path/to/project/myapp/manage.py mycommand...

Foreign key needs a value from the key's table to match a column in another table.

Pardon the excessive amount of code, but I'm not sure if I can explain my question otherwise I have a Django project that I am working on which has the following: class Project(models.Model): name = models.CharField(max_length=100, unique=True) dir = models.CharField(max_length=300, blank=True, unique=True ) def __unicode__(self):...

Django and AuthOpenId error

I'm trying to set up OpenID authentication in Django, using django-authopenid. The instructions are pretty good, but having followed them and made all the requisite changes in settings.py and added the required templates, my whole site is now showing a 500 error, having previously worked fine. The Apache logs show: Exception occurred ...