I'm looking to add a method that my Ticket model has called process to the admin, so that I could click a link in the list view, and "process" my model instance (do an API call behind the scenes).
To clarify:
class Ticket(models.Model):
title = models.CharField(max_length=255)
def process(self):
... hardcore processing...
I have model from which I only want to create one instance, and no more instances should be allowed.
Is this possible? I've got a feeling that I've seen this done somewhere, but unfortunately I'm unable to locate it.
EDIT:
I need this for a stupidly simple CMS. I have an abstract class for which FrontPage and Page classes inherits. I ...
When creating a flatpage, I want the user to select a template from a predefined list. In order to keep the Flatpage model untouched, I prefer ChoiceField over ModelChoiceField (the latter provides the PK of the template, but I need the name for the template_name field):
class NewFlatpageForm(FlatpageForm):
template_name = forms.Ch...
I have 2 django model
class Location
address = models.CharField(max_length=100)
city = models.CharField(max_length=20)
class Client
location = models.ForeignKey(Location)
name = models.CharField(max_length=100)
And I have the following admin.py
class ClientAdmin(admin.ModelAdmin):
fieldsets = [
('Client Details', {'field...
I cannot find which part of code print the "+" that is close to every foreign key field.
In fieldset.html there is only the call to {{ field.field }}, but in the file django/forms/widgets.py the code that prints the select, doesn't contain that code, so I suppose that there is a piece of code that manage the foreign key: where is it?
...
I want to change the way that the "+" icon for the foreign key in the admin site is shown.
I found that the widget that prints the code is RelatedFieldWidgetWrapper that is in django/contrib/admin/widgets.py.
So I wrote my version of this class and I changed its render function.
But now how can I use it? I mean... in the definition of...
I use this snippet to show several fields in my admin backend as readonly, but as noticed in the comments, it does not work on stackedinline/tabularinline. Is there any other way to achieve this? I have a list of objects attached to a model and just want to show it in the model's details view without the possibility to change values.
...
Which is the widget that renders the foreign key in the admin site?
I saw that there is a widget called RelatedFieldWidgetWrapper (that print only the "+" icon) and another for the select, but I suppose that there is a widget that call both to render the entire field.
Thanks
...
# admin.py
class CustomerAdmin(admin.ModelAdmin):
list_display = ('foo', 'number_of_orders')
# models.py
class Order(models.Model):
bar = models.CharField[...]
customer = models.ForeignKey(Customer)
class Customer(models.Model):
foo = models.CharField[...]
def number_of_orders(self):
return u'%s' % Order.o...
I just created the following model:
class Categoria(models.Model):
nombre=models.CharField(max_length=30)
padre=models.ForeignKey('self', blank=True, null=True)
def __unicode__(self):
return self.nombre
Then registered to the admin interface and syncdb'd
Everything ok if I just add plain ASCII chars. But if I add...
Is there a way to extend another apps ModelAdmin?
I have a project that uses functionality offered by django.contrib.comments.
The CommentsAdmin ModelAdmin class has:
actions = ["flag_comments", "approve_comments", "remove_comments"]
I would like to extend the CommentsAdmin ModelAdmin in my project to include an action ban_user.
I've...
I'm building a simple app, a sort of project/tasks manager where I can have several projects and several tasks that are assigned to one project.
I enabled Django admin for all this sort of tasks and it's working like a charm. Also, I have some users that have projects assigned to them. So what I want now is to enable a cut down version ...
In one of the models overview panel, after I filter the items by month, I have to select them all and then create a document with information regarding them (kind of like a monthly report). This is a problem when one month has more than 100 items as Django paginates the filtering results.
Is there a way to increase the number of items s...
I have a booking model that needs to check if the item being booked out is available. I would like to have the logic behind figuring out if the item is available centralised so that no matter where I save the instance this code validates that it can be saved.
At the moment I have this code in a custom save function of my model class:
d...
I'm using the last svn revision of grappelli and rev 11840 of django
(before multidatabases and stuff), and i'm trying to use generic
relations in the admin, but doesn't work,
The model:
class AutorProyectoLey(DatedModel):
tipo_autor = models.ForeignKey(ContentType)
autor_id = models.PositiveIntegerField()
content_object = ...
Hey,
In the django admin panel I currently have a DateField showing a nice Javascript calendar for inputting dates. However, I am only interested in the Month and Year. So I was wondering if it was possible to have the calendar only show the months and year. (Extra brownie points if you can restrict its usage so that no dates in the fut...
Hey,
I am trying to have the pictures I upload in the Django admin panel to show up as thumbnails instead of the path. I have sorl installed and can make thumbnails that show up in my views.
I have found 2 snippets (http://www.djangosnippets.org/snippets/579/ and http://www.djangosnippets.org/snippets/934/) that I have tried to impleme...
I'm trying to follow the guidelines in this answer, but I'm getting stuck with how to edit the template.
The relevant part of my admin.py:
SegmentFormset = forms.models.inlineformset_factory(Division,Segment)
class DivisionForm(forms.ModelForm):
def __init__(self, **kwargs):
super(DivisionForm, self).__init__(**kwargs)
...
I've added a custom field to a ModelForm for use in the admin:
class MyModel(models.Model):
name = models.CharField(max_length=64)
...etc...
class MyModelAdminForm(forms.ModelForm):
dynamicfield = forms.IntegerField()
def __init__(self, *args, **kwargs):
super(MyModelAdminForm, self).__init__(*args, **kwargs)
...
Consider a wiki application. There is a model Page, that has many Revisions and each revision has many blocks.
What is the simplest way to create an admin in which, you select a page and all the blocks of the latest revision appear; bonus points for letting change of revision by a dropdown (which is by default, sorted in reverse order a...