django-admin

Unique BooleanField value in Django?

Suppose my models.py is like so: class Character(models.Model): name = models.CharField(max_length=255) is_the_chosen_one = models.BooleanField() I want only one of my Character instances to have is_the_chosen_one == True and all others to have is_the_chosen_one == False . How can I best ensure this uniqueness constraint is re...

Django forms: how to display media (javascript) for a DateTimeInput widget ?

Hello (please excuse me for my bad english ;) ), Imagine the classes bellow: models.py from django import models class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) object_id = models.PositiveIntegerField(_('object id')) content_object = generic.GenericForeignKey('con...

How can I add a related object to the Admin index view?

I want to be able to show if an Image has been associated with each Product from the list_display view. I seem to be having trouble because I'm dealing with an associated object. models.py class ImageMain(models.Model): """This is the Main Image of the product""" product = models.ForeignKey(Product) photo = models.ImageFiel...

Django: how to including inline model fields in the list_display?

I'm attempting to extend django's contrib.auth User model, using an inline 'Profile' model to include extra fields. from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin class Profile(models.Model): user = models.ForeignKey(User, unique=True, related_name='profil...

Django: disallow can_delete on GenericStackedInline

Hello, I've built this model which contains a generic foreign key: class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) object_id = models.PositiveIntegerField(_('object id')) content_object = generic.GenericForeignKey('content_type', 'object_id') Next I've made a gene...

Django error : Truncated incorrect DOUBLE value: 'AnonymousUser'

Hi guys, i dont know what mean this error, the erro comming when im try to enter to the admin ..webapps/django/lib/python2.5/django/db/backends/mysql/base.py:84: Warning: Truncated incorrect DOUBLE value: 'AnonymousUser' and another error is : "403 Forbidden Cross Site Request Forgery detected. Request aborted." somebody know about...

Django SESSION_COOKIE_DOMAIN error

Im trying to using SESSION_COOKIE_DOMAIN, but i got error in any browser when i try to go into my admin: Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again. any idea? ...

Putting in extra restrictions when filtering on foreignkey in django-admin

When getting members based on Unit, I only want to get the ones who are actually in that unit as of now. I've got a model looking like this: class Member(models.Model): name = models.CharField(max_length=256) unit = models.ManyToManyField(Unit, through='Membership') class Membership(models.Model): member = models.ForeignKe...

Print a template variable on an overwritten admin form in Django

I have a Doctor-model which has a field called first_created. It is just a DateField that is auto_add_now, hence it is not displayed when editing a doctor in the admin interface. I want to display this field on the admin interface, at the top of the site as say, a static or something. It is supposed to ease the process of typing in dat...

Styling certain admin change list rows

Is there a straightforward, common way to apply custom styling on admin change list element depending on its properties? update To be more precise: let's say I have a simple model object. Foo field1 field2 field3 @property property1() @property property2() ModelAdmin.list_display is defined as a subset of th...

Django Model in one to one relationship and displaying it from the admin

For the following models: class Price: cad = models.DecimalField(max_digits=8, decimal_places=2) usd = models.DecimalField(max_digits=8, decimal_places=2) class Product: name = models.CharField(max_length=255) price = models.ForeignKey(Price) For each product, it's related to one and only one Price object which will c...

How can I tell whether I'm on an add or edit page in Django's Admin?

For the following code: class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author) title = models.CharField(max_length=100) class BookInline(admin.TabularInline): model = Book extra = 1 class AuthorAdmin(admin.ModelAdmin): inlines = [ ...

Only showing year in django admin, a YearField instead of DateField?

I've got a model where I need to store birth year. I'm using django admin. The person using this will be filling out loads of people every day, and DateField() shows too much (not interested in the day/month). This is a mockup model showing how it is now: class Person(models.Model): name = models.CharField(max_length=256) born = mo...

List foreign keys linking to a model

How can I display objects that link to an object via a ForeignKey in Django (specifically in the admin interface). For example, if I click on an object, I'll not only see the object but also any other object that link to it. e.g. I have a model for "Manufacturer" and another one for "Model"...the "Model" model links to "Manufacturer" v...

Redirecting in Admin Site

I have an app called CMS with Category and Article. Quite simple. I overwrite app_index.html to enable ajax-based drag-n-drop ordering and to move articles from one category to another. Now I would like to redirect after saving/deleting an article or a category to cms' app_index.html instead of the model's change_list.html. How can thi...

Closing a django admin add related object popup window on save

In the django admin, when a user successfully saves (after my clean method) a new or changed related object which was edited in a popup, I'd like the popup to close instead of going to a different view. I believe I could use response_change or response_add to get it to go to a different view, but is there a way I can get the window to c...

Where is a good tutorial how to write custo, django widgets?

I'm trying to modify the adimn interface. I need a custom type of textbox that does some pre/post processing on the text. If I understand correctly, a custom widget is the way to go about this. Where is a good tutorial how to write custom widgets for Django? ...

How to override and call super for response_change or response_add in django admin

I would like to override response_change in a ModelAdmin in order to update a field in the parent window. After doing the update, I'd like to give control back to the overriden response_change. A simplified version of what I have tried is: class MyModelAdmin(admin.ModelAdmin): def response_change(self, request, obj): // per...

Custom form in inline form

I have a custom form to display goals. Goals are edited inline in a Game. class GoalForm(forms.ModelForm): class Meta: model = Goal def __init__(self, *args, **kwargs): super(GoalForm, self).__init__(*args, **kwargs) self.fields['goal_scorer'].queryset = Player.objects.filter(gameroster__game=self.instance.g...

The default "delete selected" admin action in Django

How can I remove or change the verbose name of the default admin action "delete selected X item" in the Django admin panel? ...