django

middleware vs. context processor for view dependent navigation/display

This is a very similar question to this SO thread on middleware and views communicating We'd like to have our templates be given a standard set of context variables. So, a context processor seems appropriate, however, it doesn't seem like the context processor is view-aware. We'd previously been forced to inspect the call stack to get...

How do unit tests work in django-tagging, because I want mine to run like that?

Few times while browsing tests dir in various Django apps I stumbled across models.py and settings.py files (in django-tagging for example). But there's no code to be found that syncs test models or applies custom test settings - but tests make use of them just as if django would auto-magically load them. However if I try to run django...

Controlling Django ModelForm output

I've got a Model in Django, example code below (not my actual code): class Department(models.Model): name = models.CharField(max_length=100) abbreviation = models.CharField(max_length=4) Let's say I do the following in the Django shell: >>> Department(name='Computer Science',abbreviation='C S ').save() >>> Department(name='Ma...

How do you debug Django sites using Win 7 XP Mode?

I am developing a Django site using Windows 7 as my dev environment. I have IE6 running through XP mode. Accessing my site through localhost:8000 doesn't work in IE6 (probably since it is still running a VM). Is there a way to access my site in IE6 while it is being served through Django's test server running on Windows 7? ...

Django - SQL Query - Timestamp

Can anyone turn me to a tutorial, code or some kind of resource that will help me out with the following problem. I have a table in a mySQL database. It contains an ID, Timestamp, another ID and a value. I'm passing it the 'main' ID which can uniquely identify a piece of data. However, I want to do a time search on this piece of data(th...

Ruby to python one-liner conversion

I have a little one-liner in my Rails app that returns a range of copyright dates with an optional parameter, e.g.: def copyright_dates(start_year = Date.today().year) [start_year, Date.today().year].sort.uniq.join(" - ") end I'm moving the app over to Django, and while I love it, I miss a bit of the conciseness. The same method i...

models.py with ManyToMany and progmatically adding data via a shell script

Hi Guys, First post to stackoverflow I did do a search and came up dry. I also own the django book (Forcier,Bissex,Chun) and they don't explain how to do this. In short I can't figure out how to progmatically add a data via a python shell script to the ManyToMay model.. from django.db import models from django.contrib import adm...

Django Template For Loop: How do you perform an action for the first record?

Hi Guys, I know django purposely does not allow a whole lot of logic in the templates. However sometimes you are required to evaluate something and based on that change your options. How do you change a value in a template or insert something only if it's the first record? But you would still like to loop through the rest. For example...

Using the "extra fields " from django many-to-many relationships with extra fields.

Django documents give this example of associating extra data with a M2M relationship. Although that is straight forward, now that I am trying to make use of the extra data in my views it is feeling very clumsy (which typically means "I'm doing it wrong"). For example, using the models defined in the linked document above I can do the ...

Django,prepopulated_fields

Hi guys, i want to know if prepopulated_field is available outside of the ModelAdmin? I want to make a slugfield where the value comes from the field title. Regards, Asinox ...

How do you solve MySQL & Django Admin Foreign Key constraint

I have a Style table to identify a model number for each product type: class Style(models.Model): style = models.AutoField(primary_key=True) name = models.CharField('Title', max_length=150) etc.. And I need a product table which identifies all the product variations of the aforemention model number: class Product(models.Mod...

ForeignKey and Django Template

Hey, So here's the problem. Imagine 2 models: Photographer and Photo. Strict rule is that there can be only 1 photographer for image, so in Photo there's a ForeignKey link to Photographer. class Photographer(models.Model): name = models.CharField(max_length = 40) class Photo(models.Model): name = models.CharField(max_length =...

Django Is telling me table already exists on syncdb - can't figure out why

Posted the model at http://pastebin.com/f609771cc getting error: (yes it's windows) File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.OperationalError: (1050, "Table 'memorial_music' already exists") scanned the whole project directory and m...

URLconfs in Django

I am going through the Django sample application and come across the URLConf. I thought the import statement on the top resolves the url location, but for 'mysite.polls.urls' I couldn't remove the quotes by including in the import statement. Why should I use quotes for 'mysite.polls.urls' and not for admin url? and what should I do if ...

django sql join with like

I have following models class Artist(models.Model): name = models.CharField(max_length=200, unique=True) photo = models.CharField(max_length=250) views = models.IntegerField() class Meta: verbose_name = "artist" ordering = ['-views'] def __unicode__(self): return self.name class Song(models...

User produced site content, potentially massive dataset - Zope/Plone or Django?

I am looking to produce a site similar to a venue "What's on" site. The plan is that the venues can register an account to the site and then through their own 'admin' section upload/post all their latest events that are on. I am hoping that very large number of venues will sign up and each have a large number of events thus producing a ...

django auto entry generation

Hello, I am trying to make an automated database entry generation with Django, whenever I trigger it to happen. For instance, assume I have a such model: class status_entry(models.Model): name = models.TextField() date = models.DateField() status = models.BooleanField() and I have several entries to the model such as: 1 ...

Django, calendar

Hi guys, im need to use a calendar, im developing a website for house's rental, my first own web project, so, the idea is that the user select a initial date and finish date, in the same month o any months (form January until April por example), and in the view (template) of the house availability i want to show all months (12) and where...

Django template user request question

Hey, I have a model Book which can be added to user's Favorites. So I defined 2 classes: class Book(models.Model): name = models.CharField(max_length = 40) class UserFavorite(models.Model): book = models.ForeignKey(Book) user = models.ForeignKey(User) Now I'd like to show on the main page popular books with an icon eith...

How does one make logging color in Django/Google App Engine?

If one iswriting a Django/ Google App Engine application and would like to have logs that are conveniently conspicuous based on color (i.e. errors in red), how does one set that up? I've copied the helpful solution from this question, but I'm not sure how to integrate it into Django/Google App Engine. I figured one would put the follow...