1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Cleaned up and refactored ModelAdmin.formfield_for_dbfield:

* The new method uses an admin configuration option (`formfield_overrides`); this makes custom admin widgets especially easy.
  * Refactored what was left of `formfield_for_dbfield` into a handful of smaller methods so that it's easier to hook in and return custom fields where needed.
  * These `formfield_for_*` methods now pass around `request` so that you can easily modify fields based on request (as in #3987).

Fixes #8306, #3987, #9148.

Thanks to James Bennet for the original patch; Alex Gaynor and Brian Rosner also contributed.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9760 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2009-01-16 15:32:31 +00:00
parent d579e716fe
commit f212b24b64
8 changed files with 369 additions and 83 deletions

View File

@@ -2,9 +2,12 @@
from django.conf import settings
from django.db import models
from django.core.files.storage import default_storage
from django.contrib.auth.models import User
class Member(models.Model):
name = models.CharField(max_length=100)
birthdate = models.DateTimeField(blank=True, null=True)
gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')])
def __unicode__(self):
return self.name
@@ -40,6 +43,28 @@ class Inventory(models.Model):
def __unicode__(self):
return self.name
class Event(models.Model):
band = models.ForeignKey(Band)
date = models.DateField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
description = models.TextField(blank=True)
link = models.URLField(blank=True)
min_age = models.IntegerField(blank=True, null=True)
class Car(models.Model):
owner = models.ForeignKey(User)
make = models.CharField(max_length=30)
model = models.CharField(max_length=30)
def __unicode__(self):
return u"%s %s" % (self.make, self.model)
class CarTire(models.Model):
"""
A single car tire. This to test that a user can only select their own cars.
"""
car = models.ForeignKey(Car)
__test__ = {'WIDGETS_TESTS': """
>>> from datetime import datetime