With methods on your model that return boolean values, you can mark them as boolean so the admin's list displays show the pretty icons, like this example from the docs:
class Person(models.Model):
birthday = models.DateField()
def born_in_fifties(self):
return self.birthday.strftime('%Y')[:3] == '195'
born_in_fiftie...
heya,
I think my understanding of Django's FK and admin is a bit faulty, so I'd value any input on how to model the below case.
Firstly, we have generic Address objects. Then, we have User's, who each have a UserProfile. Through this, Users belong to departments, as well as having addresses.
Departments themselves can also have multip...
This seems like it should be obvious, but the solution is eluding me. Normally I would just write a simple view function which would populate an appropriate form and pass it along to the view, but the solution feels so close ..
I have a form. I want to instantiate this form using an object_id that I've captured in the url, then send it ...
I'm trying to get the hang of Django URL namespaces. But I can't find any examples or documentation.
Here is what I have tried.
urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^foo/', include('sub_urls', namespace='foo', app_name='foo')),
(r'^bar/', include('sub_urls', namespace='bar', app_name=...
Everybody in Django world seems to hate threadlocals(http://code.djangoproject.com/ticket/4280, http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser). I read Armin's essay on this(http://lucumr.pocoo.org/2006/7/10/why-i-cant-stand-threadlocal-and-others), but most of it hinges on threadlocals is bad because it is inelegant.
I...
To the risk of being closed as duplicate (I can't really find it...) I have the following question. I am sure it's either under my nose, or not possible, but I prefer to ask.
Is it possible to bind to multiple, shorter variable names in django? I know the existence of with, but with assumes you open a block. I would like to bind three o...
Using django 1.0.1 on windows xp and postgres database
I have a very strange problem in the Django admin page. Using the model and admin below, the field "balance" does populate with objects from the Balance model. However, it does NOT populate the locationparameter field: the name "locationparameter" does appear, but there is no pull-d...
I am used to Ubuntu, I like it, I know my way around it.
I am looking forward to upgrade my work laptop.
I find the awesome hardware that a Macbook Pro is made of, a turn-on.
Now, having never used a mac before, I'd like to know how easy it is to move my development environment to a mac from being on Ubuntu.
My work is primarily web ...
The above mentioned things are giving me almost the same results was wondering whats the main difference in them.
...
I am implementing the stock Django comments to an existing site.
I'd like comments to appear in multiple apps and models and have all the comments behave the same - i.e. an email sent, plus other bits (listening to 'flag' signals and dealing with accordingly)
Where's the best place to put my custom moderator code?
I understand that ...
Ok, I have a question from a "client" perspective. Let's say we are talking about website designed for distribution: products + their logistics info.
Definitely less than a 2k rows, rarely changed but often accessed. Typical row with several columns will have to consist of a picture so it might make it a bit "heavy". I was proposed a w...
My views.py has become too big and it's hard to find the right view. So how do i split it in several files and then import it? Does it involve any speed loss? Can i do the same with models.py?
...
If you change your urls.py or you stupidly write some template code that refers to a URL that ultimately doesn't reverse to a URL you get the infamous:
NoReverseMatch: Reverse for '<name>' with arguments 'xxx' and keyword arguments '{xxx}' not found.
Is there a way to have the line in the template file included in the error?
...
This might be a naive question, but when using a python framework, what approaches are available to provide the kind of functionality that can be exposed using an ActiveX control as an embedded object. The specific example I have in mind is a third party ocx we are using in some ASP.NET pages to provide TWAIN interaction on the client si...
I'm a bit compulsive about having clean, readable and perfectly indented HTML. With Django’s template engine I almost have been able to achieve this with the exception of block text, or rather HTML generated by TinyMCE through the admin panel. The closest I could get is using the wordwrap filter; however this tag does not take any argume...
I run a lab annotation website where users can annotate samples with tags relating to disease, tissue type, etc. Here is a simple example from models.py:
from django.contrib.auth.models import User
from django.db import models
class Sample(models.Model):
name = models.CharField(max_length = 255)
tags=models.ManyToManyField('T...
A third party is sending us a flat file that is supposed to contain exclusively printable ASCII characters. However, we've discovered that there's a string of about 50 0x00 bytes in the middle of the file.
We want to be able to upload the file to our web application, but I've discovered that Django doesn't seem to like the null chara...
I have a client with a "Directions" page in their website and they wanted to add a Google map to the page, so they went to maps and put in their location and then used the "embed" link to get the html for the iframe. They then opened up the Flatpage for "Directions" page in the admin and went to html mode in TinyMCE and then pasted in th...
This is what I had before (but realized that you can't obviously do it in this order:
class MasterAdmin(models.Model):
"""
A permanent admin (one per Account) that shouldn't be deleted.
"""
admin = models.OneToOneField(AccountAdmin)
class Account(models.Model):
"""
A top-level account in the system.
"""
...
I have the following:
class AccountAdmin(models.Model):
account = models.ForeignKey(Account)
is_master = models.BooleanField()
name = models.CharField(max_length=255)
email = models.EmailField()
class Meta:
unique_together = (('Account', 'is_master'), ('Account', 'username'),)
If I then create a new Accou...