django

Django - Make two separate queries, combine the results, then eliminate duplicates

Is there a fast and easy way to do this? I haven't been able to find anything that's already out there that seems to do this already. Since it's a queryset, i don't think i can use the unique properties of Set to solve the problem either. any ideas? ...

Adding Multiple Models to inlineformset_factory

I have a model like below. class Content(SimpleModel): title = models.CharField(max_length=255) body = models.TextField() slug = models.SlugField(max_length=50) def __unicode__(self): return self.title class MediumStuff(models.Model): meta_value = models.TextField() meta_key = models.SlugField('Fie...

How do I update an instance of a Django Model with request.POST if POST is a nested array?

I have a form that submits the following data: question[priority] = "3" question[effort] = "5" question[question] = "A question" That data is submitted to the URL /questions/1/save where 1 is the question.id. What I'd love to do is get question #1 and update it based on the POST data. I've got some of it working, but I don't know how ...

django count of manytomany field

i wanted to place the foo/view code below into a property under the Foo model object, but the debug message says 'bar' cannot be found. Why does it work in the views.py, but not work when i place it in models.py( i did remember to import Bar)? thanks! foo/models.py class Foo(models.Model): title = models.CharField(_(u'Title'), max_l...

Django multisite project layout

I've a django server that server multiple sites, each site being a separate django project. The layout is roughly : Django/ project1/ app1 app2 . settings.py urls.py templates project2/ app1 etc. static/ project1/ media/ css/ etc. project2 ...

In django-haystack, how can I use subclasses of models?

I'm trying to get haystack (with xapian-haystack) to search my model here by name and description. I have a subclass of item ('device') which has a manufacturer field. So I have a model 'item': class Item(models.Model): name = models.CharField(max_length=255, unique=True) description = models.TextField(null=True, blank=True) ...

Change Form Validation for Admin Login in Django

I use a custom auth backend in my django application that allows users to login with ther emails. But when I try to login in the admin I get the message: "usernames cant contain the '@' char" I suppose this error is raised before it reaches the auth backend, so its a form issue, right ? ...

How can I upload my files to my static server from a production server?

I have django and django's admin setup on my production box. This means that all file uploads are stored on the production box, all the media is stored there. I have a separate server for files now ( different box, ip ). I want to upload my files there. What are the advantages and disadvantages of these methods I've thought about, and a...

How to keep all my django applications in specific folder

I have a Django project, let's say "project1". Typical folder structure for applications is: /project1/ /app1/ /app2/ ... __init__.py manage.py settings.py urls.py What should I do if I want to hold all of my applications in some separate folder, 'apps' for example? So th...

Django doesn't create a {{ debug }} variable in DEBUG mode

As of the documentation, there should be variables called "debug" and "sql_queries" usable in templates if all requirements are met. I have set the following (and checked their values with the debug toolbar): DEBUG = True TEMPLATE_DEBUG = True TEMPLATE_CONTEXT_PROCESSORS left at its default value (containing 'django.core.context_proce...

Where is the best place to associate a 'form display text' with SQLAlchemy mapped property?

In django orm I can use the 'verbose_name' kwarg to set a label that will be displayed in model forms. Now I'm dynamically generating WTForms for each model in a SQLAlchemy mapped backend, but I'm not sure where to associate a display text to use in the auto generated fields for each form. For example, in django I could do this: class U...

How to develop applications for facebook?

I have a choice between ASP.NET (preferably MVC) and Python (Django only). Which toolkit is more stable? I have read the comments section of the Facebook Developer Toolkit and it seems that a lot of people aren't happy with it, is there an alternative? What about Python libraries for facebook, are there any good libraries to develop face...

Querying across database tables

I've got Django tables like the following (I've removed non-essential fields): class Person(models.Model): nameidx = models.IntegerField(primary_key=True) name = models.CharField(max_length=300, verbose_name="Name") class Owner(models.Model): id = models.IntegerField(primary_key=True) nameidx = models.IntegerField(...

Automatically add a variable into context on per-application basis in Django?

I want to add a context variable in Django, so that I could define its value on per-application basis, or leave it empty. Example: apps/someapp/views.py: def_context_var('app_name', 'Calendar') templates/base.html: {% if app_name %}You are in {{ app_name }} app.{% endif %} .... {% if app_name %}Subsections of {{ app_name }}: ...{%...

How to insert into a ForeignKey field using raw SQL?

I've got tables like the following (Django model definition, with a postgres database underlying it): class Person(models.Model): id = models.IntegerField(primary_key=True) name = models.CharField(max_length=300) class Owner(models.Model): id = models.IntegerField() person = models.ForeignKey(Person) I use a Pyth...

Django + apache: How can I create a server alias which invisibly redirects to my django app on the server?

I am trying to figure out a how to forward a specific alias of a server to a specific django web app, and at the same time, keep the URL address bar in the user's browser to only show the server alias. To be more specific: This is for an intranet project at my company. We have a big linux server which does a lot of computational wo...

How Make WebPage thumbnail on Google App Engine?

Hi! I'm using Django / Python. After saving the model I want to make a screenshot (preview) of how it looks in the template and save it on model field. Please tell me how to do it. ...

Django: control access to "static" files

Ok, I know that serving media files through Django is a not recommended. However, I'm in a situation where I'd like to serve "static" files using fine-grained access control through Django models. Example: I want to serve my movie library to myself over the web. I'm often travelling and I'd like to be able to view any of my movies where...

Preparing a web site for international usage

I am preparing to develop a web application that will (hopefully) be used by an audience with many different native languages. What should I do to prepare my software project to have the user interface be almost entirely internationalized? Are there any software stacks that make this easier? ...

how do you iterate over a list in django

This is a sample view code def link(reqest): title = ['Home Page', 'Current Time', '10 hours later'] return render_to_response('time.html', title) This is a sample template code {% for item in title %} {{item}} {% if not forloop.last %} | {% endif %} {% endfor %} This is a sample url code (r'^now/$', current_time,...